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

Synchronize didOpen and didClose notifications #1901

Merged
merged 1 commit into from
Apr 8, 2024
Merged
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
39 changes: 20 additions & 19 deletions lib/ruby_lsp/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -260,30 +260,31 @@ 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)

# Clear diagnostics for the closed file, so that they no longer appear in the problems tab
send_message(
Notification.new(
method: "textDocument/publishDiagnostics",
params: Interface::PublishDiagnosticsParams.new(uri: uri.to_s, diagnostics: []),
),
)
# Clear diagnostics for the closed file, so that they no longer appear in the problems tab
send_message(
Notification.new(
method: "textDocument/publishDiagnostics",
params: Interface::PublishDiagnosticsParams.new(uri: uri.to_s, diagnostics: []),
),
)
end
end

sig { params(message: T::Hash[Symbol, T.untyped]).void }
Expand Down
Loading