solargraph 0.58.3 → 0.59.0
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 +6 -5
- data/.github/workflows/plugins.yml +46 -34
- data/.github/workflows/rspec.yml +15 -28
- data/.github/workflows/typecheck.yml +3 -2
- data/.rubocop.yml +38 -6
- data/.rubocop_todo.yml +53 -966
- data/CHANGELOG.md +12 -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 +39 -28
- data/lib/solargraph/api_map.rb +156 -72
- data/lib/solargraph/bench.rb +2 -3
- data/lib/solargraph/complex_type/conformance.rb +176 -0
- data/lib/solargraph/complex_type/type_methods.rb +30 -18
- data/lib/solargraph/complex_type/unique_type.rb +216 -57
- data/lib/solargraph/complex_type.rb +171 -58
- 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/doc_map.rb +38 -39
- data/lib/solargraph/equality.rb +4 -4
- data/lib/solargraph/gem_pins.rb +6 -6
- 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 +30 -22
- 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/search.rb +1 -1
- data/lib/solargraph/language_server/message/initialize.rb +20 -14
- 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/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/request.rb +4 -2
- data/lib/solargraph/language_server/transport/data_reader.rb +11 -13
- data/lib/solargraph/language_server/uri_helpers.rb +2 -2
- 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 +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 +11 -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 +9 -8
- 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 +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 +124 -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 +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 +156 -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/type_alias.rb +16 -0
- data/lib/solargraph/pin/reference.rb +20 -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 +22 -19
- data/lib/solargraph/position.rb +17 -10
- data/lib/solargraph/range.rb +16 -15
- data/lib/solargraph/rbs_map/conversions.rb +358 -229
- 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 +4 -2
- 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/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 +9 -6
- 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 +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 +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 +195 -121
- 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/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_map.rb +17 -18
- data/lib/solargraph/yard_tags.rb +2 -2
- data/lib/solargraph/yardoc.rb +7 -4
- data/lib/solargraph.rb +31 -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 +37 -35
- metadata +41 -41
- 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
|
@@ -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
|
|
@@ -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
|
|
@@ -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
|
)
|
|
@@ -26,20 +26,27 @@ module Solargraph
|
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
# FIXME: lsp default is utf-16, may have different position
|
|
29
|
-
result[:capabilities][:positionEncoding] =
|
|
29
|
+
result[:capabilities][:positionEncoding] = 'utf-32' if params.dig('capabilities', 'general',
|
|
30
|
+
'positionEncodings')&.include?('utf-32')
|
|
30
31
|
result[:capabilities].merge! static_completion unless dynamic_registration_for?('textDocument', 'completion')
|
|
31
|
-
result[:capabilities].merge! static_signature_help unless dynamic_registration_for?('textDocument',
|
|
32
|
+
result[:capabilities].merge! static_signature_help unless dynamic_registration_for?('textDocument',
|
|
33
|
+
'signatureHelp')
|
|
32
34
|
# result[:capabilities].merge! static_on_type_formatting unless dynamic_registration_for?('textDocument', 'onTypeFormatting')
|
|
33
35
|
result[:capabilities].merge! static_hover unless dynamic_registration_for?('textDocument', 'hover')
|
|
34
|
-
result[:capabilities].merge! static_document_formatting unless dynamic_registration_for?('textDocument',
|
|
35
|
-
|
|
36
|
+
result[:capabilities].merge! static_document_formatting unless dynamic_registration_for?('textDocument',
|
|
37
|
+
'formatting')
|
|
38
|
+
result[:capabilities].merge! static_document_symbols unless dynamic_registration_for?('textDocument',
|
|
39
|
+
'documentSymbol')
|
|
36
40
|
result[:capabilities].merge! static_definitions unless dynamic_registration_for?('textDocument', 'definition')
|
|
37
|
-
result[:capabilities].merge! static_type_definitions unless dynamic_registration_for?('textDocument',
|
|
41
|
+
result[:capabilities].merge! static_type_definitions unless dynamic_registration_for?('textDocument',
|
|
42
|
+
'typeDefinition')
|
|
38
43
|
result[:capabilities].merge! static_rename unless dynamic_registration_for?('textDocument', 'rename')
|
|
39
44
|
result[:capabilities].merge! static_references unless dynamic_registration_for?('textDocument', 'references')
|
|
40
45
|
result[:capabilities].merge! static_workspace_symbols unless dynamic_registration_for?('workspace', 'symbol')
|
|
41
|
-
result[:capabilities].merge! static_folding_range unless dynamic_registration_for?('textDocument',
|
|
42
|
-
|
|
46
|
+
result[:capabilities].merge! static_folding_range unless dynamic_registration_for?('textDocument',
|
|
47
|
+
'foldingRange')
|
|
48
|
+
result[:capabilities].merge! static_highlights unless dynamic_registration_for?('textDocument',
|
|
49
|
+
'documentHighlight')
|
|
43
50
|
# @todo Temporarily disabled
|
|
44
51
|
# result[:capabilities].merge! static_code_action unless dynamic_registration_for?('textDocument', 'codeAction')
|
|
45
52
|
set_result result
|
|
@@ -71,7 +78,7 @@ module Solargraph
|
|
|
71
78
|
def static_code_action
|
|
72
79
|
{
|
|
73
80
|
codeActionProvider: true,
|
|
74
|
-
codeActionKinds: [
|
|
81
|
+
codeActionKinds: ['quickfix']
|
|
75
82
|
}
|
|
76
83
|
end
|
|
77
84
|
|
|
@@ -144,11 +151,10 @@ module Solargraph
|
|
|
144
151
|
# @return [Hash{Symbol => Hash{Symbol => Boolean}}]
|
|
145
152
|
def static_rename
|
|
146
153
|
{
|
|
147
|
-
renameProvider: {prepareProvider: true}
|
|
154
|
+
renameProvider: { prepareProvider: true }
|
|
148
155
|
}
|
|
149
156
|
end
|
|
150
157
|
|
|
151
|
-
|
|
152
158
|
# @return [Hash{Symbol => Boolean}]
|
|
153
159
|
def static_references
|
|
154
160
|
return {} unless host.options['references']
|
|
@@ -178,10 +184,10 @@ module Solargraph
|
|
|
178
184
|
# enforce strict true/false-ness
|
|
179
185
|
# @sg-ignore
|
|
180
186
|
def dynamic_registration_for? section, capability
|
|
181
|
-
result =
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
187
|
+
result = params['capabilities'] &&
|
|
188
|
+
params['capabilities'][section] &&
|
|
189
|
+
params['capabilities'][section][capability] &&
|
|
190
|
+
params['capabilities'][section][capability]['dynamicRegistration']
|
|
185
191
|
host.allow_registration("#{section}/#{capability}") if result
|
|
186
192
|
result
|
|
187
193
|
end
|
|
@@ -6,7 +6,7 @@ module Solargraph
|
|
|
6
6
|
module TextDocument
|
|
7
7
|
class Completion < Base
|
|
8
8
|
def process
|
|
9
|
-
return set_error(ErrorCodes::REQUEST_CANCELLED,
|
|
9
|
+
return set_error(ErrorCodes::REQUEST_CANCELLED, 'cancelled by so many request') if host.pending_completions?
|
|
10
10
|
|
|
11
11
|
line = params['position']['line']
|
|
12
12
|
col = params['position']['character']
|
|
@@ -15,15 +15,16 @@ module Solargraph
|
|
|
15
15
|
items = []
|
|
16
16
|
last_context = nil
|
|
17
17
|
idx = -1
|
|
18
|
+
# @sg-ignore Need to add nil check here
|
|
18
19
|
completion.pins.each do |pin|
|
|
19
20
|
idx += 1 if last_context != pin.context
|
|
20
21
|
items.push pin.completion_item.merge({
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
textEdit: {
|
|
23
|
+
range: completion.range.to_hash,
|
|
24
|
+
newText: pin.name.sub(/=$/, ' = ').sub(/:$/, ': ')
|
|
25
|
+
},
|
|
26
|
+
sortText: "#{idx.to_s.rjust(4, '0')}#{pin.name}"
|
|
27
|
+
})
|
|
27
28
|
items.last[:data][:uri] = params['textDocument']['uri']
|
|
28
29
|
last_context = pin.context
|
|
29
30
|
end
|
|
@@ -31,12 +32,13 @@ module Solargraph
|
|
|
31
32
|
isIncomplete: false,
|
|
32
33
|
items: items
|
|
33
34
|
)
|
|
34
|
-
rescue InvalidOffsetError
|
|
35
|
+
rescue InvalidOffsetError
|
|
35
36
|
Logging.logger.info "Completion ignored invalid offset: #{params['textDocument']['uri']}, line #{line}, character #{col}"
|
|
36
37
|
set_result empty_result
|
|
37
38
|
end
|
|
38
39
|
rescue FileNotFoundError => e
|
|
39
40
|
Logging.logger.warn "[#{e.class}] #{e.message}"
|
|
41
|
+
# @sg-ignore Need to add nil check here
|
|
40
42
|
Logging.logger.warn e.backtrace.join("\n")
|
|
41
43
|
set_result empty_result
|
|
42
44
|
end
|
|
@@ -1,40 +1,49 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
module Solargraph
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
3
|
+
module Solargraph
|
|
4
|
+
module LanguageServer
|
|
5
|
+
module Message
|
|
6
|
+
module TextDocument
|
|
7
|
+
class Definition < Base
|
|
8
|
+
def process
|
|
9
|
+
@line = params['position']['line']
|
|
10
|
+
@column = params['position']['character']
|
|
11
|
+
set_result(code_location || require_location || [])
|
|
12
|
+
end
|
|
10
13
|
|
|
11
|
-
|
|
14
|
+
private
|
|
12
15
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
16
|
+
# @return [Array<Hash>, nil]
|
|
17
|
+
def code_location
|
|
18
|
+
suggestions = host.definitions_at(params['textDocument']['uri'], @line, @column)
|
|
19
|
+
# @sg-ignore Need to add nil check here
|
|
20
|
+
return nil if suggestions.empty?
|
|
21
|
+
# @sg-ignore Need to add nil check here
|
|
22
|
+
suggestions.reject { |pin| pin.best_location.nil? || pin.best_location.filename.nil? }.map do |pin|
|
|
23
|
+
{
|
|
24
|
+
uri: file_to_uri(pin.best_location.filename),
|
|
25
|
+
range: pin.best_location.range.to_hash
|
|
26
|
+
}
|
|
27
|
+
end
|
|
28
|
+
end
|
|
24
29
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
30
|
+
# @return [Array<Hash>, nil]
|
|
31
|
+
def require_location
|
|
32
|
+
# @todo Terrible hack
|
|
33
|
+
lib = host.library_for(params['textDocument']['uri'])
|
|
34
|
+
rloc = Solargraph::Location.new(uri_to_file(params['textDocument']['uri']),
|
|
35
|
+
Solargraph::Range.from_to(@line, @column, @line, @column))
|
|
36
|
+
dloc = lib.locate_ref(rloc)
|
|
37
|
+
return nil if dloc.nil?
|
|
38
|
+
[
|
|
39
|
+
{
|
|
40
|
+
uri: file_to_uri(dloc.filename),
|
|
41
|
+
range: dloc.range.to_hash
|
|
42
|
+
}
|
|
43
|
+
]
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
38
47
|
end
|
|
39
48
|
end
|
|
40
49
|
end
|
|
@@ -1,16 +1,23 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
module Solargraph
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
3
|
+
module Solargraph
|
|
4
|
+
module LanguageServer
|
|
5
|
+
module Message
|
|
6
|
+
module TextDocument
|
|
7
|
+
class DocumentHighlight < Base
|
|
8
|
+
def process
|
|
9
|
+
locs = host.references_from(params['textDocument']['uri'], params['position']['line'],
|
|
10
|
+
params['position']['character'], strip: true, only: true)
|
|
11
|
+
result = locs.map do |loc|
|
|
12
|
+
{
|
|
13
|
+
range: loc.range.to_hash,
|
|
14
|
+
kind: 1
|
|
15
|
+
}
|
|
16
|
+
end
|
|
17
|
+
set_result result
|
|
18
|
+
end
|
|
19
|
+
end
|
|
12
20
|
end
|
|
13
|
-
set_result result
|
|
14
21
|
end
|
|
15
22
|
end
|
|
16
23
|
end
|