From 32acba7c60b43008a6337f05e8f8dacbb28add6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Kondzior?= Date: Sun, 12 Oct 2025 18:28:26 +0200 Subject: [PATCH] Add initialization option bypassTypechecker --- jekyll/troubleshooting.markdown | 20 ++++++++++++++++++++ lib/ruby_lsp/global_state.rb | 5 ++--- test/global_state_test.rb | 10 ++++++++++ vscode/src/client.ts | 4 ++-- 4 files changed, 34 insertions(+), 5 deletions(-) diff --git a/jekyll/troubleshooting.markdown b/jekyll/troubleshooting.markdown index 412be0a6fe..a94461acdd 100644 --- a/jekyll/troubleshooting.markdown +++ b/jekyll/troubleshooting.markdown @@ -129,6 +129,26 @@ and are working on a codebase that uses Sorbet, then this may indicate the To avoid duplicate/conflicting behavior, Ruby LSP disables some features when a Sorbet codebase is detected, with the intention that Sorbet can provide better accuracy. +When working on the Ruby LSP repository itself, you may want to disable Sorbet detection so that Ruby LSP provides all features directly. + +You can do this by setting the **bypassTypechecker** option during initialization: + +- **In VS Code:** + + Set the `rubyLsp.bypassTypechecker` option in your workspace settings, or open the project using the provided ruby-lsp.code-workspace file. + +- **In other editors:** + + Add the following to your editor’s LSP client configuration. + + ```json + { + "initializationOptions": { + "bypassTypechecker": true + } + } + ```` + ### Gem installation locations and permissions To launch the Ruby LSP server, the `ruby-lsp` gem must be installed. And in order to automatically index your project's diff --git a/lib/ruby_lsp/global_state.rb b/lib/ruby_lsp/global_state.rb index 1fa4fd88b3..c5b1b1e25f 100644 --- a/lib/ruby_lsp/global_state.rb +++ b/lib/ruby_lsp/global_state.rb @@ -155,7 +155,8 @@ def apply_options(options) @test_library = detect_test_library(direct_dependencies) notifications << Notification.window_log_message("Detected test library: #{@test_library}") - @has_type_checker = detect_typechecker(all_dependencies) + bypass_typechecker = options.dig(:initializationOptions, :bypassTypechecker) || ENV["RUBY_LSP_BYPASS_TYPECHECKER"] + @has_type_checker = bypass_typechecker ? false : detect_typechecker(all_dependencies) if @has_type_checker notifications << Notification.window_log_message( "Ruby LSP detected this is a Sorbet project and will defer to the Sorbet LSP for some functionality", @@ -277,8 +278,6 @@ def detect_test_library(dependencies) #: (Array[String] dependencies) -> bool def detect_typechecker(dependencies) - return false if ENV["RUBY_LSP_BYPASS_TYPECHECKER"] - dependencies.any?(/^sorbet-static/) rescue Bundler::GemfileNotFound false diff --git a/test/global_state_test.rb b/test/global_state_test.rb index 35f96e7540..d798a342a9 100644 --- a/test/global_state_test.rb +++ b/test/global_state_test.rb @@ -199,6 +199,16 @@ def test_type_checker_is_detected_based_on_transitive_sorbet_static assert_predicate(state, :has_type_checker) end + def test_type_checker_is_bypassed_based_on_initialization_options + state = GlobalState.new + + Bundler.locked_gems.stubs(dependencies: {}) + stub_all_dependencies("sorbet-static") + state.apply_options({ initializationOptions: { bypassTypechecker: true } }) + + refute(state.has_type_checker) + end + def test_addon_settings_are_stored global_state = GlobalState.new diff --git a/vscode/src/client.ts b/vscode/src/client.ts index d7cf40784d..e63bd6bef5 100644 --- a/vscode/src/client.ts +++ b/vscode/src/client.ts @@ -84,11 +84,10 @@ function getLspExecutables(workspaceFolder: vscode.WorkspaceFolder, env: NodeJS. const branch: string = config.get("branch")!; const customBundleGemfile: string = config.get("bundleGemfile")!; const useBundlerCompose: boolean = config.get("useBundlerCompose")!; - const bypassTypechecker: boolean = config.get("bypassTypechecker")!; const executableOptions: ExecutableOptions = { cwd: workspaceFolder.uri.fsPath, - env: bypassTypechecker ? { ...env, RUBY_LSP_BYPASS_TYPECHECKER: "true" } : env, + env: env, shell: true, }; @@ -239,6 +238,7 @@ function collectClientOptions( addonSettings: configuration.get("addonSettings"), enabledFeatureFlags: enabledFeatureFlags(), telemetryMachineId: vscode.env.machineId, + bypassTypechecker: configuration.get("bypassTypechecker"), }, }; }