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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

(CAT-1595) - Remove diagnostic on textDoucment onDidClose #356

Merged
merged 2 commits into from
Nov 24, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 12 additions & 3 deletions lib/puppet-languageserver/global_queues/validation_queue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,21 @@ def execute_job(job_object)
super(job_object)
session_state = session_state_from_connection_id(job_object.connection_id)
document_store = session_state.nil? ? nil : session_state.documents
raise "Document store is not available for connection id #{job_object.connection_id}" if document_store.nil?
raise "Document store is not available for connection id #{job_object.connection_id}" unless document_store

# Check if the document still exists
doc = document_store.get_document(job_object.file_uri)
unless doc
# Send an empty diagnostics message to clear the diagnostics
send_diagnostics(job_object.connection_id, job_object.file_uri, [])
PuppetLanguageServer.log_message(:debug, "#{self.class.name}: Ignoring #{job_object.file_uri} as it is has been removed.")
return
end

# Check if the document is the latest version
content = document_store.document_content(job_object.file_uri, job_object.doc_version)
if content.nil?
PuppetLanguageServer.log_message(:debug, "#{self.class.name}: Ignoring #{job_object.file_uri} as it is not the latest version or has been removed")
unless content
PuppetLanguageServer.log_message(:debug, "#{self.class.name}: Ignoring #{job_object.file_uri} as it is not the latest version.")
return
end

Expand Down
6 changes: 3 additions & 3 deletions lib/puppet-languageserver/message_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -328,10 +328,11 @@ def notification_textdocument_didopen(client_handler_id, json_rpc_message)
enqueue_validation(file_uri, doc_version, client_handler_id)
end

def notification_textdocument_didclose(_, json_rpc_message)
def notification_textdocument_didclose(client_handler_id, json_rpc_message)
PuppetLanguageServer.log_message(:info, 'Received textDocument/didClose notification.')
file_uri = json_rpc_message.params['textDocument']['uri']
documents.remove_document(file_uri)
enqueue_validation(file_uri, nil, client_handler_id)
end

def notification_textdocument_didchange(client_handler_id, json_rpc_message)
Expand Down Expand Up @@ -390,8 +391,7 @@ def unhandled_exception(error, options)

private

def enqueue_validation(file_uri, doc_version, client_handler_id)
options = {}
def enqueue_validation(file_uri, doc_version, client_handler_id, options = {})
if documents.document_type(file_uri) == :puppetfile
options[:resolve_puppetfile] = language_client.use_puppetfile_resolver
options[:puppet_version] = Puppet.version
Expand Down
5 changes: 5 additions & 0 deletions lib/puppet-languageserver/session_state/document_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ def document_content(uri, doc_version = nil)
doc.nil? ? nil : doc.content.clone
end

def get_document(uri)
doc = @documents[uri]
doc.nil? ? nil : doc.content.clone
end

def document_tokens(uri, doc_version = nil)
@doc_mutex.synchronize do
return nil if @documents[uri].nil?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ def job(file_uri, document_version, connection_id, job_options = {})
allow(PuppetLanguageServer::Puppetfile::ValidationProvider).to receive(:validate).and_raise("PuppetLanguageServer::Puppetfile::ValidationProvider.validate mock should not be called")
end

it 'should not send validation results for documents that do not exist' do
expect(subject).to_not receive(:send_diagnostics)
it 'should send empty validation results for documents that do not exist' do
expect(subject).to receive(:send_diagnostics).with(connection_id, VALIDATE_MISSING_FILENAME, [])

subject.execute(VALIDATE_MISSING_FILENAME, 1, connection_id)
end
Expand Down