Skip to content

Commit f257fd7

Browse files
authored
Remove git scheme from document selector (#3540)
1 parent 2596f87 commit f257fd7

File tree

2 files changed

+24
-41
lines changed

2 files changed

+24
-41
lines changed

vscode/src/client.ts

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,6 @@ function collectClientOptions(
181181

182182
const features: EnabledFeatures = configuration.get("enabledFeatures")!;
183183
const enabledFeatures = Object.keys(features).filter((key) => features[key]);
184-
const supportedSchemes = ["file", "git"];
185184

186185
const fsPath = workspaceFolder.uri.fsPath.replace(/\/$/, "");
187186

@@ -191,9 +190,7 @@ function collectClientOptions(
191190
// 3. Default gems
192191
let documentSelector: DocumentSelector = SUPPORTED_LANGUAGE_IDS.flatMap(
193192
(language) => {
194-
return supportedSchemes.map((scheme) => {
195-
return { scheme, language, pattern: `${fsPath}/**/*` };
196-
});
193+
return { scheme: "file", language, pattern: `${fsPath}/**/*` };
197194
},
198195
);
199196

@@ -209,34 +206,32 @@ function collectClientOptions(
209206
}
210207

211208
ruby.gemPath.forEach((gemPath) => {
212-
supportedSchemes.forEach((scheme) => {
213-
// On Windows, gem paths may be using backslashes, but those are not valid as a glob pattern. We need to ensure
214-
// that we're using forward slashes for the document selectors
215-
const pathAsGlobPattern = gemPath.replace(/\\/g, "/");
209+
// On Windows, gem paths may be using backslashes, but those are not valid as a glob pattern. We need to ensure
210+
// that we're using forward slashes for the document selectors
211+
const pathAsGlobPattern = gemPath.replace(/\\/g, "/");
212+
213+
documentSelector.push({
214+
scheme: "file",
215+
language: "ruby",
216+
pattern: `${pathAsGlobPattern}/**/*`,
217+
});
216218

219+
// Because of how default gems are installed, the gemPath location is actually not exactly where the files are
220+
// located. With the regex, we are correcting the default gem path from this (where the files are not located)
221+
// /opt/rubies/3.3.1/lib/ruby/gems/3.3.0
222+
//
223+
// to this (where the files are actually stored)
224+
// /opt/rubies/3.3.1/lib/ruby/3.3.0
225+
//
226+
// Notice that we still need to add the regular path to the selector because some version managers will install
227+
// gems under the non-corrected path
228+
if (/lib\/ruby\/gems\/(?=\d)/.test(pathAsGlobPattern)) {
217229
documentSelector.push({
218-
scheme,
230+
scheme: "file",
219231
language: "ruby",
220-
pattern: `${pathAsGlobPattern}/**/*`,
232+
pattern: `${pathAsGlobPattern.replace(/lib\/ruby\/gems\/(?=\d)/, "lib/ruby/")}/**/*`,
221233
});
222-
223-
// Because of how default gems are installed, the gemPath location is actually not exactly where the files are
224-
// located. With the regex, we are correcting the default gem path from this (where the files are not located)
225-
// /opt/rubies/3.3.1/lib/ruby/gems/3.3.0
226-
//
227-
// to this (where the files are actually stored)
228-
// /opt/rubies/3.3.1/lib/ruby/3.3.0
229-
//
230-
// Notice that we still need to add the regular path to the selector because some version managers will install
231-
// gems under the non-corrected path
232-
if (/lib\/ruby\/gems\/(?=\d)/.test(pathAsGlobPattern)) {
233-
documentSelector.push({
234-
scheme,
235-
language: "ruby",
236-
pattern: `${pathAsGlobPattern.replace(/lib\/ruby\/gems\/(?=\d)/, "lib/ruby/")}/**/*`,
237-
});
238-
}
239-
});
234+
}
240235
});
241236

242237
// This is a temporary solution as an escape hatch for users who cannot upgrade the `ruby-lsp` gem to a version that

vscode/src/test/suite/client.test.ts

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ suite("Client", () => {
619619
test("document selectors match default gems and bundled gems appropriately", () => {
620620
const selector = client.clientOptions
621621
.documentSelector! as TextDocumentFilter[];
622-
assert.strictEqual(selector.length, 10);
622+
assert.strictEqual(selector.length, 5);
623623

624624
// We don't care about the order of the document filters, just that they are present. This assertion helper is just
625625
// a convenience to search the registered filters
@@ -641,26 +641,14 @@ suite("Client", () => {
641641
};
642642

643643
assertSelector("ruby", `${workspaceUri.fsPath}/**/*`, "file");
644-
assertSelector("ruby", `${workspaceUri.fsPath}/**/*`, "git");
645644
assertSelector("erb", `${workspaceUri.fsPath}/**/*`, "file");
646-
assertSelector("erb", `${workspaceUri.fsPath}/**/*`, "git");
647-
648645
assertSelector(
649646
"ruby",
650647
new RegExp(`ruby\\/\\d\\.\\d\\.\\d\\/\\*\\*\\/\\*`),
651648
"file",
652649
);
653-
assertSelector(
654-
"ruby",
655-
new RegExp(`ruby\\/\\d\\.\\d\\.\\d\\/\\*\\*\\/\\*`),
656-
"git",
657-
);
658-
659650
assertSelector("ruby", /lib\/ruby\/gems\/\d\.\d\.\d\/\*\*\/\*/, "file");
660-
assertSelector("ruby", /lib\/ruby\/gems\/\d\.\d\.\d\/\*\*\/\*/, "git");
661-
662651
assertSelector("ruby", /lib\/ruby\/\d\.\d\.\d\/\*\*\/\*/, "file");
663-
assertSelector("ruby", /lib\/ruby\/\d\.\d\.\d\/\*\*\/\*/, "git");
664652
});
665653

666654
test("requests for non existing documents do not crash the server", async () => {

0 commit comments

Comments
 (0)