Skip to content

Commit deaeca3

Browse files
committed
Debug
1 parent bc11fbb commit deaeca3

File tree

6 files changed

+32
-15
lines changed

6 files changed

+32
-15
lines changed

lib/core_ext/uri.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ def from_path(path:, fragment: nil, scheme: "file")
1111
# On Windows, if the path begins with the disk name, we need to add a leading slash to make it a valid URI
1212
escaped_path = if /^[A-Z]:/i.match?(path)
1313
DEFAULT_PARSER.escape("/#{path}")
14+
elsif path.start_with?("//?/")
15+
# Some paths on Windows start with "//?/". This is a special prefix that allows for long file paths
16+
DEFAULT_PARSER.escape(path.delete_prefix("//?"))
1417
else
1518
DEFAULT_PARSER.escape(path)
1619
end

lib/ruby_lsp/listeners/document_link.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def gem_paths
3030
lookup[spec.name] = {}
3131
lookup[spec.name][spec.version.to_s] = {}
3232

33-
Dir.glob("**/*.rb", base: "#{spec.full_gem_path}/").each do |path|
33+
Dir.glob("**/*.rb", base: "#{spec.full_gem_path.delete_prefix("//?/")}/").each do |path|
3434
lookup[spec.name][spec.version.to_s][path] = "#{spec.full_gem_path}/#{path}"
3535
end
3636
end

test/requests/support/uri_test.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,10 @@ def test_from_path_with_fragment
5050
uri = URI::Generic.from_path(path: "/some/unix/path/to/file.rb", fragment: "L1,3-2,9")
5151
assert_equal("file:///some/unix/path/to/file.rb#L1,3-2,9", uri.to_s)
5252
end
53+
54+
def test_from_path_windows_long_file_paths
55+
uri = URI::Generic.from_path(path: "//?/C:/hostedtoolcache/windows/Ruby/3.3.1/x64/lib/ruby/3.3.0/open-uri.rb")
56+
assert_equal("C:/hostedtoolcache/windows/Ruby/3.3.1/x64/lib/ruby/3.3.0/open-uri.rb", uri.to_standardized_path)
57+
end
5358
end
5459
end

vscode/src/ruby/chruby.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export class Chruby extends VersionManager {
6060
PATH: `${path.join(gemHome, "bin")}${path.delimiter}${path.join(
6161
defaultGems,
6262
"bin",
63-
)}${path.delimiter}${path.dirname(rubyUri.fsPath)}${path.delimiter}${process.env.PATH}`,
63+
)}${path.delimiter}${path.dirname(rubyUri.fsPath)}${path.delimiter}${this.getProcessPath()}`,
6464
};
6565

6666
return {
@@ -70,6 +70,19 @@ export class Chruby extends VersionManager {
7070
};
7171
}
7272

73+
protected getProcessPath() {
74+
return process.env.PATH;
75+
}
76+
77+
// Returns the full URI to the Ruby executable
78+
protected async findRubyUri(rubyVersion: RubyVersion): Promise<vscode.Uri> {
79+
if (/\d+\.\d+\.\d+/.exec(rubyVersion.version)) {
80+
return this.findRubyUriForCompleteVersion(rubyVersion);
81+
}
82+
83+
return this.findRubyUriWithOmittedPatch(rubyVersion);
84+
}
85+
7386
// Run the activation script using the Ruby installation we found so that we can discover gem paths
7487
protected async runActivationScript(rubyExecutableUri: vscode.Uri): Promise<{
7588
defaultGems: string;
@@ -105,15 +118,6 @@ export class Chruby extends VersionManager {
105118
return this.parseWithErrorHandling(result.stderr);
106119
}
107120

108-
// Returns the full URI to the Ruby executable
109-
protected async findRubyUri(rubyVersion: RubyVersion): Promise<vscode.Uri> {
110-
if (/\d+\.\d+\.\d+/.exec(rubyVersion.version)) {
111-
return this.findRubyUriForCompleteVersion(rubyVersion);
112-
}
113-
114-
return this.findRubyUriWithOmittedPatch(rubyVersion);
115-
}
116-
117121
private async findRubyUriWithOmittedPatch(
118122
rubyVersion: RubyVersion,
119123
): Promise<vscode.Uri> {

vscode/src/ruby/rubyInstaller.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable no-process-env */
12
import os from "os";
23

34
import * as vscode from "vscode";
@@ -16,6 +17,12 @@ interface RubyVersion {
1617
//
1718
// If we can't find it there, then we throw an error and rely on the user to manually select where Ruby is installed.
1819
export class RubyInstaller extends Chruby {
20+
// Environment variables are case sensitive on Windows when we access them through NodeJS. We need to ensure that
21+
// we're searching through common variations, so that we don't accidentally miss the path we should inherit
22+
protected getProcessPath() {
23+
return process.env.Path ?? process.env.PATH ?? process.env.path;
24+
}
25+
1926
// Returns the full URI to the Ruby executable
2027
protected async findRubyUri(rubyVersion: RubyVersion): Promise<vscode.Uri> {
2128
const [major, minor, _patch] = rubyVersion.version.split(".").map(Number);

vscode/src/test/suite/ruby/rubyInstaller.test.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ suite("RubyInstaller", () => {
6060
const windows = new RubyInstaller(workspaceFolder, outputChannel);
6161
const { env, version, yjit } = await windows.activate();
6262

63-
assert.match(env.GEM_PATH!, /ruby\/3\.3\.0/);
64-
assert.match(env.GEM_PATH!, /lib\/ruby\/gems\/3\.3\.0/);
63+
assert.match(env.GEM_PATH!, /lib\\ruby\\gems\\3\.3\.0/);
6564
assert.strictEqual(version, RUBY_VERSION);
6665
assert.notStrictEqual(yjit, undefined);
6766

@@ -90,8 +89,7 @@ suite("RubyInstaller", () => {
9089
const windows = new RubyInstaller(workspaceFolder, outputChannel);
9190
const { env, version, yjit } = await windows.activate();
9291

93-
assert.match(env.GEM_PATH!, /ruby\/3\.3\.0/);
94-
assert.match(env.GEM_PATH!, /lib\/ruby\/gems\/3\.3\.0/);
92+
assert.match(env.GEM_PATH!, /lib\\ruby\\gems\\3\.3\.0/);
9593
assert.strictEqual(version, RUBY_VERSION);
9694
assert.notStrictEqual(yjit, undefined);
9795

0 commit comments

Comments
 (0)