diff --git a/vscode/src/client.ts b/vscode/src/client.ts index d388d80ac1..4d19ba280a 100644 --- a/vscode/src/client.ts +++ b/vscode/src/client.ts @@ -157,6 +157,7 @@ function collectClientOptions( const supportedSchemes = ["file", "git"]; const fsPath = workspaceFolder.uri.fsPath.replace(/\/$/, ""); + const pathConverter = ruby.pathConverter; // For each workspace, the language client is responsible for handling requests for: // 1. Files inside of the workspace itself @@ -164,38 +165,14 @@ function collectClientOptions( // 3. Default gems let documentSelector: DocumentSelector = SUPPORTED_LANGUAGE_IDS.flatMap( (language) => { - return supportedSchemes.map((scheme) => { - return { scheme, language, pattern: `${fsPath}/**/*` }; + return pathConverter.alternativePaths(fsPath).flatMap((pathVariant) => { + return supportedSchemes.map((scheme) => { + return { scheme, language, pattern: `${pathVariant}/**/*` }; + }); }); }, ); - const pathConverter = ruby.pathConverter; - - const pushAlternativePaths = ( - path: string, - schemes: string[] = supportedSchemes, - ) => { - schemes.forEach((scheme) => { - [ - pathConverter.toLocalPath(path), - pathConverter.toRemotePath(path), - ].forEach((convertedPath) => { - if (convertedPath !== path) { - SUPPORTED_LANGUAGE_IDS.forEach((language) => { - documentSelector.push({ - scheme, - language, - pattern: `${convertedPath}/**/*`, - }); - }); - } - }); - }); - }; - - pushAlternativePaths(fsPath); - // Only the first language server we spawn should handle unsaved files, otherwise requests will be duplicated across // all workspaces if (isMainWorkspace) { @@ -209,37 +186,35 @@ function collectClientOptions( ruby.gemPath.forEach((gemPath) => { supportedSchemes.forEach((scheme) => { - documentSelector.push({ - scheme, - language: "ruby", - pattern: `${gemPath}/**/*`, - }); - - pushAlternativePaths(gemPath, [scheme]); - - // Because of how default gems are installed, the gemPath location is actually not exactly where the files are - // located. With the regex, we are correcting the default gem path from this (where the files are not located) - // /opt/rubies/3.3.1/lib/ruby/gems/3.3.0 - // - // to this (where the files are actually stored) - // /opt/rubies/3.3.1/lib/ruby/3.3.0 - // - // Notice that we still need to add the regular path to the selector because some version managers will install - // gems under the non-corrected path - if (/lib\/ruby\/gems\/(?=\d)/.test(gemPath)) { - const correctedPath = gemPath.replace( - /lib\/ruby\/gems\/(?=\d)/, - "lib/ruby/", - ); - + pathConverter.alternativePaths(gemPath).forEach((pathVariant) => { documentSelector.push({ scheme, language: "ruby", - pattern: `${correctedPath}/**/*`, + pattern: `${pathVariant}/**/*`, }); - pushAlternativePaths(correctedPath, [scheme]); - } + // Because of how default gems are installed, the gemPath location is actually not exactly where the files are + // located. With the regex, we are correcting the default gem path from this (where the files are not located) + // /opt/rubies/3.3.1/lib/ruby/gems/3.3.0 + // + // to this (where the files are actually stored) + // /opt/rubies/3.3.1/lib/ruby/3.3.0 + // + // Notice that we still need to add the regular path to the selector because some version managers will install + // gems under the non-corrected path + if (/lib\/ruby\/gems\/(?=\d)/.test(pathVariant)) { + const correctedPath = pathVariant.replace( + /lib\/ruby\/gems\/(?=\d)/, + "lib/ruby/", + ); + + documentSelector.push({ + scheme, + language: "ruby", + pattern: `${correctedPath}/**/*`, + }); + } + }); }); }); diff --git a/vscode/src/common.ts b/vscode/src/common.ts index 54b7e64cea..d0aa3a1640 100644 --- a/vscode/src/common.ts +++ b/vscode/src/common.ts @@ -69,6 +69,7 @@ export interface PathConverterInterface { toRemotePath: (localPath: string) => string; toLocalPath: (remotePath: string) => string; toRemoteUri: (localUri: vscode.Uri) => vscode.Uri; + alternativePaths: (path: string) => string[]; } export class PathConverter implements PathConverterInterface { @@ -85,6 +86,10 @@ export class PathConverter implements PathConverterInterface { toRemoteUri(localUri: vscode.Uri) { return localUri; } + + alternativePaths(path: string) { + return [path]; + } } // Event emitter used to signal that the language status items need to be refreshed diff --git a/vscode/src/docker.ts b/vscode/src/docker.ts index 3b959ac8d5..cbbe619ffe 100644 --- a/vscode/src/docker.ts +++ b/vscode/src/docker.ts @@ -101,6 +101,16 @@ export class ContainerPathConverter implements PathConverterInterface { const remotePath = this.toRemotePath(localUri.fsPath); return vscode.Uri.file(remotePath); } + + alternativePaths(path: string) { + const alternatives = [ + this.toRemotePath(path), + this.toLocalPath(path), + path, + ]; + + return Array.from(new Set(alternatives)); + } } function fetchComposeBindings(