solargraph 0.54.0 → 0.54.1
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/CHANGELOG.md +19 -0
- data/lib/solargraph/api_map/store.rb +6 -2
- data/lib/solargraph/api_map.rb +15 -8
- data/lib/solargraph/complex_type/type_methods.rb +10 -11
- data/lib/solargraph/complex_type/unique_type.rb +72 -9
- data/lib/solargraph/complex_type.rb +66 -17
- data/lib/solargraph/language_server/host/message_worker.rb +29 -3
- data/lib/solargraph/language_server/message/text_document/definition.rb +3 -3
- data/lib/solargraph/language_server/message/text_document/document_symbol.rb +3 -3
- data/lib/solargraph/language_server/message/text_document/hover.rb +1 -1
- data/lib/solargraph/language_server/message/text_document/type_definition.rb +3 -3
- data/lib/solargraph/language_server/message/workspace/workspace_symbol.rb +2 -2
- data/lib/solargraph/language_server/progress.rb +19 -2
- data/lib/solargraph/library.rb +30 -39
- data/lib/solargraph/location.rb +14 -1
- data/lib/solargraph/parser/parser_gem/node_chainer.rb +13 -7
- data/lib/solargraph/parser/parser_gem/node_methods.rb +1 -1
- data/lib/solargraph/parser/parser_gem/node_processors/args_node.rb +23 -19
- data/lib/solargraph/parser/parser_gem/node_processors/lvasgn_node.rb +2 -2
- data/lib/solargraph/parser/parser_gem/node_processors/masgn_node.rb +8 -2
- data/lib/solargraph/parser/parser_gem/node_processors/send_node.rb +1 -1
- data/lib/solargraph/parser.rb +2 -5
- data/lib/solargraph/pin/base.rb +15 -1
- data/lib/solargraph/pin/base_variable.rb +1 -1
- data/lib/solargraph/pin/block.rb +5 -23
- data/lib/solargraph/pin/callable.rb +147 -0
- data/lib/solargraph/pin/closure.rb +8 -3
- data/lib/solargraph/pin/common.rb +2 -6
- data/lib/solargraph/pin/conversions.rb +3 -2
- data/lib/solargraph/pin/instance_variable.rb +2 -2
- data/lib/solargraph/pin/method.rb +51 -31
- data/lib/solargraph/pin/namespace.rb +4 -4
- data/lib/solargraph/pin/parameter.rb +9 -11
- data/lib/solargraph/pin/proxy_type.rb +1 -1
- data/lib/solargraph/pin/signature.rb +3 -129
- data/lib/solargraph/pin.rb +4 -1
- data/lib/solargraph/range.rb +2 -4
- data/lib/solargraph/rbs_map/conversions.rb +70 -37
- data/lib/solargraph/rbs_map/core_fills.rb +6 -6
- data/lib/solargraph/shell.rb +17 -2
- data/lib/solargraph/source/chain/array.rb +6 -5
- data/lib/solargraph/source/chain/block_symbol.rb +1 -1
- data/lib/solargraph/source/chain/block_variable.rb +1 -1
- data/lib/solargraph/source/chain/call.rb +78 -50
- data/lib/solargraph/source/chain/link.rb +9 -0
- data/lib/solargraph/source/chain/or.rb +1 -1
- data/lib/solargraph/source/chain.rb +41 -17
- data/lib/solargraph/source/cursor.rb +13 -2
- data/lib/solargraph/source.rb +102 -85
- data/lib/solargraph/source_map/clip.rb +4 -4
- data/lib/solargraph/source_map/data.rb +30 -0
- data/lib/solargraph/source_map.rb +28 -16
- data/lib/solargraph/type_checker/rules.rb +6 -1
- data/lib/solargraph/type_checker.rb +7 -7
- data/lib/solargraph/version.rb +1 -1
- data/lib/solargraph/views/environment.erb +3 -5
- metadata +4 -2
data/lib/solargraph/source.rb
CHANGED
@@ -19,13 +19,22 @@ module Solargraph
|
|
19
19
|
attr_reader :filename
|
20
20
|
|
21
21
|
# @return [String]
|
22
|
-
|
22
|
+
def code
|
23
|
+
finalize
|
24
|
+
@code
|
25
|
+
end
|
23
26
|
|
24
|
-
# @return [Parser::AST::Node]
|
25
|
-
|
27
|
+
# @return [Parser::AST::Node, nil]
|
28
|
+
def node
|
29
|
+
finalize
|
30
|
+
@node
|
31
|
+
end
|
26
32
|
|
27
33
|
# @return [Hash{Integer => Array<String>}]
|
28
|
-
|
34
|
+
def comments
|
35
|
+
finalize
|
36
|
+
@comments
|
37
|
+
end
|
29
38
|
|
30
39
|
# @todo Deprecate?
|
31
40
|
# @return [Integer]
|
@@ -39,17 +48,6 @@ module Solargraph
|
|
39
48
|
@repaired = code
|
40
49
|
@filename = filename
|
41
50
|
@version = version
|
42
|
-
@domains = []
|
43
|
-
begin
|
44
|
-
@node, @comments = Solargraph::Parser.parse_with_comments(@code, filename)
|
45
|
-
@parsed = true
|
46
|
-
rescue Parser::SyntaxError, EncodingError => e
|
47
|
-
@node = nil
|
48
|
-
@comments = {}
|
49
|
-
@parsed = false
|
50
|
-
ensure
|
51
|
-
@code.freeze
|
52
|
-
end
|
53
51
|
end
|
54
52
|
|
55
53
|
# @param range [Solargraph::Range]
|
@@ -64,9 +62,9 @@ module Solargraph
|
|
64
62
|
# @param c2 [Integer]
|
65
63
|
# @return [String]
|
66
64
|
def from_to l1, c1, l2, c2
|
67
|
-
b = Solargraph::Position.line_char_to_offset(
|
68
|
-
e = Solargraph::Position.line_char_to_offset(
|
69
|
-
|
65
|
+
b = Solargraph::Position.line_char_to_offset(code, l1, c1)
|
66
|
+
e = Solargraph::Position.line_char_to_offset(code, l2, c2)
|
67
|
+
code[b..e-1]
|
70
68
|
end
|
71
69
|
|
72
70
|
# Get the nearest node that contains the specified index.
|
@@ -85,10 +83,9 @@ module Solargraph
|
|
85
83
|
# @param column [Integer]
|
86
84
|
# @return [Array<AST::Node>]
|
87
85
|
def tree_at(line, column)
|
88
|
-
# offset = Position.line_char_to_offset(@code, line, column)
|
89
86
|
position = Position.new(line, column)
|
90
87
|
stack = []
|
91
|
-
inner_tree_at
|
88
|
+
inner_tree_at node, position, stack
|
92
89
|
stack
|
93
90
|
end
|
94
91
|
|
@@ -104,68 +101,53 @@ module Solargraph
|
|
104
101
|
@version = updater.version
|
105
102
|
return self
|
106
103
|
end
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
104
|
+
Source.new(@code, filename, updater.version).tap do |src|
|
105
|
+
src.repaired = @repaired
|
106
|
+
src.error_ranges.concat error_ranges
|
107
|
+
src.changes.concat(changes + updater.changes)
|
111
108
|
end
|
112
|
-
incr_code = updater.repair(@repaired)
|
113
|
-
synced = Source.new(incr_code, filename)
|
114
|
-
synced.error_ranges.concat (error_ranges + updater.changes.map(&:range))
|
115
|
-
synced.code = real_code
|
116
|
-
synced.version = updater.version
|
117
|
-
synced
|
118
109
|
end
|
119
110
|
|
120
111
|
# @param position [Position, Array(Integer, Integer)]
|
121
112
|
# @return [Source::Cursor]
|
122
113
|
def cursor_at position
|
114
|
+
finalize
|
123
115
|
Cursor.new(self, position)
|
124
116
|
end
|
125
117
|
|
126
118
|
# @return [Boolean]
|
127
119
|
def parsed?
|
120
|
+
finalize
|
128
121
|
@parsed
|
129
122
|
end
|
130
123
|
|
131
124
|
def repaired?
|
132
|
-
|
125
|
+
code != @repaired
|
133
126
|
end
|
134
127
|
|
135
128
|
# @param position [Position]
|
136
129
|
# @return [Boolean]
|
137
130
|
def string_at? position
|
138
|
-
if
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
return true if [:STR, :str].include?(node.type) && range.include?(position) && range.start != position
|
155
|
-
if node.type == :dstr
|
156
|
-
inner = node_at(position.line, position.column)
|
157
|
-
next if inner.nil?
|
158
|
-
inner_range = Range.from_node(inner)
|
159
|
-
next unless range.include?(inner_range.ending)
|
160
|
-
return true if inner.type == :str
|
161
|
-
inner_code = at(Solargraph::Range.new(inner_range.start, position))
|
162
|
-
return true if (inner.type == :dstr && inner_range.ending.character <= position.character) && !inner_code.end_with?('}') ||
|
163
|
-
(inner.type != :dstr && inner_range.ending.line == position.line && position.character <= inner_range.ending.character && inner_code.end_with?('}'))
|
164
|
-
end
|
165
|
-
break if range.ending.line > position.line
|
131
|
+
return false if Position.to_offset(code, position) >= code.length
|
132
|
+
string_nodes.each do |node|
|
133
|
+
range = Range.from_node(node)
|
134
|
+
next if range.ending.line < position.line
|
135
|
+
break if range.ending.line > position.line
|
136
|
+
return true if node.type == :str && range.include?(position) && range.start != position
|
137
|
+
return true if [:STR, :str].include?(node.type) && range.include?(position) && range.start != position
|
138
|
+
if node.type == :dstr
|
139
|
+
inner = node_at(position.line, position.column)
|
140
|
+
next if inner.nil?
|
141
|
+
inner_range = Range.from_node(inner)
|
142
|
+
next unless range.include?(inner_range.ending)
|
143
|
+
return true if inner.type == :str
|
144
|
+
inner_code = at(Solargraph::Range.new(inner_range.start, position))
|
145
|
+
return true if (inner.type == :dstr && inner_range.ending.character <= position.character) && !inner_code.end_with?('}') ||
|
146
|
+
(inner.type != :dstr && inner_range.ending.line == position.line && position.character <= inner_range.ending.character && inner_code.end_with?('}'))
|
166
147
|
end
|
167
|
-
|
148
|
+
break if range.ending.line > position.line
|
168
149
|
end
|
150
|
+
false
|
169
151
|
end
|
170
152
|
|
171
153
|
# @return [::Array<Range>]
|
@@ -199,8 +181,8 @@ module Solargraph
|
|
199
181
|
# @return [String]
|
200
182
|
def code_for(node)
|
201
183
|
rng = Range.from_node(node)
|
202
|
-
b = Position.line_char_to_offset(
|
203
|
-
e = Position.line_char_to_offset(
|
184
|
+
b = Position.line_char_to_offset(code, rng.start.line, rng.start.column)
|
185
|
+
e = Position.line_char_to_offset(code, rng.ending.line, rng.ending.column)
|
204
186
|
frag = code[b..e-1].to_s
|
205
187
|
frag.strip.gsub(/,$/, '')
|
206
188
|
end
|
@@ -225,15 +207,9 @@ module Solargraph
|
|
225
207
|
Location.new(filename, range)
|
226
208
|
end
|
227
209
|
|
228
|
-
FOLDING_NODE_TYPES =
|
229
|
-
%i[
|
230
|
-
CLASS SCLASS MODULE DEFN DEFS IF WHILE UNLESS ITER STR HASH ARRAY LIST
|
231
|
-
].freeze
|
232
|
-
else
|
233
|
-
%i[
|
210
|
+
FOLDING_NODE_TYPES = %i[
|
234
211
|
class sclass module def defs if str dstr array while unless kwbegin hash block
|
235
212
|
].freeze
|
236
|
-
end
|
237
213
|
|
238
214
|
# Get an array of ranges that can be folded, e.g., the range of a class
|
239
215
|
# definition or an if condition.
|
@@ -251,8 +227,7 @@ module Solargraph
|
|
251
227
|
end
|
252
228
|
|
253
229
|
def synchronized?
|
254
|
-
|
255
|
-
@synchronized
|
230
|
+
true
|
256
231
|
end
|
257
232
|
|
258
233
|
# Get a hash of comments grouped by the line numbers of the associated code.
|
@@ -262,8 +237,9 @@ module Solargraph
|
|
262
237
|
@associated_comments ||= begin
|
263
238
|
result = {}
|
264
239
|
buffer = String.new('')
|
240
|
+
# @type [Integer, nil]
|
265
241
|
last = nil
|
266
|
-
|
242
|
+
comments.each_pair do |num, snip|
|
267
243
|
if !last || num == last + 1
|
268
244
|
buffer.concat "#{snip.text}\n"
|
269
245
|
else
|
@@ -295,12 +271,9 @@ module Solargraph
|
|
295
271
|
def inner_folding_ranges top, result = [], parent = nil
|
296
272
|
return unless Parser.is_ast_node?(top)
|
297
273
|
if FOLDING_NODE_TYPES.include?(top.type)
|
298
|
-
|
299
|
-
|
300
|
-
range
|
301
|
-
if result.empty? || range.start.line > result.last.start.line
|
302
|
-
result.push range unless range.ending.line - range.start.line < 2
|
303
|
-
end
|
274
|
+
range = Range.from_node(top)
|
275
|
+
if result.empty? || range.start.line > result.last.start.line
|
276
|
+
result.push range unless range.ending.line - range.start.line < 2
|
304
277
|
end
|
305
278
|
end
|
306
279
|
top.children.each do |child|
|
@@ -341,12 +314,12 @@ module Solargraph
|
|
341
314
|
|
342
315
|
# @return [Array<Parser::AST::Node>]
|
343
316
|
def string_nodes
|
344
|
-
@string_nodes ||= string_nodes_in(
|
317
|
+
@string_nodes ||= string_nodes_in(node)
|
345
318
|
end
|
346
319
|
|
347
320
|
# @return [Array<Range>]
|
348
321
|
def comment_ranges
|
349
|
-
@comment_ranges ||=
|
322
|
+
@comment_ranges ||= comments.values.map(&:range)
|
350
323
|
end
|
351
324
|
|
352
325
|
# Get an array of foldable comment block ranges. Blocks are excluded if
|
@@ -402,16 +375,58 @@ module Solargraph
|
|
402
375
|
|
403
376
|
protected
|
404
377
|
|
378
|
+
def changes
|
379
|
+
@changes ||= []
|
380
|
+
end
|
381
|
+
|
405
382
|
# @return [String]
|
406
383
|
attr_writer :filename
|
407
384
|
|
408
385
|
# @return [Integer]
|
409
386
|
attr_writer :version
|
410
387
|
|
388
|
+
def finalize
|
389
|
+
return if @finalized && changes.empty?
|
390
|
+
|
391
|
+
changes.each do |change|
|
392
|
+
@code = change.write(@code)
|
393
|
+
end
|
394
|
+
@finalized = true
|
395
|
+
begin
|
396
|
+
@node, @comments = Solargraph::Parser.parse_with_comments(@code, filename)
|
397
|
+
@parsed = true
|
398
|
+
@repaired = @code
|
399
|
+
rescue Parser::SyntaxError, EncodingError => e
|
400
|
+
@node = nil
|
401
|
+
@comments = {}
|
402
|
+
@parsed = false
|
403
|
+
ensure
|
404
|
+
@code.freeze
|
405
|
+
end
|
406
|
+
if !@parsed && !changes.empty?
|
407
|
+
changes.each do |change|
|
408
|
+
@repaired = change.repair(@repaired)
|
409
|
+
end
|
410
|
+
error_ranges.concat(changes.map(&:range))
|
411
|
+
begin
|
412
|
+
@node, @comments = Solargraph::Parser.parse_with_comments(@repaired, filename)
|
413
|
+
@parsed = true
|
414
|
+
rescue Parser::SyntaxError, EncodingError => e
|
415
|
+
@node = nil
|
416
|
+
@comments = {}
|
417
|
+
@parsed = false
|
418
|
+
end
|
419
|
+
elsif @parsed
|
420
|
+
error_ranges.clear
|
421
|
+
end
|
422
|
+
changes.clear
|
423
|
+
end
|
424
|
+
|
411
425
|
# @param val [String]
|
412
426
|
# @return [String]
|
413
427
|
def code=(val)
|
414
|
-
@code_lines= nil
|
428
|
+
@code_lines = nil
|
429
|
+
@finalized = false
|
415
430
|
@code = val
|
416
431
|
end
|
417
432
|
|
@@ -422,7 +437,12 @@ module Solargraph
|
|
422
437
|
attr_writer :error_ranges
|
423
438
|
|
424
439
|
# @return [String]
|
425
|
-
|
440
|
+
attr_writer :repaired
|
441
|
+
|
442
|
+
def repaired
|
443
|
+
finalize
|
444
|
+
@repaired
|
445
|
+
end
|
426
446
|
|
427
447
|
# @return [Boolean]
|
428
448
|
attr_writer :parsed
|
@@ -433,9 +453,6 @@ module Solargraph
|
|
433
453
|
# @return [Boolean]
|
434
454
|
attr_writer :synchronized
|
435
455
|
|
436
|
-
# @return [Source::Updater]
|
437
|
-
attr_accessor :last_updater
|
438
|
-
|
439
456
|
private
|
440
457
|
|
441
458
|
# @return [Array<String>]
|
@@ -2,8 +2,8 @@
|
|
2
2
|
|
3
3
|
module Solargraph
|
4
4
|
class SourceMap
|
5
|
-
# A static analysis tool for obtaining definitions,
|
6
|
-
# signatures, and type inferences from a
|
5
|
+
# A static analysis tool for obtaining definitions, Completions,
|
6
|
+
# signatures, and type inferences from a Cursor.
|
7
7
|
#
|
8
8
|
class Clip
|
9
9
|
# @param api_map [ApiMap]
|
@@ -53,10 +53,10 @@ module Solargraph
|
|
53
53
|
if result.tag == 'Class'
|
54
54
|
# HACK: Exception to return BasicObject from Class#new
|
55
55
|
dfn = cursor.chain.define(api_map, block, locals).first
|
56
|
-
return ComplexType.try_parse('BasicObject') if dfn && dfn.path == 'Class#new'
|
56
|
+
return ComplexType.try_parse('::BasicObject') if dfn && dfn.path == 'Class#new'
|
57
57
|
end
|
58
58
|
return result unless result.tag == 'self'
|
59
|
-
|
59
|
+
cursor.chain.base.infer(api_map, block, locals)
|
60
60
|
end
|
61
61
|
|
62
62
|
# Get an array of all the locals that are visible from the cursors's
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Solargraph
|
4
|
+
class SourceMap
|
5
|
+
class Data
|
6
|
+
def initialize source
|
7
|
+
@source = source
|
8
|
+
end
|
9
|
+
|
10
|
+
def pins
|
11
|
+
generate
|
12
|
+
@pins || []
|
13
|
+
end
|
14
|
+
|
15
|
+
def locals
|
16
|
+
generate
|
17
|
+
@locals || []
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def generate
|
23
|
+
return if @generated
|
24
|
+
|
25
|
+
@generated = true
|
26
|
+
@pins, @locals = Mapper.map(@source)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -4,40 +4,41 @@ require 'yard'
|
|
4
4
|
require 'solargraph/yard_tags'
|
5
5
|
|
6
6
|
module Solargraph
|
7
|
-
# An index of
|
7
|
+
# An index of Pins and other ApiMap-related data for a single Source
|
8
|
+
# that can be queried.
|
8
9
|
#
|
9
10
|
class SourceMap
|
10
11
|
autoload :Mapper, 'solargraph/source_map/mapper'
|
11
12
|
autoload :Clip, 'solargraph/source_map/clip'
|
12
13
|
autoload :Completion, 'solargraph/source_map/completion'
|
14
|
+
autoload :Data, 'solargraph/source_map/data'
|
13
15
|
|
14
16
|
# @return [Source]
|
15
17
|
attr_reader :source
|
16
18
|
|
17
19
|
# @return [Array<Pin::Base>]
|
18
|
-
|
20
|
+
def pins
|
21
|
+
data.pins
|
22
|
+
end
|
19
23
|
|
20
24
|
# @return [Array<Pin::LocalVariable>]
|
21
|
-
|
25
|
+
def locals
|
26
|
+
data.locals
|
27
|
+
end
|
22
28
|
|
23
29
|
# @param source [Source]
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
# HACK: Keep the library from changing this
|
28
|
-
@source = source.dup
|
29
|
-
@pins = pins
|
30
|
-
@locals = locals
|
30
|
+
def initialize source
|
31
|
+
@source = source
|
32
|
+
|
31
33
|
environ.merge Convention.for_local(self) unless filename.nil?
|
32
34
|
self.convention_pins = environ.pins
|
33
|
-
@pin_class_hash = pins.to_set.classify(&:class).transform_values(&:to_a)
|
34
35
|
@pin_select_cache = {}
|
35
36
|
end
|
36
37
|
|
37
38
|
# @param klass [Class]
|
38
39
|
# @return [Array<Pin::Base>]
|
39
40
|
def pins_by_class klass
|
40
|
-
@pin_select_cache[klass] ||=
|
41
|
+
@pin_select_cache[klass] ||= pin_class_hash.select { |key, _| key <= klass }.values.flatten
|
41
42
|
end
|
42
43
|
|
43
44
|
# A hash representing the state of the source map's API.
|
@@ -47,7 +48,7 @@ module Solargraph
|
|
47
48
|
#
|
48
49
|
# @return [Integer]
|
49
50
|
def api_hash
|
50
|
-
@api_hash ||= (pins_by_class(Pin::Constant) + pins_by_class(Pin::Namespace).select { |pin| pin.namespace.to_s > '' } + pins_by_class(Pin::Reference) + pins_by_class(Pin::Method).map(&:node)).hash
|
51
|
+
@api_hash ||= (pins_by_class(Pin::Constant) + pins_by_class(Pin::Namespace).select { |pin| pin.namespace.to_s > '' } + pins_by_class(Pin::Reference) + pins_by_class(Pin::Method).map(&:node) + locals).hash
|
51
52
|
end
|
52
53
|
|
53
54
|
# @return [String]
|
@@ -117,10 +118,13 @@ module Solargraph
|
|
117
118
|
_locate_pin line, character, Pin::Namespace, Pin::Method, Pin::Block
|
118
119
|
end
|
119
120
|
|
121
|
+
# @todo Candidate for deprecation
|
122
|
+
#
|
120
123
|
# @param other_map [SourceMap]
|
121
124
|
# @return [Boolean]
|
122
125
|
def try_merge! other_map
|
123
126
|
return false if pins.length != other_map.pins.length || locals.length != other_map.locals.length || requires.map(&:name).uniq.sort != other_map.requires.map(&:name).uniq.sort
|
127
|
+
|
124
128
|
pins.each_index do |i|
|
125
129
|
return false unless pins[i].try_merge!(other_map.pins[i])
|
126
130
|
end
|
@@ -161,16 +165,24 @@ module Solargraph
|
|
161
165
|
SourceMap.map(source)
|
162
166
|
end
|
163
167
|
|
168
|
+
# @deprecated
|
164
169
|
# @param source [Source]
|
165
170
|
# @return [SourceMap]
|
166
171
|
def map source
|
167
|
-
|
168
|
-
new(source, *result)
|
172
|
+
new(source)
|
169
173
|
end
|
170
174
|
end
|
171
175
|
|
172
176
|
private
|
173
177
|
|
178
|
+
def pin_class_hash
|
179
|
+
@pin_class_hash ||= pins.to_set.classify(&:class).transform_values(&:to_a)
|
180
|
+
end
|
181
|
+
|
182
|
+
def data
|
183
|
+
@data ||= Data.new(source)
|
184
|
+
end
|
185
|
+
|
174
186
|
# @return [Array<Pin::Base>]
|
175
187
|
def convention_pins
|
176
188
|
@convention_pins || []
|
@@ -179,7 +191,7 @@ module Solargraph
|
|
179
191
|
# @param pins [Array<Pin::Base>]
|
180
192
|
# @return [Array<Pin::Base>]
|
181
193
|
def convention_pins=(pins)
|
182
|
-
# unmemoizing the document_symbols in case it was called from any of
|
194
|
+
# unmemoizing the document_symbols in case it was called from any of conventions
|
183
195
|
@document_symbols = nil
|
184
196
|
@convention_pins = pins
|
185
197
|
end
|
@@ -9,7 +9,8 @@ module Solargraph
|
|
9
9
|
normal: 0,
|
10
10
|
typed: 1,
|
11
11
|
strict: 2,
|
12
|
-
strong: 3
|
12
|
+
strong: 3,
|
13
|
+
alpha: 4
|
13
14
|
}.freeze
|
14
15
|
|
15
16
|
# @return [Symbol]
|
@@ -52,6 +53,10 @@ module Solargraph
|
|
52
53
|
def validate_tags?
|
53
54
|
rank > LEVELS[:normal]
|
54
55
|
end
|
56
|
+
|
57
|
+
def require_all_return_types_match_inferred?
|
58
|
+
rank >= LEVELS[:alpha]
|
59
|
+
end
|
55
60
|
end
|
56
61
|
end
|
57
62
|
end
|
@@ -90,11 +90,11 @@ module Solargraph
|
|
90
90
|
def method_return_type_problems_for pin
|
91
91
|
return [] if pin.is_a?(Pin::MethodAlias)
|
92
92
|
result = []
|
93
|
-
declared = pin.typify(api_map).
|
93
|
+
declared = pin.typify(api_map).self_to_type(pin.full_context).qualify(api_map, pin.full_context.tag)
|
94
94
|
if declared.undefined?
|
95
95
|
if pin.return_type.undefined? && rules.require_type_tags?
|
96
96
|
if pin.attribute?
|
97
|
-
inferred = pin.probe(api_map).
|
97
|
+
inferred = pin.probe(api_map).self_to_type(pin.full_context)
|
98
98
|
result.push Problem.new(pin.location, "Missing @return tag for #{pin.path}", pin: pin) unless inferred.defined?
|
99
99
|
else
|
100
100
|
result.push Problem.new(pin.location, "Missing @return tag for #{pin.path}", pin: pin)
|
@@ -106,14 +106,14 @@ module Solargraph
|
|
106
106
|
end
|
107
107
|
elsif rules.validate_tags?
|
108
108
|
unless pin.node.nil? || declared.void? || virtual_pin?(pin) || abstract?(pin)
|
109
|
-
inferred = pin.probe(api_map).
|
109
|
+
inferred = pin.probe(api_map).self_to_type(pin.full_context)
|
110
110
|
if inferred.undefined?
|
111
111
|
unless rules.ignore_all_undefined? || external?(pin)
|
112
112
|
result.push Problem.new(pin.location, "#{pin.path} return type could not be inferred", pin: pin)
|
113
113
|
end
|
114
114
|
else
|
115
|
-
unless (rules.
|
116
|
-
result.push Problem.new(pin.location, "Declared return type #{declared} does not match inferred type #{inferred} for #{pin.path}", pin: pin)
|
115
|
+
unless (rules.require_all_return_types_match_inferred? ? all_types_match?(api_map, inferred, declared) : any_types_match?(api_map, declared, inferred))
|
116
|
+
result.push Problem.new(pin.location, "Declared return type #{declared.rooted_tags} does not match inferred type #{inferred.rooted_tags} for #{pin.path}", pin: pin)
|
117
117
|
end
|
118
118
|
end
|
119
119
|
end
|
@@ -154,7 +154,7 @@ module Solargraph
|
|
154
154
|
break if par.decl == :restarg || par.decl == :kwrestarg || par.decl == :blockarg
|
155
155
|
unless params[par.name]
|
156
156
|
if pin.attribute?
|
157
|
-
inferred = pin.probe(api_map).
|
157
|
+
inferred = pin.probe(api_map).self_to_type(pin.full_context)
|
158
158
|
if inferred.undefined?
|
159
159
|
result.push Problem.new(pin.location, "Missing @param tag for #{par.name} on #{pin.path}", pin: pin)
|
160
160
|
end
|
@@ -377,7 +377,7 @@ module Solargraph
|
|
377
377
|
break
|
378
378
|
end
|
379
379
|
ptype = params.key?(par.name) ? params[par.name][:qualified] : ComplexType::UNDEFINED
|
380
|
-
ptype = ptype.
|
380
|
+
ptype = ptype.self_to_type(par.context)
|
381
381
|
if ptype.nil?
|
382
382
|
# @todo Some level (strong, I guess) should require the param here
|
383
383
|
else
|
data/lib/solargraph/version.rb
CHANGED
@@ -35,11 +35,9 @@
|
|
35
35
|
<li>
|
36
36
|
Core Cache Directory: N/A <%# @todo Fix %>
|
37
37
|
</li>
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
</li>
|
42
|
-
<% end %>
|
38
|
+
<li>
|
39
|
+
Parser Target Version: <%= Solargraph::Parser.version %>
|
40
|
+
</li>
|
43
41
|
<li>
|
44
42
|
Using Bundler: <%= ENV.key?('BUNDLE_BIN_PATH') %>
|
45
43
|
</li>
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: solargraph
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.54.
|
4
|
+
version: 0.54.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fred Snyder
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-04-
|
11
|
+
date: 2025-04-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: backport
|
@@ -524,6 +524,7 @@ files:
|
|
524
524
|
- lib/solargraph/pin/base.rb
|
525
525
|
- lib/solargraph/pin/base_variable.rb
|
526
526
|
- lib/solargraph/pin/block.rb
|
527
|
+
- lib/solargraph/pin/callable.rb
|
527
528
|
- lib/solargraph/pin/class_variable.rb
|
528
529
|
- lib/solargraph/pin/closure.rb
|
529
530
|
- lib/solargraph/pin/common.rb
|
@@ -589,6 +590,7 @@ files:
|
|
589
590
|
- lib/solargraph/source_map.rb
|
590
591
|
- lib/solargraph/source_map/clip.rb
|
591
592
|
- lib/solargraph/source_map/completion.rb
|
593
|
+
- lib/solargraph/source_map/data.rb
|
592
594
|
- lib/solargraph/source_map/mapper.rb
|
593
595
|
- lib/solargraph/type_checker.rb
|
594
596
|
- lib/solargraph/type_checker/checks.rb
|