From d10247ab0c147c5b954d2453c3138cd4dce87edd Mon Sep 17 00:00:00 2001 From: eyza Date: Mon, 28 Oct 2024 19:25:04 +0100 Subject: [PATCH] Fixed diagnostic errors for GSC file references on Linux systems --- src/GscFileCache.ts | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/GscFileCache.ts b/src/GscFileCache.ts index e509c4e..3f08762 100644 --- a/src/GscFileCache.ts +++ b/src/GscFileCache.ts @@ -62,6 +62,24 @@ export class GscFileCache { return id; } + + + /** + * Generates an ID from a given vscode.Uri that represents game path, which is case-insensitive. + * @param uri - The URI to generate an ID from. + * @returns A string that represents a consistent ID for the given URI + */ + public static getGamePathId(uri: vscode.Uri): string { + let normalizedPath = uri.path; // it uses forward slashes + + // Normalize the path to be case-insensitive + normalizedPath = normalizedPath.toLowerCase(); + + // Include the authority and other relevant parts of the Uri + const id = `${uri.scheme}://${uri.authority}${normalizedPath}`; + + return id; + } } @@ -142,7 +160,7 @@ export class GscWorkspaceFileData { } addParsedFile(gscFile: GscFile) { - const id = GscFileCache.getUriId(gscFile.uri); + const id = GscFileCache.getGamePathId(gscFile.uri); if (!this.parsedFiles.has(id)) { LoggerOutput.log("[GscFileCache] Added file to cache", vscode.workspace.asRelativePath(gscFile.uri)); } else { @@ -154,7 +172,7 @@ export class GscWorkspaceFileData { } getParsedFile(uri: vscode.Uri): GscFile | undefined { - const id = GscFileCache.getUriId(uri); + const id = GscFileCache.getGamePathId(uri); const data = this.parsedFiles.get(id); return data; @@ -162,7 +180,7 @@ export class GscWorkspaceFileData { getParsedFilesByFileOrFolderPath(uri: vscode.Uri): GscFile[] { const files: GscFile[] = []; - const id = GscFileCache.getUriId(uri); + const id = GscFileCache.getGamePathId(uri); for (const [fileId, file] of this.parsedFiles) { if (fileId === id || fileId.startsWith(id + "/")) { files.push(file); @@ -172,7 +190,7 @@ export class GscWorkspaceFileData { } removeParsedFile(uri: vscode.Uri): boolean { - const id = GscFileCache.getUriId(uri); + const id = GscFileCache.getGamePathId(uri); const removed = this.parsedFiles.delete(id); if (removed) {