Skip to content

Commit

Permalink
Synchronize didOpen and didClose notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
vinistock committed Apr 8, 2024
1 parent aa46c58 commit 6389345
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions lib/ruby_lsp/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -260,22 +260,23 @@ def run_initialized

sig { params(message: T::Hash[Symbol, T.untyped]).void }
def text_document_did_open(message)
text_document = message.dig(:params, :textDocument)
@store.set(
uri: text_document[:uri],
source: text_document[:text],
version: text_document[:version],
encoding: @global_state.encoding,
)
rescue Errno::ENOENT
# If someone re-opens the editor with a file that was deleted or doesn't exist in the current branch, we don't
# want to crash
@mutex.synchronize do
text_document = message.dig(:params, :textDocument)
@store.set(
uri: text_document[:uri],
source: text_document[:text],
version: text_document[:version],
encoding: @global_state.encoding,
)
end
end

sig { params(message: T::Hash[Symbol, T.untyped]).void }
def text_document_did_close(message)
uri = message.dig(:params, :textDocument, :uri)
@store.delete(uri)
@mutex.synchronize do
uri = message.dig(:params, :textDocument, :uri)
@store.delete(uri)
end

# Clear diagnostics for the closed file, so that they no longer appear in the problems tab
send_message(
Expand Down

0 comments on commit 6389345

Please sign in to comment.