From 88f456464f8153f00a81f251ed4d8f137f6b7fc3 Mon Sep 17 00:00:00 2001 From: Vinicius Stock Date: Mon, 26 May 2025 13:11:29 -0400 Subject: [PATCH] Remove git scheme from document selector --- vscode/src/client.ts | 51 +++++++++++++--------------- vscode/src/test/suite/client.test.ts | 14 +------- 2 files changed, 24 insertions(+), 41 deletions(-) diff --git a/vscode/src/client.ts b/vscode/src/client.ts index 066a53c2f6..13aa672364 100644 --- a/vscode/src/client.ts +++ b/vscode/src/client.ts @@ -181,7 +181,6 @@ function collectClientOptions( const features: EnabledFeatures = configuration.get("enabledFeatures")!; const enabledFeatures = Object.keys(features).filter((key) => features[key]); - const supportedSchemes = ["file", "git"]; const fsPath = workspaceFolder.uri.fsPath.replace(/\/$/, ""); @@ -191,9 +190,7 @@ function collectClientOptions( // 3. Default gems let documentSelector: DocumentSelector = SUPPORTED_LANGUAGE_IDS.flatMap( (language) => { - return supportedSchemes.map((scheme) => { - return { scheme, language, pattern: `${fsPath}/**/*` }; - }); + return { scheme: "file", language, pattern: `${fsPath}/**/*` }; }, ); @@ -209,34 +206,32 @@ function collectClientOptions( } ruby.gemPath.forEach((gemPath) => { - supportedSchemes.forEach((scheme) => { - // On Windows, gem paths may be using backslashes, but those are not valid as a glob pattern. We need to ensure - // that we're using forward slashes for the document selectors - const pathAsGlobPattern = gemPath.replace(/\\/g, "/"); + // On Windows, gem paths may be using backslashes, but those are not valid as a glob pattern. We need to ensure + // that we're using forward slashes for the document selectors + const pathAsGlobPattern = gemPath.replace(/\\/g, "/"); + + documentSelector.push({ + scheme: "file", + language: "ruby", + pattern: `${pathAsGlobPattern}/**/*`, + }); + // 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(pathAsGlobPattern)) { documentSelector.push({ - scheme, + scheme: "file", language: "ruby", - pattern: `${pathAsGlobPattern}/**/*`, + pattern: `${pathAsGlobPattern.replace(/lib\/ruby\/gems\/(?=\d)/, "lib/ruby/")}/**/*`, }); - - // 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(pathAsGlobPattern)) { - documentSelector.push({ - scheme, - language: "ruby", - pattern: `${pathAsGlobPattern.replace(/lib\/ruby\/gems\/(?=\d)/, "lib/ruby/")}/**/*`, - }); - } - }); + } }); // This is a temporary solution as an escape hatch for users who cannot upgrade the `ruby-lsp` gem to a version that diff --git a/vscode/src/test/suite/client.test.ts b/vscode/src/test/suite/client.test.ts index 2d3df66a0e..8f78a62b9f 100644 --- a/vscode/src/test/suite/client.test.ts +++ b/vscode/src/test/suite/client.test.ts @@ -619,7 +619,7 @@ suite("Client", () => { test("document selectors match default gems and bundled gems appropriately", () => { const selector = client.clientOptions .documentSelector! as TextDocumentFilter[]; - assert.strictEqual(selector.length, 10); + assert.strictEqual(selector.length, 5); // We don't care about the order of the document filters, just that they are present. This assertion helper is just // a convenience to search the registered filters @@ -641,26 +641,14 @@ suite("Client", () => { }; assertSelector("ruby", `${workspaceUri.fsPath}/**/*`, "file"); - assertSelector("ruby", `${workspaceUri.fsPath}/**/*`, "git"); assertSelector("erb", `${workspaceUri.fsPath}/**/*`, "file"); - assertSelector("erb", `${workspaceUri.fsPath}/**/*`, "git"); - assertSelector( "ruby", new RegExp(`ruby\\/\\d\\.\\d\\.\\d\\/\\*\\*\\/\\*`), "file", ); - assertSelector( - "ruby", - new RegExp(`ruby\\/\\d\\.\\d\\.\\d\\/\\*\\*\\/\\*`), - "git", - ); - assertSelector("ruby", /lib\/ruby\/gems\/\d\.\d\.\d\/\*\*\/\*/, "file"); - assertSelector("ruby", /lib\/ruby\/gems\/\d\.\d\.\d\/\*\*\/\*/, "git"); - assertSelector("ruby", /lib\/ruby\/\d\.\d\.\d\/\*\*\/\*/, "file"); - assertSelector("ruby", /lib\/ruby\/\d\.\d\.\d\/\*\*\/\*/, "git"); }); test("requests for non existing documents do not crash the server", async () => {