Class: Solargraph::LanguageServer::Host::Diagnoser
- Inherits:
-
Object
- Object
- Solargraph::LanguageServer::Host::Diagnoser
- Defined in:
- lib/solargraph/language_server/host/diagnoser.rb
Overview
An asynchronous diagnosis reporter.
Instance Method Summary collapse
-
#initialize(host) ⇒ Diagnoser
constructor
A new instance of Diagnoser.
-
#schedule(uri) ⇒ void
Schedule a file to be diagnosed.
-
#start ⇒ self
Start the diagnosis thread.
-
#stop ⇒ void
Stop the diagnosis thread.
-
#stopped? ⇒ Boolean
True is the diagnoser is stopped.
-
#tick ⇒ void
Perform diagnoses.
Constructor Details
#initialize(host) ⇒ Diagnoser
Returns a new instance of Diagnoser.
10 11 12 13 14 15 |
# File 'lib/solargraph/language_server/host/diagnoser.rb', line 10 def initialize host @host = host @mutex = Mutex.new @queue = [] @stopped = true end |
Instance Method Details
#schedule(uri) ⇒ void
This method returns an undefined value.
Schedule a file to be diagnosed.
21 22 23 |
# File 'lib/solargraph/language_server/host/diagnoser.rb', line 21 def schedule uri mutex.synchronize { queue.push uri } end |
#start ⇒ self
Start the diagnosis thread.
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/solargraph/language_server/host/diagnoser.rb', line 42 def start return unless @stopped @stopped = false Thread.new do until stopped? tick sleep 0.1 end end self end |
#stop ⇒ void
This method returns an undefined value.
Stop the diagnosis thread.
28 29 30 |
# File 'lib/solargraph/language_server/host/diagnoser.rb', line 28 def stop @stopped = true end |
#stopped? ⇒ Boolean
True is the diagnoser is stopped.
35 36 37 |
# File 'lib/solargraph/language_server/host/diagnoser.rb', line 35 def stopped? @stopped end |
#tick ⇒ void
This method returns an undefined value.
Perform diagnoses.
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/solargraph/language_server/host/diagnoser.rb', line 57 def tick return if queue.empty? || host.synchronizing? if !host.['diagnostics'] mutex.synchronize { queue.clear } return end current = mutex.synchronize { queue.shift } return if queue.include?(current) host.diagnose current end |