Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure default gem path is also in document selector #2738

Merged
merged 1 commit into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions vscode/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,17 +148,27 @@ function collectClientOptions(
});
}

// Because of how default gems are installed, the entry in the `GEM_PATH` 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
ruby.gemPath.forEach((gemPath) => {
documentSelector.push({
language: "ruby",
pattern: `${gemPath.replace(/lib\/ruby\/gems\/(?=\d)/, "lib/ruby/")}/**/*`,
pattern: `${gemPath}/**/*`,
});

// 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)) {
documentSelector.push({
language: "ruby",
pattern: `${gemPath.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
Expand Down
6 changes: 6 additions & 0 deletions vscode/src/test/suite/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,7 @@ suite("Client", () => {
workspaceRubyFilter,
workspaceERBFilter,
bundledGemsFilter,
defaultPathFilter,
defaultGemsFilter,
] = client.clientOptions.documentSelector!;

Expand Down Expand Up @@ -702,6 +703,11 @@ suite("Client", () => {
new RegExp(`ruby\\/\\d\\.\\d\\.\\d\\/\\*\\*\\/\\*`),
);

assert.match(
(defaultPathFilter as TextDocumentFilter).pattern!,
/lib\/ruby\/gems\/\d\.\d\.\d\/\*\*\/\*/,
);

assert.match(
(defaultGemsFilter as TextDocumentFilter).pattern!,
/lib\/ruby\/\d\.\d\.\d\/\*\*\/\*/,
Expand Down
Loading