Skip to content
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
4 changes: 2 additions & 2 deletions lib/ruby_lsp/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1051,14 +1051,14 @@ def handle_ruby_file_change(index, file_path, change_type)
load_path_entry = $LOAD_PATH.find { |load_path| file_path.start_with?(load_path) }
uri = URI::Generic.from_path(load_path_entry: load_path_entry, path: file_path)

content = File.read(file_path)

case change_type
when Constant::FileChangeType::CREATED
content = File.read(file_path)
# If we receive a late created notification for a file that has already been claimed by the client, we want to
# handle change for that URI so that the require path tree is updated
@store.key?(uri) ? index.handle_change(uri, content) : index.index_single(uri, content)
when Constant::FileChangeType::CHANGED
content = File.read(file_path)
# We only handle changes on file watched notifications if the client is not the one managing this URI.
# Otherwise, these changes are handled when running the combined requests
index.handle_change(uri, content) unless @store.key?(uri)
Expand Down
22 changes: 22 additions & 0 deletions test/server_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,28 @@ def test_did_change_watched_files_does_not_fail_for_non_existing_files
end
end

def test_did_change_watched_files_handles_deletions
path = File.join(Dir.pwd, "lib", "foo.rb")

@server.global_state.index.expects(:delete).once.with do |uri|
uri.full_path == path
end

uri = URI::Generic.from_path(path: path)

@server.process_message({
method: "workspace/didChangeWatchedFiles",
params: {
changes: [
{
uri: uri,
type: RubyLsp::Constant::FileChangeType::DELETED,
},
],
},
})
end

def test_did_change_watched_files_reports_addon_errors
Class.new(RubyLsp::Addon) do
def activate(global_state, outgoing_queue); end
Expand Down