solargraph 0.58.3 → 0.59.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 +12 -5
- data/.github/workflows/plugins.yml +54 -34
- data/.github/workflows/rspec.yml +15 -28
- data/.github/workflows/typecheck.yml +6 -3
- data/.rubocop.yml +38 -6
- data/.rubocop_todo.yml +53 -966
- data/CHANGELOG.md +24 -0
- 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 +12 -3
- data/lib/solargraph/api_map/index.rb +29 -18
- data/lib/solargraph/api_map/source_to_yard.rb +22 -9
- data/lib/solargraph/api_map/store.rb +40 -30
- data/lib/solargraph/api_map.rb +160 -78
- data/lib/solargraph/bench.rb +2 -3
- data/lib/solargraph/complex_type/conformance.rb +176 -0
- data/lib/solargraph/complex_type/type_methods.rb +31 -18
- data/lib/solargraph/complex_type/unique_type.rb +221 -63
- data/lib/solargraph/complex_type.rb +173 -59
- data/lib/solargraph/convention/active_support_concern.rb +111 -111
- data/lib/solargraph/convention/base.rb +50 -50
- data/lib/solargraph/convention/data_definition/data_assignment_node.rb +1 -1
- 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 +1 -1
- data/lib/solargraph/convention/gemspec.rb +1 -1
- data/lib/solargraph/convention/rakefile.rb +1 -1
- 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 +2 -2
- data/lib/solargraph/converters/dd.rb +2 -0
- data/lib/solargraph/converters/dl.rb +2 -0
- data/lib/solargraph/converters/dt.rb +2 -0
- data/lib/solargraph/converters/misc.rb +2 -0
- 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 +4 -8
- data/lib/solargraph/diagnostics.rb +55 -55
- data/lib/solargraph/doc_map.rb +38 -39
- data/lib/solargraph/environ.rb +52 -52
- data/lib/solargraph/equality.rb +4 -4
- data/lib/solargraph/gem_pins.rb +4 -15
- data/lib/solargraph/language_server/error_codes.rb +10 -10
- 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 +35 -28
- data/lib/solargraph/language_server/message/base.rb +1 -1
- data/lib/solargraph/language_server/message/client/register_capability.rb +1 -3
- data/lib/solargraph/language_server/message/completion_item/resolve.rb +6 -8
- 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 +7 -7
- data/lib/solargraph/language_server/message/extended/download_core.rb +2 -1
- data/lib/solargraph/language_server/message/extended/environment.rb +25 -25
- data/lib/solargraph/language_server/message/extended/search.rb +1 -1
- data/lib/solargraph/language_server/message/initialize.rb +20 -14
- data/lib/solargraph/language_server/message/initialized.rb +28 -28
- 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 +17 -10
- 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 +13 -6
- data/lib/solargraph/language_server/message/text_document/references.rb +17 -10
- data/lib/solargraph/language_server/message/text_document/rename.rb +20 -13
- 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/text_document.rb +28 -28
- data/lib/solargraph/language_server/message/workspace/did_change_configuration.rb +34 -28
- data/lib/solargraph/language_server/message/workspace/did_change_watched_files.rb +38 -30
- data/lib/solargraph/language_server/message/workspace/did_change_workspace_folders.rb +23 -17
- data/lib/solargraph/language_server/message/workspace/workspace_symbol.rb +27 -17
- data/lib/solargraph/language_server/message.rb +1 -1
- data/lib/solargraph/language_server/progress.rb +143 -143
- data/lib/solargraph/language_server/request.rb +4 -2
- data/lib/solargraph/language_server/transport/adapter.rb +68 -68
- data/lib/solargraph/language_server/transport/data_reader.rb +11 -13
- data/lib/solargraph/language_server/uri_helpers.rb +2 -2
- data/lib/solargraph/language_server.rb +20 -20
- data/lib/solargraph/library.rb +57 -38
- data/lib/solargraph/location.rb +17 -14
- data/lib/solargraph/logging.rb +22 -4
- data/lib/solargraph/page.rb +1 -1
- data/lib/solargraph/parser/comment_ripper.rb +19 -4
- data/lib/solargraph/parser/flow_sensitive_typing.rb +324 -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 +30 -14
- data/lib/solargraph/parser/parser_gem/flawed_builder.rb +1 -1
- data/lib/solargraph/parser/parser_gem/node_chainer.rb +51 -25
- data/lib/solargraph/parser/parser_gem/node_methods.rb +181 -73
- data/lib/solargraph/parser/parser_gem/node_processors/alias_node.rb +24 -24
- 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 +11 -12
- data/lib/solargraph/parser/parser_gem/node_processors/casgn_node.rb +36 -36
- data/lib/solargraph/parser/parser_gem/node_processors/cvasgn_node.rb +24 -24
- data/lib/solargraph/parser/parser_gem/node_processors/def_node.rb +10 -3
- data/lib/solargraph/parser/parser_gem/node_processors/defs_node.rb +9 -8
- data/lib/solargraph/parser/parser_gem/node_processors/gvasgn_node.rb +24 -24
- 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/namespace_node.rb +40 -40
- 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/sym_node.rb +20 -20
- data/lib/solargraph/parser/parser_gem/node_processors/until_node.rb +1 -1
- 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 +2 -0
- data/lib/solargraph/parser/region.rb +9 -3
- data/lib/solargraph/parser/snippet.rb +3 -1
- data/lib/solargraph/parser.rb +2 -0
- data/lib/solargraph/pin/base.rb +126 -82
- 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 +3 -5
- 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 +158 -104
- data/lib/solargraph/pin/method_alias.rb +8 -0
- data/lib/solargraph/pin/namespace.rb +19 -12
- data/lib/solargraph/pin/parameter.rb +102 -36
- data/lib/solargraph/pin/proxy_type.rb +4 -1
- data/lib/solargraph/pin/reference/override.rb +1 -1
- data/lib/solargraph/pin/reference/require.rb +14 -14
- data/lib/solargraph/pin/reference/superclass.rb +2 -0
- data/lib/solargraph/pin/reference/type_alias.rb +16 -0
- data/lib/solargraph/pin/reference.rb +20 -0
- data/lib/solargraph/pin/search.rb +8 -7
- data/lib/solargraph/pin/signature.rb +15 -12
- data/lib/solargraph/pin/singleton.rb +11 -11
- 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 +22 -19
- data/lib/solargraph/position.rb +17 -10
- data/lib/solargraph/range.rb +16 -15
- data/lib/solargraph/rbs_map/conversions.rb +367 -231
- data/lib/solargraph/rbs_map/core_fills.rb +18 -11
- 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 +76 -32
- data/lib/solargraph/server_methods.rb +1 -1
- data/lib/solargraph/shell.rb +258 -66
- data/lib/solargraph/source/chain/array.rb +3 -12
- data/lib/solargraph/source/chain/block_symbol.rb +13 -13
- data/lib/solargraph/source/chain/block_variable.rb +13 -13
- data/lib/solargraph/source/chain/call.rb +96 -56
- data/lib/solargraph/source/chain/class_variable.rb +1 -1
- data/lib/solargraph/source/chain/constant.rb +5 -1
- data/lib/solargraph/source/chain/global_variable.rb +1 -1
- data/lib/solargraph/source/chain/hash.rb +8 -5
- data/lib/solargraph/source/chain/head.rb +19 -19
- 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 +12 -22
- data/lib/solargraph/source/chain/literal.rb +22 -15
- data/lib/solargraph/source/chain/or.rb +10 -4
- data/lib/solargraph/source/chain/q_call.rb +2 -0
- data/lib/solargraph/source/chain/variable.rb +3 -1
- data/lib/solargraph/source/chain/z_super.rb +1 -3
- data/lib/solargraph/source/chain.rb +51 -38
- data/lib/solargraph/source/change.rb +12 -5
- data/lib/solargraph/source/cursor.rb +33 -18
- 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 +54 -30
- data/lib/solargraph/source_map/data.rb +4 -1
- data/lib/solargraph/source_map/mapper.rb +69 -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 +196 -122
- data/lib/solargraph/version.rb +1 -1
- data/lib/solargraph/workspace/config.rb +14 -11
- data/lib/solargraph/workspace/gemspecs.rb +367 -0
- data/lib/solargraph/workspace/require_paths.rb +1 -0
- data/lib/solargraph/workspace.rb +50 -28
- data/lib/solargraph/yard_map/cache.rb +25 -25
- data/lib/solargraph/yard_map/helpers.rb +8 -3
- data/lib/solargraph/yard_map/mapper/to_constant.rb +28 -28
- 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_map.rb +17 -18
- data/lib/solargraph/yard_tags.rb +2 -2
- data/lib/solargraph/yardoc.rb +7 -4
- data/lib/solargraph.rb +33 -10
- data/rbs/fills/rubygems/0/dependency.rbs +193 -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 +37 -35
- metadata +41 -42
- 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/rbs/fills/tuple/tuple.rbs +0 -149
data/lib/solargraph/gem_pins.rb
CHANGED
|
@@ -11,17 +11,6 @@ module Solargraph
|
|
|
11
11
|
include Logging
|
|
12
12
|
end
|
|
13
13
|
|
|
14
|
-
# @param pins [Array<Pin::Base>]
|
|
15
|
-
# @return [Array<Pin::Base>]
|
|
16
|
-
def self.combine_method_pins_by_path(pins)
|
|
17
|
-
method_pins, alias_pins = pins.partition { |pin| pin.class == Pin::Method }
|
|
18
|
-
by_path = method_pins.group_by(&:path)
|
|
19
|
-
by_path.transform_values! do |pins|
|
|
20
|
-
GemPins.combine_method_pins(*pins)
|
|
21
|
-
end
|
|
22
|
-
by_path.values + alias_pins
|
|
23
|
-
end
|
|
24
|
-
|
|
25
14
|
# @param pins [Array<Pin::Method>]
|
|
26
15
|
# @return [Pin::Method, nil]
|
|
27
16
|
def self.combine_method_pins(*pins)
|
|
@@ -46,7 +35,7 @@ module Solargraph
|
|
|
46
35
|
# @param yard_plugins [Array<String>] The names of YARD plugins to use.
|
|
47
36
|
# @param gemspec [Gem::Specification]
|
|
48
37
|
# @return [Array<Pin::Base>]
|
|
49
|
-
def self.build_yard_pins
|
|
38
|
+
def self.build_yard_pins yard_plugins, gemspec
|
|
50
39
|
Yardoc.cache(yard_plugins, gemspec) unless Yardoc.cached?(gemspec)
|
|
51
40
|
return [] unless Yardoc.cached?(gemspec)
|
|
52
41
|
yardoc = Yardoc.load!(gemspec)
|
|
@@ -57,13 +46,13 @@ module Solargraph
|
|
|
57
46
|
# @param rbs_pins [Array<Pin::Base>]
|
|
58
47
|
#
|
|
59
48
|
# @return [Array<Pin::Base>]
|
|
60
|
-
def self.combine
|
|
49
|
+
def self.combine yard_pins, rbs_pins
|
|
61
50
|
in_yard = Set.new
|
|
62
51
|
rbs_api_map = Solargraph::ApiMap.new(pins: rbs_pins)
|
|
63
52
|
combined = yard_pins.map do |yard_pin|
|
|
64
53
|
in_yard.add yard_pin.path
|
|
65
54
|
rbs_pin = rbs_api_map.get_path_pins(yard_pin.path).filter { |pin| pin.is_a? Pin::Method }.first
|
|
66
|
-
next yard_pin unless rbs_pin && yard_pin.
|
|
55
|
+
next yard_pin unless rbs_pin && yard_pin.instance_of?(Pin::Method)
|
|
67
56
|
|
|
68
57
|
unless rbs_pin
|
|
69
58
|
# @sg-ignore https://github.com/castwide/solargraph/pull/1114
|
|
@@ -91,7 +80,7 @@ module Solargraph
|
|
|
91
80
|
# @param choices [Array<ComplexType>]
|
|
92
81
|
# @return [ComplexType]
|
|
93
82
|
def best_return_type *choices
|
|
94
|
-
choices.find
|
|
83
|
+
choices.find(&:defined?) || choices.first || ComplexType::UNDEFINED
|
|
95
84
|
end
|
|
96
85
|
end
|
|
97
86
|
end
|
|
@@ -5,16 +5,16 @@ module Solargraph
|
|
|
5
5
|
# The ErrorCode constants for the language server protocol.
|
|
6
6
|
#
|
|
7
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 = -
|
|
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
18
|
end
|
|
19
19
|
end
|
|
20
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,15 +648,14 @@ 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
|
|
648
651
|
# @yieldparam [String] The action received from the client
|
|
649
652
|
# @return [void]
|
|
650
|
-
def show_message_request
|
|
651
|
-
send_request
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
653
|
+
def show_message_request(text, type, actions, &)
|
|
654
|
+
send_request('window/showMessageRequest', {
|
|
655
|
+
type: type,
|
|
656
|
+
message: text,
|
|
657
|
+
actions: actions
|
|
658
|
+
}, &)
|
|
656
659
|
end
|
|
657
660
|
|
|
658
661
|
# Get a list of IDs for server requests that are waiting for responses
|
|
@@ -663,7 +666,7 @@ module Solargraph
|
|
|
663
666
|
requests.keys
|
|
664
667
|
end
|
|
665
668
|
|
|
666
|
-
# @return [Hash{String =>
|
|
669
|
+
# @return [Hash{String => Boolean,String}]
|
|
667
670
|
def default_configuration
|
|
668
671
|
{
|
|
669
672
|
'completion' => true,
|
|
@@ -729,9 +732,11 @@ module Solargraph
|
|
|
729
732
|
end
|
|
730
733
|
|
|
731
734
|
# @param path [String]
|
|
735
|
+
# @sg-ignore Need to be able to choose signature on String#gsub
|
|
732
736
|
# @return [String]
|
|
733
737
|
def normalize_separators path
|
|
734
738
|
return path if File::ALT_SEPARATOR.nil?
|
|
739
|
+
# @sg-ignore flow sensitive typing needs to handle constants
|
|
735
740
|
path.gsub(File::ALT_SEPARATOR, File::SEPARATOR)
|
|
736
741
|
end
|
|
737
742
|
|
|
@@ -742,9 +747,12 @@ module Solargraph
|
|
|
742
747
|
params['contentChanges'].each do |recvd|
|
|
743
748
|
chng = check_diff(params['textDocument']['uri'], recvd)
|
|
744
749
|
changes.push Solargraph::Source::Change.new(
|
|
745
|
-
(chng['range'].nil?
|
|
746
|
-
|
|
747
|
-
|
|
750
|
+
(if chng['range'].nil?
|
|
751
|
+
nil
|
|
752
|
+
else
|
|
753
|
+
Solargraph::Range.from_to(chng['range']['start']['line'], chng['range']['start']['character'],
|
|
754
|
+
chng['range']['end']['line'], chng['range']['end']['character'])
|
|
755
|
+
end
|
|
748
756
|
),
|
|
749
757
|
chng['text']
|
|
750
758
|
)
|
|
@@ -764,8 +772,7 @@ module Solargraph
|
|
|
764
772
|
source = sources.find(uri)
|
|
765
773
|
return change if source.code.length + 1 != change['text'].length
|
|
766
774
|
diffs = Diff::LCS.diff(source.code, change['text'])
|
|
767
|
-
return change if diffs.
|
|
768
|
-
# @sg-ignore push this upstream
|
|
775
|
+
return change if diffs.empty? || diffs.length > 1 || diffs.first.length > 1
|
|
769
776
|
# @type [Diff::LCS::Change]
|
|
770
777
|
diff = diffs.first.first
|
|
771
778
|
return change unless diff.adding? && ['.', ':', '(', ',', ' '].include?(diff.element)
|
|
@@ -808,10 +815,10 @@ module Solargraph
|
|
|
808
815
|
# documentSymbolProvider: true,
|
|
809
816
|
# workspaceSymbolProvider: true,
|
|
810
817
|
# workspace: {
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
818
|
+
# workspaceFolders: {
|
|
819
|
+
# supported: true,
|
|
820
|
+
# changeNotifications: true
|
|
821
|
+
# }
|
|
815
822
|
# }
|
|
816
823
|
'textDocument/definition' => {
|
|
817
824
|
definitionProvider: true
|
|
@@ -858,7 +865,7 @@ module Solargraph
|
|
|
858
865
|
end
|
|
859
866
|
|
|
860
867
|
# @param library [Library]
|
|
861
|
-
#
|
|
868
|
+
#
|
|
862
869
|
# @return [void]
|
|
863
870
|
def sync_library_map library
|
|
864
871
|
total = library.workspace.sources.length
|
|
@@ -69,7 +69,7 @@ module Solargraph
|
|
|
69
69
|
}
|
|
70
70
|
response[:result] = result unless result.nil?
|
|
71
71
|
response[:error] = error unless error.nil?
|
|
72
|
-
response[:result] = nil if result.nil?
|
|
72
|
+
response[:result] = nil if result.nil? && error.nil?
|
|
73
73
|
json = response.to_json
|
|
74
74
|
envelope = "Content-Length: #{json.bytesize}\r\n\r\n#{json}"
|
|
75
75
|
Solargraph.logger.debug envelope
|
|
@@ -21,9 +21,9 @@ module Solargraph
|
|
|
21
21
|
docs = pins
|
|
22
22
|
.reject { |pin| pin.documentation.empty? && pin.return_type.undefined? }
|
|
23
23
|
result = params
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
.transform_keys(&:to_sym)
|
|
25
|
+
.merge(pins.first.resolve_completion_item)
|
|
26
|
+
.merge(documentation: markup_content(join_docs(docs)))
|
|
27
27
|
result[:detail] = pins.first.detail
|
|
28
28
|
result
|
|
29
29
|
end
|
|
@@ -43,12 +43,10 @@ module Solargraph
|
|
|
43
43
|
def join_docs pins
|
|
44
44
|
result = []
|
|
45
45
|
last_link = nil
|
|
46
|
-
pins.
|
|
46
|
+
pins.each do |pin|
|
|
47
47
|
this_link = host.options['enablePages'] ? pin.link_documentation : pin.text_documentation
|
|
48
|
-
if this_link && this_link != last_link && this_link != 'undefined'
|
|
49
|
-
|
|
50
|
-
end
|
|
51
|
-
result.push pin.documentation unless result.last && result.last.end_with?(pin.documentation)
|
|
48
|
+
result.push this_link if this_link && this_link != last_link && this_link != 'undefined'
|
|
49
|
+
result.push pin.documentation unless result.last&.end_with?(pin.documentation)
|
|
52
50
|
last_link = this_link
|
|
53
51
|
end
|
|
54
52
|
result.join("\n\n")
|
|
@@ -1,12 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
# @todo PR the RBS gem to add this
|
|
5
|
-
# @!parse
|
|
6
|
-
# module ::Gem
|
|
7
|
-
# class SpecFetcher; end
|
|
8
|
-
# end
|
|
9
|
-
|
|
10
3
|
module Solargraph
|
|
11
4
|
module LanguageServer
|
|
12
5
|
module Message
|
|
@@ -23,8 +16,8 @@ module Solargraph
|
|
|
23
16
|
|
|
24
17
|
# @param obj [Gem::SpecFetcher]
|
|
25
18
|
# @return [Gem::SpecFetcher]
|
|
26
|
-
|
|
27
|
-
|
|
19
|
+
class << self
|
|
20
|
+
attr_writer :fetcher
|
|
28
21
|
end
|
|
29
22
|
|
|
30
23
|
GEM_ZERO = Gem::Version.new('0.0.0')
|
|
@@ -47,11 +40,11 @@ module Solargraph
|
|
|
47
40
|
['Update now'] do |result|
|
|
48
41
|
next unless result == 'Update now'
|
|
49
42
|
cmd = if host.options['useBundler']
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
43
|
+
'bundle update solargraph'
|
|
44
|
+
else
|
|
45
|
+
'gem update solargraph'
|
|
46
|
+
end
|
|
47
|
+
_, s = Open3.capture2(cmd)
|
|
55
48
|
if s == 0
|
|
56
49
|
host.show_message 'Successfully updated the Solargraph gem.', LanguageServer::MessageTypes::INFO
|
|
57
50
|
host.send_notification '$/solargraph/restart', {}
|
|
@@ -64,12 +57,13 @@ module Solargraph
|
|
|
64
57
|
end
|
|
65
58
|
elsif fetched?
|
|
66
59
|
Solargraph::Logging.logger.warn error
|
|
60
|
+
# @sg-ignore Need to add nil check here
|
|
67
61
|
host.show_message(error, MessageTypes::ERROR) if params['verbose']
|
|
68
62
|
end
|
|
69
63
|
set_result({
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
64
|
+
installed: current,
|
|
65
|
+
available: available
|
|
66
|
+
})
|
|
73
67
|
end
|
|
74
68
|
|
|
75
69
|
private
|
|
@@ -78,12 +72,12 @@ module Solargraph
|
|
|
78
72
|
attr_reader :current
|
|
79
73
|
|
|
80
74
|
# @return [Gem::Version]
|
|
75
|
+
# @sg-ignore Need to add nil check here
|
|
81
76
|
def available
|
|
82
77
|
if !@available && !@fetched
|
|
83
78
|
@fetched = true
|
|
84
79
|
begin
|
|
85
80
|
@available ||= begin
|
|
86
|
-
# @sg-ignore Variable type could not be inferred for tuple
|
|
87
81
|
# @type [Gem::Dependency, nil]
|
|
88
82
|
tuple = CheckGemVersion.fetcher.search_for_dependency(Gem::Dependency.new('solargraph')).flatten.first
|
|
89
83
|
if tuple.nil?
|
|
@@ -13,16 +13,16 @@ module Solargraph
|
|
|
13
13
|
def process
|
|
14
14
|
cmd = [host.command_path, 'gems']
|
|
15
15
|
cmd.push '--rebuild' if params['rebuild']
|
|
16
|
-
|
|
17
|
-
if s
|
|
18
|
-
host.show_message "An error occurred while building gem documentation.", LanguageServer::MessageTypes::ERROR
|
|
16
|
+
_, s = Open3.capture2(*cmd)
|
|
17
|
+
if s == 0
|
|
19
18
|
set_result({
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
status: 'ok'
|
|
20
|
+
})
|
|
22
21
|
else
|
|
22
|
+
host.show_message 'An error occurred while building gem documentation.', LanguageServer::MessageTypes::ERROR
|
|
23
23
|
set_result({
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
status: 'err'
|
|
25
|
+
})
|
|
26
26
|
end
|
|
27
27
|
end
|
|
28
28
|
end
|
|
@@ -10,7 +10,8 @@ module Solargraph
|
|
|
10
10
|
#
|
|
11
11
|
class DownloadCore < Base
|
|
12
12
|
def process
|
|
13
|
-
host.show_message
|
|
13
|
+
host.show_message 'Downloading cores is deprecated. Solargraph currently uses RBS for core and stdlib documentation',
|
|
14
|
+
LanguageServer::MessageTypes::INFO
|
|
14
15
|
end
|
|
15
16
|
end
|
|
16
17
|
end
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Solargraph
|
|
4
|
-
module LanguageServer
|
|
5
|
-
module Message
|
|
6
|
-
module Extended
|
|
7
|
-
# Update YARD documentation for installed gems. If the `rebuild`
|
|
8
|
-
# parameter is true, rebuild existing yardocs.
|
|
9
|
-
#
|
|
10
|
-
class Environment < Base
|
|
11
|
-
def process
|
|
12
|
-
# Make sure the environment page can report RuboCop's version
|
|
13
|
-
require 'rubocop'
|
|
14
|
-
|
|
15
|
-
page = Solargraph::Page.new(host.options['viewsPath'])
|
|
16
|
-
content = page.render('environment', layout: true, locals: { config: host.options, folders: host.folders })
|
|
17
|
-
set_result(
|
|
18
|
-
content: content
|
|
19
|
-
)
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
end
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Solargraph
|
|
4
|
+
module LanguageServer
|
|
5
|
+
module Message
|
|
6
|
+
module Extended
|
|
7
|
+
# Update YARD documentation for installed gems. If the `rebuild`
|
|
8
|
+
# parameter is true, rebuild existing yardocs.
|
|
9
|
+
#
|
|
10
|
+
class Environment < Base
|
|
11
|
+
def process
|
|
12
|
+
# Make sure the environment page can report RuboCop's version
|
|
13
|
+
require 'rubocop'
|
|
14
|
+
|
|
15
|
+
page = Solargraph::Page.new(host.options['viewsPath'])
|
|
16
|
+
content = page.render('environment', layout: true, locals: { config: host.options, folders: host.folders })
|
|
17
|
+
set_result(
|
|
18
|
+
content: content
|
|
19
|
+
)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -8,7 +8,7 @@ module Solargraph
|
|
|
8
8
|
def process
|
|
9
9
|
results = host.search(params['query'])
|
|
10
10
|
page = Solargraph::Page.new(host.options['viewsPath'])
|
|
11
|
-
content = page.render('search', layout: true, locals: {query: params['query'], results: results})
|
|
11
|
+
content = page.render('search', layout: true, locals: { query: params['query'], results: results })
|
|
12
12
|
set_result(
|
|
13
13
|
content: content
|
|
14
14
|
)
|