Skip to content

Commit

Permalink
Always apply workspace URI configuration to indexer (#3034)
Browse files Browse the repository at this point in the history
### Motivation

Fixes #2365

We regressed on the fix to use the workspace URI given by the editor as the entry point for indexing. The changes to receive indexing configurations from the editor started returning early if no configurations are passed, but we still need to apply the workspace URI even if the user didn't specify any other configs.

### Implementation

Started applying the workspace URI to the indexing config every time.

### Automated Tests

Added a test that reproduces the bug.
  • Loading branch information
vinistock authored Jan 9, 2025
1 parent 41fceb9 commit c47b562
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/ruby_lsp/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1260,10 +1260,10 @@ def process_indexing_configuration(indexing_options)
return
end

return unless indexing_options

configuration = @global_state.index.configuration
configuration.workspace_path = @global_state.workspace_path
return unless indexing_options

# The index expects snake case configurations, but VS Code standardizes on camel case settings
configuration.apply_config(indexing_options.transform_keys { |key| key.to_s.gsub(/([A-Z])/, "_\\1").downcase })
end
Expand Down
17 changes: 16 additions & 1 deletion test/server_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,21 @@ def test_formatting_errors_push_window_notification
)
end

def test_applies_workspace_uri_to_indexing_configs_even_if_no_configs_are_specified
@server.process_message({
id: 1,
method: "initialize",
params: {
initializationOptions: {},
capabilities: { general: { positionEncodings: ["utf-8"] } },
workspaceFolders: [{ uri: URI::Generic.from_path(path: "/fake").to_s }],
},
})

index = @server.instance_variable_get(:@global_state).index
assert_equal("/fake", index.configuration.instance_variable_get(:@workspace_path))
end

def test_returns_nil_diagnostics_and_formatting_for_files_outside_workspace
capture_subprocess_io do
@server.process_message({
Expand All @@ -233,7 +248,7 @@ def test_returns_nil_diagnostics_and_formatting_for_files_outside_workspace
params: {
initializationOptions: { enabledFeatures: ["formatting", "diagnostics"] },
capabilities: { general: { positionEncodings: ["utf-8"] } },
workspaceFolders: [{ uri: URI::Generic.from_path(path: Dir.pwd).to_standardized_path }],
workspaceFolders: [{ uri: URI::Generic.from_path(path: Dir.pwd).to_s }],
},
})
end
Expand Down

0 comments on commit c47b562

Please sign in to comment.