module Solargraph::LanguageServer::Host::Dispatch

Methods for associating sources with libraries via URIs.

Public Instance Methods

explicit_library_for(uri) click to toggle source

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]

# File lib/solargraph/language_server/host/dispatch.rb, line 58
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
generic_library() click to toggle source

@return [Library]

# File lib/solargraph/language_server/host/dispatch.rb, line 106
def generic_library
  @generic_library ||= Solargraph::Library.new
end
generic_library_for(uri) click to toggle source

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]

# File lib/solargraph/language_server/host/dispatch.rb, line 99
def generic_library_for uri
  generic_library.attach sources.find(uri)
  generic_library.catalog
  generic_library
end
implicit_library_for(uri) click to toggle source

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]

# File lib/solargraph/language_server/host/dispatch.rb, line 80
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)
      lib.catalog
      return lib
    end
  end
  nil
end
libraries() click to toggle source

@return [Array<Library>]

# File lib/solargraph/language_server/host/dispatch.rb, line 19
def libraries
  @libraries ||= []
end
library_for(uri) click to toggle source

Find the best libary match for the given URI.

@param uri [String] @return [Library]

# File lib/solargraph/language_server/host/dispatch.rb, line 40
def library_for uri
  result = explicit_library_for(uri) ||
    implicit_library_for(uri) ||
    generic_library_for(uri)
  result.attach sources.find(uri) if sources.include?(uri)
  result
end
sources() click to toggle source

@return [Sources]

# File lib/solargraph/language_server/host/dispatch.rb, line 10
def sources
  @sources ||= begin
    src = Sources.new
    src.add_observer self, :update_libraries
    src
  end
end
update_libraries(uri) click to toggle source

The Sources observer callback that merges a source into the host's libraries when it gets updated.

@param uri [String] @return [void]

# File lib/solargraph/language_server/host/dispatch.rb, line 28
def update_libraries uri
  src = sources.find(uri)
  libraries.each do |lib|
    lib.merge src if lib.contain?(src.filename)
  end
  diagnoser.schedule uri
end