Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make indexing a stable feature #946

Merged
merged 1 commit into from
Aug 29, 2023
Merged
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
56 changes: 26 additions & 30 deletions lib/ruby_lsp/executor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,6 @@ def did_change_watched_files(changes)

sig { void }
def perform_initial_indexing
return unless @store.experimental_features

# The begin progress invocation happens during `initialize`, so that the notification is sent before we are
# stuck indexing files
RubyIndexer.configuration.load_config
Expand Down Expand Up @@ -643,37 +641,35 @@ def initialize_request(options)
)
end

if @store.experimental_features
# Dynamically registered capabilities
file_watching_caps = options.dig(:capabilities, :workspace, :didChangeWatchedFiles)

# Not every client supports dynamic registration or file watching
if file_watching_caps&.dig(:dynamicRegistration) && file_watching_caps&.dig(:relativePatternSupport)
@message_queue << Request.new(
message: "client/registerCapability",
params: Interface::RegistrationParams.new(
registrations: [
# Register watching Ruby files
Interface::Registration.new(
id: "workspace/didChangeWatchedFiles",
method: "workspace/didChangeWatchedFiles",
register_options: Interface::DidChangeWatchedFilesRegistrationOptions.new(
watchers: [
Interface::FileSystemWatcher.new(
glob_pattern: "**/*.rb",
kind: Constant::WatchKind::CREATE | Constant::WatchKind::CHANGE | Constant::WatchKind::DELETE,
),
],
),
# Dynamically registered capabilities
file_watching_caps = options.dig(:capabilities, :workspace, :didChangeWatchedFiles)

# Not every client supports dynamic registration or file watching
if file_watching_caps&.dig(:dynamicRegistration) && file_watching_caps&.dig(:relativePatternSupport)
@message_queue << Request.new(
message: "client/registerCapability",
params: Interface::RegistrationParams.new(
registrations: [
# Register watching Ruby files
Interface::Registration.new(
id: "workspace/didChangeWatchedFiles",
method: "workspace/didChangeWatchedFiles",
register_options: Interface::DidChangeWatchedFilesRegistrationOptions.new(
watchers: [
Interface::FileSystemWatcher.new(
glob_pattern: "**/*.rb",
kind: Constant::WatchKind::CREATE | Constant::WatchKind::CHANGE | Constant::WatchKind::DELETE,
),
],
),
],
),
)
end

begin_progress("indexing-progress", "Ruby LSP: indexing files")
),
],
),
)
end

begin_progress("indexing-progress", "Ruby LSP: indexing files")

Interface::InitializeResult.new(
capabilities: Interface::ServerCapabilities.new(
text_document_sync: Interface::TextDocumentSyncOptions.new(
Expand Down
8 changes: 6 additions & 2 deletions test/executor_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,12 @@ def test_initialize_uses_utf_16_if_no_encodings_are_specified
end

def test_initialized_populates_index
@store.experimental_features = true
@executor.execute({ method: "initialized", params: {} })
index = @executor.instance_variable_get(:@index)
refute_empty(index.instance_variable_get(:@entries))
end

def test_initialized_recovers_from_indexing_failures
@store.experimental_features = true
RubyIndexer::Index.any_instance.expects(:index_all).once.raises(StandardError, "boom!")

@executor.execute({ method: "initialized", params: {} })
Expand Down Expand Up @@ -204,6 +202,12 @@ def test_shows_error_if_formatter_set_to_rubocop_but_rubocop_not_available

assert_equal("none", @store.formatter)
refute_empty(@message_queue)

# Account for starting and ending the progress notifications during initialized
assert_equal("window/workDoneProgress/create", @message_queue.pop.message)
assert_equal("$/progress", @message_queue.pop.message)
assert_equal("$/progress", @message_queue.pop.message)

notification = T.must(@message_queue.pop)
assert_equal("window/showMessage", notification.message)
assert_equal(
Expand Down
6 changes: 3 additions & 3 deletions test/integration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -364,11 +364,9 @@ def test_diagnostics
end

def test_workspace_symbol
initialize_lsp(["workspaceSymbol"], experimental_features_enabled: true)
initialize_lsp(["workspaceSymbol"])
open_file_with("class Foo\nend")
# Read the response for the progress indicator notifications
read_response("window/workDoneProgress/create")
read_response("$/progress")
read_response("textDocument/didOpen")

# Populate the index
Expand Down Expand Up @@ -447,6 +445,8 @@ def initialize_lsp(enabled_features, experimental_features_enabled: false)

enabled_providers = enabled_features.map { |feature| FEATURE_TO_PROVIDER[feature] }
assert_equal([:positionEncoding, :textDocumentSync, *enabled_providers], response[:capabilities].keys)
read_response("window/workDoneProgress/create")
read_response("$/progress")
end

def open_file_with(content)
Expand Down
2 changes: 0 additions & 2 deletions test/requests/definition_expectations_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ def run_expectations(source)
position = @__params&.first || { character: 0, line: 0 }

store = RubyLsp::Store.new
store.experimental_features = true
store.set(uri: URI("file:///folder/fake.rb"), source: source, version: 1)
executor = RubyLsp::Executor.new(store, message_queue)

Expand Down Expand Up @@ -58,7 +57,6 @@ def test_jumping_to_default_gems
uri = URI::Generic.from_path(path: path)

store = RubyLsp::Store.new
store.experimental_features = true
store.set(uri: URI("file:///folder/fake.rb"), source: <<~RUBY, version: 1)
Pathname
RUBY
Expand Down