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:


8
9
10
11
12
13
# File 'lib/solargraph/language_server/host/diagnoser.rb', line 8

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)

19
20
21
# File 'lib/solargraph/language_server/host/diagnoser.rb', line 19

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

#startself

Start the diagnosis thread.

Returns:

  • (self)

40
41
42
43
44
45
46
47
48
49
50
# File 'lib/solargraph/language_server/host/diagnoser.rb', line 40

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.


26
27
28
# File 'lib/solargraph/language_server/host/diagnoser.rb', line 26

def stop
  @stopped = true
end

#stopped?Boolean

True is the diagnoser is stopped.

Returns:

  • (Boolean)

33
34
35
# File 'lib/solargraph/language_server/host/diagnoser.rb', line 33

def stopped?
  @stopped
end

#tickvoid

This method returns an undefined value.

Perform diagnoses.


55
56
57
58
59
60
61
62
63
64
# File 'lib/solargraph/language_server/host/diagnoser.rb', line 55

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