Skip to content

Commit

Permalink
Ignore non-ruby files in file watcher (#1912)
Browse files Browse the repository at this point in the history
Currently there is only a listener for ruby files but that might changein the future.
Addons are also able to register additional file watcher events, config files as an example
  • Loading branch information
Earlopain committed Apr 10, 2024
1 parent a2f9ece commit 9e91813
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/ruby_lsp/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
21 changes: 21 additions & 0 deletions test/server_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 9e91813

Please sign in to comment.