Class: Solargraph::LanguageServer::Host::Diagnoser

Inherits:
Object
  • Object
show all
Defined in:
lib/solargraph/language_server/host/diagnoser.rb

Overview

An asynchronous diagnosis reporter.

Instance Method Summary collapse

Constructor Details

#initialize(host) ⇒ Diagnoser

Returns a new instance of Diagnoser.

Parameters:



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.

Parameters:

  • uri (String)


21
22
23
# File 'lib/solargraph/language_server/host/diagnoser.rb', line 21

def schedule uri
  mutex.synchronize { queue.push uri }
end

#startself

Start the diagnosis thread.

Returns:

  • (self)


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

#stopvoid

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.

Returns:

  • (Boolean)


35
36
37
# File 'lib/solargraph/language_server/host/diagnoser.rb', line 35

def stopped?
  @stopped
end

#tickvoid

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.options['diagnostics']
    mutex.synchronize { queue.clear }
    return
  end
  current = mutex.synchronize { queue.shift }
  return if queue.include?(current)
  host.diagnose current
end