solargraph 0.59.0.dev.1 → 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/.github/workflows/plugins.yml +4 -1
- data/.github/workflows/rspec.yml +3 -14
- data/.gitignore +1 -0
- data/.rubocop.yml +32 -5
- data/.rubocop_todo.yml +37 -931
- data/CHANGELOG.md +7 -1
- data/Gemfile +3 -1
- data/Rakefile +25 -23
- data/bin/solargraph +2 -1
- data/lib/solargraph/api_map/index.rb +5 -11
- data/lib/solargraph/api_map/source_to_yard.rb +9 -8
- data/lib/solargraph/api_map/store.rb +22 -20
- data/lib/solargraph/api_map.rb +50 -37
- data/lib/solargraph/bench.rb +44 -45
- data/lib/solargraph/complex_type/type_methods.rb +12 -15
- data/lib/solargraph/complex_type/unique_type.rb +54 -43
- data/lib/solargraph/complex_type.rb +69 -61
- data/lib/solargraph/convention/data_definition/data_assignment_node.rb +61 -61
- data/lib/solargraph/convention/data_definition/data_definition_node.rb +4 -4
- data/lib/solargraph/convention/data_definition.rb +1 -1
- 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 +1 -1
- data/lib/solargraph/convention/struct_definition/struct_definition_node.rb +3 -3
- data/lib/solargraph/convention/struct_definition.rb +3 -3
- 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/rubocop.rb +10 -10
- data/lib/solargraph/diagnostics/rubocop_helpers.rb +3 -3
- data/lib/solargraph/diagnostics/type_check.rb +10 -10
- data/lib/solargraph/diagnostics/update_errors.rb +37 -41
- data/lib/solargraph/doc_map.rb +9 -10
- data/lib/solargraph/equality.rb +3 -3
- data/lib/solargraph/gem_pins.rb +7 -5
- data/lib/solargraph/language_server/error_codes.rb +20 -20
- data/lib/solargraph/language_server/host/diagnoser.rb +89 -89
- data/lib/solargraph/language_server/host/dispatch.rb +2 -3
- data/lib/solargraph/language_server/host/message_worker.rb +2 -2
- data/lib/solargraph/language_server/host/sources.rb +1 -1
- data/lib/solargraph/language_server/host.rb +24 -21
- 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 +10 -11
- 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 +8 -8
- data/lib/solargraph/language_server/message/text_document/definition.rb +41 -34
- 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 -21
- data/lib/solargraph/language_server/message/text_document/formatting.rb +6 -6
- data/lib/solargraph/language_server/message/text_document/hover.rb +3 -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 +2 -2
- data/lib/solargraph/language_server/message/text_document/type_definition.rb +25 -19
- 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 -19
- 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 +28 -33
- data/lib/solargraph/location.rb +10 -12
- data/lib/solargraph/logging.rb +4 -4
- data/lib/solargraph/page.rb +92 -92
- data/lib/solargraph/parser/comment_ripper.rb +12 -4
- data/lib/solargraph/parser/flow_sensitive_typing.rb +32 -42
- data/lib/solargraph/parser/node_processor/base.rb +4 -4
- data/lib/solargraph/parser/node_processor.rb +1 -1
- data/lib/solargraph/parser/parser_gem/class_methods.rb +4 -4
- data/lib/solargraph/parser/parser_gem/flawed_builder.rb +19 -19
- data/lib/solargraph/parser/parser_gem/node_chainer.rb +20 -20
- data/lib/solargraph/parser/parser_gem/node_methods.rb +66 -65
- data/lib/solargraph/parser/parser_gem/node_processors/args_node.rb +12 -12
- data/lib/solargraph/parser/parser_gem/node_processors/block_node.rb +1 -1
- data/lib/solargraph/parser/parser_gem/node_processors/def_node.rb +3 -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 +3 -3
- data/lib/solargraph/parser/parser_gem/node_processors/ivasgn_node.rb +2 -1
- data/lib/solargraph/parser/parser_gem/node_processors/opasgn_node.rb +1 -1
- data/lib/solargraph/parser/parser_gem/node_processors/sclass_node.rb +3 -5
- data/lib/solargraph/parser/parser_gem/node_processors/send_node.rb +118 -112
- data/lib/solargraph/parser/parser_gem/node_processors/until_node.rb +29 -29
- data/lib/solargraph/parser/parser_gem/node_processors/when_node.rb +1 -1
- data/lib/solargraph/parser/parser_gem/node_processors/while_node.rb +1 -1
- data/lib/solargraph/parser/parser_gem.rb +14 -12
- data/lib/solargraph/parser/snippet.rb +2 -0
- data/lib/solargraph/parser.rb +25 -23
- data/lib/solargraph/pin/base.rb +78 -64
- data/lib/solargraph/pin/base_variable.rb +28 -71
- data/lib/solargraph/pin/block.rb +3 -2
- data/lib/solargraph/pin/breakable.rb +2 -0
- data/lib/solargraph/pin/callable.rb +23 -26
- data/lib/solargraph/pin/closure.rb +5 -4
- data/lib/solargraph/pin/common.rb +5 -2
- data/lib/solargraph/pin/compound_statement.rb +3 -3
- data/lib/solargraph/pin/constant.rb +43 -45
- data/lib/solargraph/pin/conversions.rb +9 -4
- data/lib/solargraph/pin/delegated_method.rb +4 -4
- data/lib/solargraph/pin/documenting.rb +3 -2
- data/lib/solargraph/pin/local_variable.rb +4 -4
- data/lib/solargraph/pin/method.rb +71 -70
- data/lib/solargraph/pin/namespace.rb +13 -12
- data/lib/solargraph/pin/parameter.rb +28 -27
- data/lib/solargraph/pin/proxy_type.rb +2 -0
- data/lib/solargraph/pin/reference.rb +17 -0
- data/lib/solargraph/pin/search.rb +2 -2
- data/lib/solargraph/pin/signature.rb +9 -14
- data/lib/solargraph/pin/symbol.rb +1 -0
- data/lib/solargraph/pin/until.rb +1 -3
- data/lib/solargraph/pin/while.rb +1 -3
- data/lib/solargraph/pin_cache.rb +16 -19
- data/lib/solargraph/position.rb +35 -17
- data/lib/solargraph/range.rb +10 -9
- data/lib/solargraph/rbs_map/conversions.rb +312 -206
- data/lib/solargraph/rbs_map/core_fills.rb +91 -84
- data/lib/solargraph/rbs_map/stdlib_map.rb +0 -1
- data/lib/solargraph/rbs_map.rb +3 -12
- data/lib/solargraph/server_methods.rb +16 -16
- data/lib/solargraph/shell.rb +63 -53
- data/lib/solargraph/source/chain/array.rb +39 -37
- data/lib/solargraph/source/chain/call.rb +49 -44
- data/lib/solargraph/source/chain/class_variable.rb +13 -13
- data/lib/solargraph/source/chain/constant.rb +3 -1
- data/lib/solargraph/source/chain/global_variable.rb +13 -13
- data/lib/solargraph/source/chain/hash.rb +8 -6
- data/lib/solargraph/source/chain/if.rb +11 -10
- data/lib/solargraph/source/chain/instance_variable.rb +3 -1
- data/lib/solargraph/source/chain/link.rb +99 -109
- data/lib/solargraph/source/chain/literal.rb +4 -6
- data/lib/solargraph/source/chain/or.rb +2 -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 +24 -16
- data/lib/solargraph/source/change.rb +3 -3
- data/lib/solargraph/source/cursor.rb +18 -18
- data/lib/solargraph/source/encoding_fixes.rb +6 -7
- data/lib/solargraph/source/source_chainer.rb +46 -32
- data/lib/solargraph/source/updater.rb +1 -1
- data/lib/solargraph/source.rb +27 -29
- data/lib/solargraph/source_map/clip.rb +38 -30
- data/lib/solargraph/source_map/mapper.rb +52 -46
- data/lib/solargraph/source_map.rb +8 -4
- data/lib/solargraph/type_checker/rules.rb +8 -8
- data/lib/solargraph/type_checker.rb +95 -101
- data/lib/solargraph/version.rb +1 -1
- data/lib/solargraph/workspace/config.rb +10 -9
- data/lib/solargraph/workspace/gemspecs.rb +1 -1
- data/lib/solargraph/workspace.rb +21 -44
- data/lib/solargraph/yard_map/helpers.rb +6 -2
- data/lib/solargraph/yard_map/mapper/to_method.rb +8 -6
- data/lib/solargraph/yard_map/mapper/to_namespace.rb +1 -1
- data/lib/solargraph/yard_map/mapper.rb +12 -12
- data/lib/solargraph/yard_tags.rb +20 -20
- data/lib/solargraph.rb +5 -5
- data/solargraph.gemspec +35 -34
- metadata +28 -28
|
@@ -1,89 +1,89 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Solargraph
|
|
4
|
-
module LanguageServer
|
|
5
|
-
class Host
|
|
6
|
-
# An asynchronous diagnosis reporter.
|
|
7
|
-
#
|
|
8
|
-
class Diagnoser
|
|
9
|
-
# @param host [Host]
|
|
10
|
-
def initialize host
|
|
11
|
-
@host = host
|
|
12
|
-
@mutex = Mutex.new
|
|
13
|
-
@queue = []
|
|
14
|
-
@stopped = true
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
# Schedule a file to be diagnosed.
|
|
18
|
-
#
|
|
19
|
-
# @param uri [String]
|
|
20
|
-
# @return [void]
|
|
21
|
-
def schedule uri
|
|
22
|
-
mutex.synchronize { queue.push uri }
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
# Stop the diagnosis thread.
|
|
26
|
-
#
|
|
27
|
-
# @return [void]
|
|
28
|
-
def stop
|
|
29
|
-
@stopped = true
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
# True is the diagnoser is stopped.
|
|
33
|
-
#
|
|
34
|
-
# @return [Boolean]
|
|
35
|
-
def stopped?
|
|
36
|
-
@stopped
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
# Start the diagnosis thread.
|
|
40
|
-
#
|
|
41
|
-
# @return [self, nil]
|
|
42
|
-
def start
|
|
43
|
-
return unless @stopped
|
|
44
|
-
@stopped = false
|
|
45
|
-
Thread.new do
|
|
46
|
-
until stopped?
|
|
47
|
-
tick
|
|
48
|
-
sleep 0.1
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
self
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
# Perform diagnoses.
|
|
55
|
-
#
|
|
56
|
-
# @return [void]
|
|
57
|
-
def tick
|
|
58
|
-
return if queue.empty? || host.synchronizing?
|
|
59
|
-
|
|
60
|
-
mutex.synchronize { queue.clear }
|
|
61
|
-
return
|
|
62
|
-
end
|
|
63
|
-
current = mutex.synchronize { queue.shift }
|
|
64
|
-
return if queue.include?(current)
|
|
65
|
-
begin
|
|
66
|
-
host.diagnose current
|
|
67
|
-
rescue InvalidOffsetError
|
|
68
|
-
# @todo This error can occur when the Source is out of sync with
|
|
69
|
-
# with the ApiMap. It's probably not the best way to handle it,
|
|
70
|
-
# but it's quick and easy.
|
|
71
|
-
Logging.logger.warn "Deferring diagnosis due to invalid offset: #{current}"
|
|
72
|
-
mutex.synchronize { queue.push current }
|
|
73
|
-
end
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
private
|
|
77
|
-
|
|
78
|
-
# @return [Host]
|
|
79
|
-
attr_reader :host
|
|
80
|
-
|
|
81
|
-
# @return [Mutex]
|
|
82
|
-
attr_reader :mutex
|
|
83
|
-
|
|
84
|
-
# @return [::Array]
|
|
85
|
-
attr_reader :queue
|
|
86
|
-
end
|
|
87
|
-
end
|
|
88
|
-
end
|
|
89
|
-
end
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Solargraph
|
|
4
|
+
module LanguageServer
|
|
5
|
+
class Host
|
|
6
|
+
# An asynchronous diagnosis reporter.
|
|
7
|
+
#
|
|
8
|
+
class Diagnoser
|
|
9
|
+
# @param host [Host]
|
|
10
|
+
def initialize host
|
|
11
|
+
@host = host
|
|
12
|
+
@mutex = Mutex.new
|
|
13
|
+
@queue = []
|
|
14
|
+
@stopped = true
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# Schedule a file to be diagnosed.
|
|
18
|
+
#
|
|
19
|
+
# @param uri [String]
|
|
20
|
+
# @return [void]
|
|
21
|
+
def schedule uri
|
|
22
|
+
mutex.synchronize { queue.push uri }
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# Stop the diagnosis thread.
|
|
26
|
+
#
|
|
27
|
+
# @return [void]
|
|
28
|
+
def stop
|
|
29
|
+
@stopped = true
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# True is the diagnoser is stopped.
|
|
33
|
+
#
|
|
34
|
+
# @return [Boolean]
|
|
35
|
+
def stopped?
|
|
36
|
+
@stopped
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# Start the diagnosis thread.
|
|
40
|
+
#
|
|
41
|
+
# @return [self, nil]
|
|
42
|
+
def start
|
|
43
|
+
return unless @stopped
|
|
44
|
+
@stopped = false
|
|
45
|
+
Thread.new do
|
|
46
|
+
until stopped?
|
|
47
|
+
tick
|
|
48
|
+
sleep 0.1
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
self
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# Perform diagnoses.
|
|
55
|
+
#
|
|
56
|
+
# @return [void]
|
|
57
|
+
def tick
|
|
58
|
+
return if queue.empty? || host.synchronizing?
|
|
59
|
+
unless host.options['diagnostics']
|
|
60
|
+
mutex.synchronize { queue.clear }
|
|
61
|
+
return
|
|
62
|
+
end
|
|
63
|
+
current = mutex.synchronize { queue.shift }
|
|
64
|
+
return if queue.include?(current)
|
|
65
|
+
begin
|
|
66
|
+
host.diagnose current
|
|
67
|
+
rescue InvalidOffsetError
|
|
68
|
+
# @todo This error can occur when the Source is out of sync with
|
|
69
|
+
# with the ApiMap. It's probably not the best way to handle it,
|
|
70
|
+
# but it's quick and easy.
|
|
71
|
+
Logging.logger.warn "Deferring diagnosis due to invalid offset: #{current}"
|
|
72
|
+
mutex.synchronize { queue.push current }
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
private
|
|
77
|
+
|
|
78
|
+
# @return [Host]
|
|
79
|
+
attr_reader :host
|
|
80
|
+
|
|
81
|
+
# @return [Mutex]
|
|
82
|
+
attr_reader :mutex
|
|
83
|
+
|
|
84
|
+
# @return [::Array]
|
|
85
|
+
attr_reader :queue
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
@@ -45,12 +45,11 @@ module Solargraph
|
|
|
45
45
|
# @param uri [String]
|
|
46
46
|
# @return [Library]
|
|
47
47
|
def library_for uri
|
|
48
|
-
|
|
48
|
+
explicit_library_for(uri) ||
|
|
49
49
|
implicit_library_for(uri) ||
|
|
50
50
|
generic_library_for(uri)
|
|
51
51
|
# previous library for already call attach. avoid call twice
|
|
52
52
|
# result.attach sources.find(uri) if sources.include?(uri)
|
|
53
|
-
result
|
|
54
53
|
end
|
|
55
54
|
|
|
56
55
|
# Find an explicit library match for the given URI. An explicit match
|
|
@@ -119,8 +118,8 @@ module Solargraph
|
|
|
119
118
|
.tap { |lib| lib.add_observer self }
|
|
120
119
|
end
|
|
121
120
|
|
|
122
|
-
# @param library [Solargraph::Library]
|
|
123
121
|
# @param progress [Solargraph::LanguageServer::Progress, nil]
|
|
122
|
+
#
|
|
124
123
|
# @return [void]
|
|
125
124
|
def update progress
|
|
126
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
|
|
@@ -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
|
|
@@ -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
|
|
@@ -119,7 +119,7 @@ module Solargraph
|
|
|
119
119
|
nil
|
|
120
120
|
end
|
|
121
121
|
else
|
|
122
|
-
logger.warn
|
|
122
|
+
logger.warn 'Invalid message received.'
|
|
123
123
|
logger.debug request
|
|
124
124
|
nil
|
|
125
125
|
end
|
|
@@ -154,7 +154,7 @@ module Solargraph
|
|
|
154
154
|
lib.delete(*filenames)
|
|
155
155
|
end
|
|
156
156
|
uris.each do |uri|
|
|
157
|
-
send_notification
|
|
157
|
+
send_notification 'textDocument/publishDiagnostics', {
|
|
158
158
|
uri: uri,
|
|
159
159
|
diagnostics: []
|
|
160
160
|
}
|
|
@@ -209,7 +209,7 @@ module Solargraph
|
|
|
209
209
|
logger.info "Diagnosing #{uri}"
|
|
210
210
|
begin
|
|
211
211
|
results = library.diagnose uri_to_file(uri)
|
|
212
|
-
send_notification
|
|
212
|
+
send_notification 'textDocument/publishDiagnostics', {
|
|
213
213
|
uri: uri,
|
|
214
214
|
diagnostics: results
|
|
215
215
|
}
|
|
@@ -354,7 +354,7 @@ module Solargraph
|
|
|
354
354
|
# @return [void]
|
|
355
355
|
def send_notification method, params
|
|
356
356
|
response = {
|
|
357
|
-
jsonrpc:
|
|
357
|
+
jsonrpc: '2.0',
|
|
358
358
|
method: method,
|
|
359
359
|
params: params
|
|
360
360
|
}
|
|
@@ -377,7 +377,7 @@ module Solargraph
|
|
|
377
377
|
def send_request method, params, &block
|
|
378
378
|
@request_mutex.synchronize do
|
|
379
379
|
message = {
|
|
380
|
-
jsonrpc:
|
|
380
|
+
jsonrpc: '2.0',
|
|
381
381
|
method: method,
|
|
382
382
|
params: params,
|
|
383
383
|
id: @next_request_id
|
|
@@ -419,13 +419,13 @@ module Solargraph
|
|
|
419
419
|
# @return [void]
|
|
420
420
|
def unregister_capabilities methods
|
|
421
421
|
logger.debug "Unregistering capabilities: #{methods}"
|
|
422
|
-
unregisterations = methods.select{|m| registered?(m)}.map
|
|
422
|
+
unregisterations = methods.select { |m| registered?(m) }.map do |m|
|
|
423
423
|
@registered_capabilities.delete m
|
|
424
424
|
{
|
|
425
425
|
id: m,
|
|
426
426
|
method: m
|
|
427
427
|
}
|
|
428
|
-
|
|
428
|
+
end
|
|
429
429
|
return if unregisterations.empty?
|
|
430
430
|
send_request 'client/unregisterCapability', { unregisterations: unregisterations }
|
|
431
431
|
end
|
|
@@ -493,7 +493,7 @@ module Solargraph
|
|
|
493
493
|
params['data']['location']['range']['end']['character']
|
|
494
494
|
)
|
|
495
495
|
)
|
|
496
|
-
result.concat
|
|
496
|
+
result.concat(library.locate_pins(location).select { |pin| pin.name == params['label'] })
|
|
497
497
|
end
|
|
498
498
|
if params['data']['path']
|
|
499
499
|
result.concat library.path_pins(params['data']['path'])
|
|
@@ -547,7 +547,7 @@ module Solargraph
|
|
|
547
547
|
end
|
|
548
548
|
|
|
549
549
|
# @return [Bool] if has pending completion request
|
|
550
|
-
def
|
|
550
|
+
def pending_completions?
|
|
551
551
|
message_worker.messages.reverse_each.any? { |req| req['method'] == 'textDocument/completion' }
|
|
552
552
|
end
|
|
553
553
|
|
|
@@ -648,7 +648,7 @@ module Solargraph
|
|
|
648
648
|
# @param text [String]
|
|
649
649
|
# @param type [Integer] A MessageType constant
|
|
650
650
|
# @param actions [Array<String>] Response options for the client
|
|
651
|
-
# @param block The block that processes the response
|
|
651
|
+
# @param block [Proc] The block that processes the response
|
|
652
652
|
# @yieldparam [String] The action received from the client
|
|
653
653
|
# @return [void]
|
|
654
654
|
def show_message_request text, type, actions, &block
|
|
@@ -667,7 +667,7 @@ module Solargraph
|
|
|
667
667
|
requests.keys
|
|
668
668
|
end
|
|
669
669
|
|
|
670
|
-
# @return [Hash{String =>
|
|
670
|
+
# @return [Hash{String => Boolean,String}]
|
|
671
671
|
def default_configuration
|
|
672
672
|
{
|
|
673
673
|
'completion' => true,
|
|
@@ -748,9 +748,12 @@ module Solargraph
|
|
|
748
748
|
params['contentChanges'].each do |recvd|
|
|
749
749
|
chng = check_diff(params['textDocument']['uri'], recvd)
|
|
750
750
|
changes.push Solargraph::Source::Change.new(
|
|
751
|
-
(chng['range'].nil?
|
|
752
|
-
|
|
753
|
-
|
|
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
|
|
754
757
|
),
|
|
755
758
|
chng['text']
|
|
756
759
|
)
|
|
@@ -770,7 +773,7 @@ module Solargraph
|
|
|
770
773
|
source = sources.find(uri)
|
|
771
774
|
return change if source.code.length + 1 != change['text'].length
|
|
772
775
|
diffs = Diff::LCS.diff(source.code, change['text'])
|
|
773
|
-
return change if diffs.
|
|
776
|
+
return change if diffs.empty? || diffs.length > 1 || diffs.first.length > 1
|
|
774
777
|
# @type [Diff::LCS::Change]
|
|
775
778
|
diff = diffs.first.first
|
|
776
779
|
return change unless diff.adding? && ['.', ':', '(', ',', ' '].include?(diff.element)
|
|
@@ -813,10 +816,10 @@ module Solargraph
|
|
|
813
816
|
# documentSymbolProvider: true,
|
|
814
817
|
# workspaceSymbolProvider: true,
|
|
815
818
|
# workspace: {
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
819
|
+
# workspaceFolders: {
|
|
820
|
+
# supported: true,
|
|
821
|
+
# changeNotifications: true
|
|
822
|
+
# }
|
|
820
823
|
# }
|
|
821
824
|
'textDocument/definition' => {
|
|
822
825
|
definitionProvider: true
|
|
@@ -863,7 +866,7 @@ module Solargraph
|
|
|
863
866
|
end
|
|
864
867
|
|
|
865
868
|
# @param library [Library]
|
|
866
|
-
#
|
|
869
|
+
#
|
|
867
870
|
# @return [void]
|
|
868
871
|
def sync_library_map library
|
|
869
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
|