Skip to content

Commit 03237a0

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 ae8010c commit 03237a0

6 files changed

Lines changed: 29 additions & 71 deletions

File tree

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
@@ -35,13 +35,8 @@ def stdout
3535
def initialize(project_path, **options)
3636
@project_path = project_path
3737
@branch = options[:branch] #: String?
38-
@path = options[:path] #: String?
38+
@lsp_path = options[:lsp_path] #: String?
3939
@launcher = options[:launcher] #: bool?
40-
41-
if @branch && !@branch.empty? && @path && !@path.empty?
42-
raise ArgumentError, "Branch and path options are mutually exclusive. Please specify only one."
43-
end
44-
4540
patch_thor_to_print_progress_to_stderr! if @launcher
4641

4742
# Regular bundle paths
@@ -171,13 +166,8 @@ def write_custom_gemfile
171166

172167
unless @dependencies["ruby-lsp"]
173168
ruby_lsp_entry = +'gem "ruby-lsp", require: false, group: :development'
174-
if @branch && !@branch.empty?
175-
ruby_lsp_entry << ", github: \"Shopify/ruby-lsp\", branch: \"#{@branch}\""
176-
end
177-
if @path && !@path.empty?
178-
absolute_path = File.expand_path(@path, @project_path)
179-
ruby_lsp_entry << ", path: \"#{absolute_path}\""
180-
end
169+
ruby_lsp_entry << ", github: \"Shopify/ruby-lsp\", branch: \"#{@branch}\"" if @branch
170+
ruby_lsp_entry << ", path: \"#{@lsp_path}\"" if @lsp_path
181171
parts << ruby_lsp_entry
182172
end
183173

test/setup_bundler_test.rb

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

283283
def test_creates_composed_bundle_with_specified_path
284284
Dir.mktmpdir do |dir|
285-
local_path = "local-ruby-lsp"
286-
FileUtils.mkdir_p(File.join(dir, local_path, "lib"))
285+
local_path = File.join(dir, "local-ruby-lsp")
286+
FileUtils.mkdir_p(File.join(local_path, "lib"))
287287

288288
Dir.chdir(dir) do
289289
bundle_gemfile = Pathname.new(".ruby-lsp").expand_path(Dir.pwd) + "Gemfile"
290290
Bundler.with_unbundled_env do
291291
stub_bundle_with_env(bundle_env(dir, bundle_gemfile.to_s))
292-
run_script(File.realpath(dir), path: local_path)
292+
run_script(File.realpath(dir), lsp_path: local_path)
293293
end
294294

295295
assert_path_exists(".ruby-lsp")
296296
assert_path_exists(".ruby-lsp/Gemfile")
297-
expected_absolute_path = File.expand_path(local_path, File.realpath(dir))
298-
assert_match(%r{ruby-lsp.*path: "#{Regexp.escape(expected_absolute_path)}"}, File.read(".ruby-lsp/Gemfile"))
297+
assert_match(%r{ruby-lsp.*path: "#{Regexp.escape(local_path)}"}, File.read(".ruby-lsp/Gemfile"))
299298
assert_match("debug", File.read(".ruby-lsp/Gemfile"))
300299
end
301300
end
302301
end
303302

304-
def test_raises_error_when_both_branch_and_path_are_specified
305-
Dir.mktmpdir do |dir|
306-
Dir.chdir(dir) do
307-
error = assert_raises(ArgumentError) do
308-
RubyLsp::SetupBundler.new(dir, branch: "test-branch", path: "local-path")
309-
end
310-
assert_equal("Branch and path options are mutually exclusive. Please specify only one.", error.message)
311-
end
312-
end
313-
end
314303

315304
def test_returns_bundle_app_config_if_there_is_local_config
316305
Dir.mktmpdir do |dir|

vscode/package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -468,9 +468,8 @@
468468
"default": ""
469469
},
470470
"rubyLsp.serverPath": {
471-
"description": "Absolute or workspace-relative path to a local ruby-lsp repository or its ruby-lsp executable. Only supported if not using bundleGemfile",
472-
"type": "string",
473-
"default": ""
471+
"description": "Absolute path to a local ruby-lsp repository. Only supported if not using bundleGemfile",
472+
"type": "string"
474473
},
475474
"rubyLsp.pullDiagnosticsOn": {
476475
"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)