* Method to generate the final path to open in browser * @param prefix Url prefix eg http://localhost:3000 * @param path Path of the file * @param urlGenerator Optional generator function * @returns Returns the final path to open in browser
(prefix: string, path: String, urlGenerator: string | undefined)
| 33 | * @returns Returns the final path to open in browser |
| 34 | */ |
| 35 | generatePath(prefix: string, path: String, urlGenerator: string | undefined) { |
| 36 | // Adds a trailing slash if the prefix doesn't have one |
| 37 | const urlPrefix = prefix.endsWith("/") ? prefix : prefix + "/"; |
| 38 | // Generate the path based on the urlGenerator function if one is provided |
| 39 | const generatedPath = urlGenerator ? eval(urlGenerator)(path) : undefined; |
| 40 | // If the path is generated, return it |
| 41 | if (generatedPath) { |
| 42 | return urlPrefix + this.sanitizePath(generatedPath); |
| 43 | } |
| 44 | // Otherwise, generate the path based on the file path, gets the path after the routes folder and splits everything by the dot |
| 45 | const pathChunks = path.split("routes/")[1].split("."); |
| 46 | // Removes the extension from the path |
| 47 | const pathChunksWithoutExtension = pathChunks.slice(0, pathChunks.length - 1).join("/"); |
| 48 | // Converts the path to a URL by splitting the path by the slash, removing unneeded segments and joining everything back together |
| 49 | const sanitizedPathChunks = pathChunksWithoutExtension |
| 50 | .split("/") |
| 51 | .map((chunk) => this.convertRemixPathToUrl(chunk)) |
| 52 | .filter((chunk) => chunk !== "") |
| 53 | .join("/"); |
| 54 | |
| 55 | return urlPrefix + this.sanitizePath(sanitizedPathChunks); |
| 56 | } |
| 57 | |
| 58 | provideCodeLenses( |
| 59 | document: vscode.TextDocument, |
no test coverage detected