class Solargraph::LanguageServer::Host::Diagnoser
An asynchronous diagnosis reporter.
Attributes
host[R]
@return [Host]
mutex[R]
@return [Mutex]
queue[R]
@return [Array]
Public Class Methods
new(host)
click to toggle source
@param host [Host]
# File lib/solargraph/language_server/host/diagnoser.rb, line 9 def initialize host @host = host @mutex = Mutex.new @queue = [] @stopped = true end
Public Instance Methods
schedule(uri)
click to toggle source
Schedule a file to be diagnosed.
@param uri [String] @return [void]
# File lib/solargraph/language_server/host/diagnoser.rb, line 20 def schedule uri mutex.synchronize { queue.push uri } end
start()
click to toggle source
Start the diagnosis thread.
@return [self]
# File lib/solargraph/language_server/host/diagnoser.rb, line 41 def start return unless @stopped @stopped = false Thread.new do until stopped? tick sleep 0.1 end end self end
stop()
click to toggle source
Stop the diagnosis thread.
@return [void]
# File lib/solargraph/language_server/host/diagnoser.rb, line 27 def stop @stopped = true end
stopped?()
click to toggle source
True is the diagnoser is stopped.
@return [Boolean]
# File lib/solargraph/language_server/host/diagnoser.rb, line 34 def stopped? @stopped end
tick()
click to toggle source
Perform diagnoses.
@return [void]
# File lib/solargraph/language_server/host/diagnoser.rb, line 56 def tick return if queue.empty? || host.synchronizing? if !host.options['diagnostics'] mutex.synchronize { queue.clear } return end current = mutex.synchronize { queue.shift } return if queue.include?(current) begin host.diagnose current rescue InvalidOffsetError # @todo This error can occur when the Source is out of sync with # with the ApiMap. It's probably not the best way to handle it, # but it's quick and easy. Logging.logger.warn "Deferring diagnosis due to invalid offset: #{current}" mutex.synchronize { queue.push current } end end