class Solargraph::LanguageServer::Host::Sources
A Host class for managing sources.
Attributes
@return [Mutex]
Public Class Methods
# 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
@return [void]
# File lib/solargraph/language_server/host/sources.rb, line 46 def add_uri(uri) queue.push(uri) @has_uri.signal end
@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
@return [void]
# File lib/solargraph/language_server/host/sources.rb, line 132 def clear open_source_hash.clear end
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 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
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
@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 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
# 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
@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
@return [void]
# File lib/solargraph/language_server/host/sources.rb, line 58 def stop @stopped = true end
# File lib/solargraph/language_server/host/sources.rb, line 19 def stopped? @stopped end
@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 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
@return [Hash]
# File lib/solargraph/language_server/host/sources.rb, line 139 def open_source_hash @open_source_hash ||= {} end
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