Skip to content

Commit

Permalink
Ensure default gem path is also in document selector
Browse files Browse the repository at this point in the history
  • Loading branch information
vinistock committed Oct 18, 2024
1 parent ef1a27d commit 30fbcbc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
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

0 comments on commit 30fbcbc

Please sign in to comment.