diff --git a/lib/ruby_lsp/server.rb b/lib/ruby_lsp/server.rb index b09341381..66c136efa 100644 --- a/lib/ruby_lsp/server.rb +++ b/lib/ruby_lsp/server.rb @@ -610,6 +610,7 @@ def workspace_did_change_watched_files(message) uri = URI(change[:uri]) file_path = uri.to_standardized_path next if file_path.nil? || File.directory?(file_path) + next unless file_path.end_with?(".rb") load_path_entry = $LOAD_PATH.find { |load_path| file_path.start_with?(load_path) } indexable = RubyIndexer::IndexablePath.new(load_path_entry, file_path) diff --git a/test/server_test.rb b/test/server_test.rb index 152ca8db6..278f95e99 100644 --- a/test/server_test.rb +++ b/test/server_test.rb @@ -474,6 +474,27 @@ def test_backtrace_is_printed_to_stderr_on_exceptions assert_match(%r{ruby-lsp/lib/ruby_lsp/server\.rb:\d+:in `process_message'}, stderr) end + def test_changed_file_only_indexes_ruby + @server.global_state.index.expects(:index_single).once.with do |indexable| + indexable.full_path == "/foo.rb" + end + @server.process_message({ + method: "workspace/didChangeWatchedFiles", + params: { + changes: [ + { + uri: URI("file:///foo.rb"), + type: RubyLsp::Constant::FileChangeType::CREATED, + }, + { + uri: URI("file:///.rubocop.yml"), + type: RubyLsp::Constant::FileChangeType::CREATED, + }, + ], + }, + }) + end + private def with_uninstalled_rubocop(&block)