solargraph 0.46.0 → 0.54.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/FUNDING.yml +1 -0
- data/.github/workflows/plugins.yml +40 -0
- data/.github/workflows/rspec.yml +37 -41
- data/.github/workflows/typecheck.yml +34 -0
- data/.gitignore +9 -9
- data/.rspec +2 -2
- data/.yardopts +2 -2
- data/CHANGELOG.md +1338 -1115
- data/Gemfile +0 -0
- data/LICENSE +1 -1
- data/README.md +131 -128
- data/Rakefile +0 -0
- data/SPONSORS.md +10 -18
- data/bin/solargraph +0 -0
- data/lib/solargraph/api_map/cache.rb +109 -70
- data/lib/solargraph/api_map/index.rb +167 -0
- data/lib/solargraph/api_map/source_to_yard.rb +88 -81
- data/lib/solargraph/api_map/store.rb +260 -256
- data/lib/solargraph/api_map.rb +870 -686
- data/lib/solargraph/bench.rb +44 -27
- data/lib/solargraph/cache.rb +77 -0
- data/lib/solargraph/complex_type/type_methods.rb +217 -130
- data/lib/solargraph/complex_type/unique_type.rb +386 -75
- data/lib/solargraph/complex_type.rb +394 -221
- data/lib/solargraph/convention/base.rb +33 -33
- data/lib/solargraph/convention/gemfile.rb +15 -15
- data/lib/solargraph/convention/gemspec.rb +22 -22
- data/lib/solargraph/convention/rakefile.rb +17 -0
- data/lib/solargraph/convention.rb +47 -47
- data/lib/solargraph/converters/dd.rb +17 -12
- data/lib/solargraph/converters/dl.rb +15 -12
- data/lib/solargraph/converters/dt.rb +15 -12
- data/lib/solargraph/converters/misc.rb +1 -1
- data/lib/solargraph/diagnostics/base.rb +29 -29
- data/lib/solargraph/diagnostics/require_not_found.rb +53 -53
- data/lib/solargraph/diagnostics/rubocop.rb +113 -98
- data/lib/solargraph/diagnostics/rubocop_helpers.rb +66 -63
- data/lib/solargraph/diagnostics/severities.rb +15 -15
- data/lib/solargraph/diagnostics/type_check.rb +55 -54
- data/lib/solargraph/diagnostics/update_errors.rb +41 -41
- data/lib/solargraph/diagnostics.rb +55 -55
- data/lib/solargraph/doc_map.rb +188 -0
- data/lib/solargraph/environ.rb +45 -45
- data/lib/solargraph/equality.rb +33 -0
- data/lib/solargraph/gem_pins.rb +72 -0
- data/lib/solargraph/language_server/completion_item_kinds.rb +35 -35
- data/lib/solargraph/language_server/error_codes.rb +20 -20
- data/lib/solargraph/language_server/host/diagnoser.rb +89 -89
- data/lib/solargraph/language_server/host/dispatch.rb +128 -111
- data/lib/solargraph/language_server/host/message_worker.rb +106 -59
- data/lib/solargraph/language_server/host/sources.rb +99 -156
- data/lib/solargraph/language_server/host.rb +861 -865
- data/lib/solargraph/language_server/message/base.rb +96 -89
- data/lib/solargraph/language_server/message/cancel_request.rb +13 -13
- data/lib/solargraph/language_server/message/client/register_capability.rb +15 -15
- data/lib/solargraph/language_server/message/client.rb +11 -11
- data/lib/solargraph/language_server/message/completion_item/resolve.rb +60 -58
- data/lib/solargraph/language_server/message/completion_item.rb +11 -11
- data/lib/solargraph/language_server/message/exit_notification.rb +13 -13
- data/lib/solargraph/language_server/message/extended/check_gem_version.rb +112 -100
- data/lib/solargraph/language_server/message/extended/document.rb +20 -20
- data/lib/solargraph/language_server/message/extended/document_gems.rb +32 -32
- data/lib/solargraph/language_server/message/extended/download_core.rb +19 -23
- data/lib/solargraph/language_server/message/extended/environment.rb +25 -25
- data/lib/solargraph/language_server/message/extended/search.rb +20 -20
- data/lib/solargraph/language_server/message/extended.rb +21 -21
- data/lib/solargraph/language_server/message/initialize.rb +191 -162
- data/lib/solargraph/language_server/message/initialized.rb +28 -27
- data/lib/solargraph/language_server/message/method_not_found.rb +16 -16
- data/lib/solargraph/language_server/message/method_not_implemented.rb +14 -14
- data/lib/solargraph/language_server/message/shutdown.rb +13 -13
- data/lib/solargraph/language_server/message/text_document/base.rb +19 -19
- data/lib/solargraph/language_server/message/text_document/code_action.rb +17 -17
- data/lib/solargraph/language_server/message/text_document/completion.rb +56 -59
- data/lib/solargraph/language_server/message/text_document/definition.rb +38 -38
- data/lib/solargraph/language_server/message/text_document/did_change.rb +15 -15
- data/lib/solargraph/language_server/message/text_document/did_close.rb +15 -15
- data/lib/solargraph/language_server/message/text_document/did_open.rb +15 -15
- data/lib/solargraph/language_server/message/text_document/did_save.rb +17 -17
- data/lib/solargraph/language_server/message/text_document/document_highlight.rb +16 -16
- data/lib/solargraph/language_server/message/text_document/document_symbol.rb +26 -23
- data/lib/solargraph/language_server/message/text_document/folding_range.rb +26 -26
- data/lib/solargraph/language_server/message/text_document/formatting.rb +131 -126
- data/lib/solargraph/language_server/message/text_document/hover.rb +58 -54
- data/lib/solargraph/language_server/message/text_document/on_type_formatting.rb +34 -34
- data/lib/solargraph/language_server/message/text_document/prepare_rename.rb +11 -11
- data/lib/solargraph/language_server/message/text_document/references.rb +16 -16
- data/lib/solargraph/language_server/message/text_document/rename.rb +19 -19
- data/lib/solargraph/language_server/message/text_document/signature_help.rb +24 -29
- data/lib/solargraph/language_server/message/text_document/type_definition.rb +24 -0
- data/lib/solargraph/language_server/message/text_document.rb +28 -28
- data/lib/solargraph/language_server/message/workspace/did_change_configuration.rb +35 -30
- data/lib/solargraph/language_server/message/workspace/did_change_watched_files.rb +40 -33
- data/lib/solargraph/language_server/message/workspace/did_change_workspace_folders.rb +24 -24
- data/lib/solargraph/language_server/message/workspace/workspace_symbol.rb +23 -23
- data/lib/solargraph/language_server/message/workspace.rb +14 -14
- data/lib/solargraph/language_server/message.rb +94 -93
- data/lib/solargraph/language_server/message_types.rb +14 -14
- data/lib/solargraph/language_server/progress.rb +135 -0
- data/lib/solargraph/language_server/request.rb +24 -24
- data/lib/solargraph/language_server/symbol_kinds.rb +36 -36
- data/lib/solargraph/language_server/transport/adapter.rb +68 -53
- data/lib/solargraph/language_server/transport/data_reader.rb +74 -72
- data/lib/solargraph/language_server/transport.rb +13 -13
- data/lib/solargraph/language_server/uri_helpers.rb +49 -49
- data/lib/solargraph/language_server.rb +20 -19
- data/lib/solargraph/library.rb +663 -546
- data/lib/solargraph/location.rb +58 -37
- data/lib/solargraph/logging.rb +27 -27
- data/lib/solargraph/page.rb +89 -83
- data/lib/solargraph/parser/comment_ripper.rb +56 -52
- data/lib/solargraph/parser/node_methods.rb +83 -43
- data/lib/solargraph/parser/node_processor/base.rb +87 -77
- data/lib/solargraph/parser/node_processor.rb +45 -43
- data/lib/solargraph/parser/{legacy → parser_gem}/class_methods.rb +153 -135
- data/lib/solargraph/parser/{legacy → parser_gem}/flawed_builder.rb +18 -16
- data/lib/solargraph/parser/{legacy → parser_gem}/node_chainer.rb +164 -148
- data/lib/solargraph/parser/parser_gem/node_methods.rb +495 -0
- data/lib/solargraph/parser/{rubyvm → parser_gem}/node_processors/alias_node.rb +23 -23
- data/lib/solargraph/parser/parser_gem/node_processors/args_node.rb +57 -0
- data/lib/solargraph/parser/{rubyvm → parser_gem}/node_processors/begin_node.rb +15 -15
- data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/block_node.rb +43 -42
- data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/casgn_node.rb +35 -25
- data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/cvasgn_node.rb +23 -23
- data/lib/solargraph/parser/{rubyvm → parser_gem}/node_processors/def_node.rb +50 -63
- data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/defs_node.rb +36 -36
- data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/gvasgn_node.rb +23 -23
- data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/ivasgn_node.rb +38 -38
- data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/lvasgn_node.rb +28 -28
- data/lib/solargraph/parser/parser_gem/node_processors/masgn_node.rb +53 -0
- data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/namespace_node.rb +39 -39
- data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/orasgn_node.rb +16 -16
- data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/resbody_node.rb +36 -36
- data/lib/solargraph/parser/parser_gem/node_processors/sclass_node.rb +42 -0
- data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/send_node.rb +259 -257
- data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/sym_node.rb +18 -18
- data/lib/solargraph/parser/parser_gem/node_processors.rb +56 -0
- data/lib/solargraph/parser/parser_gem.rb +12 -0
- data/lib/solargraph/parser/region.rb +66 -66
- data/lib/solargraph/parser/snippet.rb +15 -13
- data/lib/solargraph/parser.rb +22 -26
- data/lib/solargraph/pin/base.rb +378 -296
- data/lib/solargraph/pin/base_variable.rb +118 -84
- data/lib/solargraph/pin/block.rb +101 -72
- data/lib/solargraph/pin/callable.rb +147 -0
- data/lib/solargraph/pin/class_variable.rb +8 -8
- data/lib/solargraph/pin/closure.rb +57 -37
- data/lib/solargraph/pin/common.rb +70 -70
- data/lib/solargraph/pin/constant.rb +43 -43
- data/lib/solargraph/pin/conversions.rb +123 -96
- data/lib/solargraph/pin/delegated_method.rb +101 -0
- data/lib/solargraph/pin/documenting.rb +98 -105
- data/lib/solargraph/pin/duck_method.rb +16 -16
- data/lib/solargraph/pin/global_variable.rb +8 -8
- data/lib/solargraph/pin/instance_variable.rb +34 -30
- data/lib/solargraph/pin/keyword.rb +15 -15
- data/lib/solargraph/pin/keyword_param.rb +8 -8
- data/lib/solargraph/pin/local_variable.rb +67 -55
- data/lib/solargraph/pin/method.rb +527 -245
- data/lib/solargraph/pin/method_alias.rb +31 -31
- data/lib/solargraph/pin/namespace.rb +107 -91
- data/lib/solargraph/pin/parameter.rb +212 -201
- data/lib/solargraph/pin/proxy_type.rb +29 -29
- data/lib/solargraph/pin/reference/extend.rb +10 -10
- data/lib/solargraph/pin/reference/include.rb +10 -10
- data/lib/solargraph/pin/reference/override.rb +29 -29
- data/lib/solargraph/pin/reference/prepend.rb +10 -10
- data/lib/solargraph/pin/reference/require.rb +14 -14
- data/lib/solargraph/pin/reference/superclass.rb +10 -10
- data/lib/solargraph/pin/reference.rb +22 -14
- data/lib/solargraph/pin/search.rb +56 -56
- data/lib/solargraph/pin/signature.rb +17 -0
- data/lib/solargraph/pin/singleton.rb +11 -11
- data/lib/solargraph/pin/symbol.rb +47 -47
- data/lib/solargraph/pin.rb +41 -37
- data/lib/solargraph/position.rb +107 -100
- data/lib/solargraph/range.rb +98 -95
- data/lib/solargraph/rbs_map/conversions.rb +646 -0
- data/lib/solargraph/rbs_map/core_fills.rb +50 -0
- data/lib/solargraph/rbs_map/core_map.rb +28 -0
- data/lib/solargraph/rbs_map/stdlib_map.rb +33 -0
- data/lib/solargraph/rbs_map.rb +93 -0
- data/lib/solargraph/server_methods.rb +16 -16
- data/lib/solargraph/shell.rb +269 -226
- data/lib/solargraph/source/chain/array.rb +33 -0
- data/lib/solargraph/source/chain/block_symbol.rb +13 -0
- data/lib/solargraph/source/chain/block_variable.rb +13 -13
- data/lib/solargraph/source/chain/call.rb +303 -204
- data/lib/solargraph/source/chain/class_variable.rb +13 -13
- data/lib/solargraph/source/chain/constant.rb +89 -75
- data/lib/solargraph/source/chain/global_variable.rb +13 -13
- data/lib/solargraph/source/chain/hash.rb +33 -28
- data/lib/solargraph/source/chain/head.rb +19 -19
- data/lib/solargraph/source/chain/if.rb +28 -0
- data/lib/solargraph/source/chain/instance_variable.rb +13 -13
- data/lib/solargraph/source/chain/link.rb +98 -71
- data/lib/solargraph/source/chain/literal.rb +28 -23
- data/lib/solargraph/source/chain/or.rb +23 -23
- data/lib/solargraph/source/chain/q_call.rb +11 -11
- data/lib/solargraph/source/chain/variable.rb +13 -13
- data/lib/solargraph/source/chain/z_super.rb +30 -30
- data/lib/solargraph/source/chain.rb +252 -164
- data/lib/solargraph/source/change.rb +82 -79
- data/lib/solargraph/source/cursor.rb +167 -164
- data/lib/solargraph/source/source_chainer.rb +194 -191
- data/lib/solargraph/source/updater.rb +55 -54
- data/lib/solargraph/source.rb +495 -522
- data/lib/solargraph/source_map/clip.rb +232 -224
- data/lib/solargraph/source_map/completion.rb +23 -23
- data/lib/solargraph/source_map/data.rb +30 -0
- data/lib/solargraph/source_map/mapper.rb +255 -212
- data/lib/solargraph/source_map.rb +217 -180
- data/lib/solargraph/type_checker/checks.rb +120 -99
- data/lib/solargraph/type_checker/param_def.rb +35 -35
- data/lib/solargraph/type_checker/problem.rb +32 -32
- data/lib/solargraph/type_checker/rules.rb +62 -57
- data/lib/solargraph/type_checker.rb +672 -543
- data/lib/solargraph/version.rb +5 -5
- data/lib/solargraph/views/environment.erb +56 -58
- data/lib/solargraph/workspace/config.rb +239 -231
- data/lib/solargraph/workspace.rb +239 -215
- data/lib/solargraph/yard_map/cache.rb +25 -19
- data/lib/solargraph/yard_map/helpers.rb +16 -16
- data/lib/solargraph/yard_map/mapper/to_constant.rb +26 -25
- data/lib/solargraph/yard_map/mapper/to_method.rb +94 -78
- data/lib/solargraph/yard_map/mapper/to_namespace.rb +28 -27
- data/lib/solargraph/yard_map/mapper.rb +78 -77
- data/lib/solargraph/yard_map/to_method.rb +86 -79
- data/lib/solargraph/yard_map.rb +18 -460
- data/lib/solargraph/yard_tags.rb +20 -0
- data/lib/solargraph/yardoc.rb +52 -0
- data/lib/solargraph.rb +72 -69
- data/solargraph.gemspec +21 -10
- metadata +184 -115
- data/.travis.yml +0 -19
- data/lib/solargraph/api_map/bundler_methods.rb +0 -22
- data/lib/solargraph/compat.rb +0 -37
- data/lib/solargraph/convention/rspec.rb +0 -30
- data/lib/solargraph/documentor.rb +0 -76
- data/lib/solargraph/language_server/host/cataloger.rb +0 -56
- data/lib/solargraph/parser/legacy/node_methods.rb +0 -325
- data/lib/solargraph/parser/legacy/node_processors/alias_node.rb +0 -23
- data/lib/solargraph/parser/legacy/node_processors/args_node.rb +0 -35
- data/lib/solargraph/parser/legacy/node_processors/begin_node.rb +0 -15
- data/lib/solargraph/parser/legacy/node_processors/def_node.rb +0 -63
- data/lib/solargraph/parser/legacy/node_processors/sclass_node.rb +0 -21
- data/lib/solargraph/parser/legacy/node_processors.rb +0 -54
- data/lib/solargraph/parser/legacy.rb +0 -12
- data/lib/solargraph/parser/rubyvm/class_methods.rb +0 -144
- data/lib/solargraph/parser/rubyvm/node_chainer.rb +0 -160
- data/lib/solargraph/parser/rubyvm/node_methods.rb +0 -315
- data/lib/solargraph/parser/rubyvm/node_processors/args_node.rb +0 -85
- data/lib/solargraph/parser/rubyvm/node_processors/block_node.rb +0 -42
- data/lib/solargraph/parser/rubyvm/node_processors/casgn_node.rb +0 -22
- data/lib/solargraph/parser/rubyvm/node_processors/cvasgn_node.rb +0 -23
- data/lib/solargraph/parser/rubyvm/node_processors/defs_node.rb +0 -57
- data/lib/solargraph/parser/rubyvm/node_processors/gvasgn_node.rb +0 -23
- data/lib/solargraph/parser/rubyvm/node_processors/ivasgn_node.rb +0 -38
- data/lib/solargraph/parser/rubyvm/node_processors/kw_arg_node.rb +0 -39
- data/lib/solargraph/parser/rubyvm/node_processors/lit_node.rb +0 -20
- data/lib/solargraph/parser/rubyvm/node_processors/lvasgn_node.rb +0 -27
- data/lib/solargraph/parser/rubyvm/node_processors/namespace_node.rb +0 -39
- data/lib/solargraph/parser/rubyvm/node_processors/opt_arg_node.rb +0 -26
- data/lib/solargraph/parser/rubyvm/node_processors/orasgn_node.rb +0 -15
- data/lib/solargraph/parser/rubyvm/node_processors/resbody_node.rb +0 -45
- data/lib/solargraph/parser/rubyvm/node_processors/sclass_node.rb +0 -21
- data/lib/solargraph/parser/rubyvm/node_processors/scope_node.rb +0 -15
- data/lib/solargraph/parser/rubyvm/node_processors/send_node.rb +0 -277
- data/lib/solargraph/parser/rubyvm/node_processors/sym_node.rb +0 -18
- data/lib/solargraph/parser/rubyvm/node_processors.rb +0 -63
- data/lib/solargraph/parser/rubyvm.rb +0 -40
- data/lib/solargraph/yard_map/core_docs.rb +0 -170
- data/lib/solargraph/yard_map/core_fills.rb +0 -208
- data/lib/solargraph/yard_map/core_gen.rb +0 -76
- data/lib/solargraph/yard_map/rdoc_to_yard.rb +0 -140
- data/lib/solargraph/yard_map/stdlib_fills.rb +0 -43
- data/lib/yard-solargraph.rb +0 -33
- data/yardoc/2.2.2.tar.gz +0 -0
@@ -1,89 +1,89 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Solargraph
|
4
|
-
module LanguageServer
|
5
|
-
class Host
|
6
|
-
# An asynchronous diagnosis reporter.
|
7
|
-
#
|
8
|
-
class Diagnoser
|
9
|
-
# @param host [Host]
|
10
|
-
def initialize host
|
11
|
-
@host = host
|
12
|
-
@mutex = Mutex.new
|
13
|
-
@queue = []
|
14
|
-
@stopped = true
|
15
|
-
end
|
16
|
-
|
17
|
-
# Schedule a file to be diagnosed.
|
18
|
-
#
|
19
|
-
# @param uri [String]
|
20
|
-
# @return [void]
|
21
|
-
def schedule uri
|
22
|
-
mutex.synchronize { queue.push uri }
|
23
|
-
end
|
24
|
-
|
25
|
-
# Stop the diagnosis thread.
|
26
|
-
#
|
27
|
-
# @return [void]
|
28
|
-
def stop
|
29
|
-
@stopped = true
|
30
|
-
end
|
31
|
-
|
32
|
-
# True is the diagnoser is stopped.
|
33
|
-
#
|
34
|
-
# @return [Boolean]
|
35
|
-
def stopped?
|
36
|
-
@stopped
|
37
|
-
end
|
38
|
-
|
39
|
-
# Start the diagnosis thread.
|
40
|
-
#
|
41
|
-
# @return [self]
|
42
|
-
def start
|
43
|
-
return unless @stopped
|
44
|
-
@stopped = false
|
45
|
-
Thread.new do
|
46
|
-
until stopped?
|
47
|
-
tick
|
48
|
-
sleep 0.1
|
49
|
-
end
|
50
|
-
end
|
51
|
-
self
|
52
|
-
end
|
53
|
-
|
54
|
-
# Perform diagnoses.
|
55
|
-
#
|
56
|
-
# @return [void]
|
57
|
-
def tick
|
58
|
-
return if queue.empty? || host.synchronizing?
|
59
|
-
if !host.options['diagnostics']
|
60
|
-
mutex.synchronize { queue.clear }
|
61
|
-
return
|
62
|
-
end
|
63
|
-
current = mutex.synchronize { queue.shift }
|
64
|
-
return if queue.include?(current)
|
65
|
-
begin
|
66
|
-
host.diagnose current
|
67
|
-
rescue InvalidOffsetError
|
68
|
-
# @todo This error can occur when the Source is out of sync with
|
69
|
-
# with the ApiMap. It's probably not the best way to handle it,
|
70
|
-
# but it's quick and easy.
|
71
|
-
Logging.logger.warn "Deferring diagnosis due to invalid offset: #{current}"
|
72
|
-
mutex.synchronize { queue.push current }
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
private
|
77
|
-
|
78
|
-
# @return [Host]
|
79
|
-
attr_reader :host
|
80
|
-
|
81
|
-
# @return [Mutex]
|
82
|
-
attr_reader :mutex
|
83
|
-
|
84
|
-
# @return [Array]
|
85
|
-
attr_reader :queue
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Solargraph
|
4
|
+
module LanguageServer
|
5
|
+
class Host
|
6
|
+
# An asynchronous diagnosis reporter.
|
7
|
+
#
|
8
|
+
class Diagnoser
|
9
|
+
# @param host [Host]
|
10
|
+
def initialize host
|
11
|
+
@host = host
|
12
|
+
@mutex = Mutex.new
|
13
|
+
@queue = []
|
14
|
+
@stopped = true
|
15
|
+
end
|
16
|
+
|
17
|
+
# Schedule a file to be diagnosed.
|
18
|
+
#
|
19
|
+
# @param uri [String]
|
20
|
+
# @return [void]
|
21
|
+
def schedule uri
|
22
|
+
mutex.synchronize { queue.push uri }
|
23
|
+
end
|
24
|
+
|
25
|
+
# Stop the diagnosis thread.
|
26
|
+
#
|
27
|
+
# @return [void]
|
28
|
+
def stop
|
29
|
+
@stopped = true
|
30
|
+
end
|
31
|
+
|
32
|
+
# True is the diagnoser is stopped.
|
33
|
+
#
|
34
|
+
# @return [Boolean]
|
35
|
+
def stopped?
|
36
|
+
@stopped
|
37
|
+
end
|
38
|
+
|
39
|
+
# Start the diagnosis thread.
|
40
|
+
#
|
41
|
+
# @return [self, nil]
|
42
|
+
def start
|
43
|
+
return unless @stopped
|
44
|
+
@stopped = false
|
45
|
+
Thread.new do
|
46
|
+
until stopped?
|
47
|
+
tick
|
48
|
+
sleep 0.1
|
49
|
+
end
|
50
|
+
end
|
51
|
+
self
|
52
|
+
end
|
53
|
+
|
54
|
+
# Perform diagnoses.
|
55
|
+
#
|
56
|
+
# @return [void]
|
57
|
+
def tick
|
58
|
+
return if queue.empty? || host.synchronizing?
|
59
|
+
if !host.options['diagnostics']
|
60
|
+
mutex.synchronize { queue.clear }
|
61
|
+
return
|
62
|
+
end
|
63
|
+
current = mutex.synchronize { queue.shift }
|
64
|
+
return if queue.include?(current)
|
65
|
+
begin
|
66
|
+
host.diagnose current
|
67
|
+
rescue InvalidOffsetError
|
68
|
+
# @todo This error can occur when the Source is out of sync with
|
69
|
+
# with the ApiMap. It's probably not the best way to handle it,
|
70
|
+
# but it's quick and easy.
|
71
|
+
Logging.logger.warn "Deferring diagnosis due to invalid offset: #{current}"
|
72
|
+
mutex.synchronize { queue.push current }
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
private
|
77
|
+
|
78
|
+
# @return [Host]
|
79
|
+
attr_reader :host
|
80
|
+
|
81
|
+
# @return [Mutex]
|
82
|
+
attr_reader :mutex
|
83
|
+
|
84
|
+
# @return [::Array]
|
85
|
+
attr_reader :queue
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -1,111 +1,128 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Solargraph
|
4
|
-
module LanguageServer
|
5
|
-
class Host
|
6
|
-
# Methods for associating sources with libraries via URIs.
|
7
|
-
#
|
8
|
-
module Dispatch
|
9
|
-
# @
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
#
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
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
|
-
|
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
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
#
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Solargraph
|
4
|
+
module LanguageServer
|
5
|
+
class Host
|
6
|
+
# Methods for associating sources with libraries via URIs.
|
7
|
+
#
|
8
|
+
module Dispatch
|
9
|
+
# @abstract
|
10
|
+
# @return [Host::Diagnoser]
|
11
|
+
def diagnoser
|
12
|
+
raise NotImplementedError, 'Host::Dispatch requires a diagnoser method'
|
13
|
+
end
|
14
|
+
|
15
|
+
# @return [Sources]
|
16
|
+
def sources
|
17
|
+
@sources ||= begin
|
18
|
+
src = Sources.new
|
19
|
+
src.add_observer self, :update_libraries
|
20
|
+
src
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# @return [::Array<Library>]
|
25
|
+
def libraries
|
26
|
+
@libraries ||= []
|
27
|
+
end
|
28
|
+
|
29
|
+
# The Sources observer callback that merges a source into the host's
|
30
|
+
# libraries when it gets updated.
|
31
|
+
#
|
32
|
+
# @param uri [String]
|
33
|
+
# @return [void]
|
34
|
+
def update_libraries uri
|
35
|
+
src = sources.find(uri)
|
36
|
+
using = libraries.select { |lib| lib.contain?(src.filename) }
|
37
|
+
using.push library_for(uri) if using.empty?
|
38
|
+
using.each { |lib| lib.merge src }
|
39
|
+
diagnoser.schedule uri
|
40
|
+
end
|
41
|
+
|
42
|
+
# Find the best libary match for the given URI.
|
43
|
+
#
|
44
|
+
# @param uri [String]
|
45
|
+
# @return [Library]
|
46
|
+
def library_for uri
|
47
|
+
result = explicit_library_for(uri) ||
|
48
|
+
implicit_library_for(uri) ||
|
49
|
+
generic_library_for(uri)
|
50
|
+
# previous library for already call attach. avoid call twice
|
51
|
+
# result.attach sources.find(uri) if sources.include?(uri)
|
52
|
+
result
|
53
|
+
end
|
54
|
+
|
55
|
+
# Find an explicit library match for the given URI. An explicit match
|
56
|
+
# means the libary's workspace includes the file.
|
57
|
+
#
|
58
|
+
# If a matching library is found, the source corresponding to the URI
|
59
|
+
# gets attached to it.
|
60
|
+
#
|
61
|
+
# @raise [FileNotFoundError] if the source could not be attached.
|
62
|
+
#
|
63
|
+
# @param uri [String]
|
64
|
+
# @return [Library, nil]
|
65
|
+
def explicit_library_for uri
|
66
|
+
filename = UriHelpers.uri_to_file(uri)
|
67
|
+
libraries.each do |lib|
|
68
|
+
if lib.contain?(filename)
|
69
|
+
lib.attach sources.find(uri) if sources.include?(uri)
|
70
|
+
return lib
|
71
|
+
end
|
72
|
+
end
|
73
|
+
nil
|
74
|
+
end
|
75
|
+
|
76
|
+
# Find an implicit library match for the given URI. An implicit match
|
77
|
+
# means the file is located inside the library's workspace directory,
|
78
|
+
# regardless of whether the workspace is configured to include it.
|
79
|
+
#
|
80
|
+
# If a matching library is found, the source corresponding to the URI
|
81
|
+
# gets attached to it.
|
82
|
+
#
|
83
|
+
# @raise [FileNotFoundError] if the source could not be attached.
|
84
|
+
#
|
85
|
+
# @param uri [String]
|
86
|
+
# @return [Library, nil]
|
87
|
+
def implicit_library_for uri
|
88
|
+
filename = UriHelpers.uri_to_file(uri)
|
89
|
+
libraries.each do |lib|
|
90
|
+
if filename.start_with?(lib.workspace.directory)
|
91
|
+
lib.attach sources.find(uri)
|
92
|
+
return lib
|
93
|
+
end
|
94
|
+
end
|
95
|
+
nil
|
96
|
+
end
|
97
|
+
|
98
|
+
def options
|
99
|
+
@options ||= {}.freeze
|
100
|
+
end
|
101
|
+
|
102
|
+
# Get a generic library for the given URI and attach the corresponding
|
103
|
+
# source.
|
104
|
+
#
|
105
|
+
# @raise [FileNotFoundError] if the source could not be attached.
|
106
|
+
#
|
107
|
+
# @param uri [String]
|
108
|
+
# @return [Library]
|
109
|
+
def generic_library_for uri
|
110
|
+
generic_library.attach sources.find(uri)
|
111
|
+
generic_library
|
112
|
+
end
|
113
|
+
|
114
|
+
# @return [Library]
|
115
|
+
def generic_library
|
116
|
+
@generic_library ||= Solargraph::Library.new(Solargraph::Workspace.new('', nil, options), nil)
|
117
|
+
.tap { |lib| lib.add_observer self }
|
118
|
+
end
|
119
|
+
|
120
|
+
# @param library [Solargraph::Library]
|
121
|
+
# @return [void]
|
122
|
+
def update progress
|
123
|
+
progress&.send(self)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
@@ -1,59 +1,106 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Solargraph
|
4
|
-
module LanguageServer
|
5
|
-
class Host
|
6
|
-
# A serial worker Thread to handle
|
7
|
-
#
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
@
|
21
|
-
end
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
def
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
def
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Solargraph
|
4
|
+
module LanguageServer
|
5
|
+
class Host
|
6
|
+
# A serial worker Thread to handle incoming messages.
|
7
|
+
#
|
8
|
+
class MessageWorker
|
9
|
+
UPDATE_METHODS = [
|
10
|
+
'textDocument/didOpen',
|
11
|
+
'textDocument/didChange',
|
12
|
+
'workspace/didChangeWatchedFiles'
|
13
|
+
].freeze
|
14
|
+
|
15
|
+
# @param host [Host]
|
16
|
+
def initialize(host)
|
17
|
+
@host = host
|
18
|
+
@mutex = Mutex.new
|
19
|
+
@resource = ConditionVariable.new
|
20
|
+
@stopped = true
|
21
|
+
end
|
22
|
+
|
23
|
+
# pending handle messages
|
24
|
+
# @return [Array<Hash>]
|
25
|
+
def messages
|
26
|
+
@messages ||= []
|
27
|
+
end
|
28
|
+
|
29
|
+
def stopped?
|
30
|
+
@stopped
|
31
|
+
end
|
32
|
+
|
33
|
+
# @return [void]
|
34
|
+
def stop
|
35
|
+
@stopped = true
|
36
|
+
end
|
37
|
+
|
38
|
+
# @param message [Hash] The message to handle. Will be forwarded to Host#receive
|
39
|
+
# @return [void]
|
40
|
+
def queue(message)
|
41
|
+
@mutex.synchronize do
|
42
|
+
messages.push(message)
|
43
|
+
@resource.signal
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# @return [void]
|
48
|
+
def start
|
49
|
+
return unless @stopped
|
50
|
+
@stopped = false
|
51
|
+
Thread.new do
|
52
|
+
tick until stopped?
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# @return [void]
|
57
|
+
def tick
|
58
|
+
message = @mutex.synchronize do
|
59
|
+
@resource.wait(@mutex) if messages.empty?
|
60
|
+
next_message
|
61
|
+
end
|
62
|
+
handler = @host.receive(message)
|
63
|
+
handler&.send_response
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
def next_message
|
69
|
+
cancel_message || next_priority
|
70
|
+
end
|
71
|
+
|
72
|
+
def cancel_message
|
73
|
+
# Handle cancellations first
|
74
|
+
idx = messages.find_index { |msg| msg['method'] == '$/cancelRequest' }
|
75
|
+
return unless idx
|
76
|
+
|
77
|
+
msg = messages[idx]
|
78
|
+
messages.delete_at idx
|
79
|
+
msg
|
80
|
+
end
|
81
|
+
|
82
|
+
def next_priority
|
83
|
+
# Prioritize updates and version-dependent messages for performance
|
84
|
+
idx = messages.find_index do |msg|
|
85
|
+
UPDATE_METHODS.include?(msg['method']) || version_dependent?(msg)
|
86
|
+
end
|
87
|
+
return messages.shift unless idx
|
88
|
+
|
89
|
+
msg = messages[idx]
|
90
|
+
messages.delete_at idx
|
91
|
+
msg
|
92
|
+
end
|
93
|
+
|
94
|
+
# True if the message requires a previous update to have executed in
|
95
|
+
# order to work correctly.
|
96
|
+
#
|
97
|
+
# @param msg [Hash{String => Object}]
|
98
|
+
# @todo need boolish type from RBS
|
99
|
+
# @return [Object]
|
100
|
+
def version_dependent? msg
|
101
|
+
msg['textDocument'] && msg['position']
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|