Class: PuppetLanguageServer::GlobalQueues::ValidationQueue
- Inherits:
-
SingleInstanceQueue
- Object
- SingleInstanceQueue
- PuppetLanguageServer::GlobalQueues::ValidationQueue
- Defined in:
- lib/puppet-languageserver/global_queues/validation_queue.rb
Overview
Class for enqueing and running document level validation asynchronously
Uses a single instance queue so only the latest document needs to be processed. It will also ignore sending back validation results to the client if the document is updated during the validation process
Instance Method Summary collapse
Methods inherited from SingleInstanceQueue
#drain_queue, #enqueue, #enqueue_job, #execute, #initialize, #new_job, #reset_queue
Constructor Details
This class inherits a constructor from PuppetLanguageServer::GlobalQueues::SingleInstanceQueue
Instance Method Details
#execute_job(job_object) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/puppet-languageserver/global_queues/validation_queue.rb', line 33 def execute_job(job_object) super 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}" 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.(: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) unless content PuppetLanguageServer.(:debug, "#{self.class.name}: Ignoring #{job_object.file_uri} as it is not the latest version.") return end # Perform validation = job_object..dup results = case document_store.document_type(job_object.file_uri) when :manifest [:tasks_mode] = document_store.plan_file?(job_object.file_uri) PuppetLanguageServer::Manifest::ValidationProvider.validate(session_state, content, ) when :epp PuppetLanguageServer::Epp::ValidationProvider.validate(content) when :puppetfile [:document_uri] = job_object.file_uri PuppetLanguageServer::Puppetfile::ValidationProvider.validate(content, ) else [] end # Because this may be asynchronous it's possible the user has edited the document while we're performing validation. # Check if the document is still latest version and ignore the results if it's no longer the latest current_version = document_store.document_version(job_object.file_uri) if current_version != job_object.doc_version PuppetLanguageServer.(:debug, "ValidationQueue Thread: Ignoring #{job_object.file_uri} as has changed version from #{job_object.doc_version} to #{current_version}") return end # Send the response send_diagnostics(job_object.connection_id, job_object.file_uri, results) end |
#job_class ⇒ Object
29 30 31 |
# File 'lib/puppet-languageserver/global_queues/validation_queue.rb', line 29 def job_class ValidationQueueJob end |
#max_queue_threads ⇒ Object
25 26 27 |
# File 'lib/puppet-languageserver/global_queues/validation_queue.rb', line 25 def max_queue_threads 1 end |