class Solargraph::LanguageServer::Host::Sources

A Host class for managing sources.

Attributes

mutex[R]

@return [Mutex]

Public Class Methods

new() click to toggle source
# File lib/solargraph/language_server/host/sources.rb, line 13
def initialize
  @mutex = Mutex.new
  @stopped = true
  @has_uri = ConditionVariable.new
end

Public Instance Methods

add_uri(uri) click to toggle source

@return [void]

# File lib/solargraph/language_server/host/sources.rb, line 46
def add_uri(uri)
  queue.push(uri)
  @has_uri.signal
end
async_update(uri, updater) click to toggle source

@param uri [String] @param updater [Source::Updater] @return [void]

# File lib/solargraph/language_server/host/sources.rb, line 96
def async_update uri, updater
  src = find(uri)
  mutex.synchronize do
    open_source_hash[uri] = src.start_synchronize(updater)
    add_uri(uri)
  end
  changed
  notify_observers uri
end
clear() click to toggle source

@return [void]

# File lib/solargraph/language_server/host/sources.rb, line 132
def clear
  open_source_hash.clear
end
close(uri) click to toggle source

Close the source with the given URI.

@param uri [String] @return [void]

# File lib/solargraph/language_server/host/sources.rb, line 120
def close uri
  open_source_hash.delete uri
end
find(uri) click to toggle source

Find the source with the given URI.

@raise [FileNotFoundError] if the URI does not match an open source.

@param uri [String] @return [Source]

# File lib/solargraph/language_server/host/sources.rb, line 112
def find uri
  open_source_hash[uri] || raise(Solargraph::FileNotFoundError, "Host could not find #{uri}")
end
include?(uri) click to toggle source

True if a source with given URI is currently open. @param uri [String] @return [Boolean]

# File lib/solargraph/language_server/host/sources.rb, line 127
def include? uri
  open_source_hash.key? uri
end
next_uri() click to toggle source

@return [String]

# File lib/solargraph/language_server/host/sources.rb, line 52
def next_uri
  @has_uri.wait(mutex) if queue.empty?
  queue.shift
end
open(uri, text, version) click to toggle source

Open a source.

@param uri [String] @param text [String] @param version [Integer] @return [Source]

# File lib/solargraph/language_server/host/sources.rb, line 68
def open uri, text, version
  filename = uri_to_file(uri)
  source = Solargraph::Source.new(text, filename, version)
  open_source_hash[uri] = source
end
open_from_disk(uri) click to toggle source
# File lib/solargraph/language_server/host/sources.rb, line 74
def open_from_disk uri
  source = Solargraph::Source.load(UriHelpers.uri_to_file(uri))
  open_source_hash[uri] = source
end
start() click to toggle source

@return [void]

# File lib/solargraph/language_server/host/sources.rb, line 24
def start
  return unless @stopped
  @stopped = false
  Thread.new do
    tick until stopped?
  end
end
stop() click to toggle source

@return [void]

# File lib/solargraph/language_server/host/sources.rb, line 58
def stop
  @stopped = true
end
stopped?() click to toggle source
# File lib/solargraph/language_server/host/sources.rb, line 19
def stopped?
  @stopped
end
tick() click to toggle source

@return [void]

# File lib/solargraph/language_server/host/sources.rb, line 33
def tick
  uri = mutex.synchronize { next_uri }

  return if queue.include?(uri)
  mutex.synchronize do
    nxt = open_source_hash[uri].finish_synchronize
    open_source_hash[uri] = nxt
    changed
    notify_observers uri
  end
end
update(uri, updater) click to toggle source

Update an existing source.

@raise [FileNotFoundError] if the URI does not match an open source.

@param uri [String] @param updater [Source::Updater] @return [Source]

# File lib/solargraph/language_server/host/sources.rb, line 86
def update uri, updater
  src = find(uri)
  mutex.synchronize { open_source_hash[uri] = src.synchronize(updater) }
  changed
  notify_observers uri
end

Private Instance Methods

open_source_hash() click to toggle source

@return [Hash]

# File lib/solargraph/language_server/host/sources.rb, line 139
def open_source_hash
  @open_source_hash ||= {}
end
queue() click to toggle source

An array of source URIs that are waiting to finish synchronizing.

@return [Array<String>]

# File lib/solargraph/language_server/host/sources.rb, line 149
def queue
  @queue ||= []
end