solargraph 0.32.1 → 0.32.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.rubocop.yml +6 -0
- data/.travis.yml +25 -0
- data/EXAMPLES.md +76 -0
- data/Gemfile +3 -0
- data/LANGUAGE_SERVER.md +51 -0
- data/LICENSE +21 -0
- data/OVERVIEW.md +37 -0
- data/README.md +106 -0
- data/Rakefile +14 -0
- data/SERVER.md +95 -0
- data/bin/solargraph +0 -0
- data/bin/solargraph-runtime +5 -5
- data/lib/solargraph.rb +54 -54
- data/lib/solargraph/api_map.rb +659 -659
- data/lib/solargraph/api_map/cache.rb +49 -49
- data/lib/solargraph/api_map/source_to_yard.rb +67 -67
- data/lib/solargraph/api_map/store.rb +201 -201
- data/lib/solargraph/bundle.rb +24 -24
- data/lib/solargraph/complex_type.rb +150 -150
- data/lib/solargraph/complex_type/type_methods.rb +124 -124
- data/lib/solargraph/complex_type/unique_type.rb +44 -44
- data/lib/solargraph/core_fills.rb +37 -37
- data/lib/solargraph/diagnostics.rb +52 -52
- data/lib/solargraph/diagnostics/base.rb +20 -20
- data/lib/solargraph/diagnostics/require_not_found.rb +28 -28
- data/lib/solargraph/diagnostics/rubocop.rb +98 -98
- data/lib/solargraph/diagnostics/rubocop_helpers.rb +46 -46
- data/lib/solargraph/diagnostics/type_not_defined.rb +108 -108
- data/lib/solargraph/diagnostics/update_errors.rb +38 -38
- data/lib/solargraph/language_server/completion_item_kinds.rb +33 -33
- data/lib/solargraph/language_server/error_codes.rb +18 -18
- data/lib/solargraph/language_server/host.rb +684 -681
- data/lib/solargraph/language_server/host/cataloger.rb +54 -79
- data/lib/solargraph/language_server/host/diagnoser.rb +80 -80
- data/lib/solargraph/language_server/host/dispatch.rb +112 -113
- data/lib/solargraph/language_server/host/sources.rb +138 -138
- data/lib/solargraph/language_server/message.rb +90 -90
- data/lib/solargraph/language_server/message/base.rb +83 -83
- data/lib/solargraph/language_server/message/completion_item/resolve.rb +40 -40
- data/lib/solargraph/language_server/message/exit_notification.rb +11 -11
- data/lib/solargraph/language_server/message/extended.rb +19 -19
- data/lib/solargraph/language_server/message/extended/check_gem_version.rb +86 -86
- data/lib/solargraph/language_server/message/extended/document.rb +18 -18
- data/lib/solargraph/language_server/message/extended/document_gems.rb +30 -30
- data/lib/solargraph/language_server/message/extended/environment.rb +20 -20
- data/lib/solargraph/language_server/message/extended/search.rb +18 -18
- data/lib/solargraph/language_server/message/initialize.rb +141 -141
- data/lib/solargraph/language_server/message/initialized.rb +23 -23
- data/lib/solargraph/language_server/message/shutdown.rb +11 -11
- data/lib/solargraph/language_server/message/text_document.rb +25 -25
- data/lib/solargraph/language_server/message/text_document/completion.rb +51 -51
- data/lib/solargraph/language_server/message/text_document/definition.rb +18 -18
- data/lib/solargraph/language_server/message/text_document/did_change.rb +13 -13
- data/lib/solargraph/language_server/message/text_document/document_symbol.rb +21 -21
- data/lib/solargraph/language_server/message/text_document/folding_range.rb +24 -24
- data/lib/solargraph/language_server/message/text_document/formatting.rb +50 -50
- data/lib/solargraph/language_server/message/text_document/hover.rb +31 -31
- data/lib/solargraph/language_server/message/text_document/on_type_formatting.rb +32 -32
- data/lib/solargraph/language_server/message/text_document/prepare_rename.rb +9 -9
- data/lib/solargraph/language_server/message/text_document/references.rb +14 -14
- data/lib/solargraph/language_server/message/text_document/rename.rb +17 -17
- data/lib/solargraph/language_server/message/text_document/signature_help.rb +19 -19
- data/lib/solargraph/language_server/message/workspace.rb +12 -12
- data/lib/solargraph/language_server/message/workspace/did_change_configuration.rb +29 -29
- data/lib/solargraph/language_server/message/workspace/did_change_watched_files.rb +29 -27
- data/lib/solargraph/language_server/message/workspace/did_change_workspace_folders.rb +24 -24
- data/lib/solargraph/language_server/message/workspace/workspace_symbol.rb +21 -21
- data/lib/solargraph/language_server/request.rb +22 -22
- data/lib/solargraph/language_server/symbol_kinds.rb +34 -34
- data/lib/solargraph/language_server/transport.rb +11 -11
- data/lib/solargraph/language_server/transport/adapter.rb +60 -60
- data/lib/solargraph/language_server/transport/data_reader.rb +66 -66
- data/lib/solargraph/language_server/uri_helpers.rb +25 -25
- data/lib/solargraph/library.rb +421 -419
- data/lib/solargraph/live_map.rb +126 -126
- data/lib/solargraph/live_map/cache.rb +38 -38
- data/lib/solargraph/location.rb +31 -31
- data/lib/solargraph/logging.rb +25 -25
- data/lib/solargraph/page.rb +68 -68
- data/lib/solargraph/pin.rb +50 -50
- data/lib/solargraph/pin/attribute.rb +41 -41
- data/lib/solargraph/pin/base.rb +280 -280
- data/lib/solargraph/pin/base_method.rb +76 -76
- data/lib/solargraph/pin/base_variable.rb +72 -72
- data/lib/solargraph/pin/block.rb +32 -32
- data/lib/solargraph/pin/block_parameter.rb +103 -103
- data/lib/solargraph/pin/class_variable.rb +9 -9
- data/lib/solargraph/pin/constant.rb +30 -30
- data/lib/solargraph/pin/conversions.rb +79 -79
- data/lib/solargraph/pin/documenting.rb +41 -41
- data/lib/solargraph/pin/duck_method.rb +14 -14
- data/lib/solargraph/pin/global_variable.rb +9 -9
- data/lib/solargraph/pin/instance_variable.rb +9 -9
- data/lib/solargraph/pin/keyword.rb +17 -17
- data/lib/solargraph/pin/local_variable.rb +23 -23
- data/lib/solargraph/pin/localized.rb +22 -22
- data/lib/solargraph/pin/method.rb +126 -126
- data/lib/solargraph/pin/method_alias.rb +30 -30
- data/lib/solargraph/pin/method_parameter.rb +40 -40
- data/lib/solargraph/pin/namespace.rb +54 -54
- data/lib/solargraph/pin/plugin/method.rb +25 -25
- data/lib/solargraph/pin/proxy_type.rb +35 -35
- data/lib/solargraph/pin/reference.rb +22 -22
- data/lib/solargraph/pin/reference/extend.rb +11 -11
- data/lib/solargraph/pin/reference/include.rb +11 -11
- data/lib/solargraph/pin/reference/require.rb +15 -15
- data/lib/solargraph/pin/reference/superclass.rb +11 -11
- data/lib/solargraph/pin/symbol.rb +44 -44
- data/lib/solargraph/pin/yard_pin.rb +10 -10
- data/lib/solargraph/pin/yard_pin/constant.rb +14 -14
- data/lib/solargraph/pin/yard_pin/method.rb +35 -35
- data/lib/solargraph/pin/yard_pin/namespace.rb +19 -19
- data/lib/solargraph/pin/yard_pin/yard_mixin.rb +14 -14
- data/lib/solargraph/plugin.rb +8 -8
- data/lib/solargraph/plugin/base.rb +41 -41
- data/lib/solargraph/plugin/canceler.rb +11 -11
- data/lib/solargraph/plugin/process.rb +172 -172
- data/lib/solargraph/plugin/runtime.rb +134 -134
- data/lib/solargraph/position.rb +110 -110
- data/lib/solargraph/range.rb +83 -83
- data/lib/solargraph/server_methods.rb +14 -14
- data/lib/solargraph/shell.rb +102 -102
- data/lib/solargraph/source.rb +521 -521
- data/lib/solargraph/source/chain.rb +120 -120
- data/lib/solargraph/source/chain/call.rb +107 -107
- data/lib/solargraph/source/chain/class_variable.rb +11 -11
- data/lib/solargraph/source/chain/constant.rb +30 -30
- data/lib/solargraph/source/chain/global_variable.rb +11 -11
- data/lib/solargraph/source/chain/head.rb +33 -33
- data/lib/solargraph/source/chain/instance_variable.rb +11 -11
- data/lib/solargraph/source/chain/link.rb +33 -33
- data/lib/solargraph/source/chain/literal.rb +21 -21
- data/lib/solargraph/source/chain/variable.rb +11 -11
- data/lib/solargraph/source/change.rb +77 -77
- data/lib/solargraph/source/cursor.rb +157 -157
- data/lib/solargraph/source/node_chainer.rb +96 -96
- data/lib/solargraph/source/node_methods.rb +225 -225
- data/lib/solargraph/source/source_chainer.rb +183 -183
- data/lib/solargraph/source_map.rb +169 -169
- data/lib/solargraph/source_map/clip.rb +145 -145
- data/lib/solargraph/source_map/completion.rb +21 -21
- data/lib/solargraph/source_map/mapper.rb +149 -149
- data/lib/solargraph/source_map/node_processor.rb +78 -78
- data/lib/solargraph/source_map/node_processor/alias_node.rb +19 -19
- data/lib/solargraph/source_map/node_processor/args_node.rb +28 -28
- data/lib/solargraph/source_map/node_processor/base.rb +68 -68
- data/lib/solargraph/source_map/node_processor/begin_node.rb +11 -11
- data/lib/solargraph/source_map/node_processor/block_node.rb +14 -14
- data/lib/solargraph/source_map/node_processor/casgn_node.rb +14 -14
- data/lib/solargraph/source_map/node_processor/cvasgn_node.rb +14 -14
- data/lib/solargraph/source_map/node_processor/def_node.rb +54 -54
- data/lib/solargraph/source_map/node_processor/defs_node.rb +21 -21
- data/lib/solargraph/source_map/node_processor/gvasgn_node.rb +12 -12
- data/lib/solargraph/source_map/node_processor/ivasgn_node.rb +18 -18
- data/lib/solargraph/source_map/node_processor/lvasgn_node.rb +16 -16
- data/lib/solargraph/source_map/node_processor/namespace_node.rb +26 -26
- data/lib/solargraph/source_map/node_processor/orasgn_node.rb +12 -12
- data/lib/solargraph/source_map/node_processor/sclass_node.rb +11 -11
- data/lib/solargraph/source_map/node_processor/send_node.rb +162 -162
- data/lib/solargraph/source_map/node_processor/sym_node.rb +11 -11
- data/lib/solargraph/source_map/region.rb +58 -58
- data/lib/solargraph/version.rb +3 -3
- data/lib/solargraph/views/environment.erb +53 -53
- data/lib/solargraph/workspace.rb +183 -183
- data/lib/solargraph/workspace/config.rb +170 -170
- data/lib/solargraph/yard_map.rb +298 -298
- data/lib/solargraph/yard_map/cache.rb +17 -17
- data/lib/solargraph/yard_map/core_docs.rb +163 -163
- data/lib/solargraph/yard_map/core_gen.rb +76 -76
- data/lib/yard-coregen.rb +16 -16
- data/lib/yard-solargraph.rb +18 -18
- data/solargraph.gemspec +37 -0
- data/travis-bundler.rb +10 -0
- metadata +19 -6
@@ -1,79 +1,54 @@
|
|
1
|
-
module Solargraph
|
2
|
-
module LanguageServer
|
3
|
-
class Host
|
4
|
-
# An asynchronous library cataloging handler.
|
5
|
-
#
|
6
|
-
class Cataloger
|
7
|
-
def initialize host
|
8
|
-
@host = host
|
9
|
-
@
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
#
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
#
|
28
|
-
#
|
29
|
-
|
30
|
-
|
31
|
-
@stopped =
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
#
|
42
|
-
#
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
# Perform cataloging.
|
56
|
-
#
|
57
|
-
# @return [void]
|
58
|
-
def tick
|
59
|
-
return if pings.empty?
|
60
|
-
mutex.synchronize do
|
61
|
-
lib = pings.shift
|
62
|
-
lib.catalog unless pings.include?(lib)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
private
|
67
|
-
|
68
|
-
# @return [Host]
|
69
|
-
attr_reader :host
|
70
|
-
|
71
|
-
# @return [Mutex]
|
72
|
-
attr_reader :mutex
|
73
|
-
|
74
|
-
# @return [Array]
|
75
|
-
attr_reader :pings
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
1
|
+
module Solargraph
|
2
|
+
module LanguageServer
|
3
|
+
class Host
|
4
|
+
# An asynchronous library cataloging handler.
|
5
|
+
#
|
6
|
+
class Cataloger
|
7
|
+
def initialize host
|
8
|
+
@host = host
|
9
|
+
@stopped = true
|
10
|
+
end
|
11
|
+
|
12
|
+
# Stop the catalog thread.
|
13
|
+
#
|
14
|
+
# @return [void]
|
15
|
+
def stop
|
16
|
+
@stopped = true
|
17
|
+
end
|
18
|
+
|
19
|
+
# True if the cataloger is stopped.
|
20
|
+
#
|
21
|
+
# @return [Boolean]
|
22
|
+
def stopped?
|
23
|
+
@stopped
|
24
|
+
end
|
25
|
+
|
26
|
+
# Start the catalog thread.
|
27
|
+
#
|
28
|
+
# @return [void]
|
29
|
+
def start
|
30
|
+
return unless stopped?
|
31
|
+
@stopped = false
|
32
|
+
Thread.new do
|
33
|
+
until stopped?
|
34
|
+
tick
|
35
|
+
sleep 0.01
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
# Perform cataloging.
|
41
|
+
#
|
42
|
+
# @return [void]
|
43
|
+
def tick
|
44
|
+
host.catalog
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
# @return [Host]
|
50
|
+
attr_reader :host
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -1,80 +1,80 @@
|
|
1
|
-
module Solargraph
|
2
|
-
module LanguageServer
|
3
|
-
class Host
|
4
|
-
# An asynchronous diagnosis reporter.
|
5
|
-
#
|
6
|
-
class Diagnoser
|
7
|
-
# @param host [Host]
|
8
|
-
def initialize host
|
9
|
-
@host = host
|
10
|
-
@mutex = Mutex.new
|
11
|
-
@queue = []
|
12
|
-
@stopped = true
|
13
|
-
end
|
14
|
-
|
15
|
-
# Schedule a file to be diagnosed.
|
16
|
-
#
|
17
|
-
# @param uri [String]
|
18
|
-
# @return [void]
|
19
|
-
def schedule uri
|
20
|
-
mutex.synchronize { queue.push uri }
|
21
|
-
end
|
22
|
-
|
23
|
-
# Stop the diagnosis thread.
|
24
|
-
#
|
25
|
-
# @return [void]
|
26
|
-
def stop
|
27
|
-
@stopped = true
|
28
|
-
end
|
29
|
-
|
30
|
-
# True is the diagnoser is stopped.
|
31
|
-
#
|
32
|
-
# @return [Boolean]
|
33
|
-
def stopped?
|
34
|
-
@stopped
|
35
|
-
end
|
36
|
-
|
37
|
-
# Start the diagnosis thread.
|
38
|
-
#
|
39
|
-
# @return [self]
|
40
|
-
def start
|
41
|
-
return unless @stopped
|
42
|
-
@stopped = false
|
43
|
-
Thread.new do
|
44
|
-
until stopped?
|
45
|
-
tick
|
46
|
-
sleep 0.1
|
47
|
-
end
|
48
|
-
end
|
49
|
-
self
|
50
|
-
end
|
51
|
-
|
52
|
-
# Perform diagnoses.
|
53
|
-
#
|
54
|
-
# @return [void]
|
55
|
-
def tick
|
56
|
-
return if queue.empty? || host.synchronizing?
|
57
|
-
if !host.options['diagnostics']
|
58
|
-
mutex.synchronize { queue.clear }
|
59
|
-
return
|
60
|
-
end
|
61
|
-
current = nil
|
62
|
-
mutex.synchronize { current = queue.shift }
|
63
|
-
return if queue.include?(current)
|
64
|
-
host.diagnose current
|
65
|
-
end
|
66
|
-
|
67
|
-
private
|
68
|
-
|
69
|
-
# @return [Host]
|
70
|
-
attr_reader :host
|
71
|
-
|
72
|
-
# @return [Mutex]
|
73
|
-
attr_reader :mutex
|
74
|
-
|
75
|
-
# @return [Array]
|
76
|
-
attr_reader :queue
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
1
|
+
module Solargraph
|
2
|
+
module LanguageServer
|
3
|
+
class Host
|
4
|
+
# An asynchronous diagnosis reporter.
|
5
|
+
#
|
6
|
+
class Diagnoser
|
7
|
+
# @param host [Host]
|
8
|
+
def initialize host
|
9
|
+
@host = host
|
10
|
+
@mutex = Mutex.new
|
11
|
+
@queue = []
|
12
|
+
@stopped = true
|
13
|
+
end
|
14
|
+
|
15
|
+
# Schedule a file to be diagnosed.
|
16
|
+
#
|
17
|
+
# @param uri [String]
|
18
|
+
# @return [void]
|
19
|
+
def schedule uri
|
20
|
+
mutex.synchronize { queue.push uri }
|
21
|
+
end
|
22
|
+
|
23
|
+
# Stop the diagnosis thread.
|
24
|
+
#
|
25
|
+
# @return [void]
|
26
|
+
def stop
|
27
|
+
@stopped = true
|
28
|
+
end
|
29
|
+
|
30
|
+
# True is the diagnoser is stopped.
|
31
|
+
#
|
32
|
+
# @return [Boolean]
|
33
|
+
def stopped?
|
34
|
+
@stopped
|
35
|
+
end
|
36
|
+
|
37
|
+
# Start the diagnosis thread.
|
38
|
+
#
|
39
|
+
# @return [self]
|
40
|
+
def start
|
41
|
+
return unless @stopped
|
42
|
+
@stopped = false
|
43
|
+
Thread.new do
|
44
|
+
until stopped?
|
45
|
+
tick
|
46
|
+
sleep 0.1
|
47
|
+
end
|
48
|
+
end
|
49
|
+
self
|
50
|
+
end
|
51
|
+
|
52
|
+
# Perform diagnoses.
|
53
|
+
#
|
54
|
+
# @return [void]
|
55
|
+
def tick
|
56
|
+
return if queue.empty? || host.synchronizing?
|
57
|
+
if !host.options['diagnostics']
|
58
|
+
mutex.synchronize { queue.clear }
|
59
|
+
return
|
60
|
+
end
|
61
|
+
current = nil
|
62
|
+
mutex.synchronize { current = queue.shift }
|
63
|
+
return if queue.include?(current)
|
64
|
+
host.diagnose current
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
|
69
|
+
# @return [Host]
|
70
|
+
attr_reader :host
|
71
|
+
|
72
|
+
# @return [Mutex]
|
73
|
+
attr_reader :mutex
|
74
|
+
|
75
|
+
# @return [Array]
|
76
|
+
attr_reader :queue
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -1,113 +1,112 @@
|
|
1
|
-
module Solargraph
|
2
|
-
module LanguageServer
|
3
|
-
class Host
|
4
|
-
# Methods for associating sources with libraries via URIs.
|
5
|
-
#
|
6
|
-
module Dispatch
|
7
|
-
# @return [Sources]
|
8
|
-
def sources
|
9
|
-
@sources ||= begin
|
10
|
-
src = Sources.new
|
11
|
-
src.add_observer self, :update_libraries
|
12
|
-
src
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
# @return [Array<Library>]
|
17
|
-
def libraries
|
18
|
-
@libraries ||= []
|
19
|
-
end
|
20
|
-
|
21
|
-
# The Sources observer callback that merges a source into the host's
|
22
|
-
# libraries when it gets updated.
|
23
|
-
#
|
24
|
-
# @param uri [String]
|
25
|
-
# @return [void]
|
26
|
-
def update_libraries uri
|
27
|
-
src = sources.find(uri)
|
28
|
-
# @todo This module should not call cataloger and diagnoser
|
29
|
-
libraries.each do |lib|
|
30
|
-
if lib.contain?(src.filename) || lib.open?(src.filename)
|
31
|
-
lib.merge src
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
#
|
39
|
-
#
|
40
|
-
# @
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
#
|
49
|
-
#
|
50
|
-
#
|
51
|
-
#
|
52
|
-
#
|
53
|
-
#
|
54
|
-
#
|
55
|
-
#
|
56
|
-
# @
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
lib
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
#
|
70
|
-
#
|
71
|
-
#
|
72
|
-
#
|
73
|
-
#
|
74
|
-
#
|
75
|
-
#
|
76
|
-
#
|
77
|
-
#
|
78
|
-
# @
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
#
|
84
|
-
#
|
85
|
-
|
86
|
-
|
87
|
-
lib
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
#
|
95
|
-
#
|
96
|
-
#
|
97
|
-
#
|
98
|
-
#
|
99
|
-
# @
|
100
|
-
|
101
|
-
|
102
|
-
generic_library
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
end
|
1
|
+
module Solargraph
|
2
|
+
module LanguageServer
|
3
|
+
class Host
|
4
|
+
# Methods for associating sources with libraries via URIs.
|
5
|
+
#
|
6
|
+
module Dispatch
|
7
|
+
# @return [Sources]
|
8
|
+
def sources
|
9
|
+
@sources ||= begin
|
10
|
+
src = Sources.new
|
11
|
+
src.add_observer self, :update_libraries
|
12
|
+
src
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# @return [Array<Library>]
|
17
|
+
def libraries
|
18
|
+
@libraries ||= []
|
19
|
+
end
|
20
|
+
|
21
|
+
# The Sources observer callback that merges a source into the host's
|
22
|
+
# libraries when it gets updated.
|
23
|
+
#
|
24
|
+
# @param uri [String]
|
25
|
+
# @return [void]
|
26
|
+
def update_libraries uri
|
27
|
+
src = sources.find(uri)
|
28
|
+
# @todo This module should not call cataloger and diagnoser
|
29
|
+
libraries.each do |lib|
|
30
|
+
if lib.contain?(src.filename) || lib.open?(src.filename)
|
31
|
+
lib.merge src
|
32
|
+
end
|
33
|
+
end
|
34
|
+
diagnoser.schedule uri if src.synchronized?
|
35
|
+
end
|
36
|
+
|
37
|
+
# Find the best libary match for the given URI.
|
38
|
+
#
|
39
|
+
# @param uri [String]
|
40
|
+
# @return [Library]
|
41
|
+
def library_for uri
|
42
|
+
explicit_library_for(uri) ||
|
43
|
+
implicit_library_for(uri) ||
|
44
|
+
generic_library_for(uri)
|
45
|
+
end
|
46
|
+
|
47
|
+
# Find an explicit library match for the given URI. An explicit match
|
48
|
+
# means the libary's workspace includes the file.
|
49
|
+
#
|
50
|
+
# If a matching library is found, the source corresponding to the URI
|
51
|
+
# gets attached to it.
|
52
|
+
#
|
53
|
+
# @raise [FileNotFoundError] if the source could not be attached.
|
54
|
+
#
|
55
|
+
# @param uri [String]
|
56
|
+
# @return [Library, nil]
|
57
|
+
def explicit_library_for uri
|
58
|
+
filename = UriHelpers.uri_to_file(uri)
|
59
|
+
libraries.each do |lib|
|
60
|
+
if lib.contain?(filename)
|
61
|
+
lib.attach sources.find(uri) if sources.include?(uri)
|
62
|
+
return lib
|
63
|
+
end
|
64
|
+
end
|
65
|
+
nil
|
66
|
+
end
|
67
|
+
|
68
|
+
# Find an implicit library match for the given URI. An implicit match
|
69
|
+
# means the file is located inside the library's workspace directory,
|
70
|
+
# regardless of whether the workspace is configured to include it.
|
71
|
+
#
|
72
|
+
# If a matching library is found, the source corresponding to the URI
|
73
|
+
# gets attached to it.
|
74
|
+
#
|
75
|
+
# @raise [FileNotFoundError] if the source could not be attached.
|
76
|
+
#
|
77
|
+
# @param uri [String]
|
78
|
+
# @return [Library, nil]
|
79
|
+
def implicit_library_for uri
|
80
|
+
filename = UriHelpers.uri_to_file(uri)
|
81
|
+
libraries.each do |lib|
|
82
|
+
# @todo We probably shouldn't depend on attachments to select
|
83
|
+
# a library.
|
84
|
+
# return lib if lib.open?(filename)
|
85
|
+
if filename.start_with?(lib.workspace.directory)
|
86
|
+
lib.attach sources.find(uri)
|
87
|
+
return lib
|
88
|
+
end
|
89
|
+
end
|
90
|
+
nil
|
91
|
+
end
|
92
|
+
|
93
|
+
# Get a generic library for the given URI and attach the corresponding
|
94
|
+
# source.
|
95
|
+
#
|
96
|
+
# @raise [FileNotFoundError] if the source could not be attached.
|
97
|
+
#
|
98
|
+
# @param uri [String]
|
99
|
+
# @return [Library]
|
100
|
+
def generic_library_for uri
|
101
|
+
generic_library.attach sources.find(uri)
|
102
|
+
generic_library
|
103
|
+
end
|
104
|
+
|
105
|
+
# @return [Library]
|
106
|
+
def generic_library
|
107
|
+
@generic_library ||= Solargraph::Library.new
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|