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
20 changes: 20 additions & 0 deletions jekyll/troubleshooting.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions lib/ruby_lsp/global_state.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions test/global_state_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions vscode/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down Expand Up @@ -239,6 +238,7 @@ function collectClientOptions(
addonSettings: configuration.get("addonSettings"),
enabledFeatureFlags: enabledFeatureFlags(),
telemetryMachineId: vscode.env.machineId,
bypassTypechecker: configuration.get("bypassTypechecker"),
},
};
}
Expand Down