solargraph 0.32.1 → 0.32.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.rubocop.yml +6 -0
- data/.travis.yml +25 -0
- data/EXAMPLES.md +76 -0
- data/Gemfile +3 -0
- data/LANGUAGE_SERVER.md +51 -0
- data/LICENSE +21 -0
- data/OVERVIEW.md +37 -0
- data/README.md +106 -0
- data/Rakefile +14 -0
- data/SERVER.md +95 -0
- data/bin/solargraph +0 -0
- data/bin/solargraph-runtime +5 -5
- data/lib/solargraph.rb +54 -54
- data/lib/solargraph/api_map.rb +659 -659
- data/lib/solargraph/api_map/cache.rb +49 -49
- data/lib/solargraph/api_map/source_to_yard.rb +67 -67
- data/lib/solargraph/api_map/store.rb +201 -201
- data/lib/solargraph/bundle.rb +24 -24
- data/lib/solargraph/complex_type.rb +150 -150
- data/lib/solargraph/complex_type/type_methods.rb +124 -124
- data/lib/solargraph/complex_type/unique_type.rb +44 -44
- data/lib/solargraph/core_fills.rb +37 -37
- data/lib/solargraph/diagnostics.rb +52 -52
- data/lib/solargraph/diagnostics/base.rb +20 -20
- data/lib/solargraph/diagnostics/require_not_found.rb +28 -28
- data/lib/solargraph/diagnostics/rubocop.rb +98 -98
- data/lib/solargraph/diagnostics/rubocop_helpers.rb +46 -46
- data/lib/solargraph/diagnostics/type_not_defined.rb +108 -108
- data/lib/solargraph/diagnostics/update_errors.rb +38 -38
- data/lib/solargraph/language_server/completion_item_kinds.rb +33 -33
- data/lib/solargraph/language_server/error_codes.rb +18 -18
- data/lib/solargraph/language_server/host.rb +684 -681
- data/lib/solargraph/language_server/host/cataloger.rb +54 -79
- data/lib/solargraph/language_server/host/diagnoser.rb +80 -80
- data/lib/solargraph/language_server/host/dispatch.rb +112 -113
- data/lib/solargraph/language_server/host/sources.rb +138 -138
- data/lib/solargraph/language_server/message.rb +90 -90
- data/lib/solargraph/language_server/message/base.rb +83 -83
- data/lib/solargraph/language_server/message/completion_item/resolve.rb +40 -40
- data/lib/solargraph/language_server/message/exit_notification.rb +11 -11
- data/lib/solargraph/language_server/message/extended.rb +19 -19
- data/lib/solargraph/language_server/message/extended/check_gem_version.rb +86 -86
- data/lib/solargraph/language_server/message/extended/document.rb +18 -18
- data/lib/solargraph/language_server/message/extended/document_gems.rb +30 -30
- data/lib/solargraph/language_server/message/extended/environment.rb +20 -20
- data/lib/solargraph/language_server/message/extended/search.rb +18 -18
- data/lib/solargraph/language_server/message/initialize.rb +141 -141
- data/lib/solargraph/language_server/message/initialized.rb +23 -23
- data/lib/solargraph/language_server/message/shutdown.rb +11 -11
- data/lib/solargraph/language_server/message/text_document.rb +25 -25
- data/lib/solargraph/language_server/message/text_document/completion.rb +51 -51
- data/lib/solargraph/language_server/message/text_document/definition.rb +18 -18
- data/lib/solargraph/language_server/message/text_document/did_change.rb +13 -13
- data/lib/solargraph/language_server/message/text_document/document_symbol.rb +21 -21
- data/lib/solargraph/language_server/message/text_document/folding_range.rb +24 -24
- data/lib/solargraph/language_server/message/text_document/formatting.rb +50 -50
- data/lib/solargraph/language_server/message/text_document/hover.rb +31 -31
- data/lib/solargraph/language_server/message/text_document/on_type_formatting.rb +32 -32
- data/lib/solargraph/language_server/message/text_document/prepare_rename.rb +9 -9
- data/lib/solargraph/language_server/message/text_document/references.rb +14 -14
- data/lib/solargraph/language_server/message/text_document/rename.rb +17 -17
- data/lib/solargraph/language_server/message/text_document/signature_help.rb +19 -19
- data/lib/solargraph/language_server/message/workspace.rb +12 -12
- data/lib/solargraph/language_server/message/workspace/did_change_configuration.rb +29 -29
- data/lib/solargraph/language_server/message/workspace/did_change_watched_files.rb +29 -27
- data/lib/solargraph/language_server/message/workspace/did_change_workspace_folders.rb +24 -24
- data/lib/solargraph/language_server/message/workspace/workspace_symbol.rb +21 -21
- data/lib/solargraph/language_server/request.rb +22 -22
- data/lib/solargraph/language_server/symbol_kinds.rb +34 -34
- data/lib/solargraph/language_server/transport.rb +11 -11
- data/lib/solargraph/language_server/transport/adapter.rb +60 -60
- data/lib/solargraph/language_server/transport/data_reader.rb +66 -66
- data/lib/solargraph/language_server/uri_helpers.rb +25 -25
- data/lib/solargraph/library.rb +421 -419
- data/lib/solargraph/live_map.rb +126 -126
- data/lib/solargraph/live_map/cache.rb +38 -38
- data/lib/solargraph/location.rb +31 -31
- data/lib/solargraph/logging.rb +25 -25
- data/lib/solargraph/page.rb +68 -68
- data/lib/solargraph/pin.rb +50 -50
- data/lib/solargraph/pin/attribute.rb +41 -41
- data/lib/solargraph/pin/base.rb +280 -280
- data/lib/solargraph/pin/base_method.rb +76 -76
- data/lib/solargraph/pin/base_variable.rb +72 -72
- data/lib/solargraph/pin/block.rb +32 -32
- data/lib/solargraph/pin/block_parameter.rb +103 -103
- data/lib/solargraph/pin/class_variable.rb +9 -9
- data/lib/solargraph/pin/constant.rb +30 -30
- data/lib/solargraph/pin/conversions.rb +79 -79
- data/lib/solargraph/pin/documenting.rb +41 -41
- data/lib/solargraph/pin/duck_method.rb +14 -14
- data/lib/solargraph/pin/global_variable.rb +9 -9
- data/lib/solargraph/pin/instance_variable.rb +9 -9
- data/lib/solargraph/pin/keyword.rb +17 -17
- data/lib/solargraph/pin/local_variable.rb +23 -23
- data/lib/solargraph/pin/localized.rb +22 -22
- data/lib/solargraph/pin/method.rb +126 -126
- data/lib/solargraph/pin/method_alias.rb +30 -30
- data/lib/solargraph/pin/method_parameter.rb +40 -40
- data/lib/solargraph/pin/namespace.rb +54 -54
- data/lib/solargraph/pin/plugin/method.rb +25 -25
- data/lib/solargraph/pin/proxy_type.rb +35 -35
- data/lib/solargraph/pin/reference.rb +22 -22
- data/lib/solargraph/pin/reference/extend.rb +11 -11
- data/lib/solargraph/pin/reference/include.rb +11 -11
- data/lib/solargraph/pin/reference/require.rb +15 -15
- data/lib/solargraph/pin/reference/superclass.rb +11 -11
- data/lib/solargraph/pin/symbol.rb +44 -44
- data/lib/solargraph/pin/yard_pin.rb +10 -10
- data/lib/solargraph/pin/yard_pin/constant.rb +14 -14
- data/lib/solargraph/pin/yard_pin/method.rb +35 -35
- data/lib/solargraph/pin/yard_pin/namespace.rb +19 -19
- data/lib/solargraph/pin/yard_pin/yard_mixin.rb +14 -14
- data/lib/solargraph/plugin.rb +8 -8
- data/lib/solargraph/plugin/base.rb +41 -41
- data/lib/solargraph/plugin/canceler.rb +11 -11
- data/lib/solargraph/plugin/process.rb +172 -172
- data/lib/solargraph/plugin/runtime.rb +134 -134
- data/lib/solargraph/position.rb +110 -110
- data/lib/solargraph/range.rb +83 -83
- data/lib/solargraph/server_methods.rb +14 -14
- data/lib/solargraph/shell.rb +102 -102
- data/lib/solargraph/source.rb +521 -521
- data/lib/solargraph/source/chain.rb +120 -120
- data/lib/solargraph/source/chain/call.rb +107 -107
- data/lib/solargraph/source/chain/class_variable.rb +11 -11
- data/lib/solargraph/source/chain/constant.rb +30 -30
- data/lib/solargraph/source/chain/global_variable.rb +11 -11
- data/lib/solargraph/source/chain/head.rb +33 -33
- data/lib/solargraph/source/chain/instance_variable.rb +11 -11
- data/lib/solargraph/source/chain/link.rb +33 -33
- data/lib/solargraph/source/chain/literal.rb +21 -21
- data/lib/solargraph/source/chain/variable.rb +11 -11
- data/lib/solargraph/source/change.rb +77 -77
- data/lib/solargraph/source/cursor.rb +157 -157
- data/lib/solargraph/source/node_chainer.rb +96 -96
- data/lib/solargraph/source/node_methods.rb +225 -225
- data/lib/solargraph/source/source_chainer.rb +183 -183
- data/lib/solargraph/source_map.rb +169 -169
- data/lib/solargraph/source_map/clip.rb +145 -145
- data/lib/solargraph/source_map/completion.rb +21 -21
- data/lib/solargraph/source_map/mapper.rb +149 -149
- data/lib/solargraph/source_map/node_processor.rb +78 -78
- data/lib/solargraph/source_map/node_processor/alias_node.rb +19 -19
- data/lib/solargraph/source_map/node_processor/args_node.rb +28 -28
- data/lib/solargraph/source_map/node_processor/base.rb +68 -68
- data/lib/solargraph/source_map/node_processor/begin_node.rb +11 -11
- data/lib/solargraph/source_map/node_processor/block_node.rb +14 -14
- data/lib/solargraph/source_map/node_processor/casgn_node.rb +14 -14
- data/lib/solargraph/source_map/node_processor/cvasgn_node.rb +14 -14
- data/lib/solargraph/source_map/node_processor/def_node.rb +54 -54
- data/lib/solargraph/source_map/node_processor/defs_node.rb +21 -21
- data/lib/solargraph/source_map/node_processor/gvasgn_node.rb +12 -12
- data/lib/solargraph/source_map/node_processor/ivasgn_node.rb +18 -18
- data/lib/solargraph/source_map/node_processor/lvasgn_node.rb +16 -16
- data/lib/solargraph/source_map/node_processor/namespace_node.rb +26 -26
- data/lib/solargraph/source_map/node_processor/orasgn_node.rb +12 -12
- data/lib/solargraph/source_map/node_processor/sclass_node.rb +11 -11
- data/lib/solargraph/source_map/node_processor/send_node.rb +162 -162
- data/lib/solargraph/source_map/node_processor/sym_node.rb +11 -11
- data/lib/solargraph/source_map/region.rb +58 -58
- data/lib/solargraph/version.rb +3 -3
- data/lib/solargraph/views/environment.erb +53 -53
- data/lib/solargraph/workspace.rb +183 -183
- data/lib/solargraph/workspace/config.rb +170 -170
- data/lib/solargraph/yard_map.rb +298 -298
- data/lib/solargraph/yard_map/cache.rb +17 -17
- data/lib/solargraph/yard_map/core_docs.rb +163 -163
- data/lib/solargraph/yard_map/core_gen.rb +76 -76
- data/lib/yard-coregen.rb +16 -16
- data/lib/yard-solargraph.rb +18 -18
- data/solargraph.gemspec +37 -0
- data/travis-bundler.rb +10 -0
- metadata +19 -6
@@ -1,18 +1,18 @@
|
|
1
|
-
module Solargraph
|
2
|
-
module LanguageServer
|
3
|
-
# The ErrorCode constants for the language server protocol.
|
4
|
-
#
|
5
|
-
module ErrorCodes
|
6
|
-
PARSE_ERROR = -32700
|
7
|
-
INVALID_REQUEST = -32600
|
8
|
-
METHOD_NOT_FOUND = -32601
|
9
|
-
INVALID_PARAMS = -32602
|
10
|
-
INTERNAL_ERROR = -32603
|
11
|
-
SERVER_ERROR_START = -32099
|
12
|
-
SERVER_ERROR_END = -32000
|
13
|
-
SERVER_NOT_INITIALIZED = -32002
|
14
|
-
UNKNOWN_ERROR_CODE = -32001
|
15
|
-
REQUEST_CANCELLED = -32800
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
1
|
+
module Solargraph
|
2
|
+
module LanguageServer
|
3
|
+
# The ErrorCode constants for the language server protocol.
|
4
|
+
#
|
5
|
+
module ErrorCodes
|
6
|
+
PARSE_ERROR = -32700
|
7
|
+
INVALID_REQUEST = -32600
|
8
|
+
METHOD_NOT_FOUND = -32601
|
9
|
+
INVALID_PARAMS = -32602
|
10
|
+
INTERNAL_ERROR = -32603
|
11
|
+
SERVER_ERROR_START = -32099
|
12
|
+
SERVER_ERROR_END = -32000
|
13
|
+
SERVER_NOT_INITIALIZED = -32002
|
14
|
+
UNKNOWN_ERROR_CODE = -32001
|
15
|
+
REQUEST_CANCELLED = -32800
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -1,681 +1,684 @@
|
|
1
|
-
require 'thread'
|
2
|
-
require 'set'
|
3
|
-
|
4
|
-
module Solargraph
|
5
|
-
module LanguageServer
|
6
|
-
# The language server protocol's data provider. Hosts are responsible for
|
7
|
-
# querying the library and processing messages. They also provide thread
|
8
|
-
# safety for multi-threaded transports.
|
9
|
-
#
|
10
|
-
class Host
|
11
|
-
autoload :Diagnoser, 'solargraph/language_server/host/diagnoser'
|
12
|
-
autoload :Cataloger, 'solargraph/language_server/host/cataloger'
|
13
|
-
autoload :Sources, 'solargraph/language_server/host/sources'
|
14
|
-
autoload :Dispatch, 'solargraph/language_server/host/dispatch'
|
15
|
-
|
16
|
-
include UriHelpers
|
17
|
-
include Logging
|
18
|
-
include Dispatch
|
19
|
-
|
20
|
-
def initialize
|
21
|
-
@cancel_semaphore = Mutex.new
|
22
|
-
@buffer_semaphore = Mutex.new
|
23
|
-
@register_semaphore = Mutex.new
|
24
|
-
@cancel = []
|
25
|
-
@buffer = ''
|
26
|
-
@stopped = true
|
27
|
-
@next_request_id = 0
|
28
|
-
@dynamic_capabilities = Set.new
|
29
|
-
@registered_capabilities = Set.new
|
30
|
-
end
|
31
|
-
|
32
|
-
# Start asynchronous process handling.
|
33
|
-
#
|
34
|
-
# @return [void]
|
35
|
-
def start
|
36
|
-
return unless stopped?
|
37
|
-
@stopped = false
|
38
|
-
diagnoser.start
|
39
|
-
cataloger.start
|
40
|
-
sources.start
|
41
|
-
end
|
42
|
-
|
43
|
-
# Update the configuration options with the provided hash.
|
44
|
-
#
|
45
|
-
# @param update [Hash]
|
46
|
-
def configure update
|
47
|
-
return if update.nil?
|
48
|
-
options.merge! update
|
49
|
-
logger.level = LOG_LEVELS[options['logLevel']] || DEFAULT_LOG_LEVEL
|
50
|
-
end
|
51
|
-
|
52
|
-
# @return [Hash]
|
53
|
-
def options
|
54
|
-
@options ||= default_configuration
|
55
|
-
end
|
56
|
-
|
57
|
-
# Cancel the method with the specified ID.
|
58
|
-
#
|
59
|
-
# @param id [Integer]
|
60
|
-
def cancel id
|
61
|
-
@cancel_semaphore.synchronize { @cancel.push id }
|
62
|
-
end
|
63
|
-
|
64
|
-
# True if the host received a request to cancel the method with the
|
65
|
-
# specified ID.
|
66
|
-
#
|
67
|
-
# @param id [Integer]
|
68
|
-
# @return [Boolean]
|
69
|
-
def cancel? id
|
70
|
-
result = false
|
71
|
-
@cancel_semaphore.synchronize { result = @cancel.include? id }
|
72
|
-
result
|
73
|
-
end
|
74
|
-
|
75
|
-
# Delete the specified ID from the list of cancelled IDs if it exists.
|
76
|
-
#
|
77
|
-
# @param id [Integer]
|
78
|
-
# @return [void]
|
79
|
-
def clear id
|
80
|
-
@cancel_semaphore.synchronize { @cancel.delete id }
|
81
|
-
end
|
82
|
-
|
83
|
-
# Start processing a request from the client. After the message is
|
84
|
-
# processed, the transport is responsible for sending the response.
|
85
|
-
#
|
86
|
-
# @param request [Hash] The contents of the message.
|
87
|
-
# @return [Solargraph::LanguageServer::Message::Base] The message handler.
|
88
|
-
def receive request
|
89
|
-
if request['method']
|
90
|
-
logger.info "Server received #{request['method']}"
|
91
|
-
logger.debug request
|
92
|
-
message = Message.select(request['method']).new(self, request)
|
93
|
-
begin
|
94
|
-
message.process
|
95
|
-
rescue Exception => e
|
96
|
-
logger.warn "Error processing request: [#{e.class}] #{e.message}"
|
97
|
-
logger.warn e.backtrace
|
98
|
-
message.set_error Solargraph::LanguageServer::ErrorCodes::INTERNAL_ERROR, "[#{e.class}] #{e.message}"
|
99
|
-
end
|
100
|
-
message
|
101
|
-
elsif request['id']
|
102
|
-
# @todo What if the id is invalid?
|
103
|
-
requests[request['id']].process(request['result'])
|
104
|
-
requests.delete request['id']
|
105
|
-
else
|
106
|
-
logger.warn "Invalid message received."
|
107
|
-
logger.debug request
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
# Respond to a notification that a file was created in the workspace.
|
112
|
-
# The libraries will determine whether the file should be merged; see
|
113
|
-
# Solargraph::Library#create_from_disk.
|
114
|
-
#
|
115
|
-
# @param uri [String] The file uri.
|
116
|
-
# @return [Boolean] True if a library accepted the file.
|
117
|
-
def create uri
|
118
|
-
filename = uri_to_file(uri)
|
119
|
-
result = false
|
120
|
-
libraries.each do |lib|
|
121
|
-
result = true if lib.create_from_disk
|
122
|
-
end
|
123
|
-
diagnoser.schedule uri if open?(uri)
|
124
|
-
result
|
125
|
-
end
|
126
|
-
|
127
|
-
# Delete the specified file from the library.
|
128
|
-
#
|
129
|
-
# @param uri [String] The file uri.
|
130
|
-
# @return [void]
|
131
|
-
def delete uri
|
132
|
-
# sources.close uri # @todo It's possible for a deleted file to be open in an editor
|
133
|
-
filename = uri_to_file(uri)
|
134
|
-
libraries.each do |lib|
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
#
|
145
|
-
#
|
146
|
-
# @param
|
147
|
-
# @param
|
148
|
-
# @
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
library
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
#
|
165
|
-
#
|
166
|
-
# @
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
#
|
173
|
-
#
|
174
|
-
# @
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
# @
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
library
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
#
|
212
|
-
#
|
213
|
-
#
|
214
|
-
# @
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
#
|
222
|
-
#
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
#
|
231
|
-
#
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
#
|
243
|
-
#
|
244
|
-
# @param
|
245
|
-
# @
|
246
|
-
|
247
|
-
|
248
|
-
#
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
path =
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
'
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
#
|
266
|
-
#
|
267
|
-
# @
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
#
|
277
|
-
#
|
278
|
-
# @
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
#
|
300
|
-
#
|
301
|
-
# @param
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
envelope
|
311
|
-
|
312
|
-
logger.
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
#
|
317
|
-
#
|
318
|
-
#
|
319
|
-
#
|
320
|
-
# @param
|
321
|
-
# @param
|
322
|
-
# @
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
envelope
|
334
|
-
|
335
|
-
|
336
|
-
logger.
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
#
|
341
|
-
#
|
342
|
-
#
|
343
|
-
#
|
344
|
-
# @
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
#
|
363
|
-
#
|
364
|
-
#
|
365
|
-
#
|
366
|
-
# @
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
#
|
384
|
-
#
|
385
|
-
# @
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
#
|
394
|
-
#
|
395
|
-
# @
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
#
|
402
|
-
#
|
403
|
-
# @
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
#
|
427
|
-
#
|
428
|
-
#
|
429
|
-
#
|
430
|
-
# @
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
params['data']['location']['range']['start']['
|
441
|
-
params['data']['location']['range']['
|
442
|
-
params['data']['location']['range']['end']['
|
443
|
-
|
444
|
-
|
445
|
-
)
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
# @
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
filename
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
# @param
|
463
|
-
# @param
|
464
|
-
# @
|
465
|
-
|
466
|
-
|
467
|
-
library
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
# @param
|
472
|
-
# @param
|
473
|
-
# @
|
474
|
-
|
475
|
-
|
476
|
-
library
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
# @param
|
481
|
-
# @param
|
482
|
-
# @
|
483
|
-
|
484
|
-
|
485
|
-
library
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
# @param
|
490
|
-
# @param
|
491
|
-
# @param
|
492
|
-
# @
|
493
|
-
|
494
|
-
|
495
|
-
library
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
# @
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
# @
|
508
|
-
|
509
|
-
|
510
|
-
result
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
# @
|
516
|
-
|
517
|
-
|
518
|
-
result
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
# @
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
#
|
528
|
-
#
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
#
|
534
|
-
#
|
535
|
-
# @param
|
536
|
-
# @
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
#
|
546
|
-
#
|
547
|
-
# @param
|
548
|
-
# @param
|
549
|
-
# @param
|
550
|
-
# @
|
551
|
-
# @
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
#
|
562
|
-
#
|
563
|
-
#
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
'
|
573
|
-
'
|
574
|
-
'
|
575
|
-
'
|
576
|
-
'
|
577
|
-
'
|
578
|
-
'
|
579
|
-
'
|
580
|
-
'
|
581
|
-
'
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
# @
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
#
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
}
|
659
|
-
'textDocument/
|
660
|
-
|
661
|
-
},
|
662
|
-
'textDocument/
|
663
|
-
|
664
|
-
},
|
665
|
-
'textDocument/
|
666
|
-
|
667
|
-
},
|
668
|
-
'
|
669
|
-
|
670
|
-
},
|
671
|
-
'
|
672
|
-
|
673
|
-
},
|
674
|
-
'textDocument/
|
675
|
-
|
676
|
-
}
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
end
|
1
|
+
require 'thread'
|
2
|
+
require 'set'
|
3
|
+
|
4
|
+
module Solargraph
|
5
|
+
module LanguageServer
|
6
|
+
# The language server protocol's data provider. Hosts are responsible for
|
7
|
+
# querying the library and processing messages. They also provide thread
|
8
|
+
# safety for multi-threaded transports.
|
9
|
+
#
|
10
|
+
class Host
|
11
|
+
autoload :Diagnoser, 'solargraph/language_server/host/diagnoser'
|
12
|
+
autoload :Cataloger, 'solargraph/language_server/host/cataloger'
|
13
|
+
autoload :Sources, 'solargraph/language_server/host/sources'
|
14
|
+
autoload :Dispatch, 'solargraph/language_server/host/dispatch'
|
15
|
+
|
16
|
+
include UriHelpers
|
17
|
+
include Logging
|
18
|
+
include Dispatch
|
19
|
+
|
20
|
+
def initialize
|
21
|
+
@cancel_semaphore = Mutex.new
|
22
|
+
@buffer_semaphore = Mutex.new
|
23
|
+
@register_semaphore = Mutex.new
|
24
|
+
@cancel = []
|
25
|
+
@buffer = ''
|
26
|
+
@stopped = true
|
27
|
+
@next_request_id = 0
|
28
|
+
@dynamic_capabilities = Set.new
|
29
|
+
@registered_capabilities = Set.new
|
30
|
+
end
|
31
|
+
|
32
|
+
# Start asynchronous process handling.
|
33
|
+
#
|
34
|
+
# @return [void]
|
35
|
+
def start
|
36
|
+
return unless stopped?
|
37
|
+
@stopped = false
|
38
|
+
diagnoser.start
|
39
|
+
cataloger.start
|
40
|
+
sources.start
|
41
|
+
end
|
42
|
+
|
43
|
+
# Update the configuration options with the provided hash.
|
44
|
+
#
|
45
|
+
# @param update [Hash]
|
46
|
+
def configure update
|
47
|
+
return if update.nil?
|
48
|
+
options.merge! update
|
49
|
+
logger.level = LOG_LEVELS[options['logLevel']] || DEFAULT_LOG_LEVEL
|
50
|
+
end
|
51
|
+
|
52
|
+
# @return [Hash]
|
53
|
+
def options
|
54
|
+
@options ||= default_configuration
|
55
|
+
end
|
56
|
+
|
57
|
+
# Cancel the method with the specified ID.
|
58
|
+
#
|
59
|
+
# @param id [Integer]
|
60
|
+
def cancel id
|
61
|
+
@cancel_semaphore.synchronize { @cancel.push id }
|
62
|
+
end
|
63
|
+
|
64
|
+
# True if the host received a request to cancel the method with the
|
65
|
+
# specified ID.
|
66
|
+
#
|
67
|
+
# @param id [Integer]
|
68
|
+
# @return [Boolean]
|
69
|
+
def cancel? id
|
70
|
+
result = false
|
71
|
+
@cancel_semaphore.synchronize { result = @cancel.include? id }
|
72
|
+
result
|
73
|
+
end
|
74
|
+
|
75
|
+
# Delete the specified ID from the list of cancelled IDs if it exists.
|
76
|
+
#
|
77
|
+
# @param id [Integer]
|
78
|
+
# @return [void]
|
79
|
+
def clear id
|
80
|
+
@cancel_semaphore.synchronize { @cancel.delete id }
|
81
|
+
end
|
82
|
+
|
83
|
+
# Start processing a request from the client. After the message is
|
84
|
+
# processed, the transport is responsible for sending the response.
|
85
|
+
#
|
86
|
+
# @param request [Hash] The contents of the message.
|
87
|
+
# @return [Solargraph::LanguageServer::Message::Base] The message handler.
|
88
|
+
def receive request
|
89
|
+
if request['method']
|
90
|
+
logger.info "Server received #{request['method']}"
|
91
|
+
logger.debug request
|
92
|
+
message = Message.select(request['method']).new(self, request)
|
93
|
+
begin
|
94
|
+
message.process
|
95
|
+
rescue Exception => e
|
96
|
+
logger.warn "Error processing request: [#{e.class}] #{e.message}"
|
97
|
+
logger.warn e.backtrace
|
98
|
+
message.set_error Solargraph::LanguageServer::ErrorCodes::INTERNAL_ERROR, "[#{e.class}] #{e.message}"
|
99
|
+
end
|
100
|
+
message
|
101
|
+
elsif request['id']
|
102
|
+
# @todo What if the id is invalid?
|
103
|
+
requests[request['id']].process(request['result'])
|
104
|
+
requests.delete request['id']
|
105
|
+
else
|
106
|
+
logger.warn "Invalid message received."
|
107
|
+
logger.debug request
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
# Respond to a notification that a file was created in the workspace.
|
112
|
+
# The libraries will determine whether the file should be merged; see
|
113
|
+
# Solargraph::Library#create_from_disk.
|
114
|
+
#
|
115
|
+
# @param uri [String] The file uri.
|
116
|
+
# @return [Boolean] True if a library accepted the file.
|
117
|
+
def create uri
|
118
|
+
filename = uri_to_file(uri)
|
119
|
+
result = false
|
120
|
+
libraries.each do |lib|
|
121
|
+
result = true if lib.create_from_disk(filename)
|
122
|
+
end
|
123
|
+
diagnoser.schedule uri if open?(uri)
|
124
|
+
result
|
125
|
+
end
|
126
|
+
|
127
|
+
# Delete the specified file from the library.
|
128
|
+
#
|
129
|
+
# @param uri [String] The file uri.
|
130
|
+
# @return [void]
|
131
|
+
def delete uri
|
132
|
+
# sources.close uri # @todo It's possible for a deleted file to be open in an editor
|
133
|
+
filename = uri_to_file(uri)
|
134
|
+
libraries.each do |lib|
|
135
|
+
lib.delete(filename)
|
136
|
+
end
|
137
|
+
send_notification "textDocument/publishDiagnostics", {
|
138
|
+
uri: uri,
|
139
|
+
diagnostics: []
|
140
|
+
}
|
141
|
+
end
|
142
|
+
|
143
|
+
# Open the specified file in the library.
|
144
|
+
#
|
145
|
+
# @param uri [String] The file uri.
|
146
|
+
# @param text [String] The contents of the file.
|
147
|
+
# @param version [Integer] A version number.
|
148
|
+
# @return [void]
|
149
|
+
def open uri, text, version
|
150
|
+
src = sources.open(uri, text, version)
|
151
|
+
libraries.each do |lib|
|
152
|
+
lib.merge src
|
153
|
+
end
|
154
|
+
diagnoser.schedule uri
|
155
|
+
end
|
156
|
+
|
157
|
+
def open_from_disk uri
|
158
|
+
library = library_for(uri)
|
159
|
+
library.open_from_disk uri_to_file(uri)
|
160
|
+
diagnoser.schedule uri
|
161
|
+
end
|
162
|
+
|
163
|
+
# True if the specified file is currently open in the library.
|
164
|
+
#
|
165
|
+
# @param uri [String]
|
166
|
+
# @return [Boolean]
|
167
|
+
def open? uri
|
168
|
+
sources.include? uri
|
169
|
+
end
|
170
|
+
|
171
|
+
# Close the file specified by the URI.
|
172
|
+
#
|
173
|
+
# @param uri [String]
|
174
|
+
# @return [void]
|
175
|
+
def close uri
|
176
|
+
logger.info "Closing #{uri}"
|
177
|
+
sources.close uri
|
178
|
+
diagnoser.schedule uri
|
179
|
+
end
|
180
|
+
|
181
|
+
# @param uri [String]
|
182
|
+
# @return [void]
|
183
|
+
def diagnose uri
|
184
|
+
if sources.include?(uri)
|
185
|
+
logger.info "Diagnosing #{uri}"
|
186
|
+
library = library_for(uri)
|
187
|
+
library.catalog
|
188
|
+
begin
|
189
|
+
results = library.diagnose uri_to_file(uri)
|
190
|
+
send_notification "textDocument/publishDiagnostics", {
|
191
|
+
uri: uri,
|
192
|
+
diagnostics: results
|
193
|
+
}
|
194
|
+
rescue DiagnosticsError => e
|
195
|
+
logger.warn "Error in diagnostics: #{e.message}"
|
196
|
+
options['diagnostics'] = false
|
197
|
+
send_notification 'window/showMessage', {
|
198
|
+
type: LanguageServer::MessageTypes::ERROR,
|
199
|
+
message: "Error in diagnostics: #{e.message}"
|
200
|
+
}
|
201
|
+
end
|
202
|
+
else
|
203
|
+
send_notification 'textDocument/publishDiagnostics', {
|
204
|
+
uri: uri,
|
205
|
+
diagnostics: []
|
206
|
+
}
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
# Update a document from the parameters of a textDocument/didChange
|
211
|
+
# method.
|
212
|
+
#
|
213
|
+
# @param params [Hash]
|
214
|
+
# @return [void]
|
215
|
+
def change params
|
216
|
+
updater = generate_updater(params)
|
217
|
+
sources.async_update params['textDocument']['uri'], updater
|
218
|
+
end
|
219
|
+
|
220
|
+
# Queue a message to be sent to the client.
|
221
|
+
#
|
222
|
+
# @param message [String] The message to send.
|
223
|
+
def queue message
|
224
|
+
@buffer_semaphore.synchronize do
|
225
|
+
@buffer += message
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
# Clear the message buffer and return the most recent data.
|
230
|
+
#
|
231
|
+
# @return [String] The most recent data or an empty string.
|
232
|
+
def flush
|
233
|
+
tmp = nil
|
234
|
+
@buffer_semaphore.synchronize do
|
235
|
+
tmp = @buffer.clone
|
236
|
+
@buffer.clear
|
237
|
+
end
|
238
|
+
tmp
|
239
|
+
end
|
240
|
+
|
241
|
+
# Prepare a library for the specified directory.
|
242
|
+
#
|
243
|
+
# @param directory [String]
|
244
|
+
# @param name [String, nil]
|
245
|
+
# @return [void]
|
246
|
+
def prepare directory, name = nil
|
247
|
+
# No need to create a library without a directory. The generic library
|
248
|
+
# will handle it.
|
249
|
+
return if directory.nil?
|
250
|
+
logger.info "Preparing library for #{directory}"
|
251
|
+
path = ''
|
252
|
+
path = normalize_separators(directory) unless directory.nil?
|
253
|
+
begin
|
254
|
+
lib = Solargraph::Library.load(path, name)
|
255
|
+
libraries.push lib
|
256
|
+
rescue WorkspaceTooLargeError => e
|
257
|
+
send_notification 'window/showMessage', {
|
258
|
+
'type' => Solargraph::LanguageServer::MessageTypes::WARNING,
|
259
|
+
'message' => e.message
|
260
|
+
}
|
261
|
+
end
|
262
|
+
end
|
263
|
+
|
264
|
+
# Prepare multiple folders.
|
265
|
+
#
|
266
|
+
# @param array [Array<Hash{String => String}>]
|
267
|
+
# @return [void]
|
268
|
+
def prepare_folders array
|
269
|
+
return if array.nil?
|
270
|
+
array.each do |folder|
|
271
|
+
prepare uri_to_file(folder['uri']), folder['name']
|
272
|
+
end
|
273
|
+
end
|
274
|
+
|
275
|
+
# Remove a directory.
|
276
|
+
#
|
277
|
+
# @param directory [String]
|
278
|
+
# @return [void]
|
279
|
+
def remove directory
|
280
|
+
logger.info "Removing library for #{directory}"
|
281
|
+
# @param lib [Library]
|
282
|
+
libraries.delete_if do |lib|
|
283
|
+
next false if lib.workspace.directory != directory
|
284
|
+
true
|
285
|
+
end
|
286
|
+
end
|
287
|
+
|
288
|
+
def remove_folders array
|
289
|
+
array.each do |folder|
|
290
|
+
remove uri_to_file(folder['uri'])
|
291
|
+
end
|
292
|
+
end
|
293
|
+
|
294
|
+
def folders
|
295
|
+
libraries.map { |lib| lib.workspace.directory }
|
296
|
+
end
|
297
|
+
|
298
|
+
# Send a notification to the client.
|
299
|
+
#
|
300
|
+
# @param method [String] The message method
|
301
|
+
# @param params [Hash] The method parameters
|
302
|
+
def send_notification method, params
|
303
|
+
response = {
|
304
|
+
jsonrpc: "2.0",
|
305
|
+
method: method,
|
306
|
+
params: params
|
307
|
+
}
|
308
|
+
json = response.to_json
|
309
|
+
envelope = "Content-Length: #{json.bytesize}\r\n\r\n#{json}"
|
310
|
+
queue envelope
|
311
|
+
logger.info "Server sent #{method}"
|
312
|
+
logger.debug params
|
313
|
+
end
|
314
|
+
|
315
|
+
# Send a request to the client and execute the provided block to process
|
316
|
+
# the response. If an ID is not provided, the host will use an auto-
|
317
|
+
# incrementing integer.
|
318
|
+
#
|
319
|
+
# @param method [String] The message method
|
320
|
+
# @param params [Hash] The method parameters
|
321
|
+
# @param id [String] An optional ID
|
322
|
+
# @yieldparam [Hash] The result sent by the client
|
323
|
+
def send_request method, params, &block
|
324
|
+
message = {
|
325
|
+
jsonrpc: "2.0",
|
326
|
+
method: method,
|
327
|
+
params: params,
|
328
|
+
id: @next_request_id
|
329
|
+
}
|
330
|
+
json = message.to_json
|
331
|
+
requests[@next_request_id] = Request.new(@next_request_id, &block)
|
332
|
+
envelope = "Content-Length: #{json.bytesize}\r\n\r\n#{json}"
|
333
|
+
queue envelope
|
334
|
+
@next_request_id += 1
|
335
|
+
logger.info "Server sent #{method}"
|
336
|
+
logger.debug params
|
337
|
+
end
|
338
|
+
|
339
|
+
# Register the methods as capabilities with the client.
|
340
|
+
# This method will avoid duplicating registrations and ignore methods
|
341
|
+
# that were not flagged for dynamic registration by the client.
|
342
|
+
#
|
343
|
+
# @param methods [Array<String>] The methods to register
|
344
|
+
# @return [void]
|
345
|
+
def register_capabilities methods
|
346
|
+
logger.debug "Registering capabilities: #{methods}"
|
347
|
+
@register_semaphore.synchronize do
|
348
|
+
send_request 'client/registerCapability', {
|
349
|
+
registrations: methods.select{|m| can_register?(m) and !registered?(m)}.map { |m|
|
350
|
+
@registered_capabilities.add m
|
351
|
+
{
|
352
|
+
id: m,
|
353
|
+
method: m,
|
354
|
+
registerOptions: dynamic_capability_options[m]
|
355
|
+
}
|
356
|
+
}
|
357
|
+
}
|
358
|
+
end
|
359
|
+
end
|
360
|
+
|
361
|
+
# Unregister the methods with the client.
|
362
|
+
# This method will avoid duplicating unregistrations and ignore methods
|
363
|
+
# that were not flagged for dynamic registration by the client.
|
364
|
+
#
|
365
|
+
# @param methods [Array<String>] The methods to unregister
|
366
|
+
# @return [void]
|
367
|
+
def unregister_capabilities methods
|
368
|
+
logger.debug "Unregistering capabilities: #{methods}"
|
369
|
+
@register_semaphore.synchronize do
|
370
|
+
send_request 'client/unregisterCapability', {
|
371
|
+
unregisterations: methods.select{|m| registered?(m)}.map{ |m|
|
372
|
+
@registered_capabilities.delete m
|
373
|
+
{
|
374
|
+
id: m,
|
375
|
+
method: m
|
376
|
+
}
|
377
|
+
}
|
378
|
+
}
|
379
|
+
end
|
380
|
+
end
|
381
|
+
|
382
|
+
# Flag a method as available for dynamic registration.
|
383
|
+
#
|
384
|
+
# @param method [String] The method name, e.g., 'textDocument/completion'
|
385
|
+
# @return [void]
|
386
|
+
def allow_registration method
|
387
|
+
@register_semaphore.synchronize do
|
388
|
+
@dynamic_capabilities.add method
|
389
|
+
end
|
390
|
+
end
|
391
|
+
|
392
|
+
# True if the specified LSP method can be dynamically registered.
|
393
|
+
#
|
394
|
+
# @param method [String]
|
395
|
+
# @return [Boolean]
|
396
|
+
def can_register? method
|
397
|
+
@dynamic_capabilities.include?(method)
|
398
|
+
end
|
399
|
+
|
400
|
+
# True if the specified method has been registered.
|
401
|
+
#
|
402
|
+
# @param method [String] The method name, e.g., 'textDocument/completion'
|
403
|
+
# @return [Boolean]
|
404
|
+
def registered? method
|
405
|
+
@registered_capabilities.include?(method)
|
406
|
+
end
|
407
|
+
|
408
|
+
def synchronizing?
|
409
|
+
!libraries.all?(&:synchronized?)
|
410
|
+
end
|
411
|
+
|
412
|
+
# @return [void]
|
413
|
+
def stop
|
414
|
+
return if @stopped
|
415
|
+
@stopped = true
|
416
|
+
cataloger.stop
|
417
|
+
diagnoser.stop
|
418
|
+
sources.stop
|
419
|
+
end
|
420
|
+
|
421
|
+
def stopped?
|
422
|
+
@stopped
|
423
|
+
end
|
424
|
+
|
425
|
+
# Locate multiple pins that match a completion item. The first match is
|
426
|
+
# based on the corresponding location in a library source if available.
|
427
|
+
# Subsequent matches are based on path.
|
428
|
+
#
|
429
|
+
# @param params [Hash] A hash representation of a completion item
|
430
|
+
# @return [Array<Pin::Base>]
|
431
|
+
def locate_pins params
|
432
|
+
return [] unless params['data'] && params['data']['uri']
|
433
|
+
library = library_for(params['data']['uri'])
|
434
|
+
result = []
|
435
|
+
if params['data']['location']
|
436
|
+
location = Location.new(
|
437
|
+
params['data']['location']['filename'],
|
438
|
+
Range.from_to(
|
439
|
+
params['data']['location']['range']['start']['line'],
|
440
|
+
params['data']['location']['range']['start']['character'],
|
441
|
+
params['data']['location']['range']['end']['line'],
|
442
|
+
params['data']['location']['range']['end']['character']
|
443
|
+
)
|
444
|
+
)
|
445
|
+
result.concat library.locate_pins(location).select{ |pin| pin.name == params['label'] }
|
446
|
+
end
|
447
|
+
if params['data']['path']
|
448
|
+
result.concat library.path_pins(params['data']['path'])
|
449
|
+
end
|
450
|
+
result.uniq
|
451
|
+
end
|
452
|
+
|
453
|
+
# @param uri [String]
|
454
|
+
# @return [String]
|
455
|
+
def read_text uri
|
456
|
+
library = library_for(uri)
|
457
|
+
filename = uri_to_file(uri)
|
458
|
+
library.read_text(filename)
|
459
|
+
end
|
460
|
+
|
461
|
+
# @param uri [String]
|
462
|
+
# @param line [Integer]
|
463
|
+
# @param column [Integer]
|
464
|
+
# @return [Solargraph::ApiMap::Completion]
|
465
|
+
def completions_at uri, line, column
|
466
|
+
library = library_for(uri)
|
467
|
+
library.completions_at uri_to_file(uri), line, column
|
468
|
+
end
|
469
|
+
|
470
|
+
# @param uri [String]
|
471
|
+
# @param line [Integer]
|
472
|
+
# @param column [Integer]
|
473
|
+
# @return [Array<Solargraph::Pin::Base>]
|
474
|
+
def definitions_at uri, line, column
|
475
|
+
library = library_for(uri)
|
476
|
+
library.definitions_at(uri_to_file(uri), line, column)
|
477
|
+
end
|
478
|
+
|
479
|
+
# @param uri [String]
|
480
|
+
# @param line [Integer]
|
481
|
+
# @param column [Integer]
|
482
|
+
# @return [Array<Solargraph::Pin::Base>]
|
483
|
+
def signatures_at uri, line, column
|
484
|
+
library = library_for(uri)
|
485
|
+
library.signatures_at(uri_to_file(uri), line, column)
|
486
|
+
end
|
487
|
+
|
488
|
+
# @param uri [String]
|
489
|
+
# @param line [Integer]
|
490
|
+
# @param column [Integer]
|
491
|
+
# @param strip [Boolean] Strip special characters from variable names
|
492
|
+
# @return [Array<Solargraph::Range>]
|
493
|
+
def references_from uri, line, column, strip: true
|
494
|
+
library = library_for(uri)
|
495
|
+
library.references_from(uri_to_file(uri), line, column, strip: strip)
|
496
|
+
end
|
497
|
+
|
498
|
+
# @param query [String]
|
499
|
+
# @return [Array<Solargraph::Pin::Base>]
|
500
|
+
def query_symbols query
|
501
|
+
result = []
|
502
|
+
(libraries + [generic_library]).each { |lib| result.concat lib.query_symbols(query) }
|
503
|
+
result.uniq
|
504
|
+
end
|
505
|
+
|
506
|
+
# @param query [String]
|
507
|
+
# @return [Array<String>]
|
508
|
+
def search query
|
509
|
+
result = []
|
510
|
+
libraries.each { |lib| result.concat lib.search(query) }
|
511
|
+
result
|
512
|
+
end
|
513
|
+
|
514
|
+
# @param query [String]
|
515
|
+
# @return [String]
|
516
|
+
def document query
|
517
|
+
result = []
|
518
|
+
libraries.each { |lib| result.concat lib.document(query) }
|
519
|
+
result
|
520
|
+
end
|
521
|
+
|
522
|
+
# @param uri [String]
|
523
|
+
# @return [Array<Solargraph::Pin::Base>]
|
524
|
+
def document_symbols uri
|
525
|
+
library = library_for(uri)
|
526
|
+
# At this level, document symbols should be unique; e.g., a
|
527
|
+
# module_function method should return the location for Module.method
|
528
|
+
# or Module#method, but not both.
|
529
|
+
library.document_symbols(uri_to_file(uri)).uniq(&:location)
|
530
|
+
end
|
531
|
+
|
532
|
+
# Send a notification to the client.
|
533
|
+
#
|
534
|
+
# @param text [String]
|
535
|
+
# @param type [Integer] A MessageType constant
|
536
|
+
# @return [void]
|
537
|
+
def show_message text, type = LanguageServer::MessageTypes::INFO
|
538
|
+
send_notification 'window/showMessage', {
|
539
|
+
type: type,
|
540
|
+
message: text
|
541
|
+
}
|
542
|
+
end
|
543
|
+
|
544
|
+
# Send a notification with optional responses.
|
545
|
+
#
|
546
|
+
# @param text [String]
|
547
|
+
# @param type [Integer] A MessageType constant
|
548
|
+
# @param actions [Array<String>] Response options for the client
|
549
|
+
# @param &block The block that processes the response
|
550
|
+
# @yieldparam [String] The action received from the client
|
551
|
+
# @return [void]
|
552
|
+
def show_message_request text, type, actions, &block
|
553
|
+
send_request 'window/showMessageRequest', {
|
554
|
+
type: type,
|
555
|
+
message: text,
|
556
|
+
actions: actions
|
557
|
+
}, &block
|
558
|
+
end
|
559
|
+
|
560
|
+
# Get a list of IDs for server requests that are waiting for responses
|
561
|
+
# from the client.
|
562
|
+
#
|
563
|
+
# @return [Array<Integer>]
|
564
|
+
def pending_requests
|
565
|
+
requests.keys
|
566
|
+
end
|
567
|
+
|
568
|
+
# @return [Hash{String => Object}]
|
569
|
+
def default_configuration
|
570
|
+
{
|
571
|
+
'completion' => true,
|
572
|
+
'hover' => true,
|
573
|
+
'symbols' => true,
|
574
|
+
'definitions' => true,
|
575
|
+
'rename' => true,
|
576
|
+
'references' => true,
|
577
|
+
'autoformat' => false,
|
578
|
+
'diagnostics' => false,
|
579
|
+
'formatting' => false,
|
580
|
+
'folding' => true,
|
581
|
+
'logLevel' => 'warn'
|
582
|
+
}
|
583
|
+
end
|
584
|
+
|
585
|
+
# @param uri [String]
|
586
|
+
# @return [Array<Range>]
|
587
|
+
def folding_ranges uri
|
588
|
+
sources.find(uri).folding_ranges
|
589
|
+
end
|
590
|
+
|
591
|
+
def catalog
|
592
|
+
libraries.each(&:catalog)
|
593
|
+
end
|
594
|
+
|
595
|
+
private
|
596
|
+
|
597
|
+
# @return [Diagnoser]
|
598
|
+
def diagnoser
|
599
|
+
@diagnoser ||= Diagnoser.new(self)
|
600
|
+
end
|
601
|
+
|
602
|
+
# @return [Cataloger]
|
603
|
+
def cataloger
|
604
|
+
@cataloger ||= Cataloger.new(self)
|
605
|
+
end
|
606
|
+
|
607
|
+
def requests
|
608
|
+
@requests ||= {}
|
609
|
+
end
|
610
|
+
|
611
|
+
def normalize_separators path
|
612
|
+
return path if File::ALT_SEPARATOR.nil?
|
613
|
+
path.gsub(File::ALT_SEPARATOR, File::SEPARATOR)
|
614
|
+
end
|
615
|
+
|
616
|
+
def generate_updater params
|
617
|
+
changes = []
|
618
|
+
params['contentChanges'].each do |chng|
|
619
|
+
changes.push Solargraph::Source::Change.new(
|
620
|
+
(chng['range'].nil? ?
|
621
|
+
nil :
|
622
|
+
Solargraph::Range.from_to(chng['range']['start']['line'], chng['range']['start']['character'], chng['range']['end']['line'], chng['range']['end']['character'])
|
623
|
+
),
|
624
|
+
chng['text']
|
625
|
+
)
|
626
|
+
end
|
627
|
+
Solargraph::Source::Updater.new(
|
628
|
+
uri_to_file(params['textDocument']['uri']),
|
629
|
+
params['textDocument']['version'],
|
630
|
+
changes
|
631
|
+
)
|
632
|
+
end
|
633
|
+
|
634
|
+
def dynamic_capability_options
|
635
|
+
@dynamic_capability_options ||= {
|
636
|
+
# textDocumentSync: 2, # @todo What should this be?
|
637
|
+
'textDocument/completion' => {
|
638
|
+
resolveProvider: true,
|
639
|
+
triggerCharacters: ['.', ':', '@']
|
640
|
+
},
|
641
|
+
# hoverProvider: true,
|
642
|
+
# definitionProvider: true,
|
643
|
+
'textDocument/signatureHelp' => {
|
644
|
+
triggerCharacters: ['(', ',']
|
645
|
+
},
|
646
|
+
# documentFormattingProvider: true,
|
647
|
+
'textDocument/onTypeFormatting' => {
|
648
|
+
firstTriggerCharacter: '{',
|
649
|
+
moreTriggerCharacter: ['(']
|
650
|
+
},
|
651
|
+
# documentSymbolProvider: true,
|
652
|
+
# workspaceSymbolProvider: true,
|
653
|
+
# workspace: {
|
654
|
+
# workspaceFolders: {
|
655
|
+
# supported: true,
|
656
|
+
# changeNotifications: true
|
657
|
+
# }
|
658
|
+
# }
|
659
|
+
'textDocument/definition' => {
|
660
|
+
definitionProvider: true
|
661
|
+
},
|
662
|
+
'textDocument/references' => {
|
663
|
+
referencesProvider: true
|
664
|
+
},
|
665
|
+
'textDocument/rename' => {
|
666
|
+
renameProvider: {prepareProvider: true}
|
667
|
+
},
|
668
|
+
'textDocument/documentSymbol' => {
|
669
|
+
documentSymbolProvider: true
|
670
|
+
},
|
671
|
+
'workspace/symbol' => {
|
672
|
+
workspaceSymbolProvider: true
|
673
|
+
},
|
674
|
+
'textDocument/formatting' => {
|
675
|
+
formattingProvider: true
|
676
|
+
},
|
677
|
+
'textDocument/foldingRange' => {
|
678
|
+
foldingRangeProvider: true
|
679
|
+
}
|
680
|
+
}
|
681
|
+
end
|
682
|
+
end
|
683
|
+
end
|
684
|
+
end
|