Skip to content

Conversation

pkondzior
Copy link
Contributor

@pkondzior pkondzior commented Oct 12, 2025

Motivation

Currently, when working on the ruby-lsp repository in editors that support the Language Server Protocol (LSP) but do not support workspace configuration (such as Zed), developers are required to use the RUBY_LSP_BYPASS_TYPECHECKER environment variable. However, this approach can be problematic, as not all editors provide a straightforward way to define or persist environment variables for LSP servers.

Additionally, in VS Code extension, the rubyLsp.bypassTypechecker workspace configuration is used to set the RUBY_LSP_BYPASS_TYPECHECKER environment variable, which is then passed to the LSP executable. While this works well for VS Code, it introduces unnecessary indirection and editor-specific handling.

By supporting this configuration directly through initializationOptions, we can simplify the setup and make the behavior consistent across all editors. The initializationOptions field is part of the LSP specification and is supported by all compliant editors, making this a more portable and standard solution.

Closes #2856

Implementation

The change introduces support for the bypassTypechecker option in the LSP initializationOptions. Previously, this behavior could only be controlled through the RUBY_LSP_BYPASS_TYPECHECKER environment variable or the VS Code workspace configuration. Now, the option can be passed directly during LSP initialization, making it editor-agnostic and compliant with the LSP specification.

The implementation updates GlobalState to respect initializationOptions[:bypassTypechecker], adjusts the VS Code client to forward this setting through initialization options instead of environment variables, and adds a dedicated test to verify the new behavior. Reviewers should confirm that backward compatibility with the environment variable remains intact and that the change does not affect Sorbet detection in normal use.

Automated Tests

A new unit test was added to verify that bypassTypechecker correctly disables type checker detection when provided through initializationOptions. Existing tests continue to cover the environment variable path, ensuring backward compatibility.
All tests pass locally.

Manual Tests

Below are step-by-step instructions to validate the new bypassTypechecker initialization option in VS Code when working in the ruby-lsp repo.

Prerequisites

  • Open the repository using the provided workspace: File → Open Workspace… → ruby-lsp.code-workspace.
  • Ensure dependencies are installed (bundle install) and the Ruby LSP VS Code extension is enabled.
  • (Optional) Install Sorbet LSP extension to observe deferral behavior when bypassTypechecker is off.

1) Verify behavior with bypassTypechecker: true

  1. Open Settings (Workspace) and set:
    rubyLsp.bypassTypechecker = true
  2. Reload the window (Developer: Reload Window).
  3. Enable LSP tracing (optional but helpful): set rubyLsp.trace.server = "verbose".
  4. Open any Ruby file in the repo (e.g., lib/ruby_lsp/global_state.rb).
  5. Expected:
    • In Output → Ruby LSP, no message like “Ruby LSP detected this is a Sorbet project…” appears.
    • “Go to Definition”, “Find References”, etc., are provided directly by Ruby LSP.
    • If tracing is enabled, the initialize payload contains:
      "initializationOptions": { "bypassTypechecker": true }

2) Verify behavior with bypassTypechecker: false

  1. Set rubyLsp.bypassTypechecker = false (or remove it).
  2. Reload the window.
  3. Expected:
    • In Output → Ruby LSP, you see a log similar to:
      “Ruby LSP detected this is a Sorbet project and will defer to the Sorbet LSP for some functionality.”
    • If Sorbet LSP extension is installed/active, those features are handled by Sorbet; if not, some features appear disabled (as documented).

@graphite-app
Copy link

graphite-app bot commented Oct 12, 2025

How to use the Graphite Merge Queue

Add the label graphite-merge to this PR to add it to the merge queue.

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

@pkondzior
Copy link
Contributor Author

I have signed the CLA!

@pkondzior pkondzior marked this pull request as ready for review October 12, 2025 17:17
@pkondzior pkondzior requested a review from a team as a code owner October 12, 2025 17:17
@pkondzior
Copy link
Contributor Author

I think we might also consider deprecating RUBY_LSP_BYPASS_TYPECHECKER if there is agreement on that I can create issue and PR addressing this with proper Notification message for that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Document bypassTypechecker` for contributors, and enable automatically where possible

1 participant