Module: Solargraph::LanguageServer::Host::Dispatch

Included in:
Solargraph::LanguageServer::Host
Defined in:
lib/solargraph/language_server/host/dispatch.rb

Overview

Methods for associating sources with libraries via URIs.

Instance Method Summary collapse

Instance Method Details

#explicit_library_for(uri) ⇒ Library?

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.

Raises:


56
57
58
59
60
61
62
63
64
65
# File 'lib/solargraph/language_server/host/dispatch.rb', line 56

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_libraryLibrary


104
105
106
# File 'lib/solargraph/language_server/host/dispatch.rb', line 104

def generic_library
  @generic_library ||= Solargraph::Library.new
end

#generic_library_for(uri) ⇒ Library

Get a generic library for the given URI and attach the corresponding source.

Raises:


97
98
99
100
101
# File 'lib/solargraph/language_server/host/dispatch.rb', line 97

def generic_library_for uri
  generic_library.attach sources.find(uri)
  generic_library.catalog
  generic_library
end

#implicit_library_for(uri) ⇒ Library?

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.

Raises:


78
79
80
81
82
83
84
85
86
87
88
# File 'lib/solargraph/language_server/host/dispatch.rb', line 78

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

#librariesArray<Library>


17
18
19
# File 'lib/solargraph/language_server/host/dispatch.rb', line 17

def libraries
  @libraries ||= []
end

#library_for(uri) ⇒ Library

Find the best libary match for the given URI.


38
39
40
41
42
43
44
# File 'lib/solargraph/language_server/host/dispatch.rb', line 38

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

#sourcesSources


8
9
10
11
12
13
14
# File 'lib/solargraph/language_server/host/dispatch.rb', line 8

def sources
  @sources ||= begin
    src = Sources.new
    src.add_observer self, :update_libraries
    src
  end
end

#update_libraries(uri) ⇒ void

This method returns an undefined value.

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


26
27
28
29
30
31
32
# File 'lib/solargraph/language_server/host/dispatch.rb', line 26

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