|
1 | 1 | import * as lsp from "vscode-languageserver" |
2 | 2 | import {TextDocument} from "vscode-languageserver-textdocument" |
3 | 3 | import {TactFile} from "@server/languages/tact/psi/TactFile" |
4 | | -import {fileURLToPath, pathToFileURL} from "node:url" |
| 4 | +import {pathToFileURL} from "node:url" |
5 | 5 | import {createFiftParser, createTactParser, createTlbParser} from "@server/parser" |
6 | 6 | import * as fs from "node:fs" |
7 | 7 | import {FiftFile} from "@server/languages/fift/psi/FiftFile" |
8 | 8 | import {TlbFile} from "@server/languages/tlb/psi/TlbFile" |
| 9 | +import {URI} from "vscode-uri" |
9 | 10 |
|
10 | 11 | export const PARSED_FILES_CACHE: Map<string, TactFile> = new Map() |
11 | 12 | export const FIFT_PARSED_FILES_CACHE: Map<string, FiftFile> = new Map() |
@@ -38,11 +39,6 @@ export function reparseTactFile(uri: string, content: string): TactFile { |
38 | 39 | return file |
39 | 40 | } |
40 | 41 |
|
41 | | -export const filePathToUri = (filePath: string): string => { |
42 | | - const url = pathToFileURL(filePath).toString() |
43 | | - return url.replace(/c:/g, "c%3A").replace(/d:/g, "d%3A") |
44 | | -} |
45 | | - |
46 | 42 | export function findFiftFile(uri: string): FiftFile { |
47 | 43 | const cached = FIFT_PARSED_FILES_CACHE.get(uri) |
48 | 44 | if (cached !== undefined) { |
@@ -119,3 +115,13 @@ export const isTlbFile = ( |
119 | 115 | uri: string, |
120 | 116 | event?: lsp.TextDocumentChangeEvent<TextDocument>, |
121 | 117 | ): boolean => event?.document.languageId === "tlb" || uri.endsWith(".tlb") |
| 118 | + |
| 119 | +export const filePathToUri = (filePath: string): string => { |
| 120 | + const url = pathToFileURL(filePath).toString() |
| 121 | + return url.replace(/c:/g, "c%3A").replace(/d:/g, "d%3A") |
| 122 | +} |
| 123 | + |
| 124 | +function fileURLToPath(uri: string): string { |
| 125 | + const normalizedUri = uri.replace(/\\/g, "/") |
| 126 | + return URI.parse(normalizedUri).fsPath |
| 127 | +} |
0 commit comments