Skip to content
Open
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
17 changes: 17 additions & 0 deletions exe/ruby-lsp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ parser = OptionParser.new do |opts|
options[:branch] = branch
end

opts.on(
"--lsp-path [PATH]",
"Launch the Ruby LSP using a local PATH rather than the release version",
) do |path|
options[:lsp_path] = path
end

opts.on("--doctor", "Run troubleshooting steps") do
options[:doctor] = true
end
Expand All @@ -54,6 +61,16 @@ rescue OptionParser::InvalidOption => e
exit(1)
end

if options[:branch] && options[:lsp_path]
warn('Invalid options: --branch and --lsp-path cannot both be set.')
exit(1)
end

if options[:lsp_path] && !File.absolute_path?(options[:lsp_path])
warn('Invalid option: --lsp-path must be an absolute path.')
exit(1)
end

# When we're running without bundler, then we need to make sure the composed bundle is fully configured and re-execute
# using `BUNDLE_GEMFILE=.ruby-lsp/Gemfile bundle exec ruby-lsp` so that we have access to the gems that are a part of
# the application's bundle
Expand Down
14 changes: 14 additions & 0 deletions jekyll/contributing.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,20 @@ with a debugger. Note that the debug mode applies only until the editor is close
Caveat: since you are debugging the language server instance that is currently running in your own editor, features will
not be available if the execution is currently suspended at a breakpoint.

#### Configuring the server version

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.

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.

```jsonc
{
"rubyLsp.serverPath": "/path/to/your/ruby-lsp-clone"
}
```

*Note: There are some exceptions to this. Most notably, when the ruby-lsp repository is opened in VS Code with the extension active, it will run the server contained within the repository.

#### Understanding Prism ASTs

The Ruby LSP uses Prism to parse and understand Ruby code. When working on a feature, it's very common to need to
Expand Down
2 changes: 2 additions & 0 deletions lib/ruby_lsp/setup_bundler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def stdout
def initialize(project_path, **options)
@project_path = project_path
@branch = options[:branch] #: String?
@lsp_path = options[:lsp_path] #: String?
@launcher = options[:launcher] #: bool?
patch_thor_to_print_progress_to_stderr! if @launcher

Expand Down Expand Up @@ -166,6 +167,7 @@ def write_custom_gemfile
unless @dependencies["ruby-lsp"]
ruby_lsp_entry = +'gem "ruby-lsp", require: false, group: :development'
ruby_lsp_entry << ", github: \"Shopify/ruby-lsp\", branch: \"#{@branch}\"" if @branch
ruby_lsp_entry << ", path: \"#{@lsp_path}\"" if @lsp_path
parts << ruby_lsp_entry
end

Expand Down
21 changes: 21 additions & 0 deletions test/setup_bundler_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,27 @@ def test_creates_composed_bundle_with_specified_branch
end
end

def test_creates_composed_bundle_with_specified_path
Dir.mktmpdir do |dir|
local_path = File.join(dir, "local-ruby-lsp")
FileUtils.mkdir_p(File.join(local_path, "lib"))

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

assert_path_exists(".ruby-lsp")
assert_path_exists(".ruby-lsp/Gemfile")
assert_match(%r{ruby-lsp.*path: "#{Regexp.escape(local_path)}"}, File.read(".ruby-lsp/Gemfile"))
assert_match("debug", File.read(".ruby-lsp/Gemfile"))
end
end
end


def test_returns_bundle_app_config_if_there_is_local_config
Dir.mktmpdir do |dir|
Dir.chdir(dir) do
Expand Down
4 changes: 4 additions & 0 deletions vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,10 @@
"type": "string",
"default": ""
},
"rubyLsp.serverPath": {
"description": "Absolute path to a local ruby-lsp repository. Only supported if not using bundleGemfile",
"type": "string"
},
"rubyLsp.pullDiagnosticsOn": {
"description": "When to pull diagnostics from the server (on change, save or both). Selecting 'save' may significantly improve performance on large files",
"type": "string",
Expand Down
12 changes: 8 additions & 4 deletions vscode/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ function getLspExecutables(workspaceFolder: vscode.WorkspaceFolder, env: NodeJS.
const customBundleGemfile: string = config.get("bundleGemfile")!;
const useBundlerCompose: boolean = config.get("useBundlerCompose")!;
const bypassTypechecker: boolean = config.get("bypassTypechecker")!;
const serverPath: string = config.get("serverPath")!;

const executableOptions: ExecutableOptions = {
cwd: workspaceFolder.uri.fsPath,
Expand Down Expand Up @@ -119,18 +120,21 @@ function getLspExecutables(workspaceFolder: vscode.WorkspaceFolder, env: NodeJS.
options: executableOptions,
};
} else {
const workspacePath = workspaceFolder.uri.fsPath;
const basePath = serverPath || workspaceFolder.uri.fsPath;
const command =
path.basename(workspacePath) === "ruby-lsp" && os.platform() !== "win32"
? path.join(workspacePath, "exe", "ruby-lsp")
path.basename(basePath) === "ruby-lsp" && os.platform() !== "win32"
? path.join(basePath, "exe", "ruby-lsp")
: "ruby-lsp";

const args = [];

if (branch.length > 0) {
args.push("--branch", branch);
}

if (serverPath) {
args.push("--lsp-path", serverPath);
}

if (featureEnabled("launcher")) {
args.push("--use-launcher");
}
Expand Down