solargraph 0.58.2 → 0.59.0.dev.2
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/.envrc +3 -0
- data/.github/workflows/linting.yml +4 -5
- data/.github/workflows/plugins.yml +41 -34
- data/.github/workflows/rspec.yml +44 -23
- data/.github/workflows/typecheck.yml +2 -2
- data/.rubocop.yml +32 -5
- data/.rubocop_todo.yml +50 -966
- data/Gemfile +3 -1
- data/README.md +3 -3
- data/Rakefile +26 -23
- data/bin/solargraph +2 -1
- data/lib/solargraph/api_map/cache.rb +3 -3
- data/lib/solargraph/api_map/constants.rb +13 -3
- data/lib/solargraph/api_map/index.rb +23 -18
- data/lib/solargraph/api_map/source_to_yard.rb +22 -9
- data/lib/solargraph/api_map/store.rb +33 -28
- data/lib/solargraph/api_map.rb +150 -82
- data/lib/solargraph/bench.rb +44 -45
- data/lib/solargraph/complex_type/conformance.rb +176 -0
- data/lib/solargraph/complex_type/type_methods.rb +28 -17
- data/lib/solargraph/complex_type/unique_type.rb +218 -57
- data/lib/solargraph/complex_type.rb +170 -57
- data/lib/solargraph/convention/data_definition/data_assignment_node.rb +61 -61
- data/lib/solargraph/convention/data_definition/data_definition_node.rb +7 -5
- data/lib/solargraph/convention/data_definition.rb +5 -2
- data/lib/solargraph/convention/gemfile.rb +15 -15
- data/lib/solargraph/convention/gemspec.rb +23 -23
- data/lib/solargraph/convention/rakefile.rb +17 -17
- data/lib/solargraph/convention/struct_definition/struct_assignment_node.rb +2 -1
- data/lib/solargraph/convention/struct_definition/struct_definition_node.rb +4 -3
- data/lib/solargraph/convention/struct_definition.rb +8 -4
- data/lib/solargraph/convention.rb +78 -78
- data/lib/solargraph/converters/dd.rb +19 -17
- data/lib/solargraph/converters/dl.rb +17 -15
- data/lib/solargraph/converters/dt.rb +17 -15
- data/lib/solargraph/converters/misc.rb +3 -1
- data/lib/solargraph/diagnostics/require_not_found.rb +1 -0
- data/lib/solargraph/diagnostics/rubocop.rb +11 -10
- data/lib/solargraph/diagnostics/rubocop_helpers.rb +5 -3
- data/lib/solargraph/diagnostics/type_check.rb +11 -10
- data/lib/solargraph/diagnostics/update_errors.rb +37 -41
- data/lib/solargraph/doc_map.rb +133 -373
- data/lib/solargraph/equality.rb +4 -4
- data/lib/solargraph/gem_pins.rb +21 -20
- data/lib/solargraph/language_server/error_codes.rb +20 -20
- data/lib/solargraph/language_server/host/diagnoser.rb +1 -1
- data/lib/solargraph/language_server/host/dispatch.rb +3 -3
- data/lib/solargraph/language_server/host/message_worker.rb +4 -3
- data/lib/solargraph/language_server/host/sources.rb +2 -1
- data/lib/solargraph/language_server/host.rb +30 -22
- data/lib/solargraph/language_server/message/base.rb +97 -97
- data/lib/solargraph/language_server/message/client/register_capability.rb +13 -15
- data/lib/solargraph/language_server/message/completion_item/resolve.rb +58 -60
- data/lib/solargraph/language_server/message/extended/check_gem_version.rb +12 -18
- data/lib/solargraph/language_server/message/extended/document.rb +1 -0
- data/lib/solargraph/language_server/message/extended/document_gems.rb +32 -32
- data/lib/solargraph/language_server/message/extended/download_core.rb +20 -19
- data/lib/solargraph/language_server/message/extended/search.rb +20 -20
- data/lib/solargraph/language_server/message/initialize.rb +197 -191
- data/lib/solargraph/language_server/message/text_document/completion.rb +10 -8
- data/lib/solargraph/language_server/message/text_document/definition.rb +41 -32
- data/lib/solargraph/language_server/message/text_document/document_highlight.rb +23 -16
- data/lib/solargraph/language_server/message/text_document/document_symbol.rb +29 -19
- data/lib/solargraph/language_server/message/text_document/formatting.rb +8 -6
- data/lib/solargraph/language_server/message/text_document/hover.rb +5 -5
- data/lib/solargraph/language_server/message/text_document/prepare_rename.rb +18 -11
- data/lib/solargraph/language_server/message/text_document/references.rb +23 -16
- data/lib/solargraph/language_server/message/text_document/rename.rb +26 -19
- data/lib/solargraph/language_server/message/text_document/signature_help.rb +3 -2
- data/lib/solargraph/language_server/message/text_document/type_definition.rb +25 -17
- data/lib/solargraph/language_server/message/workspace/did_change_configuration.rb +41 -35
- data/lib/solargraph/language_server/message/workspace/did_change_watched_files.rb +48 -40
- data/lib/solargraph/language_server/message/workspace/did_change_workspace_folders.rb +32 -26
- data/lib/solargraph/language_server/message/workspace/workspace_symbol.rb +27 -17
- data/lib/solargraph/language_server/message.rb +94 -94
- data/lib/solargraph/language_server/request.rb +29 -27
- data/lib/solargraph/language_server/transport/data_reader.rb +72 -74
- data/lib/solargraph/language_server/uri_helpers.rb +49 -49
- data/lib/solargraph/library.rb +85 -44
- data/lib/solargraph/location.rb +17 -14
- data/lib/solargraph/logging.rb +24 -4
- data/lib/solargraph/page.rb +92 -92
- data/lib/solargraph/parser/comment_ripper.rb +19 -4
- data/lib/solargraph/parser/flow_sensitive_typing.rb +326 -108
- data/lib/solargraph/parser/node_processor/base.rb +34 -4
- data/lib/solargraph/parser/node_processor.rb +8 -7
- data/lib/solargraph/parser/parser_gem/class_methods.rb +32 -14
- data/lib/solargraph/parser/parser_gem/flawed_builder.rb +19 -19
- data/lib/solargraph/parser/parser_gem/node_chainer.rb +50 -25
- data/lib/solargraph/parser/parser_gem/node_methods.rb +91 -70
- data/lib/solargraph/parser/parser_gem/node_processors/and_node.rb +4 -4
- data/lib/solargraph/parser/parser_gem/node_processors/args_node.rb +13 -11
- data/lib/solargraph/parser/parser_gem/node_processors/begin_node.rb +9 -0
- data/lib/solargraph/parser/parser_gem/node_processors/block_node.rb +12 -12
- data/lib/solargraph/parser/parser_gem/node_processors/def_node.rb +10 -3
- data/lib/solargraph/parser/parser_gem/node_processors/defs_node.rb +38 -37
- data/lib/solargraph/parser/parser_gem/node_processors/if_node.rb +36 -6
- data/lib/solargraph/parser/parser_gem/node_processors/ivasgn_node.rb +5 -3
- data/lib/solargraph/parser/parser_gem/node_processors/lvasgn_node.rb +1 -0
- data/lib/solargraph/parser/parser_gem/node_processors/masgn_node.rb +3 -1
- data/lib/solargraph/parser/parser_gem/node_processors/opasgn_node.rb +3 -3
- data/lib/solargraph/parser/parser_gem/node_processors/or_node.rb +22 -0
- data/lib/solargraph/parser/parser_gem/node_processors/orasgn_node.rb +1 -1
- data/lib/solargraph/parser/parser_gem/node_processors/resbody_node.rb +2 -1
- data/lib/solargraph/parser/parser_gem/node_processors/sclass_node.rb +4 -5
- data/lib/solargraph/parser/parser_gem/node_processors/send_node.rb +124 -113
- data/lib/solargraph/parser/parser_gem/node_processors/until_node.rb +29 -29
- data/lib/solargraph/parser/parser_gem/node_processors/when_node.rb +23 -0
- data/lib/solargraph/parser/parser_gem/node_processors/while_node.rb +6 -2
- data/lib/solargraph/parser/parser_gem/node_processors.rb +4 -0
- data/lib/solargraph/parser/parser_gem.rb +14 -12
- data/lib/solargraph/parser/region.rb +9 -3
- data/lib/solargraph/parser/snippet.rb +3 -1
- data/lib/solargraph/parser.rb +25 -23
- data/lib/solargraph/pin/base.rb +126 -80
- data/lib/solargraph/pin/base_variable.rb +273 -24
- data/lib/solargraph/pin/block.rb +29 -6
- data/lib/solargraph/pin/breakable.rb +7 -1
- data/lib/solargraph/pin/callable.rb +65 -21
- data/lib/solargraph/pin/closure.rb +7 -10
- data/lib/solargraph/pin/common.rb +24 -6
- data/lib/solargraph/pin/compound_statement.rb +55 -0
- data/lib/solargraph/pin/constant.rb +43 -45
- data/lib/solargraph/pin/conversions.rb +10 -4
- data/lib/solargraph/pin/delegated_method.rb +19 -8
- data/lib/solargraph/pin/documenting.rb +4 -2
- data/lib/solargraph/pin/instance_variable.rb +5 -1
- data/lib/solargraph/pin/keyword.rb +0 -4
- data/lib/solargraph/pin/local_variable.rb +15 -59
- data/lib/solargraph/pin/method.rb +153 -104
- data/lib/solargraph/pin/method_alias.rb +8 -0
- data/lib/solargraph/pin/namespace.rb +19 -12
- data/lib/solargraph/pin/parameter.rb +100 -36
- data/lib/solargraph/pin/proxy_type.rb +4 -1
- data/lib/solargraph/pin/reference/override.rb +1 -1
- data/lib/solargraph/pin/reference/superclass.rb +2 -0
- data/lib/solargraph/pin/reference.rb +19 -0
- data/lib/solargraph/pin/search.rb +3 -2
- data/lib/solargraph/pin/signature.rb +15 -12
- data/lib/solargraph/pin/symbol.rb +2 -1
- data/lib/solargraph/pin/until.rb +2 -4
- data/lib/solargraph/pin/while.rb +2 -4
- data/lib/solargraph/pin.rb +2 -0
- data/lib/solargraph/pin_cache.rb +490 -73
- data/lib/solargraph/position.rb +14 -10
- data/lib/solargraph/range.rb +16 -15
- data/lib/solargraph/rbs_map/conversions.rb +343 -214
- data/lib/solargraph/rbs_map/core_fills.rb +91 -84
- data/lib/solargraph/rbs_map/core_map.rb +24 -17
- data/lib/solargraph/rbs_map/stdlib_map.rb +33 -5
- data/lib/solargraph/rbs_map.rb +77 -32
- data/lib/solargraph/server_methods.rb +16 -16
- data/lib/solargraph/shell.rb +128 -73
- data/lib/solargraph/source/chain/array.rb +39 -37
- data/lib/solargraph/source/chain/call.rb +96 -56
- data/lib/solargraph/source/chain/class_variable.rb +13 -13
- data/lib/solargraph/source/chain/constant.rb +5 -1
- data/lib/solargraph/source/chain/global_variable.rb +13 -13
- data/lib/solargraph/source/chain/hash.rb +8 -5
- data/lib/solargraph/source/chain/if.rb +12 -10
- data/lib/solargraph/source/chain/instance_variable.rb +24 -1
- data/lib/solargraph/source/chain/link.rb +99 -109
- data/lib/solargraph/source/chain/literal.rb +9 -6
- data/lib/solargraph/source/chain/or.rb +10 -4
- data/lib/solargraph/source/chain/q_call.rb +13 -11
- data/lib/solargraph/source/chain/variable.rb +15 -13
- data/lib/solargraph/source/chain/z_super.rb +28 -30
- data/lib/solargraph/source/chain.rb +49 -38
- data/lib/solargraph/source/change.rb +12 -5
- data/lib/solargraph/source/cursor.rb +23 -17
- data/lib/solargraph/source/encoding_fixes.rb +6 -7
- data/lib/solargraph/source/source_chainer.rb +56 -32
- data/lib/solargraph/source/updater.rb +5 -1
- data/lib/solargraph/source.rb +59 -35
- data/lib/solargraph/source_map/clip.rb +48 -29
- data/lib/solargraph/source_map/data.rb +4 -1
- data/lib/solargraph/source_map/mapper.rb +71 -42
- data/lib/solargraph/source_map.rb +21 -9
- data/lib/solargraph/type_checker/problem.rb +3 -1
- data/lib/solargraph/type_checker/rules.rb +81 -8
- data/lib/solargraph/type_checker.rb +195 -120
- data/lib/solargraph/version.rb +1 -1
- data/lib/solargraph/workspace/config.rb +13 -10
- data/lib/solargraph/workspace/gemspecs.rb +367 -0
- data/lib/solargraph/workspace/require_paths.rb +1 -0
- data/lib/solargraph/workspace.rb +149 -30
- data/lib/solargraph/yard_map/helpers.rb +8 -3
- data/lib/solargraph/yard_map/mapper/to_method.rb +13 -7
- data/lib/solargraph/yard_map/mapper/to_namespace.rb +2 -1
- data/lib/solargraph/yard_map/mapper.rb +13 -8
- data/lib/solargraph/yard_tags.rb +20 -20
- data/lib/solargraph/yardoc.rb +33 -23
- data/lib/solargraph.rb +29 -8
- data/rbs/fills/rubygems/0/dependency.rbs +193 -0
- data/rbs/fills/tuple/tuple.rbs +28 -0
- data/rbs/shims/ast/0/node.rbs +1 -1
- data/rbs/shims/diff-lcs/1.5/diff-lcs.rbs +11 -0
- data/solargraph.gemspec +36 -34
- metadata +38 -33
- data/lib/solargraph/type_checker/checks.rb +0 -124
- data/lib/solargraph/type_checker/param_def.rb +0 -37
- data/lib/solargraph/yard_map/to_method.rb +0 -89
data/lib/solargraph/gem_pins.rb
CHANGED
|
@@ -13,8 +13,8 @@ module Solargraph
|
|
|
13
13
|
|
|
14
14
|
# @param pins [Array<Pin::Base>]
|
|
15
15
|
# @return [Array<Pin::Base>]
|
|
16
|
-
def self.combine_method_pins_by_path
|
|
17
|
-
method_pins, alias_pins = pins.partition { |pin| pin.
|
|
16
|
+
def self.combine_method_pins_by_path pins
|
|
17
|
+
method_pins, alias_pins = pins.partition { |pin| pin.instance_of?(Pin::Method) }
|
|
18
18
|
by_path = method_pins.group_by(&:path)
|
|
19
19
|
by_path.transform_values! do |pins|
|
|
20
20
|
GemPins.combine_method_pins(*pins)
|
|
@@ -43,36 +43,37 @@ module Solargraph
|
|
|
43
43
|
out
|
|
44
44
|
end
|
|
45
45
|
|
|
46
|
-
# @param yard_plugins [Array<String>] The names of YARD plugins to use.
|
|
47
|
-
# @param gemspec [Gem::Specification]
|
|
48
|
-
# @return [Array<Pin::Base>]
|
|
49
|
-
def self.build_yard_pins(yard_plugins, gemspec)
|
|
50
|
-
Yardoc.cache(yard_plugins, gemspec) unless Yardoc.cached?(gemspec)
|
|
51
|
-
return [] unless Yardoc.cached?(gemspec)
|
|
52
|
-
yardoc = Yardoc.load!(gemspec)
|
|
53
|
-
YardMap::Mapper.new(yardoc, gemspec).map
|
|
54
|
-
end
|
|
55
|
-
|
|
56
46
|
# @param yard_pins [Array<Pin::Base>]
|
|
57
47
|
# @param rbs_pins [Array<Pin::Base>]
|
|
58
48
|
#
|
|
59
49
|
# @return [Array<Pin::Base>]
|
|
60
|
-
def self.combine
|
|
50
|
+
def self.combine yard_pins, rbs_pins
|
|
61
51
|
in_yard = Set.new
|
|
62
|
-
|
|
52
|
+
rbs_store = Solargraph::ApiMap::Store.new(rbs_pins)
|
|
63
53
|
combined = yard_pins.map do |yard_pin|
|
|
64
54
|
in_yard.add yard_pin.path
|
|
65
|
-
rbs_pin =
|
|
66
|
-
|
|
55
|
+
rbs_pin = rbs_store.get_path_pins(yard_pin.path).filter { |pin| pin.is_a? Pin::Method }.first
|
|
56
|
+
|
|
57
|
+
next yard_pin unless rbs_pin && yard_pin.is_a?(Pin::Method)
|
|
67
58
|
|
|
68
59
|
unless rbs_pin
|
|
69
|
-
|
|
70
|
-
|
|
60
|
+
logger.debug do
|
|
61
|
+
"GemPins.combine: No rbs pin for #{yard_pin.path} - using YARD's '#{yard_pin.inspect} (return_type=#{yard_pin.return_type}; signatures=#{yard_pin.signatures})"
|
|
62
|
+
end
|
|
71
63
|
next yard_pin
|
|
72
64
|
end
|
|
73
65
|
|
|
66
|
+
# at this point both yard_pins and rbs_pins are methods or
|
|
67
|
+
# method aliases. if not plain methods, prefer the YARD one
|
|
68
|
+
next yard_pin if rbs_pin.class != Pin::Method
|
|
69
|
+
|
|
70
|
+
next rbs_pin if yard_pin.class != Pin::Method
|
|
71
|
+
|
|
72
|
+
# both are method pins
|
|
74
73
|
out = combine_method_pins(rbs_pin, yard_pin)
|
|
75
|
-
logger.debug
|
|
74
|
+
logger.debug do
|
|
75
|
+
"GemPins.combine: Combining yard.path=#{yard_pin.path} - rbs=#{rbs_pin.inspect} with yard=#{yard_pin.inspect} into #{out}"
|
|
76
|
+
end
|
|
76
77
|
out
|
|
77
78
|
end
|
|
78
79
|
in_rbs_only = rbs_pins.select do |pin|
|
|
@@ -91,7 +92,7 @@ module Solargraph
|
|
|
91
92
|
# @param choices [Array<ComplexType>]
|
|
92
93
|
# @return [ComplexType]
|
|
93
94
|
def best_return_type *choices
|
|
94
|
-
choices.find
|
|
95
|
+
choices.find(&:defined?) || choices.first || ComplexType::UNDEFINED
|
|
95
96
|
end
|
|
96
97
|
end
|
|
97
98
|
end
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Solargraph
|
|
4
|
-
module LanguageServer
|
|
5
|
-
# The ErrorCode constants for the language server protocol.
|
|
6
|
-
#
|
|
7
|
-
module ErrorCodes
|
|
8
|
-
PARSE_ERROR = -
|
|
9
|
-
INVALID_REQUEST = -
|
|
10
|
-
METHOD_NOT_FOUND = -
|
|
11
|
-
INVALID_PARAMS = -
|
|
12
|
-
INTERNAL_ERROR = -
|
|
13
|
-
SERVER_ERROR_START = -
|
|
14
|
-
SERVER_ERROR_END = -
|
|
15
|
-
SERVER_NOT_INITIALIZED = -
|
|
16
|
-
UNKNOWN_ERROR_CODE = -
|
|
17
|
-
REQUEST_CANCELLED = -
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
end
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Solargraph
|
|
4
|
+
module LanguageServer
|
|
5
|
+
# The ErrorCode constants for the language server protocol.
|
|
6
|
+
#
|
|
7
|
+
module ErrorCodes
|
|
8
|
+
PARSE_ERROR = -32_700
|
|
9
|
+
INVALID_REQUEST = -32_600
|
|
10
|
+
METHOD_NOT_FOUND = -32_601
|
|
11
|
+
INVALID_PARAMS = -32_602
|
|
12
|
+
INTERNAL_ERROR = -32_603
|
|
13
|
+
SERVER_ERROR_START = -32_099
|
|
14
|
+
SERVER_ERROR_END = -32_000
|
|
15
|
+
SERVER_NOT_INITIALIZED = -32_002
|
|
16
|
+
UNKNOWN_ERROR_CODE = -32_001
|
|
17
|
+
REQUEST_CANCELLED = -32_800
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -33,6 +33,7 @@ module Solargraph
|
|
|
33
33
|
# @return [void]
|
|
34
34
|
def update_libraries uri
|
|
35
35
|
src = sources.find(uri)
|
|
36
|
+
# @sg-ignore Need to add nil check here
|
|
36
37
|
using = libraries.select { |lib| lib.contain?(src.filename) }
|
|
37
38
|
using.push library_for(uri) if using.empty?
|
|
38
39
|
using.each { |lib| lib.merge src }
|
|
@@ -44,12 +45,11 @@ module Solargraph
|
|
|
44
45
|
# @param uri [String]
|
|
45
46
|
# @return [Library]
|
|
46
47
|
def library_for uri
|
|
47
|
-
|
|
48
|
+
explicit_library_for(uri) ||
|
|
48
49
|
implicit_library_for(uri) ||
|
|
49
50
|
generic_library_for(uri)
|
|
50
51
|
# previous library for already call attach. avoid call twice
|
|
51
52
|
# result.attach sources.find(uri) if sources.include?(uri)
|
|
52
|
-
result
|
|
53
53
|
end
|
|
54
54
|
|
|
55
55
|
# Find an explicit library match for the given URI. An explicit match
|
|
@@ -118,8 +118,8 @@ module Solargraph
|
|
|
118
118
|
.tap { |lib| lib.add_observer self }
|
|
119
119
|
end
|
|
120
120
|
|
|
121
|
-
# @param library [Solargraph::Library]
|
|
122
121
|
# @param progress [Solargraph::LanguageServer::Progress, nil]
|
|
122
|
+
#
|
|
123
123
|
# @return [void]
|
|
124
124
|
def update progress
|
|
125
125
|
progress&.send(self)
|
|
@@ -20,7 +20,7 @@ module Solargraph
|
|
|
20
20
|
].freeze
|
|
21
21
|
|
|
22
22
|
# @param host [Host]
|
|
23
|
-
def initialize
|
|
23
|
+
def initialize host
|
|
24
24
|
@host = host
|
|
25
25
|
@mutex = Mutex.new
|
|
26
26
|
@resource = ConditionVariable.new
|
|
@@ -28,7 +28,7 @@ module Solargraph
|
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
# pending handle messages
|
|
31
|
-
# @return [Array<Hash>]
|
|
31
|
+
# @return [Array<Hash{String => undefined}>]
|
|
32
32
|
def messages
|
|
33
33
|
@messages ||= []
|
|
34
34
|
end
|
|
@@ -44,7 +44,7 @@ module Solargraph
|
|
|
44
44
|
|
|
45
45
|
# @param message [Hash] The message to handle. Will be forwarded to Host#receive
|
|
46
46
|
# @return [void]
|
|
47
|
-
def queue
|
|
47
|
+
def queue message
|
|
48
48
|
@mutex.synchronize do
|
|
49
49
|
messages.push(message)
|
|
50
50
|
@resource.signal
|
|
@@ -66,6 +66,7 @@ module Solargraph
|
|
|
66
66
|
@resource.wait(@mutex) if messages.empty?
|
|
67
67
|
next_message
|
|
68
68
|
end
|
|
69
|
+
# @sg-ignore Need to add nil check here
|
|
69
70
|
handler = @host.receive(message)
|
|
70
71
|
handler&.send_response
|
|
71
72
|
end
|
|
@@ -13,7 +13,7 @@ module Solargraph
|
|
|
13
13
|
|
|
14
14
|
# @param uri [String]
|
|
15
15
|
# @return [void]
|
|
16
|
-
def add_uri
|
|
16
|
+
def add_uri uri
|
|
17
17
|
queue.push(uri)
|
|
18
18
|
end
|
|
19
19
|
|
|
@@ -55,6 +55,7 @@ module Solargraph
|
|
|
55
55
|
# @raise [FileNotFoundError] if the URI does not match an open source.
|
|
56
56
|
#
|
|
57
57
|
# @param uri [String]
|
|
58
|
+
# @sg-ignore flow ensitive typing should understand raise
|
|
58
59
|
# @return [Solargraph::Source]
|
|
59
60
|
def find uri
|
|
60
61
|
open_source_hash[uri] || raise(Solargraph::FileNotFoundError, "Host could not find #{uri}")
|
|
@@ -53,7 +53,7 @@ module Solargraph
|
|
|
53
53
|
logger.level = LOG_LEVELS[options['logLevel']] || DEFAULT_LOG_LEVEL
|
|
54
54
|
end
|
|
55
55
|
|
|
56
|
-
# @return [Hash{String =>
|
|
56
|
+
# @return [Hash{String => Boolean, String}]
|
|
57
57
|
def options
|
|
58
58
|
@options ||= default_configuration
|
|
59
59
|
end
|
|
@@ -105,6 +105,7 @@ module Solargraph
|
|
|
105
105
|
message.process unless cancel?(request['id'])
|
|
106
106
|
rescue StandardError => e
|
|
107
107
|
logger.warn "Error processing request: [#{e.class}] #{e.message}"
|
|
108
|
+
# @sg-ignore Need to add nil check here
|
|
108
109
|
logger.warn e.backtrace.join("\n")
|
|
109
110
|
message.set_error Solargraph::LanguageServer::ErrorCodes::INTERNAL_ERROR, "[#{e.class}] #{e.message}"
|
|
110
111
|
end
|
|
@@ -118,7 +119,7 @@ module Solargraph
|
|
|
118
119
|
nil
|
|
119
120
|
end
|
|
120
121
|
else
|
|
121
|
-
logger.warn
|
|
122
|
+
logger.warn 'Invalid message received.'
|
|
122
123
|
logger.debug request
|
|
123
124
|
nil
|
|
124
125
|
end
|
|
@@ -153,7 +154,7 @@ module Solargraph
|
|
|
153
154
|
lib.delete(*filenames)
|
|
154
155
|
end
|
|
155
156
|
uris.each do |uri|
|
|
156
|
-
send_notification
|
|
157
|
+
send_notification 'textDocument/publishDiagnostics', {
|
|
157
158
|
uri: uri,
|
|
158
159
|
diagnostics: []
|
|
159
160
|
}
|
|
@@ -208,7 +209,7 @@ module Solargraph
|
|
|
208
209
|
logger.info "Diagnosing #{uri}"
|
|
209
210
|
begin
|
|
210
211
|
results = library.diagnose uri_to_file(uri)
|
|
211
|
-
send_notification
|
|
212
|
+
send_notification 'textDocument/publishDiagnostics', {
|
|
212
213
|
uri: uri,
|
|
213
214
|
diagnostics: results
|
|
214
215
|
}
|
|
@@ -300,8 +301,11 @@ module Solargraph
|
|
|
300
301
|
end
|
|
301
302
|
end
|
|
302
303
|
|
|
304
|
+
# @sg-ignore Need to validate config
|
|
303
305
|
# @return [String]
|
|
306
|
+
# @sg-ignore Need to validate config
|
|
304
307
|
def command_path
|
|
308
|
+
# @type [String]
|
|
305
309
|
options['commandPath'] || 'solargraph'
|
|
306
310
|
end
|
|
307
311
|
|
|
@@ -350,7 +354,7 @@ module Solargraph
|
|
|
350
354
|
# @return [void]
|
|
351
355
|
def send_notification method, params
|
|
352
356
|
response = {
|
|
353
|
-
jsonrpc:
|
|
357
|
+
jsonrpc: '2.0',
|
|
354
358
|
method: method,
|
|
355
359
|
params: params
|
|
356
360
|
}
|
|
@@ -373,7 +377,7 @@ module Solargraph
|
|
|
373
377
|
def send_request method, params, &block
|
|
374
378
|
@request_mutex.synchronize do
|
|
375
379
|
message = {
|
|
376
|
-
jsonrpc:
|
|
380
|
+
jsonrpc: '2.0',
|
|
377
381
|
method: method,
|
|
378
382
|
params: params,
|
|
379
383
|
id: @next_request_id
|
|
@@ -415,13 +419,13 @@ module Solargraph
|
|
|
415
419
|
# @return [void]
|
|
416
420
|
def unregister_capabilities methods
|
|
417
421
|
logger.debug "Unregistering capabilities: #{methods}"
|
|
418
|
-
unregisterations = methods.select{|m| registered?(m)}.map
|
|
422
|
+
unregisterations = methods.select { |m| registered?(m) }.map do |m|
|
|
419
423
|
@registered_capabilities.delete m
|
|
420
424
|
{
|
|
421
425
|
id: m,
|
|
422
426
|
method: m
|
|
423
427
|
}
|
|
424
|
-
|
|
428
|
+
end
|
|
425
429
|
return if unregisterations.empty?
|
|
426
430
|
send_request 'client/unregisterCapability', { unregisterations: unregisterations }
|
|
427
431
|
end
|
|
@@ -489,7 +493,7 @@ module Solargraph
|
|
|
489
493
|
params['data']['location']['range']['end']['character']
|
|
490
494
|
)
|
|
491
495
|
)
|
|
492
|
-
result.concat
|
|
496
|
+
result.concat(library.locate_pins(location).select { |pin| pin.name == params['label'] })
|
|
493
497
|
end
|
|
494
498
|
if params['data']['path']
|
|
495
499
|
result.concat library.path_pins(params['data']['path'])
|
|
@@ -543,7 +547,7 @@ module Solargraph
|
|
|
543
547
|
end
|
|
544
548
|
|
|
545
549
|
# @return [Bool] if has pending completion request
|
|
546
|
-
def
|
|
550
|
+
def pending_completions?
|
|
547
551
|
message_worker.messages.reverse_each.any? { |req| req['method'] == 'textDocument/completion' }
|
|
548
552
|
end
|
|
549
553
|
|
|
@@ -644,7 +648,7 @@ module Solargraph
|
|
|
644
648
|
# @param text [String]
|
|
645
649
|
# @param type [Integer] A MessageType constant
|
|
646
650
|
# @param actions [Array<String>] Response options for the client
|
|
647
|
-
# @param block The block that processes the response
|
|
651
|
+
# @param block [Proc] The block that processes the response
|
|
648
652
|
# @yieldparam [String] The action received from the client
|
|
649
653
|
# @return [void]
|
|
650
654
|
def show_message_request text, type, actions, &block
|
|
@@ -663,7 +667,7 @@ module Solargraph
|
|
|
663
667
|
requests.keys
|
|
664
668
|
end
|
|
665
669
|
|
|
666
|
-
# @return [Hash{String =>
|
|
670
|
+
# @return [Hash{String => Boolean,String}]
|
|
667
671
|
def default_configuration
|
|
668
672
|
{
|
|
669
673
|
'completion' => true,
|
|
@@ -729,9 +733,11 @@ module Solargraph
|
|
|
729
733
|
end
|
|
730
734
|
|
|
731
735
|
# @param path [String]
|
|
736
|
+
# @sg-ignore Need to be able to choose signature on String#gsub
|
|
732
737
|
# @return [String]
|
|
733
738
|
def normalize_separators path
|
|
734
739
|
return path if File::ALT_SEPARATOR.nil?
|
|
740
|
+
# @sg-ignore flow sensitive typing needs to handle constants
|
|
735
741
|
path.gsub(File::ALT_SEPARATOR, File::SEPARATOR)
|
|
736
742
|
end
|
|
737
743
|
|
|
@@ -742,9 +748,12 @@ module Solargraph
|
|
|
742
748
|
params['contentChanges'].each do |recvd|
|
|
743
749
|
chng = check_diff(params['textDocument']['uri'], recvd)
|
|
744
750
|
changes.push Solargraph::Source::Change.new(
|
|
745
|
-
(chng['range'].nil?
|
|
746
|
-
|
|
747
|
-
|
|
751
|
+
(if chng['range'].nil?
|
|
752
|
+
nil
|
|
753
|
+
else
|
|
754
|
+
Solargraph::Range.from_to(chng['range']['start']['line'], chng['range']['start']['character'],
|
|
755
|
+
chng['range']['end']['line'], chng['range']['end']['character'])
|
|
756
|
+
end
|
|
748
757
|
),
|
|
749
758
|
chng['text']
|
|
750
759
|
)
|
|
@@ -764,8 +773,7 @@ module Solargraph
|
|
|
764
773
|
source = sources.find(uri)
|
|
765
774
|
return change if source.code.length + 1 != change['text'].length
|
|
766
775
|
diffs = Diff::LCS.diff(source.code, change['text'])
|
|
767
|
-
return change if diffs.
|
|
768
|
-
# @sg-ignore push this upstream
|
|
776
|
+
return change if diffs.empty? || diffs.length > 1 || diffs.first.length > 1
|
|
769
777
|
# @type [Diff::LCS::Change]
|
|
770
778
|
diff = diffs.first.first
|
|
771
779
|
return change unless diff.adding? && ['.', ':', '(', ',', ' '].include?(diff.element)
|
|
@@ -808,10 +816,10 @@ module Solargraph
|
|
|
808
816
|
# documentSymbolProvider: true,
|
|
809
817
|
# workspaceSymbolProvider: true,
|
|
810
818
|
# workspace: {
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
819
|
+
# workspaceFolders: {
|
|
820
|
+
# supported: true,
|
|
821
|
+
# changeNotifications: true
|
|
822
|
+
# }
|
|
815
823
|
# }
|
|
816
824
|
'textDocument/definition' => {
|
|
817
825
|
definitionProvider: true
|
|
@@ -858,7 +866,7 @@ module Solargraph
|
|
|
858
866
|
end
|
|
859
867
|
|
|
860
868
|
# @param library [Library]
|
|
861
|
-
#
|
|
869
|
+
#
|
|
862
870
|
# @return [void]
|
|
863
871
|
def sync_library_map library
|
|
864
872
|
total = library.workspace.sources.length
|
|
@@ -1,97 +1,97 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Solargraph
|
|
4
|
-
module LanguageServer
|
|
5
|
-
module Message
|
|
6
|
-
class Base
|
|
7
|
-
# @return [Solargraph::LanguageServer::Host]
|
|
8
|
-
attr_reader :host
|
|
9
|
-
|
|
10
|
-
# @return [Integer]
|
|
11
|
-
attr_reader :id
|
|
12
|
-
|
|
13
|
-
# @return [Hash]
|
|
14
|
-
attr_reader :request
|
|
15
|
-
|
|
16
|
-
# @return [String]
|
|
17
|
-
attr_reader :method
|
|
18
|
-
|
|
19
|
-
# @return [Hash{String => undefined}]
|
|
20
|
-
attr_reader :params
|
|
21
|
-
|
|
22
|
-
# @return [Hash, Array, nil]
|
|
23
|
-
attr_reader :result
|
|
24
|
-
|
|
25
|
-
# @return [Hash, nil]
|
|
26
|
-
attr_reader :error
|
|
27
|
-
|
|
28
|
-
# @param host [Solargraph::LanguageServer::Host]
|
|
29
|
-
# @param request [Hash]
|
|
30
|
-
def initialize host, request
|
|
31
|
-
@host = host
|
|
32
|
-
@id = request['id'].freeze
|
|
33
|
-
@request = request.freeze
|
|
34
|
-
@method = request['method'].freeze
|
|
35
|
-
@params = (request['params'] || {}).freeze
|
|
36
|
-
post_initialize
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
# @return [void]
|
|
40
|
-
def post_initialize; end
|
|
41
|
-
|
|
42
|
-
# @return [void]
|
|
43
|
-
def process; end
|
|
44
|
-
|
|
45
|
-
# @param data [Hash, Array, nil]
|
|
46
|
-
# @return [void]
|
|
47
|
-
def set_result data
|
|
48
|
-
@result = data
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
# @param code [Integer] See Solargraph::LanguageServer::ErrorCodes
|
|
52
|
-
# @param message [String]
|
|
53
|
-
# @return [void]
|
|
54
|
-
def set_error code, message
|
|
55
|
-
@error = {
|
|
56
|
-
code: code,
|
|
57
|
-
message: message
|
|
58
|
-
}
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
# @return [void]
|
|
62
|
-
def send_response
|
|
63
|
-
return if id.nil?
|
|
64
|
-
|
|
65
|
-
accept_or_cancel
|
|
66
|
-
response = {
|
|
67
|
-
jsonrpc: '2.0',
|
|
68
|
-
id: id
|
|
69
|
-
}
|
|
70
|
-
response[:result] = result unless result.nil?
|
|
71
|
-
response[:error] = error unless error.nil?
|
|
72
|
-
response[:result] = nil if result.nil?
|
|
73
|
-
json = response.to_json
|
|
74
|
-
envelope = "Content-Length: #{json.bytesize}\r\n\r\n#{json}"
|
|
75
|
-
Solargraph.logger.debug envelope
|
|
76
|
-
host.queue envelope
|
|
77
|
-
host.clear id
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
private
|
|
81
|
-
|
|
82
|
-
# @return [void]
|
|
83
|
-
def accept_or_cancel
|
|
84
|
-
if host.cancel?(id)
|
|
85
|
-
# https://microsoft.github.io/language-server-protocol/specifications/specification-current/#cancelRequest
|
|
86
|
-
# cancel should send response RequestCancelled
|
|
87
|
-
Solargraph::Logging.logger.info "Cancelled response to ##{id} #{method}"
|
|
88
|
-
set_result nil
|
|
89
|
-
set_error ErrorCodes::REQUEST_CANCELLED, 'Cancelled by client'
|
|
90
|
-
else
|
|
91
|
-
Solargraph::Logging.logger.info "Sending response to ##{id} #{method}"
|
|
92
|
-
end
|
|
93
|
-
end
|
|
94
|
-
end
|
|
95
|
-
end
|
|
96
|
-
end
|
|
97
|
-
end
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Solargraph
|
|
4
|
+
module LanguageServer
|
|
5
|
+
module Message
|
|
6
|
+
class Base
|
|
7
|
+
# @return [Solargraph::LanguageServer::Host]
|
|
8
|
+
attr_reader :host
|
|
9
|
+
|
|
10
|
+
# @return [Integer]
|
|
11
|
+
attr_reader :id
|
|
12
|
+
|
|
13
|
+
# @return [Hash]
|
|
14
|
+
attr_reader :request
|
|
15
|
+
|
|
16
|
+
# @return [String]
|
|
17
|
+
attr_reader :method
|
|
18
|
+
|
|
19
|
+
# @return [Hash{String => undefined}]
|
|
20
|
+
attr_reader :params
|
|
21
|
+
|
|
22
|
+
# @return [Hash, Array, nil]
|
|
23
|
+
attr_reader :result
|
|
24
|
+
|
|
25
|
+
# @return [Hash, nil]
|
|
26
|
+
attr_reader :error
|
|
27
|
+
|
|
28
|
+
# @param host [Solargraph::LanguageServer::Host]
|
|
29
|
+
# @param request [Hash]
|
|
30
|
+
def initialize host, request
|
|
31
|
+
@host = host
|
|
32
|
+
@id = request['id'].freeze
|
|
33
|
+
@request = request.freeze
|
|
34
|
+
@method = request['method'].freeze
|
|
35
|
+
@params = (request['params'] || {}).freeze
|
|
36
|
+
post_initialize
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# @return [void]
|
|
40
|
+
def post_initialize; end
|
|
41
|
+
|
|
42
|
+
# @return [void]
|
|
43
|
+
def process; end
|
|
44
|
+
|
|
45
|
+
# @param data [Hash, Array, nil]
|
|
46
|
+
# @return [void]
|
|
47
|
+
def set_result data
|
|
48
|
+
@result = data
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# @param code [Integer] See Solargraph::LanguageServer::ErrorCodes
|
|
52
|
+
# @param message [String]
|
|
53
|
+
# @return [void]
|
|
54
|
+
def set_error code, message
|
|
55
|
+
@error = {
|
|
56
|
+
code: code,
|
|
57
|
+
message: message
|
|
58
|
+
}
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# @return [void]
|
|
62
|
+
def send_response
|
|
63
|
+
return if id.nil?
|
|
64
|
+
|
|
65
|
+
accept_or_cancel
|
|
66
|
+
response = {
|
|
67
|
+
jsonrpc: '2.0',
|
|
68
|
+
id: id
|
|
69
|
+
}
|
|
70
|
+
response[:result] = result unless result.nil?
|
|
71
|
+
response[:error] = error unless error.nil?
|
|
72
|
+
response[:result] = nil if result.nil? && error.nil?
|
|
73
|
+
json = response.to_json
|
|
74
|
+
envelope = "Content-Length: #{json.bytesize}\r\n\r\n#{json}"
|
|
75
|
+
Solargraph.logger.debug envelope
|
|
76
|
+
host.queue envelope
|
|
77
|
+
host.clear id
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
private
|
|
81
|
+
|
|
82
|
+
# @return [void]
|
|
83
|
+
def accept_or_cancel
|
|
84
|
+
if host.cancel?(id)
|
|
85
|
+
# https://microsoft.github.io/language-server-protocol/specifications/specification-current/#cancelRequest
|
|
86
|
+
# cancel should send response RequestCancelled
|
|
87
|
+
Solargraph::Logging.logger.info "Cancelled response to ##{id} #{method}"
|
|
88
|
+
set_result nil
|
|
89
|
+
set_error ErrorCodes::REQUEST_CANCELLED, 'Cancelled by client'
|
|
90
|
+
else
|
|
91
|
+
Solargraph::Logging.logger.info "Sending response to ##{id} #{method}"
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
end
|
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Solargraph
|
|
4
|
-
module LanguageServer
|
|
5
|
-
module Message
|
|
6
|
-
module Client
|
|
7
|
-
class RegisterCapability < Solargraph::LanguageServer::Message::Base
|
|
8
|
-
def process
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
end
|
|
15
|
-
end
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Solargraph
|
|
4
|
+
module LanguageServer
|
|
5
|
+
module Message
|
|
6
|
+
module Client
|
|
7
|
+
class RegisterCapability < Solargraph::LanguageServer::Message::Base
|
|
8
|
+
def process; end
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|