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
data/lib/solargraph/source.rb
CHANGED
|
@@ -60,11 +60,13 @@ module Solargraph
|
|
|
60
60
|
# @param c1 [Integer]
|
|
61
61
|
# @param l2 [Integer]
|
|
62
62
|
# @param c2 [Integer]
|
|
63
|
+
#
|
|
64
|
+
# @sg-ignore Need to add nil check here
|
|
63
65
|
# @return [String]
|
|
64
66
|
def from_to l1, c1, l2, c2
|
|
65
67
|
b = Solargraph::Position.line_char_to_offset(code, l1, c1)
|
|
66
68
|
e = Solargraph::Position.line_char_to_offset(code, l2, c2)
|
|
67
|
-
code[b..e-1]
|
|
69
|
+
code[b..(e - 1)]
|
|
68
70
|
end
|
|
69
71
|
|
|
70
72
|
# Get the nearest node that contains the specified index.
|
|
@@ -72,7 +74,7 @@ module Solargraph
|
|
|
72
74
|
# @param line [Integer]
|
|
73
75
|
# @param column [Integer]
|
|
74
76
|
# @return [AST::Node]
|
|
75
|
-
def node_at
|
|
77
|
+
def node_at line, column
|
|
76
78
|
tree_at(line, column).first
|
|
77
79
|
end
|
|
78
80
|
|
|
@@ -81,8 +83,8 @@ module Solargraph
|
|
|
81
83
|
#
|
|
82
84
|
# @param line [Integer]
|
|
83
85
|
# @param column [Integer]
|
|
84
|
-
# @return [Array<AST::Node>]
|
|
85
|
-
def tree_at
|
|
86
|
+
# @return [Array<Parser::AST::Node>]
|
|
87
|
+
def tree_at line, column
|
|
86
88
|
position = Position.new(line, column)
|
|
87
89
|
stack = []
|
|
88
90
|
inner_tree_at node, position, stack
|
|
@@ -131,20 +133,29 @@ module Solargraph
|
|
|
131
133
|
return false if Position.to_offset(code, position) >= code.length
|
|
132
134
|
string_nodes.each do |node|
|
|
133
135
|
range = Range.from_node(node)
|
|
136
|
+
# @sg-ignore Need to add nil check here
|
|
134
137
|
next if range.ending.line < position.line
|
|
138
|
+
# @sg-ignore Need to add nil check here
|
|
135
139
|
break if range.ending.line > position.line
|
|
140
|
+
# @sg-ignore Need to add nil check here
|
|
136
141
|
return true if node.type == :str && range.include?(position) && range.start != position
|
|
137
|
-
|
|
142
|
+
# @sg-ignore Need to add nil check here
|
|
143
|
+
return true if %i[STR str].include?(node.type) && range.include?(position) && range.start != position
|
|
138
144
|
if node.type == :dstr
|
|
139
145
|
inner = node_at(position.line, position.column)
|
|
140
146
|
next if inner.nil?
|
|
141
147
|
inner_range = Range.from_node(inner)
|
|
148
|
+
# @sg-ignore Need to add nil check here
|
|
142
149
|
next unless range.include?(inner_range.ending)
|
|
143
150
|
return true if inner.type == :str
|
|
151
|
+
# @sg-ignore Need to add nil check here
|
|
144
152
|
inner_code = at(Solargraph::Range.new(inner_range.start, position))
|
|
145
|
-
|
|
153
|
+
# @sg-ignore Need to add nil check here
|
|
154
|
+
return true if (inner.type == :dstr && inner_range.ending.character <= position.character && !inner_code.end_with?('}')) ||
|
|
155
|
+
# @sg-ignore Need to add nil check here
|
|
146
156
|
(inner.type != :dstr && inner_range.ending.line == position.line && position.character <= inner_range.ending.character && inner_code.end_with?('}'))
|
|
147
157
|
end
|
|
158
|
+
# @sg-ignore Need to add nil check here
|
|
148
159
|
break if range.ending.line > position.line
|
|
149
160
|
end
|
|
150
161
|
false
|
|
@@ -160,7 +171,7 @@ module Solargraph
|
|
|
160
171
|
def comment_at? position
|
|
161
172
|
comment_ranges.each do |range|
|
|
162
173
|
return true if range.include?(position) ||
|
|
163
|
-
|
|
174
|
+
(range.ending.line == position.line && range.ending.column < position.column)
|
|
164
175
|
break if range.ending.line > position.line
|
|
165
176
|
end
|
|
166
177
|
false
|
|
@@ -179,19 +190,24 @@ module Solargraph
|
|
|
179
190
|
|
|
180
191
|
# @param node [Parser::AST::Node]
|
|
181
192
|
# @return [String]
|
|
182
|
-
def code_for
|
|
193
|
+
def code_for node
|
|
183
194
|
rng = Range.from_node(node)
|
|
195
|
+
# @sg-ignore Need to add nil check here
|
|
184
196
|
b = Position.line_char_to_offset(code, rng.start.line, rng.start.column)
|
|
197
|
+
# @sg-ignore Need to add nil check here
|
|
185
198
|
e = Position.line_char_to_offset(code, rng.ending.line, rng.ending.column)
|
|
186
|
-
frag = code[b..e-1].to_s
|
|
199
|
+
frag = code[b..(e - 1)].to_s
|
|
187
200
|
frag.strip.gsub(/,$/, '')
|
|
188
201
|
end
|
|
189
202
|
|
|
190
|
-
# @param node [
|
|
203
|
+
# @param node [AST::Node]
|
|
204
|
+
#
|
|
191
205
|
# @return [String, nil]
|
|
192
206
|
def comments_for node
|
|
193
207
|
rng = Range.from_node(node)
|
|
208
|
+
# @sg-ignore Need to add nil check here
|
|
194
209
|
stringified_comments[rng.start.line] ||= begin
|
|
210
|
+
# @sg-ignore Need to add nil check here
|
|
195
211
|
buff = associated_comments[rng.start.line]
|
|
196
212
|
buff ? stringify_comment_array(buff) : nil
|
|
197
213
|
end
|
|
@@ -208,8 +224,8 @@ module Solargraph
|
|
|
208
224
|
end
|
|
209
225
|
|
|
210
226
|
FOLDING_NODE_TYPES = %i[
|
|
211
|
-
|
|
212
|
-
|
|
227
|
+
class sclass module def defs if str dstr array while unless kwbegin hash block
|
|
228
|
+
].freeze
|
|
213
229
|
|
|
214
230
|
# Get an array of ranges that can be folded, e.g., the range of a class
|
|
215
231
|
# definition or an if condition.
|
|
@@ -219,6 +235,7 @@ module Solargraph
|
|
|
219
235
|
# @return [Array<Range>]
|
|
220
236
|
def folding_ranges
|
|
221
237
|
@folding_ranges ||= begin
|
|
238
|
+
# @type [Array<Range>]
|
|
222
239
|
result = []
|
|
223
240
|
inner_folding_ranges node, result
|
|
224
241
|
result.concat foldable_comment_block_ranges
|
|
@@ -232,7 +249,7 @@ module Solargraph
|
|
|
232
249
|
|
|
233
250
|
# Get a hash of comments grouped by the line numbers of the associated code.
|
|
234
251
|
#
|
|
235
|
-
# @return [Hash{Integer => String}]
|
|
252
|
+
# @return [Hash{Integer => String, nil}]
|
|
236
253
|
def associated_comments
|
|
237
254
|
@associated_comments ||= begin
|
|
238
255
|
# @type [Hash{Integer => String}]
|
|
@@ -265,18 +282,22 @@ module Solargraph
|
|
|
265
282
|
cursor
|
|
266
283
|
end
|
|
267
284
|
|
|
268
|
-
# @param top [Parser::AST::Node]
|
|
285
|
+
# @param top [Parser::AST::Node, nil]
|
|
269
286
|
# @param result [Array<Range>]
|
|
270
287
|
# @param parent [Symbol, nil]
|
|
271
288
|
# @return [void]
|
|
272
289
|
def inner_folding_ranges top, result = [], parent = nil
|
|
273
290
|
return unless Parser.is_ast_node?(top)
|
|
291
|
+
# @sg-ignore Translate to something flow sensitive typing understands
|
|
274
292
|
if FOLDING_NODE_TYPES.include?(top.type)
|
|
293
|
+
# @sg-ignore Translate to something flow sensitive typing understands
|
|
275
294
|
range = Range.from_node(top)
|
|
276
|
-
|
|
277
|
-
|
|
295
|
+
# @sg-ignore Need to add nil check here
|
|
296
|
+
if (result.empty? || range.start.line > result.last.start.line) && range.ending.line - range.start.line >= 2
|
|
297
|
+
result.push range
|
|
278
298
|
end
|
|
279
299
|
end
|
|
300
|
+
# @sg-ignore Translate to something flow sensitive typing understands
|
|
280
301
|
top.children.each do |child|
|
|
281
302
|
inner_folding_ranges(child, result, top.type)
|
|
282
303
|
end
|
|
@@ -290,7 +311,7 @@ module Solargraph
|
|
|
290
311
|
ctxt = String.new('')
|
|
291
312
|
started = false
|
|
292
313
|
skip = nil
|
|
293
|
-
comments.lines.each
|
|
314
|
+
comments.lines.each do |l|
|
|
294
315
|
# Trim the comment and minimum leading whitespace
|
|
295
316
|
p = l.force_encoding('UTF-8').encode('UTF-8', invalid: :replace, replace: '?').gsub(/^#+/, '')
|
|
296
317
|
if p.strip.empty?
|
|
@@ -298,17 +319,18 @@ module Solargraph
|
|
|
298
319
|
ctxt.concat p
|
|
299
320
|
else
|
|
300
321
|
here = p.index(/[^ \t]/)
|
|
322
|
+
# @sg-ignore flow sensitive typing should be able to handle redefinition
|
|
301
323
|
skip = here if skip.nil? || here < skip
|
|
302
|
-
ctxt.concat p[skip
|
|
324
|
+
ctxt.concat p[skip..]
|
|
303
325
|
end
|
|
304
326
|
started = true
|
|
305
|
-
|
|
327
|
+
end
|
|
306
328
|
ctxt
|
|
307
329
|
end
|
|
308
330
|
|
|
309
331
|
# A hash of line numbers and their associated comments.
|
|
310
332
|
#
|
|
311
|
-
# @return [Hash{Integer =>
|
|
333
|
+
# @return [Hash{Integer => String}]
|
|
312
334
|
def stringified_comments
|
|
313
335
|
@stringified_comments ||= {}
|
|
314
336
|
end
|
|
@@ -331,7 +353,7 @@ module Solargraph
|
|
|
331
353
|
return [] unless synchronized?
|
|
332
354
|
result = []
|
|
333
355
|
grouped = []
|
|
334
|
-
comments.
|
|
356
|
+
comments.each_key do |l|
|
|
335
357
|
if grouped.empty? || l == grouped.last + 1
|
|
336
358
|
grouped.push l
|
|
337
359
|
else
|
|
@@ -348,10 +370,12 @@ module Solargraph
|
|
|
348
370
|
def string_nodes_in n
|
|
349
371
|
result = []
|
|
350
372
|
if Parser.is_ast_node?(n)
|
|
351
|
-
|
|
373
|
+
# @sg-ignore Translate to something flow sensitive typing understands
|
|
374
|
+
if %i[str dstr STR DSTR].include?(n.type)
|
|
352
375
|
result.push n
|
|
353
376
|
else
|
|
354
|
-
|
|
377
|
+
# @sg-ignore Translate to something flow sensitive typing understands
|
|
378
|
+
n.children.each { |c| result.concat string_nodes_in(c) }
|
|
355
379
|
end
|
|
356
380
|
end
|
|
357
381
|
result
|
|
@@ -364,13 +388,13 @@ module Solargraph
|
|
|
364
388
|
def inner_tree_at node, position, stack
|
|
365
389
|
return if node.nil?
|
|
366
390
|
here = Range.from_node(node)
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
391
|
+
# @sg-ignore Need to add nil check here
|
|
392
|
+
return unless here.contain?(position)
|
|
393
|
+
stack.unshift node
|
|
394
|
+
node.children.each do |c|
|
|
395
|
+
next unless Parser.is_ast_node?(c)
|
|
396
|
+
next if c.loc.expression.nil?
|
|
397
|
+
inner_tree_at(c, position, stack)
|
|
374
398
|
end
|
|
375
399
|
end
|
|
376
400
|
|
|
@@ -396,10 +420,10 @@ module Solargraph
|
|
|
396
420
|
end
|
|
397
421
|
@finalized = true
|
|
398
422
|
begin
|
|
399
|
-
@node, @comments = Solargraph::Parser.parse_with_comments(@code, filename)
|
|
423
|
+
@node, @comments = Solargraph::Parser.parse_with_comments(@code, filename, 0)
|
|
400
424
|
@parsed = true
|
|
401
425
|
@repaired = @code
|
|
402
|
-
rescue Parser::SyntaxError, EncodingError
|
|
426
|
+
rescue Parser::SyntaxError, EncodingError
|
|
403
427
|
@node = nil
|
|
404
428
|
@comments = {}
|
|
405
429
|
@parsed = false
|
|
@@ -412,9 +436,9 @@ module Solargraph
|
|
|
412
436
|
end
|
|
413
437
|
error_ranges.concat(changes.map(&:range))
|
|
414
438
|
begin
|
|
415
|
-
@node, @comments = Solargraph::Parser.parse_with_comments(@repaired, filename)
|
|
439
|
+
@node, @comments = Solargraph::Parser.parse_with_comments(@repaired, filename, 0)
|
|
416
440
|
@parsed = true
|
|
417
|
-
rescue Parser::SyntaxError, EncodingError
|
|
441
|
+
rescue Parser::SyntaxError, EncodingError
|
|
418
442
|
@node = nil
|
|
419
443
|
@comments = {}
|
|
420
444
|
@parsed = false
|
|
@@ -427,7 +451,7 @@ module Solargraph
|
|
|
427
451
|
|
|
428
452
|
# @param val [String]
|
|
429
453
|
# @return [String]
|
|
430
|
-
def code=
|
|
454
|
+
def code= val
|
|
431
455
|
@code_lines = nil
|
|
432
456
|
@finalized = false
|
|
433
457
|
@code = val
|
|
@@ -12,7 +12,10 @@ module Solargraph
|
|
|
12
12
|
@api_map = api_map
|
|
13
13
|
@cursor = cursor
|
|
14
14
|
closure_pin = closure
|
|
15
|
-
|
|
15
|
+
# @sg-ignore Need to add nil check here
|
|
16
|
+
if closure_pin.is_a?(Pin::Block) && !Solargraph::Range.from_node(closure_pin.receiver).contain?(cursor.range.start)
|
|
17
|
+
closure_pin.rebind(api_map)
|
|
18
|
+
end
|
|
16
19
|
end
|
|
17
20
|
|
|
18
21
|
# @return [Array<Pin::Base>] Relevant pins for infering the type of the Cursor's position
|
|
@@ -20,7 +23,12 @@ module Solargraph
|
|
|
20
23
|
return [] if cursor.comment? || cursor.chain.literal?
|
|
21
24
|
result = cursor.chain.define(api_map, closure, locals)
|
|
22
25
|
result.concat file_global_methods
|
|
23
|
-
|
|
26
|
+
if result.empty?
|
|
27
|
+
result.concat((source_map.pins + source_map.locals).select do |p|
|
|
28
|
+
# @sg-ignore Need to add nil check here
|
|
29
|
+
p.name == cursor.word && p.location.range.contain?(cursor.position)
|
|
30
|
+
end)
|
|
31
|
+
end
|
|
24
32
|
result
|
|
25
33
|
end
|
|
26
34
|
|
|
@@ -32,7 +40,9 @@ module Solargraph
|
|
|
32
40
|
# @return [Completion]
|
|
33
41
|
def complete
|
|
34
42
|
return package_completions([]) if !source_map.source.parsed? || cursor.string?
|
|
35
|
-
|
|
43
|
+
if cursor.chain.literal? && cursor.chain.links.last.word == '<Symbol>'
|
|
44
|
+
return package_completions(api_map.get_symbols)
|
|
45
|
+
end
|
|
36
46
|
return Completion.new([], cursor.range) if cursor.chain.literal?
|
|
37
47
|
if cursor.comment?
|
|
38
48
|
tag_complete
|
|
@@ -78,7 +88,7 @@ module Solargraph
|
|
|
78
88
|
# @param phrase [String]
|
|
79
89
|
# @return [Array<Solargraph::Pin::Base>]
|
|
80
90
|
def translate phrase
|
|
81
|
-
chain = Parser.chain(Parser.parse(phrase))
|
|
91
|
+
chain = Parser.chain(Parser.parse(phrase, cursor.filename, cursor.position.line))
|
|
82
92
|
chain.define(api_map, closure, locals)
|
|
83
93
|
end
|
|
84
94
|
|
|
@@ -92,6 +102,7 @@ module Solargraph
|
|
|
92
102
|
|
|
93
103
|
# @return [SourceMap]
|
|
94
104
|
def source_map
|
|
105
|
+
# @sg-ignore Need to add nil check here
|
|
95
106
|
@source_map ||= api_map.source_map(cursor.filename)
|
|
96
107
|
end
|
|
97
108
|
|
|
@@ -125,12 +136,11 @@ module Solargraph
|
|
|
125
136
|
next unless param.keyword?
|
|
126
137
|
result.push Pin::KeywordParam.new(pin.location, "#{param.name}:")
|
|
127
138
|
end
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
end
|
|
139
|
+
next unless !pin.parameters.empty? && pin.parameters.last.kwrestarg?
|
|
140
|
+
pin.docstring.tags(:param).each do |tag|
|
|
141
|
+
next if done.include?(tag.name)
|
|
142
|
+
done.push tag.name
|
|
143
|
+
result.push Pin::KeywordParam.new(pin.location, "#{tag.name}:")
|
|
134
144
|
end
|
|
135
145
|
end
|
|
136
146
|
result
|
|
@@ -140,27 +150,34 @@ module Solargraph
|
|
|
140
150
|
# @return [Completion]
|
|
141
151
|
def package_completions result
|
|
142
152
|
frag_start = cursor.start_of_word.to_s.downcase
|
|
143
|
-
filtered = result.uniq(&:name).select
|
|
153
|
+
filtered = result.uniq(&:name).select do |s|
|
|
144
154
|
s.name.downcase.start_with?(frag_start) &&
|
|
145
|
-
(!s.is_a?(Pin::Method) || s.name.match(/^[a-z0-9_]+(
|
|
146
|
-
|
|
155
|
+
(!s.is_a?(Pin::Method) || s.name.match(/^[a-z0-9_]+(!|\?|=)?$/i))
|
|
156
|
+
end
|
|
147
157
|
Completion.new(filtered, cursor.range)
|
|
148
158
|
end
|
|
149
159
|
|
|
150
160
|
# @return [Completion]
|
|
151
161
|
def tag_complete
|
|
152
162
|
result = []
|
|
153
|
-
|
|
163
|
+
# @sg-ignore Need to add nil check here
|
|
164
|
+
match = source_map.code[0..(cursor.offset - 1)].match(/[\[<, ]([a-z0-9_:]*)\z/i)
|
|
154
165
|
if match
|
|
166
|
+
# @sg-ignore Need to add nil check here
|
|
155
167
|
full = match[1]
|
|
168
|
+
# @sg-ignore Need to add nil check here
|
|
156
169
|
if full.include?('::')
|
|
170
|
+
# @sg-ignore Need to add nil check here
|
|
157
171
|
if full.end_with?('::')
|
|
172
|
+
# @sg-ignore Need to add nil check here
|
|
158
173
|
result.concat api_map.get_constants(full[0..-3], *gates)
|
|
159
174
|
else
|
|
175
|
+
# @sg-ignore Need to add nil check here
|
|
160
176
|
result.concat api_map.get_constants(full.split('::')[0..-2].join('::'), *gates)
|
|
161
177
|
end
|
|
162
178
|
else
|
|
163
|
-
|
|
179
|
+
# @sg-ignore Need to add nil check here
|
|
180
|
+
result.concat api_map.get_constants('', full.end_with?('::') ? '' : context_pin.full_context.namespace, *gates) # .select { |pin| pin.name.start_with?(full) }
|
|
164
181
|
end
|
|
165
182
|
end
|
|
166
183
|
package_completions(result)
|
|
@@ -173,24 +190,24 @@ module Solargraph
|
|
|
173
190
|
if cursor.chain.constant? || cursor.start_of_constant?
|
|
174
191
|
full = cursor.chain.links.first.word
|
|
175
192
|
type = if cursor.chain.undefined?
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
end
|
|
193
|
+
cursor.chain.base.infer(api_map, context_pin, locals)
|
|
194
|
+
elsif full.include?('::') && cursor.chain.links.length == 1
|
|
195
|
+
# @sg-ignore Need to add nil check here
|
|
196
|
+
ComplexType.try_parse(full.split('::')[0..-2].join('::'))
|
|
197
|
+
elsif cursor.chain.links.length > 1
|
|
198
|
+
ComplexType.try_parse(full)
|
|
199
|
+
else
|
|
200
|
+
ComplexType::UNDEFINED
|
|
201
|
+
end
|
|
186
202
|
if type.undefined?
|
|
187
203
|
if full.include?('::')
|
|
188
204
|
result.concat api_map.get_constants(full, *gates)
|
|
189
205
|
else
|
|
190
|
-
result.concat api_map.get_constants('', cursor.start_of_constant? ? '' : context_pin.full_context.namespace, *gates)
|
|
206
|
+
result.concat api_map.get_constants('', cursor.start_of_constant? ? '' : context_pin.full_context.namespace, *gates) # .select { |pin| pin.name.start_with?(full) }
|
|
191
207
|
end
|
|
192
208
|
else
|
|
193
|
-
result.concat api_map.get_constants(type.namespace,
|
|
209
|
+
result.concat api_map.get_constants(type.namespace,
|
|
210
|
+
cursor.start_of_constant? ? '' : context_pin.full_context.namespace, *gates)
|
|
194
211
|
end
|
|
195
212
|
else
|
|
196
213
|
type = cursor.chain.base.infer(api_map, closure, locals)
|
|
@@ -199,14 +216,16 @@ module Solargraph
|
|
|
199
216
|
if cursor.word.start_with?('@@')
|
|
200
217
|
return package_completions(api_map.get_class_variable_pins(context_pin.full_context.namespace))
|
|
201
218
|
elsif cursor.word.start_with?('@')
|
|
202
|
-
return package_completions(api_map.get_instance_variable_pins(closure.
|
|
219
|
+
return package_completions(api_map.get_instance_variable_pins(closure.full_context.namespace,
|
|
220
|
+
closure.context.scope))
|
|
203
221
|
elsif cursor.word.start_with?('$')
|
|
204
222
|
return package_completions(api_map.get_global_variable_pins)
|
|
205
223
|
end
|
|
206
224
|
result.concat locals
|
|
207
225
|
result.concat file_global_methods unless closure.binder.namespace.empty?
|
|
208
226
|
result.concat api_map.get_constants(context_pin.context.namespace, *gates)
|
|
209
|
-
result.concat api_map.get_methods(closure.binder.namespace, scope: closure.binder.scope,
|
|
227
|
+
result.concat api_map.get_methods(closure.binder.namespace, scope: closure.binder.scope,
|
|
228
|
+
visibility: %i[public private protected])
|
|
210
229
|
result.concat api_map.get_methods('Kernel')
|
|
211
230
|
result.concat api_map.keyword_pins.to_a
|
|
212
231
|
end
|
|
@@ -8,13 +8,16 @@ module Solargraph
|
|
|
8
8
|
@source = source
|
|
9
9
|
end
|
|
10
10
|
|
|
11
|
+
# @sg-ignore Translate to something flow sensitive typing understands
|
|
11
12
|
# @return [Array<Solargraph::Pin::Base>]
|
|
13
|
+
# @sg-ignore https://github.com/castwide/solargraph/pull/1100
|
|
12
14
|
def pins
|
|
13
15
|
generate
|
|
14
16
|
@pins || []
|
|
15
17
|
end
|
|
16
18
|
|
|
17
|
-
# @
|
|
19
|
+
# @sg-ignore Translate to something flow sensitive typing understands
|
|
20
|
+
# @return [Array<Solargraph::Pin::LocalVariable>]
|
|
18
21
|
def locals
|
|
19
22
|
generate
|
|
20
23
|
@locals || []
|