solargraph 0.51.1 → 0.52.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/.yardopts +2 -2
- data/CHANGELOG.md +31 -5
- data/lib/solargraph/api_map/cache.rb +2 -0
- data/lib/solargraph/api_map/store.rb +2 -2
- data/lib/solargraph/api_map.rb +11 -4
- data/lib/solargraph/complex_type/type_methods.rb +1 -1
- data/lib/solargraph/complex_type/unique_type.rb +19 -12
- data/lib/solargraph/complex_type.rb +24 -10
- data/lib/solargraph/documentor.rb +1 -1
- data/lib/solargraph/library.rb +12 -5
- data/lib/solargraph/parser/comment_ripper.rb +1 -0
- data/lib/solargraph/parser/legacy/class_methods.rb +2 -2
- data/lib/solargraph/parser/legacy/node_chainer.rb +18 -10
- data/lib/solargraph/parser/legacy/node_methods.rb +5 -3
- data/lib/solargraph/parser/legacy/node_processors/args_node.rb +28 -13
- data/lib/solargraph/parser/legacy/node_processors.rb +22 -21
- data/lib/solargraph/parser/node_methods.rb +1 -0
- data/lib/solargraph/parser/region.rb +1 -1
- data/lib/solargraph/parser/rubyvm/class_methods.rb +1 -3
- data/lib/solargraph/parser/rubyvm/node_chainer.rb +5 -2
- data/lib/solargraph/parser.rb +2 -0
- data/lib/solargraph/pin/base.rb +1 -1
- data/lib/solargraph/pin/block.rb +2 -2
- data/lib/solargraph/pin/delegated_method.rb +1 -1
- data/lib/solargraph/pin/method.rb +63 -6
- data/lib/solargraph/pin/namespace.rb +10 -3
- data/lib/solargraph/pin/parameter.rb +9 -10
- data/lib/solargraph/pin/signature.rb +9 -1
- data/lib/solargraph/rbs_map/conversions.rb +86 -31
- data/lib/solargraph/rbs_map/core_fills.rb +9 -10
- data/lib/solargraph/rbs_map/core_map.rb +1 -1
- data/lib/solargraph/rbs_map.rb +2 -3
- data/lib/solargraph/source/chain/array.rb +29 -0
- data/lib/solargraph/source/chain/call.rb +14 -30
- data/lib/solargraph/source/chain/link.rb +1 -1
- data/lib/solargraph/source/chain/z_super.rb +1 -1
- data/lib/solargraph/source/chain.rb +9 -10
- data/lib/solargraph/source/source_chainer.rb +2 -0
- data/lib/solargraph/source.rb +3 -3
- data/lib/solargraph/source_map/clip.rb +0 -16
- data/lib/solargraph/source_map/mapper.rb +2 -1
- data/lib/solargraph/source_map.rb +2 -2
- data/lib/solargraph/type_checker.rb +18 -7
- data/lib/solargraph/version.rb +1 -1
- data/lib/solargraph/workspace.rb +2 -1
- data/lib/solargraph/yard_map/mapper.rb +1 -1
- data/lib/solargraph/yard_map.rb +6 -5
- data/lib/solargraph/yard_tags.rb +20 -0
- data/lib/solargraph.rb +2 -3
- data/solargraph.gemspec +3 -0
- metadata +32 -3
- data/lib/yard-solargraph.rb +0 -33
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fdf3486fdfc29fad9450f6c8dade8f6f9d2446b400c8032055adc93a0c9ed80f
|
4
|
+
data.tar.gz: 30cbae5663273333f57dd66eec6cc336a318bca17ea9ff2ba9da257d94f25ad3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0739d9be8146ea6b09a9bf8151328d95bea64c3fe3ddd7af6334f140c0a2eedaacff84a0e6e5b70fb5e6909b8f25ff85fb5d18f7d73f06a0294ea617dde90263'
|
7
|
+
data.tar.gz: 29de344f99fc2f5f96b2ccc6df9fea4b6220074315ef4a04777e4afaa16253e166f238e51fbe18914ad6f9af6c1983587b7898d7abe003f4ad420f7e508b6edc
|
data/.yardopts
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
lib/**/*.rb
|
2
|
-
|
1
|
+
lib/**/*.rb
|
2
|
+
--plugin yard-solargraph
|
data/CHANGELOG.md
CHANGED
@@ -1,9 +1,34 @@
|
|
1
|
+
## 0.52.0 - February 28, 2025
|
2
|
+
- Chains resolve identical names with different contexts (#679)
|
3
|
+
- Handle symbol tags in method tag values (#744)
|
4
|
+
- Infer more specific Array types when possible (#745)
|
5
|
+
- Handle interpolated symbol literals (#747)
|
6
|
+
- Handle combined conditions, else clauses in case statements (#746)
|
7
|
+
- fix: support find require xxx.rb in local workspace. (#722)
|
8
|
+
- Don't require redundant attribute @return and @param tags (#748)
|
9
|
+
- Use @yieldreturn tags for type inference (#749)
|
10
|
+
- Fix type annotations identified at 'typed' level (#750)
|
11
|
+
- Support RBS class aliases (#751)
|
12
|
+
- Better support for generics via Class @param tags (#743)
|
13
|
+
- Generic module support through RBS (#757)
|
14
|
+
- Fix inference of begin expression types (#754)
|
15
|
+
- Add argument to satisfy typechecker on which signature to use (#755)
|
16
|
+
- Fix RBS ingestion implicit initializer issues, missing param types (#756)
|
17
|
+
- Validate zsuper arity
|
18
|
+
- Use yard-solargraph plugin (#759)
|
19
|
+
- Add missing RBS types
|
20
|
+
|
21
|
+
## 0.51.2 - February 1, 2025
|
22
|
+
- Fix exception from parser when anonymous block forwarding is used (#740)
|
23
|
+
- Parameterized Object types
|
24
|
+
- Remove extraneous comment from method examples
|
25
|
+
|
1
26
|
## 0.51.1 - January 23, 2025
|
2
27
|
- Format example code
|
3
|
-
- Block infers
|
28
|
+
- Block infers yieldreceiver from chain
|
4
29
|
|
5
30
|
## 0.51.0 - January 19, 2025
|
6
|
-
- Resolve self in
|
31
|
+
- Resolve self in yieldreceiver tags
|
7
32
|
- Include absolute paths in config (#674)
|
8
33
|
- Enable diagnostics by default
|
9
34
|
- Fix cache resolution (#704)
|
@@ -12,6 +37,7 @@
|
|
12
37
|
- Enable diagnostics by default
|
13
38
|
- Remove RSpec convention (#716)
|
14
39
|
- Include convention pins in document_symbols (#724)
|
40
|
+
- Implement Go To Type Definition (#717)
|
15
41
|
- Remove e2mmap dependency (#699)
|
16
42
|
- Update rbs to 3.0
|
17
43
|
- Relax reverse_markdown dependency (#729)
|
@@ -591,7 +617,7 @@
|
|
591
617
|
## 0.31.2 - January 27, 2019
|
592
618
|
- Use YARD documentation rules to associate directives with namespaces
|
593
619
|
- Handle non-unique pin locations in completionItem/resolve
|
594
|
-
- Clip#complete handles @
|
620
|
+
- Clip#complete handles @yieldreceiver and @yieldpublic contexts
|
595
621
|
- Host::Dispatch filters library updates (castwide/vscode-solargraph#99)
|
596
622
|
- Qualify included namespaces (#148)
|
597
623
|
|
@@ -947,7 +973,7 @@
|
|
947
973
|
|
948
974
|
## 0.17.0 - February 1, 2018
|
949
975
|
- Support Solargraph configurations in workspace folders.
|
950
|
-
- Use @
|
976
|
+
- Use @yieldreceiver tag to change block contexts.
|
951
977
|
- Handle whitespace in signatures.
|
952
978
|
- Convert 'self' when inferring signature types.
|
953
979
|
- Handle bare periods without signatures.
|
@@ -990,7 +1016,7 @@
|
|
990
1016
|
- Map pins to code objects.
|
991
1017
|
- Infer return types from domain (DSL) methods.
|
992
1018
|
- Fixed visibility and results for superclasses.
|
993
|
-
- Experimental @
|
1019
|
+
- Experimental @yieldreceiver tag.
|
994
1020
|
- Improved syntax error handling in Source.fix.
|
995
1021
|
- Gem ships with Ruby 2.2.2 yardocs.
|
996
1022
|
- Experimental plugin architecture and Runtime plugin.
|
@@ -4,6 +4,7 @@ module Solargraph
|
|
4
4
|
class ApiMap
|
5
5
|
class Cache
|
6
6
|
def initialize
|
7
|
+
# @type [Hash{Array => Array<Pin::Method>}]
|
7
8
|
@methods = {}
|
8
9
|
@constants = {}
|
9
10
|
@qualified_namespaces = {}
|
@@ -15,6 +16,7 @@ module Solargraph
|
|
15
16
|
@methods[[fqns, scope, visibility.sort, deep]]
|
16
17
|
end
|
17
18
|
|
19
|
+
# @return [Array<Pin::Method>]
|
18
20
|
def set_methods fqns, scope, visibility, deep, value
|
19
21
|
@methods[[fqns, scope, visibility.sort, deep]] = value
|
20
22
|
end
|
@@ -147,8 +147,6 @@ module Solargraph
|
|
147
147
|
@pin_select_cache[klass] ||= @pin_class_hash.each_with_object(Set.new) { |(key, o), n| n.merge(o) if key <= klass }
|
148
148
|
end
|
149
149
|
|
150
|
-
private
|
151
|
-
|
152
150
|
# @param fqns [String]
|
153
151
|
# @return [Array<Solargraph::Pin::Namespace>]
|
154
152
|
def fqns_pins fqns
|
@@ -164,6 +162,8 @@ module Solargraph
|
|
164
162
|
fqns_pins_map[[base, name]]
|
165
163
|
end
|
166
164
|
|
165
|
+
private
|
166
|
+
|
167
167
|
def fqns_pins_map
|
168
168
|
@fqns_pins_map ||= Hash.new do |h, (base, name)|
|
169
169
|
value = namespace_children(base).select { |pin| pin.name == name && pin.is_a?(Pin::Namespace) }
|
data/lib/solargraph/api_map.rb
CHANGED
@@ -4,7 +4,7 @@ require 'rubygems'
|
|
4
4
|
require 'set'
|
5
5
|
require 'pathname'
|
6
6
|
require 'yard'
|
7
|
-
require '
|
7
|
+
require 'solargraph/yard_tags'
|
8
8
|
|
9
9
|
module Solargraph
|
10
10
|
# An aggregate provider for information about workspaces, sources, gems, and
|
@@ -137,7 +137,7 @@ module Solargraph
|
|
137
137
|
api_map
|
138
138
|
end
|
139
139
|
|
140
|
-
# @return [
|
140
|
+
# @return [Enumerable<Solargraph::Pin::Base>]
|
141
141
|
def pins
|
142
142
|
store.pins
|
143
143
|
end
|
@@ -199,6 +199,13 @@ module Solargraph
|
|
199
199
|
result
|
200
200
|
end
|
201
201
|
|
202
|
+
# @param namespace [String]
|
203
|
+
# @param context [String]
|
204
|
+
# @return [Array<Pin::Namespace>]
|
205
|
+
def get_namespace_pins namespace, context
|
206
|
+
store.fqns_pins(qualify(namespace, context))
|
207
|
+
end
|
208
|
+
|
202
209
|
# Get a fully qualified namespace name. This method will start the search
|
203
210
|
# in the specified context until it finds a match for the name.
|
204
211
|
#
|
@@ -245,12 +252,12 @@ module Solargraph
|
|
245
252
|
prefer_non_nil_variables(store.get_class_variables(namespace))
|
246
253
|
end
|
247
254
|
|
248
|
-
# @return [
|
255
|
+
# @return [Enumerable<Solargraph::Pin::Base>]
|
249
256
|
def get_symbols
|
250
257
|
store.get_symbols
|
251
258
|
end
|
252
259
|
|
253
|
-
# @return [
|
260
|
+
# @return [Enumerable<Solargraph::Pin::GlobalVariable>]
|
254
261
|
def get_global_variable_pins
|
255
262
|
store.pins_by_class(Pin::GlobalVariable)
|
256
263
|
end
|
@@ -101,7 +101,7 @@ module Solargraph
|
|
101
101
|
# @param context [String] The namespace from which to resolve names
|
102
102
|
# @return [ComplexType] The generated ComplexType
|
103
103
|
def qualify api_map, context = ''
|
104
|
-
return self if name ==
|
104
|
+
return self if name == GENERIC_TAG_NAME
|
105
105
|
return ComplexType.new([self]) if duck_type? || void? || undefined?
|
106
106
|
recon = (rooted? ? '' : context)
|
107
107
|
fqns = api_map.qualify(name, recon)
|
@@ -51,35 +51,42 @@ module Solargraph
|
|
51
51
|
tag
|
52
52
|
end
|
53
53
|
|
54
|
+
def items
|
55
|
+
[self]
|
56
|
+
end
|
57
|
+
|
54
58
|
def to_rbs
|
55
59
|
"#{namespace}#{parameters? ? "[#{subtypes.map { |s| s.to_rbs }.join(', ')}]" : ''}"
|
56
60
|
end
|
57
|
-
|
58
|
-
def
|
59
|
-
name ==
|
61
|
+
|
62
|
+
def generic?
|
63
|
+
name == GENERIC_TAG_NAME || all_params.any?(&:generic?)
|
60
64
|
end
|
61
65
|
|
62
|
-
|
63
|
-
|
64
|
-
|
66
|
+
# @param definitions [Pin::Namespace]
|
67
|
+
# @param context_type [ComplexType]
|
68
|
+
# @return [UniqueType]
|
69
|
+
def resolve_generics definitions, context_type
|
70
|
+
new_name = if name == GENERIC_TAG_NAME
|
71
|
+
idx = definitions.generics.index(subtypes.first&.name)
|
65
72
|
return ComplexType::UNDEFINED if idx.nil?
|
66
|
-
param_type =
|
73
|
+
param_type = context_type.all_params[idx]
|
67
74
|
return ComplexType::UNDEFINED unless param_type
|
68
75
|
param_type.to_s
|
69
76
|
else
|
70
77
|
name
|
71
78
|
end
|
72
|
-
new_key_types = if name !=
|
73
|
-
@key_types.map { |t| t.
|
79
|
+
new_key_types = if name != GENERIC_TAG_NAME
|
80
|
+
@key_types.map { |t| t.resolve_generics(definitions, context_type) }.select(&:defined?)
|
74
81
|
else
|
75
82
|
[]
|
76
83
|
end
|
77
|
-
new_subtypes = if name !=
|
78
|
-
@subtypes.map { |t| t.
|
84
|
+
new_subtypes = if name != GENERIC_TAG_NAME
|
85
|
+
@subtypes.map { |t| t.resolve_generics(definitions, context_type) }.select(&:defined?)
|
79
86
|
else
|
80
87
|
[]
|
81
88
|
end
|
82
|
-
if name !=
|
89
|
+
if name != GENERIC_TAG_NAME && !(new_key_types.empty? && new_subtypes.empty?)
|
83
90
|
if hash_parameters?
|
84
91
|
UniqueType.new(new_name, "{#{new_key_types.join(', ')} => #{new_subtypes.join(', ')}}")
|
85
92
|
elsif parameters?
|
@@ -4,26 +4,28 @@ module Solargraph
|
|
4
4
|
# A container for type data based on YARD type tags.
|
5
5
|
#
|
6
6
|
class ComplexType
|
7
|
+
GENERIC_TAG_NAME = 'generic'.freeze
|
7
8
|
# @!parse
|
8
9
|
# include TypeMethods
|
9
10
|
|
10
11
|
autoload :TypeMethods, 'solargraph/complex_type/type_methods'
|
11
12
|
autoload :UniqueType, 'solargraph/complex_type/unique_type'
|
12
13
|
|
13
|
-
# @param types [Array<UniqueType>]
|
14
|
+
# @param types [Array<[UniqueType, ComplexType]>]
|
14
15
|
def initialize types = [UniqueType::UNDEFINED]
|
15
|
-
@items = types.uniq(&:to_s)
|
16
|
+
@items = types.flat_map(&:items).uniq(&:to_s)
|
16
17
|
end
|
17
18
|
|
18
19
|
# @param api_map [ApiMap]
|
19
20
|
# @param context [String]
|
20
21
|
# @return [ComplexType]
|
21
22
|
def qualify api_map, context = ''
|
22
|
-
|
23
|
+
red = reduce_object
|
24
|
+
types = red.items.map do |t|
|
23
25
|
next t if ['Boolean', 'nil', 'void', 'undefined'].include?(t.name)
|
24
26
|
t.qualify api_map, context
|
25
27
|
end
|
26
|
-
ComplexType.new(types)
|
28
|
+
ComplexType.new(types).reduce_object
|
27
29
|
end
|
28
30
|
|
29
31
|
def first
|
@@ -41,7 +43,7 @@ module Solargraph
|
|
41
43
|
end
|
42
44
|
|
43
45
|
# @yieldparam [UniqueType]
|
44
|
-
# @return [
|
46
|
+
# @return [Enumerator<UniqueType>]
|
45
47
|
def each &block
|
46
48
|
@items.each &block
|
47
49
|
end
|
@@ -105,12 +107,15 @@ module Solargraph
|
|
105
107
|
@items.any?(&:selfy?)
|
106
108
|
end
|
107
109
|
|
108
|
-
def
|
109
|
-
any?(&:
|
110
|
+
def generic?
|
111
|
+
any?(&:generic?)
|
110
112
|
end
|
111
113
|
|
112
|
-
|
113
|
-
|
114
|
+
# @param definitions [Pin::Namespace]
|
115
|
+
# @param context_type [ComplexType]
|
116
|
+
# @return [ComplexType]
|
117
|
+
def resolve_generics definitions, context_type
|
118
|
+
result = @items.map { |i| i.resolve_generics(definitions, context_type) }
|
114
119
|
ComplexType.parse(*result.map(&:tag))
|
115
120
|
end
|
116
121
|
|
@@ -120,7 +125,7 @@ module Solargraph
|
|
120
125
|
return self unless selfy?
|
121
126
|
red = reduce_class(dst)
|
122
127
|
result = @items.map { |i| i.self_to red }
|
123
|
-
ComplexType.parse(*result.map(&:
|
128
|
+
ComplexType.parse(*result.map(&:tag))
|
124
129
|
end
|
125
130
|
|
126
131
|
def nullable?
|
@@ -131,6 +136,15 @@ module Solargraph
|
|
131
136
|
@items.first.all_params || []
|
132
137
|
end
|
133
138
|
|
139
|
+
attr_reader :items
|
140
|
+
|
141
|
+
protected
|
142
|
+
|
143
|
+
def reduce_object
|
144
|
+
return self if name != 'Object' || subtypes.empty?
|
145
|
+
ComplexType.try_parse(reduce_class(subtypes.join(', ')))
|
146
|
+
end
|
147
|
+
|
134
148
|
private
|
135
149
|
|
136
150
|
# @todo This is a quick and dirty hack that forces `self` keywords
|
data/lib/solargraph/library.rb
CHANGED
@@ -283,10 +283,15 @@ module Solargraph
|
|
283
283
|
return if map.nil?
|
284
284
|
pin = map.requires.select { |p| p.location.range.contain?(location.range.start) }.first
|
285
285
|
return nil if pin.nil?
|
286
|
+
return_if_match = proc do |full|
|
287
|
+
if source_map_hash.key?(full)
|
288
|
+
return Location.new(full, Solargraph::Range.from_to(0, 0, 0, 0))
|
289
|
+
end
|
290
|
+
end
|
286
291
|
workspace.require_paths.each do |path|
|
287
|
-
full =
|
288
|
-
|
289
|
-
|
292
|
+
full = File.join path, pin.name
|
293
|
+
return_if_match.(full)
|
294
|
+
return_if_match.(full << ".rb")
|
290
295
|
end
|
291
296
|
nil
|
292
297
|
rescue FileNotFoundError
|
@@ -497,10 +502,12 @@ module Solargraph
|
|
497
502
|
def find_external_requires source_map
|
498
503
|
new_set = source_map.requires.map(&:name).to_set
|
499
504
|
# return if new_set == source_map_external_require_hash[source_map.filename]
|
505
|
+
_filenames = nil
|
506
|
+
filenames = ->{ _filenames ||= workspace.filenames.to_set }
|
500
507
|
source_map_external_require_hash[source_map.filename] = new_set.reject do |path|
|
501
508
|
workspace.require_paths.any? do |base|
|
502
|
-
full =
|
503
|
-
|
509
|
+
full = File.join(base, path)
|
510
|
+
filenames[].include?(full) or filenames[].include?(full << ".rb")
|
504
511
|
end
|
505
512
|
end
|
506
513
|
@external_requires = nil
|
@@ -5,7 +5,7 @@ module Solargraph
|
|
5
5
|
module Legacy
|
6
6
|
module ClassMethods
|
7
7
|
# @param code [String]
|
8
|
-
# @param filename [String]
|
8
|
+
# @param filename [String, nil]
|
9
9
|
# @return [Array(Parser::AST::Node, Array<Parser::Source::Comment>)]
|
10
10
|
def parse_with_comments code, filename = nil
|
11
11
|
buffer = ::Parser::Source::Buffer.new(filename, 0)
|
@@ -128,7 +128,7 @@ module Solargraph
|
|
128
128
|
end
|
129
129
|
end
|
130
130
|
result
|
131
|
-
end
|
131
|
+
end
|
132
132
|
end
|
133
133
|
end
|
134
134
|
end
|
@@ -10,7 +10,7 @@ module Solargraph
|
|
10
10
|
Chain = Source::Chain
|
11
11
|
|
12
12
|
# @param node [Parser::AST::Node]
|
13
|
-
# @param filename [String]
|
13
|
+
# @param filename [String, nil]
|
14
14
|
def initialize node, filename = nil, in_block = false
|
15
15
|
@node = node
|
16
16
|
@filename = filename
|
@@ -25,7 +25,7 @@ module Solargraph
|
|
25
25
|
|
26
26
|
class << self
|
27
27
|
# @param node [Parser::AST::Node]
|
28
|
-
# @param filename [String]
|
28
|
+
# @param filename [String, nil]
|
29
29
|
# @return [Source::Chain]
|
30
30
|
def chain node, filename = nil, in_block = false
|
31
31
|
NodeChainer.new(node, filename, in_block).chain
|
@@ -47,7 +47,6 @@ module Solargraph
|
|
47
47
|
# @return [Array<Chain::Link>]
|
48
48
|
def generate_links n
|
49
49
|
return [] unless n.is_a?(::Parser::AST::Node)
|
50
|
-
return generate_links(n.children[0]) if n.type == :begin
|
51
50
|
return generate_links(n.children[0]) if n.type == :splat
|
52
51
|
result = []
|
53
52
|
if n.type == :block
|
@@ -95,6 +94,9 @@ module Solargraph
|
|
95
94
|
elsif n.type == :super
|
96
95
|
args = n.children.map { |c| NodeChainer.chain(c) }
|
97
96
|
result.push Chain::Call.new('super', args, @in_block > 0 || block_passed?(n))
|
97
|
+
elsif n.type == :yield
|
98
|
+
args = n.children.map { |c| NodeChainer.chain(c) }
|
99
|
+
result.push Chain::Call.new('yield', args, @in_block > 0 || block_passed?(n))
|
98
100
|
elsif n.type == :const
|
99
101
|
const = unpack_name(n)
|
100
102
|
result.push Chain::Constant.new(const)
|
@@ -116,18 +118,24 @@ module Solargraph
|
|
116
118
|
elsif n.type == :or
|
117
119
|
result.push Chain::Or.new([NodeChainer.chain(n.children[0], @filename), NodeChainer.chain(n.children[1], @filename)])
|
118
120
|
elsif [:begin, :kwbegin].include?(n.type)
|
119
|
-
result.concat generate_links(n.children
|
121
|
+
result.concat generate_links(n.children.last)
|
120
122
|
elsif n.type == :block_pass
|
121
|
-
|
123
|
+
block_variable_name_node = n.children[0]
|
124
|
+
if block_variable_name_node.nil?
|
125
|
+
# anonymous block forwarding (e.g., "&")
|
126
|
+
# added in Ruby 3.1 - https://bugs.ruby-lang.org/issues/11256
|
127
|
+
result.push Chain::BlockVariable.new(nil)
|
128
|
+
else
|
129
|
+
result.push Chain::BlockVariable.new("&#{block_variable_name_node.children[0].to_s}")
|
130
|
+
end
|
122
131
|
elsif n.type == :hash
|
123
132
|
result.push Chain::Hash.new('::Hash', hash_is_splatted?(n))
|
133
|
+
elsif n.type == :array
|
134
|
+
chained_children = n.children.map { |c| NodeChainer.chain(c) }
|
135
|
+
result.push Source::Chain::Array.new(chained_children)
|
124
136
|
else
|
125
137
|
lit = infer_literal_node_type(n)
|
126
|
-
|
127
|
-
# result.push Chain::Hash.new(lit, hash_is_splatted?(n))
|
128
|
-
# else
|
129
|
-
result.push (lit ? Chain::Literal.new(lit) : Chain::Link.new)
|
130
|
-
# end
|
138
|
+
result.push (lit ? Chain::Literal.new(lit) : Chain::Link.new)
|
131
139
|
end
|
132
140
|
result
|
133
141
|
end
|
@@ -48,7 +48,7 @@ module Solargraph
|
|
48
48
|
return '::Integer'
|
49
49
|
elsif node.type == :float
|
50
50
|
return '::Float'
|
51
|
-
elsif node.type == :sym
|
51
|
+
elsif node.type == :sym || node.type == :dsym
|
52
52
|
return '::Symbol'
|
53
53
|
elsif node.type == :regexp
|
54
54
|
return '::Regexp'
|
@@ -244,9 +244,11 @@ module Solargraph
|
|
244
244
|
node.children[1..-1].each do |cc|
|
245
245
|
if cc.nil?
|
246
246
|
result.push NIL_NODE
|
247
|
-
|
248
|
-
result.concat reduce_to_value_nodes(cc.children[1..-2]) unless cc.children.length < 1
|
247
|
+
elsif cc.type == :when
|
249
248
|
result.concat reduce_to_value_nodes([cc.children.last])
|
249
|
+
else
|
250
|
+
# else clause in case
|
251
|
+
result.concat reduce_to_value_nodes([cc])
|
250
252
|
end
|
251
253
|
end
|
252
254
|
else
|
@@ -6,25 +6,40 @@ module Solargraph
|
|
6
6
|
module NodeProcessors
|
7
7
|
class ArgsNode < Parser::NodeProcessor::Base
|
8
8
|
def process
|
9
|
-
node.
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
9
|
+
if node.type == :forward_args
|
10
|
+
forward
|
11
|
+
else
|
12
|
+
node.children.each do |u|
|
13
|
+
loc = get_node_location(u)
|
14
|
+
locals.push Solargraph::Pin::Parameter.new(
|
15
|
+
location: loc,
|
16
|
+
closure: region.closure,
|
17
|
+
comments: comments_for(node),
|
18
|
+
name: u.children[0].to_s,
|
19
|
+
assignment: u.children[1],
|
20
|
+
asgn_code: u.children[1] ? region.code_for(u.children[1]) : nil,
|
21
|
+
presence: region.closure.location.range,
|
22
|
+
decl: get_decl(u)
|
23
|
+
)
|
24
|
+
region.closure.parameters.push locals.last
|
25
|
+
end
|
22
26
|
end
|
23
27
|
process_children
|
24
28
|
end
|
25
29
|
|
26
30
|
private
|
27
31
|
|
32
|
+
def forward
|
33
|
+
loc = get_node_location(node)
|
34
|
+
locals.push Solargraph::Pin::Parameter.new(
|
35
|
+
location: loc,
|
36
|
+
closure: region.closure,
|
37
|
+
presence: region.closure.location.range,
|
38
|
+
decl: get_decl(node)
|
39
|
+
)
|
40
|
+
region.closure.parameters.push locals.last
|
41
|
+
end
|
42
|
+
|
28
43
|
def get_decl node
|
29
44
|
node.type
|
30
45
|
end
|
@@ -28,27 +28,28 @@ module Solargraph
|
|
28
28
|
end
|
29
29
|
|
30
30
|
module NodeProcessor
|
31
|
-
register :source,
|
32
|
-
register :begin,
|
33
|
-
register :kwbegin,
|
34
|
-
register :rescue,
|
35
|
-
register :resbody,
|
36
|
-
register :def,
|
37
|
-
register :defs,
|
38
|
-
register :send,
|
39
|
-
register :class,
|
40
|
-
register :module,
|
41
|
-
register :sclass,
|
42
|
-
register :ivasgn,
|
43
|
-
register :cvasgn,
|
44
|
-
register :lvasgn,
|
45
|
-
register :gvasgn,
|
46
|
-
register :casgn,
|
47
|
-
register :alias,
|
48
|
-
register :args,
|
49
|
-
register :
|
50
|
-
register :
|
51
|
-
register :
|
31
|
+
register :source, Legacy::NodeProcessors::BeginNode
|
32
|
+
register :begin, Legacy::NodeProcessors::BeginNode
|
33
|
+
register :kwbegin, Legacy::NodeProcessors::BeginNode
|
34
|
+
register :rescue, Legacy::NodeProcessors::BeginNode
|
35
|
+
register :resbody, Legacy::NodeProcessors::ResbodyNode
|
36
|
+
register :def, Legacy::NodeProcessors::DefNode
|
37
|
+
register :defs, Legacy::NodeProcessors::DefsNode
|
38
|
+
register :send, Legacy::NodeProcessors::SendNode
|
39
|
+
register :class, Legacy::NodeProcessors::NamespaceNode
|
40
|
+
register :module, Legacy::NodeProcessors::NamespaceNode
|
41
|
+
register :sclass, Legacy::NodeProcessors::SclassNode
|
42
|
+
register :ivasgn, Legacy::NodeProcessors::IvasgnNode
|
43
|
+
register :cvasgn, Legacy::NodeProcessors::CvasgnNode
|
44
|
+
register :lvasgn, Legacy::NodeProcessors::LvasgnNode
|
45
|
+
register :gvasgn, Legacy::NodeProcessors::GvasgnNode
|
46
|
+
register :casgn, Legacy::NodeProcessors::CasgnNode
|
47
|
+
register :alias, Legacy::NodeProcessors::AliasNode
|
48
|
+
register :args, Legacy::NodeProcessors::ArgsNode
|
49
|
+
register :forward_args, Legacy::NodeProcessors::ArgsNode
|
50
|
+
register :block, Legacy::NodeProcessors::BlockNode
|
51
|
+
register :or_asgn, Legacy::NodeProcessors::OrasgnNode
|
52
|
+
register :sym, Legacy::NodeProcessors::SymNode
|
52
53
|
end
|
53
54
|
end
|
54
55
|
end
|
@@ -23,7 +23,7 @@ module Solargraph
|
|
23
23
|
|
24
24
|
# @param source [Source]
|
25
25
|
# @param namespace [String]
|
26
|
-
# @param scope [Symbol]
|
26
|
+
# @param scope [Symbol, nil]
|
27
27
|
# @param visibility [Symbol]
|
28
28
|
def initialize source: Solargraph::Source.load_string(''), closure: nil,
|
29
29
|
scope: nil, visibility: :public, lvars: []
|
@@ -6,9 +6,8 @@ module Solargraph
|
|
6
6
|
module Rubyvm
|
7
7
|
module ClassMethods
|
8
8
|
# @param code [String]
|
9
|
-
# @param filename [String]
|
9
|
+
# @param filename [String, nil]
|
10
10
|
# @return [Array(Parser::AST::Node, Array<Parser::Source::Comment>)]
|
11
|
-
# @sg-ignore
|
12
11
|
def parse_with_comments code, filename = nil
|
13
12
|
node = RubyVM::AbstractSyntaxTree.parse(code).children[2]
|
14
13
|
node &&= RubyVM::AbstractSyntaxTree::NodeWrapper.from(node, code.lines)
|
@@ -22,7 +21,6 @@ module Solargraph
|
|
22
21
|
# @param filename [String, nil]
|
23
22
|
# @param line [Integer]
|
24
23
|
# @return [Parser::AST::Node]
|
25
|
-
# @sg-ignore
|
26
24
|
def parse code, filename = nil, line = 0
|
27
25
|
node = RubyVM::AbstractSyntaxTree.parse(code).children[2]
|
28
26
|
node and RubyVM::AbstractSyntaxTree::NodeWrapper.from(node, code.lines)
|
@@ -11,7 +11,7 @@ module Solargraph
|
|
11
11
|
Chain = Source::Chain
|
12
12
|
|
13
13
|
# @param node [Parser::AST::Node]
|
14
|
-
# @param filename [String]
|
14
|
+
# @param filename [String, nil]
|
15
15
|
def initialize node, filename = nil, in_block = false
|
16
16
|
@node = node
|
17
17
|
@filename = filename
|
@@ -26,7 +26,7 @@ module Solargraph
|
|
26
26
|
|
27
27
|
class << self
|
28
28
|
# @param node [Parser::AST::Node]
|
29
|
-
# @param filename [String]
|
29
|
+
# @param filename [String, nil]
|
30
30
|
# @return [Source::Chain]
|
31
31
|
def chain node, filename = nil, in_block = false
|
32
32
|
NodeChainer.new(node, filename, in_block).chain
|
@@ -104,6 +104,9 @@ module Solargraph
|
|
104
104
|
result.push Chain::BlockVariable.new("&#{n.children[1].children[0].to_s}")
|
105
105
|
elsif n.type == :HASH
|
106
106
|
result.push Chain::Hash.new('::Hash', hash_is_splatted?(n))
|
107
|
+
elsif n.type == :ARRAY
|
108
|
+
chained_children = n.children[0..-2].map { |c| NodeChainer.chain(c) }
|
109
|
+
result.push Source::Chain::Array.new(chained_children)
|
107
110
|
else
|
108
111
|
lit = infer_literal_node_type(n)
|
109
112
|
if lit
|