Skip to content

Commit

Permalink
Fixed diagnostic errors for GSC file references on Linux systems
Browse files Browse the repository at this point in the history
  • Loading branch information
eyza-cod2 committed Oct 28, 2024
1 parent ee7d41b commit d10247a
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions src/GscFileCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}


Expand Down Expand Up @@ -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 {
Expand All @@ -154,15 +172,15 @@ 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;
}

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);
Expand All @@ -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) {
Expand Down

0 comments on commit d10247a

Please sign in to comment.