Skip to content

Commit ea9961f

Browse files
authored
Merge pull request #356 from puppetlabs/CAT-1595-remove_diagnostic_onClose
(CAT-1595) - Remove diagnostic on textDoucment onDidClose
2 parents 0e156e2 + 23e6ac0 commit ea9961f

File tree

4 files changed

+22
-8
lines changed

4 files changed

+22
-8
lines changed

lib/puppet-languageserver/global_queues/validation_queue.rb

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,21 @@ def execute_job(job_object)
3434
super(job_object)
3535
session_state = session_state_from_connection_id(job_object.connection_id)
3636
document_store = session_state.nil? ? nil : session_state.documents
37-
raise "Document store is not available for connection id #{job_object.connection_id}" if document_store.nil?
37+
raise "Document store is not available for connection id #{job_object.connection_id}" unless document_store
38+
39+
# Check if the document still exists
40+
doc = document_store.get_document(job_object.file_uri)
41+
unless doc
42+
# Send an empty diagnostics message to clear the diagnostics
43+
send_diagnostics(job_object.connection_id, job_object.file_uri, [])
44+
PuppetLanguageServer.log_message(:debug, "#{self.class.name}: Ignoring #{job_object.file_uri} as it is has been removed.")
45+
return
46+
end
3847

3948
# Check if the document is the latest version
4049
content = document_store.document_content(job_object.file_uri, job_object.doc_version)
41-
if content.nil?
42-
PuppetLanguageServer.log_message(:debug, "#{self.class.name}: Ignoring #{job_object.file_uri} as it is not the latest version or has been removed")
50+
unless content
51+
PuppetLanguageServer.log_message(:debug, "#{self.class.name}: Ignoring #{job_object.file_uri} as it is not the latest version.")
4352
return
4453
end
4554

lib/puppet-languageserver/message_handler.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -328,10 +328,11 @@ def notification_textdocument_didopen(client_handler_id, json_rpc_message)
328328
enqueue_validation(file_uri, doc_version, client_handler_id)
329329
end
330330

331-
def notification_textdocument_didclose(_, json_rpc_message)
331+
def notification_textdocument_didclose(client_handler_id, json_rpc_message)
332332
PuppetLanguageServer.log_message(:info, 'Received textDocument/didClose notification.')
333333
file_uri = json_rpc_message.params['textDocument']['uri']
334334
documents.remove_document(file_uri)
335+
enqueue_validation(file_uri, nil, client_handler_id)
335336
end
336337

337338
def notification_textdocument_didchange(client_handler_id, json_rpc_message)
@@ -390,8 +391,7 @@ def unhandled_exception(error, options)
390391

391392
private
392393

393-
def enqueue_validation(file_uri, doc_version, client_handler_id)
394-
options = {}
394+
def enqueue_validation(file_uri, doc_version, client_handler_id, options = {})
395395
if documents.document_type(file_uri) == :puppetfile
396396
options[:resolve_puppetfile] = language_client.use_puppetfile_resolver
397397
options[:puppet_version] = Puppet.version

lib/puppet-languageserver/session_state/document_store.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ def document_content(uri, doc_version = nil)
8686
doc.nil? ? nil : doc.content.clone
8787
end
8888

89+
def get_document(uri)
90+
doc = @documents[uri]
91+
doc.nil? ? nil : doc.content.clone
92+
end
93+
8994
def document_tokens(uri, doc_version = nil)
9095
@doc_mutex.synchronize do
9196
return nil if @documents[uri].nil?

spec/languageserver/unit/puppet-languageserver/global_queues/validation_queue_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,8 @@ def job(file_uri, document_version, connection_id, job_options = {})
176176
allow(PuppetLanguageServer::Puppetfile::ValidationProvider).to receive(:validate).and_raise("PuppetLanguageServer::Puppetfile::ValidationProvider.validate mock should not be called")
177177
end
178178

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

182182
subject.execute(VALIDATE_MISSING_FILENAME, 1, connection_id)
183183
end

0 commit comments

Comments
 (0)