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

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

Instance Method Summary collapse

Constructor Details

#initialize(host) ⇒ Diagnoser

Returns a new instance of Diagnoser.



5
6
7
8
9
10
# File 'lib/solargraph/language_server/host/diagnoser.rb', line 5

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)


16
17
18
# File 'lib/solargraph/language_server/host/diagnoser.rb', line 16

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

#startself

Start the diagnosis thread.

Returns:

  • (self)


37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/solargraph/language_server/host/diagnoser.rb', line 37

def start
  return unless @stopped
  @stopped = false
  Thread.new do
    until stopped?
      sleep 0.1
      next if queue.empty? || host.synchronizing?
      if !host.options['diagnostics']
        mutex.synchronize { queue.clear }
        next
      end
      current = nil
      mutex.synchronize { current = queue.shift }
      next if queue.include?(current)
      host.diagnose current
      sleep 0.5
    end
  end
  self
end

#stopvoid

This method returns an undefined value.

Stop the diagnosis thread.



23
24
25
# File 'lib/solargraph/language_server/host/diagnoser.rb', line 23

def stop
  @stopped = true
end

#stopped?Boolean

True is the diagnoser is stopped.

Returns:

  • (Boolean)


30
31
32
# File 'lib/solargraph/language_server/host/diagnoser.rb', line 30

def stopped?
  @stopped
end