Skip to content

Commit f2e11fd

Browse files
committed
Rename --path to --lsp-path and require repo absolute path
- Rename CLI flag from --path to --lsp-path to prevent confusion with other path configurations - Add validation in ruby-lsp executable to require absolute paths to repo root for --lsp-path option - Do not allow serverPath to directly be an executable - Remove incorrect path expansion in SetupBundler (LSP path and project path are unrelated) - Simplify VS Code extension to pass serverPath directly without validation or fs usage - Remove duplicate validation between executable and SetupBundler - Update package.json to specify absolute path requirement and remove default value - Remove manual restart instruction from documentation (server auto-restarts on config changes) - Fix potential runtime error when serverPath is undefined by using truthy check
1 parent 752d871 commit f2e11fd

File tree

6 files changed

+29
-71
lines changed

6 files changed

+29
-71
lines changed

exe/ruby-lsp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ parser = OptionParser.new do |opts|
3030
end
3131

3232
opts.on(
33-
"--path [PATH]",
33+
"--lsp-path [PATH]",
3434
"Launch the Ruby LSP using a local PATH rather than the release version",
3535
) do |path|
36-
options[:path] = path
36+
options[:lsp_path] = path
3737
end
3838

3939
opts.on("--doctor", "Run troubleshooting steps") do
@@ -61,8 +61,13 @@ rescue OptionParser::InvalidOption => e
6161
exit(1)
6262
end
6363

64-
if options[:branch] && options[:path]
65-
warn('Invalid options: --branch and --path cannot both be set.')
64+
if options[:branch] && options[:lsp_path]
65+
warn('Invalid options: --branch and --lsp-path cannot both be set.')
66+
exit(1)
67+
end
68+
69+
if options[:lsp_path] && !File.absolute_path?(options[:lsp_path])
70+
warn('Invalid option: --lsp-path must be an absolute path.')
6671
exit(1)
6772
end
6873

jekyll/contributing.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ not be available if the execution is currently suspended at a breakpoint.
6262

6363
When developing the Ruby LSP server, you may want to test your changes in your own Ruby projects to ensure they work correctly in real-world scenarios.
6464

65-
The running server, even in debug mode, will default to the installed release version*. You can use the `rubyLsp.serverPath` configuration setting in the target workspace to start your local copy instead. Make sure to restart the language server after making changes to pick up your updates.
65+
The running server, even in debug mode, will default to the installed release version*. You can use the `rubyLsp.serverPath` configuration setting in the target workspace to start your local copy instead.
6666

6767
```jsonc
6868
{

lib/ruby_lsp/setup_bundler.rb

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,8 @@ def stdout
3939
def initialize(project_path, **options)
4040
@project_path = project_path
4141
@branch = options[:branch] #: String?
42-
@path = options[:path] #: String?
42+
@lsp_path = options[:lsp_path] #: String?
4343
@launcher = options[:launcher] #: bool?
44-
45-
if @branch && !@branch.empty? && @path && !@path.empty?
46-
raise ArgumentError, "Branch and path options are mutually exclusive. Please specify only one."
47-
end
48-
4944
force_output_to_stderr! if @launcher
5045

5146
# Regular bundle paths
@@ -176,13 +171,8 @@ def write_custom_gemfile
176171

177172
unless @dependencies["ruby-lsp"]
178173
ruby_lsp_entry = +'gem "ruby-lsp", require: false, group: :development'
179-
if @branch && !@branch.empty?
180-
ruby_lsp_entry << ", github: \"Shopify/ruby-lsp\", branch: \"#{@branch}\""
181-
end
182-
if @path && !@path.empty?
183-
absolute_path = File.expand_path(@path, @project_path)
184-
ruby_lsp_entry << ", path: \"#{absolute_path}\""
185-
end
174+
ruby_lsp_entry << ", github: \"Shopify/ruby-lsp\", branch: \"#{@branch}\"" if @branch
175+
ruby_lsp_entry << ", path: \"#{@lsp_path}\"" if @lsp_path
186176
parts << ruby_lsp_entry
187177
end
188178

test/setup_bundler_test.rb

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -318,35 +318,24 @@ def test_creates_composed_bundle_with_specified_branch
318318

319319
def test_creates_composed_bundle_with_specified_path
320320
Dir.mktmpdir do |dir|
321-
local_path = "local-ruby-lsp"
322-
FileUtils.mkdir_p(File.join(dir, local_path, "lib"))
321+
local_path = File.join(dir, "local-ruby-lsp")
322+
FileUtils.mkdir_p(File.join(local_path, "lib"))
323323

324324
Dir.chdir(dir) do
325325
bundle_gemfile = Pathname.new(".ruby-lsp").expand_path(Dir.pwd) + "Gemfile"
326326
Bundler.with_unbundled_env do
327327
stub_bundle_with_env(bundle_env(dir, bundle_gemfile.to_s))
328-
run_script(File.realpath(dir), path: local_path)
328+
run_script(File.realpath(dir), lsp_path: local_path)
329329
end
330330

331331
assert_path_exists(".ruby-lsp")
332332
assert_path_exists(".ruby-lsp/Gemfile")
333-
expected_absolute_path = File.expand_path(local_path, File.realpath(dir))
334-
assert_match(%r{ruby-lsp.*path: "#{Regexp.escape(expected_absolute_path)}"}, File.read(".ruby-lsp/Gemfile"))
333+
assert_match(%r{ruby-lsp.*path: "#{Regexp.escape(local_path)}"}, File.read(".ruby-lsp/Gemfile"))
335334
assert_match("debug", File.read(".ruby-lsp/Gemfile"))
336335
end
337336
end
338337
end
339338

340-
def test_raises_error_when_both_branch_and_path_are_specified
341-
Dir.mktmpdir do |dir|
342-
Dir.chdir(dir) do
343-
error = assert_raises(ArgumentError) do
344-
RubyLsp::SetupBundler.new(dir, branch: "test-branch", path: "local-path")
345-
end
346-
assert_equal("Branch and path options are mutually exclusive. Please specify only one.", error.message)
347-
end
348-
end
349-
end
350339

351340
def test_returns_bundle_app_config_if_there_is_local_config
352341
in_temp_dir do |dir|

vscode/package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -474,9 +474,8 @@
474474
"default": ""
475475
},
476476
"rubyLsp.serverPath": {
477-
"description": "Absolute or workspace-relative path to a local ruby-lsp repository or its ruby-lsp executable. Only supported if not using bundleGemfile",
478-
"type": "string",
479-
"default": ""
477+
"description": "Absolute path to a local ruby-lsp repository. Only supported if not using bundleGemfile",
478+
"type": "string"
480479
},
481480
"rubyLsp.pullDiagnosticsOn": {
482481
"description": "When to pull diagnostics from the server (on change, save or both). Selecting 'save' may significantly improve performance on large files",

vscode/src/client.ts

Lines changed: 10 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import path from "path";
2-
import fs from "fs";
32
import os from "os";
43
import { performance as Perf } from "perf_hooks";
54

@@ -121,45 +120,21 @@ function getLspExecutables(workspaceFolder: vscode.WorkspaceFolder, env: NodeJS.
121120
options: executableOptions,
122121
};
123122
} else {
124-
const args = [];
125-
const workspacePath = workspaceFolder.uri.fsPath;
126-
let command: string;
127-
128-
if (serverPath.length > 0 && branch.length > 0) {
129-
throw new Error(
130-
'Invalid configuration: "rubyLsp.serverPath" and "rubyLsp.branch" cannot both be set. Please unset one of them.',
131-
);
132-
}
133-
134-
if (serverPath.length > 0) {
135-
const absoluteServerPath = path.isAbsolute(serverPath) ? serverPath : path.resolve(workspacePath, serverPath);
136-
const exists = fs.existsSync(absoluteServerPath);
137-
138-
if (exists) {
139-
args.push("--path", absoluteServerPath);
140-
const stat = fs.statSync(absoluteServerPath);
141-
142-
if (stat.isDirectory()) {
143-
command = os.platform() !== "win32" ? path.join(absoluteServerPath, "exe", "ruby-lsp") : "ruby-lsp";
144-
} else {
145-
command = absoluteServerPath;
146-
}
147-
} else {
148-
throw new Error(
149-
`The configured rubyLsp.serverPath "${serverPath}" does not exist at "${absoluteServerPath}". `,
150-
);
151-
}
152-
} else {
153-
command =
154-
path.basename(workspacePath) === "ruby-lsp" && os.platform() !== "win32"
155-
? path.join(workspacePath, "exe", "ruby-lsp")
156-
: "ruby-lsp";
157-
}
123+
const basePath = serverPath || workspaceFolder.uri.fsPath;
124+
const command =
125+
path.basename(basePath) === "ruby-lsp" && os.platform() !== "win32"
126+
? path.join(basePath, "exe", "ruby-lsp")
127+
: "ruby-lsp";
158128

129+
const args = [];
159130
if (branch.length > 0) {
160131
args.push("--branch", branch);
161132
}
162133

134+
if (serverPath) {
135+
args.push("--lsp-path", serverPath);
136+
}
137+
163138
if (featureEnabled("launcher")) {
164139
args.push("--use-launcher");
165140
}

0 commit comments

Comments
 (0)