module Solargraph::LanguageServer::Host::Dispatch
Methods for associating sources with libraries via URIs.
Public Instance Methods
Source
# File lib/solargraph/language_server/host/dispatch.rb, line 11 def diagnoser raise NotImplementedError, 'Host::Dispatch requires a diagnoser method' end
@abstract @return [Host::Diagnoser]
Source
# File lib/solargraph/language_server/host/dispatch.rb, line 65 def explicit_library_for uri filename = UriHelpers.uri_to_file(uri) libraries.each do |lib| if lib.contain?(filename) lib.attach sources.find(uri) if sources.include?(uri) return lib end end nil end
Find an explicit library match for the given URI. An explicit match means the libary’s workspace includes the file.
If a matching library is found, the source corresponding to the URI gets attached to it.
@raise [FileNotFoundError] if the source could not be attached.
@param uri [String] @return [Library, nil]
Source
# File lib/solargraph/language_server/host/dispatch.rb, line 116 def generic_library @generic_library ||= Solargraph::Library.new(Solargraph::Workspace.new('', nil, options), nil) .tap { |lib| lib.add_observer self } end
@return [Library]
Source
# File lib/solargraph/language_server/host/dispatch.rb, line 110 def generic_library_for uri generic_library.attach sources.find(uri) generic_library end
Get a generic library for the given URI and attach the corresponding source.
@raise [FileNotFoundError] if the source could not be attached.
@param uri [String] @return [Library]
Source
# File lib/solargraph/language_server/host/dispatch.rb, line 87 def implicit_library_for uri filename = UriHelpers.uri_to_file(uri) libraries.each do |lib| if filename.start_with?(lib.workspace.directory) lib.attach sources.find(uri) return lib end end nil end
Find an implicit library match for the given URI. An implicit match means the file is located inside the library’s workspace directory, regardless of whether the workspace is configured to include it.
If a matching library is found, the source corresponding to the URI gets attached to it.
@raise [FileNotFoundError] if the source could not be attached.
@param uri [String] @return [Library, nil]
Source
# File lib/solargraph/language_server/host/dispatch.rb, line 25 def libraries @libraries ||= [] end
@return [::Array<Library>]
Source
# File lib/solargraph/language_server/host/dispatch.rb, line 46 def library_for uri result = explicit_library_for(uri) || implicit_library_for(uri) || generic_library_for(uri) # previous library for already call attach. avoid call twice # result.attach sources.find(uri) if sources.include?(uri) result end
Find the best libary match for the given URI.
@param uri [String] @return [Library]
Source
# File lib/solargraph/language_server/host/dispatch.rb, line 99 def options @options ||= {}.freeze end
@return [Hash{String => undefined}]
Source
# File lib/solargraph/language_server/host/dispatch.rb, line 16 def sources @sources ||= begin src = Sources.new src.add_observer self, :update_libraries src end end
@return [Sources]
Source
# File lib/solargraph/language_server/host/dispatch.rb, line 124 def update progress progress&.send(self) end
@param library [Solargraph::Library] @param progress [Solargraph::LanguageServer::Progress, nil] @return [void]
Source
# File lib/solargraph/language_server/host/dispatch.rb, line 34 def update_libraries uri src = sources.find(uri) using = libraries.select { |lib| lib.contain?(src.filename) } using.push library_for(uri) if using.empty? using.each { |lib| lib.merge src } diagnoser.schedule uri end
The Sources observer callback that merges a source into the host’s libraries when it gets updated.
@param uri [String] @return [void]