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
- #diagnoser ⇒ Host::Diagnoser abstract
-
#explicit_library_for(uri) ⇒ Library?
Find an explicit library match for the given URI.
- #generic_library ⇒ Library
-
#generic_library_for(uri) ⇒ Library
Get a generic library for the given URI and attach the corresponding source.
-
#implicit_library_for(uri) ⇒ Library?
Find an implicit library match for the given URI.
- #libraries ⇒ ::Array<Library>
-
#library_for(uri) ⇒ Library
Find the best libary match for the given URI.
- #options ⇒ Object
- #sources ⇒ Sources
- #update(progress) ⇒ void
-
#update_libraries(uri) ⇒ void
The Sources observer callback that merges a source into the host’s libraries when it gets updated.
Instance Method Details
#diagnoser ⇒ Host::Diagnoser
11 12 13 |
# File 'lib/solargraph/language_server/host/dispatch.rb', line 11 def diagnoser raise NotImplementedError, 'Host::Dispatch requires a diagnoser method' end |
#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.
65 66 67 68 69 70 71 72 73 74 |
# 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 |
#generic_library ⇒ Library
115 116 117 118 |
# File 'lib/solargraph/language_server/host/dispatch.rb', line 115 def generic_library @generic_library ||= Solargraph::Library.new(Solargraph::Workspace.new('', nil, ), nil) .tap { |lib| lib.add_observer self } end |
#generic_library_for(uri) ⇒ Library
Get a generic library for the given URI and attach the corresponding source.
109 110 111 112 |
# File 'lib/solargraph/language_server/host/dispatch.rb', line 109 def generic_library_for uri generic_library.attach sources.find(uri) 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.
87 88 89 90 91 92 93 94 95 96 |
# 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 |
#libraries ⇒ ::Array<Library>
25 26 27 |
# File 'lib/solargraph/language_server/host/dispatch.rb', line 25 def libraries @libraries ||= [] end |
#library_for(uri) ⇒ Library
Find the best libary match for the given URI.
46 47 48 49 50 51 52 53 |
# 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 |
#options ⇒ Object
98 99 100 |
# File 'lib/solargraph/language_server/host/dispatch.rb', line 98 def @options ||= {}.freeze end |
#sources ⇒ Sources
16 17 18 19 20 21 22 |
# 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 |
#update(progress) ⇒ void
This method returns an undefined value.
122 123 124 |
# File 'lib/solargraph/language_server/host/dispatch.rb', line 122 def update progress progress&.send(self) 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.
34 35 36 37 38 39 40 |
# 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 |