solargraph 0.50.0 → 0.53.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/.github/workflows/plugins.yml +40 -0
- data/.github/workflows/rspec.yml +4 -8
- data/.github/workflows/typecheck.yml +34 -0
- data/.yardopts +2 -2
- data/CHANGELOG.md +81 -3
- data/README.md +13 -16
- data/SPONSORS.md +2 -9
- data/lib/solargraph/api_map/cache.rb +60 -20
- data/lib/solargraph/api_map/store.rb +47 -11
- data/lib/solargraph/api_map.rb +161 -95
- data/lib/solargraph/bench.rb +2 -2
- data/lib/solargraph/cache.rb +30 -6
- data/lib/solargraph/complex_type/type_methods.rb +54 -9
- data/lib/solargraph/complex_type/unique_type.rb +154 -57
- data/lib/solargraph/complex_type.rb +91 -17
- data/lib/solargraph/convention.rb +0 -3
- data/lib/solargraph/converters/dd.rb +5 -0
- data/lib/solargraph/converters/dl.rb +3 -0
- data/lib/solargraph/converters/dt.rb +3 -0
- data/lib/solargraph/diagnostics/rubocop.rb +8 -7
- data/lib/solargraph/diagnostics/rubocop_helpers.rb +1 -0
- data/lib/solargraph/diagnostics/type_check.rb +1 -0
- data/lib/solargraph/diagnostics.rb +2 -2
- data/lib/solargraph/doc_map.rb +146 -0
- data/lib/solargraph/gem_pins.rb +64 -0
- data/lib/solargraph/language_server/host/cataloger.rb +1 -0
- data/lib/solargraph/language_server/host/diagnoser.rb +2 -2
- data/lib/solargraph/language_server/host/dispatch.rb +10 -4
- data/lib/solargraph/language_server/host/message_worker.rb +4 -0
- data/lib/solargraph/language_server/host/sources.rb +7 -4
- data/lib/solargraph/language_server/host.rb +26 -7
- data/lib/solargraph/language_server/message/completion_item/resolve.rb +3 -1
- data/lib/solargraph/language_server/message/extended/check_gem_version.rb +13 -1
- data/lib/solargraph/language_server/message/initialize.rb +11 -0
- data/lib/solargraph/language_server/message/initialized.rb +1 -0
- data/lib/solargraph/language_server/message/text_document/document_symbol.rb +4 -1
- data/lib/solargraph/language_server/message/text_document/formatting.rb +4 -4
- data/lib/solargraph/language_server/message/text_document/hover.rb +2 -0
- data/lib/solargraph/language_server/message/text_document/type_definition.rb +24 -0
- data/lib/solargraph/language_server/message/text_document.rb +1 -1
- data/lib/solargraph/language_server/message/workspace/did_change_configuration.rb +5 -0
- data/lib/solargraph/language_server/message.rb +1 -0
- data/lib/solargraph/language_server/transport/adapter.rb +16 -1
- data/lib/solargraph/language_server/transport/data_reader.rb +2 -0
- data/lib/solargraph/library.rb +86 -16
- data/lib/solargraph/location.rb +1 -0
- data/lib/solargraph/parser/comment_ripper.rb +4 -0
- data/lib/solargraph/parser/node_methods.rb +47 -7
- data/lib/solargraph/parser/node_processor/base.rb +9 -0
- data/lib/solargraph/parser/{legacy → parser_gem}/class_methods.rb +31 -5
- data/lib/solargraph/parser/{legacy → parser_gem}/flawed_builder.rb +3 -1
- data/lib/solargraph/parser/{legacy → parser_gem}/node_chainer.rb +57 -41
- data/lib/solargraph/parser/parser_gem/node_methods.rb +499 -0
- data/lib/solargraph/parser/{rubyvm → parser_gem}/node_processors/alias_node.rb +1 -1
- data/lib/solargraph/parser/parser_gem/node_processors/args_node.rb +53 -0
- data/lib/solargraph/parser/{rubyvm → parser_gem}/node_processors/begin_node.rb +1 -1
- data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/block_node.rb +3 -2
- data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/casgn_node.rb +2 -2
- data/lib/solargraph/parser/{rubyvm → parser_gem}/node_processors/cvasgn_node.rb +1 -1
- data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/def_node.rb +1 -1
- data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/defs_node.rb +2 -2
- data/lib/solargraph/parser/{rubyvm → parser_gem}/node_processors/gvasgn_node.rb +1 -1
- data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/ivasgn_node.rb +2 -2
- data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/lvasgn_node.rb +2 -2
- data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/namespace_node.rb +2 -2
- data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/orasgn_node.rb +1 -1
- data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/resbody_node.rb +3 -3
- data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/sclass_node.rb +1 -1
- data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/send_node.rb +2 -2
- data/lib/solargraph/parser/{rubyvm → parser_gem}/node_processors/sym_node.rb +1 -1
- data/lib/solargraph/parser/parser_gem/node_processors.rb +54 -0
- data/lib/solargraph/parser/parser_gem.rb +12 -0
- data/lib/solargraph/parser/region.rb +1 -1
- data/lib/solargraph/parser/snippet.rb +2 -0
- data/lib/solargraph/parser.rb +9 -10
- data/lib/solargraph/pin/base.rb +64 -9
- data/lib/solargraph/pin/base_variable.rb +6 -2
- data/lib/solargraph/pin/block.rb +19 -9
- data/lib/solargraph/pin/closure.rb +17 -2
- data/lib/solargraph/pin/common.rb +7 -3
- data/lib/solargraph/pin/conversions.rb +33 -3
- data/lib/solargraph/pin/delegated_method.rb +97 -0
- data/lib/solargraph/pin/documenting.rb +25 -34
- data/lib/solargraph/pin/instance_variable.rb +4 -0
- data/lib/solargraph/pin/local_variable.rb +13 -1
- data/lib/solargraph/pin/method.rb +182 -18
- data/lib/solargraph/pin/namespace.rb +18 -5
- data/lib/solargraph/pin/parameter.rb +44 -14
- data/lib/solargraph/pin/reference/override.rb +2 -2
- data/lib/solargraph/pin/reference.rb +8 -0
- data/lib/solargraph/pin/search.rb +4 -4
- data/lib/solargraph/pin/signature.rb +123 -3
- data/lib/solargraph/pin.rb +1 -1
- data/lib/solargraph/range.rb +4 -6
- data/lib/solargraph/rbs_map/conversions.rb +294 -50
- data/lib/solargraph/rbs_map/core_fills.rb +7 -24
- data/lib/solargraph/rbs_map/core_map.rb +3 -2
- data/lib/solargraph/rbs_map/core_signs.rb +2 -0
- data/lib/solargraph/rbs_map/stdlib_map.rb +2 -5
- data/lib/solargraph/rbs_map.rb +20 -11
- data/lib/solargraph/shell.rb +62 -59
- data/lib/solargraph/source/chain/array.rb +32 -0
- data/lib/solargraph/source/chain/block_symbol.rb +13 -0
- data/lib/solargraph/source/chain/call.rb +99 -46
- data/lib/solargraph/source/chain/constant.rb +15 -1
- data/lib/solargraph/source/chain/if.rb +23 -0
- data/lib/solargraph/source/chain/link.rb +8 -2
- data/lib/solargraph/source/chain/or.rb +1 -1
- data/lib/solargraph/source/chain/z_super.rb +3 -3
- data/lib/solargraph/source/chain.rb +29 -14
- data/lib/solargraph/source/change.rb +3 -0
- data/lib/solargraph/source/cursor.rb +2 -0
- data/lib/solargraph/source/source_chainer.rb +8 -5
- data/lib/solargraph/source.rb +18 -19
- data/lib/solargraph/source_map/clip.rb +25 -23
- data/lib/solargraph/source_map/mapper.rb +12 -1
- data/lib/solargraph/source_map.rb +30 -7
- data/lib/solargraph/type_checker/checks.rb +10 -2
- data/lib/solargraph/type_checker.rb +123 -45
- data/lib/solargraph/version.rb +1 -1
- data/lib/solargraph/workspace/config.rb +14 -11
- data/lib/solargraph/workspace.rb +3 -2
- data/lib/solargraph/yard_map/cache.rb +6 -0
- data/lib/solargraph/yard_map/helpers.rb +1 -1
- data/lib/solargraph/yard_map/mapper/to_method.rb +11 -1
- data/lib/solargraph/yard_map/mapper.rb +1 -1
- data/lib/solargraph/yard_map/to_method.rb +11 -4
- data/lib/solargraph/yard_map.rb +1 -284
- data/lib/solargraph/yard_tags.rb +20 -0
- data/lib/solargraph/yardoc.rb +52 -0
- data/lib/solargraph.rb +6 -4
- data/solargraph.gemspec +11 -5
- metadata +131 -75
- data/lib/solargraph/api_map/bundler_methods.rb +0 -22
- data/lib/solargraph/convention/rspec.rb +0 -30
- data/lib/solargraph/documentor.rb +0 -76
- data/lib/solargraph/parser/legacy/node_methods.rb +0 -325
- data/lib/solargraph/parser/legacy/node_processors/alias_node.rb +0 -23
- data/lib/solargraph/parser/legacy/node_processors/args_node.rb +0 -35
- data/lib/solargraph/parser/legacy/node_processors/begin_node.rb +0 -15
- data/lib/solargraph/parser/legacy/node_processors/cvasgn_node.rb +0 -23
- data/lib/solargraph/parser/legacy/node_processors/gvasgn_node.rb +0 -23
- data/lib/solargraph/parser/legacy/node_processors/sym_node.rb +0 -18
- data/lib/solargraph/parser/legacy/node_processors.rb +0 -54
- data/lib/solargraph/parser/legacy.rb +0 -12
- data/lib/solargraph/parser/rubyvm/class_methods.rb +0 -149
- data/lib/solargraph/parser/rubyvm/node_chainer.rb +0 -160
- data/lib/solargraph/parser/rubyvm/node_methods.rb +0 -315
- data/lib/solargraph/parser/rubyvm/node_processors/args_node.rb +0 -85
- data/lib/solargraph/parser/rubyvm/node_processors/block_node.rb +0 -42
- data/lib/solargraph/parser/rubyvm/node_processors/casgn_node.rb +0 -33
- data/lib/solargraph/parser/rubyvm/node_processors/def_node.rb +0 -75
- data/lib/solargraph/parser/rubyvm/node_processors/defs_node.rb +0 -68
- data/lib/solargraph/parser/rubyvm/node_processors/ivasgn_node.rb +0 -38
- data/lib/solargraph/parser/rubyvm/node_processors/kw_arg_node.rb +0 -39
- data/lib/solargraph/parser/rubyvm/node_processors/lit_node.rb +0 -20
- data/lib/solargraph/parser/rubyvm/node_processors/lvasgn_node.rb +0 -27
- data/lib/solargraph/parser/rubyvm/node_processors/namespace_node.rb +0 -39
- data/lib/solargraph/parser/rubyvm/node_processors/opt_arg_node.rb +0 -26
- data/lib/solargraph/parser/rubyvm/node_processors/orasgn_node.rb +0 -15
- data/lib/solargraph/parser/rubyvm/node_processors/resbody_node.rb +0 -45
- data/lib/solargraph/parser/rubyvm/node_processors/sclass_node.rb +0 -32
- data/lib/solargraph/parser/rubyvm/node_processors/scope_node.rb +0 -15
- data/lib/solargraph/parser/rubyvm/node_processors/send_node.rb +0 -279
- data/lib/solargraph/parser/rubyvm/node_processors.rb +0 -63
- data/lib/solargraph/parser/rubyvm/node_wrapper.rb +0 -47
- data/lib/solargraph/parser/rubyvm.rb +0 -40
- data/lib/yard-solargraph.rb +0 -33
|
@@ -1,12 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'parser/current'
|
|
4
|
+
require 'parser/source/buffer'
|
|
2
5
|
|
|
3
6
|
module Solargraph
|
|
4
7
|
module Parser
|
|
5
|
-
module
|
|
8
|
+
module ParserGem
|
|
6
9
|
module ClassMethods
|
|
7
10
|
# @param code [String]
|
|
8
|
-
# @param filename [String]
|
|
9
|
-
# @return [Array(Parser::AST::Node,
|
|
11
|
+
# @param filename [String, nil]
|
|
12
|
+
# @return [Array(Parser::AST::Node, Hash{Integer => String})]
|
|
10
13
|
def parse_with_comments code, filename = nil
|
|
11
14
|
buffer = ::Parser::Source::Buffer.new(filename, 0)
|
|
12
15
|
buffer.source = code
|
|
@@ -29,7 +32,7 @@ module Solargraph
|
|
|
29
32
|
raise Parser::SyntaxError, e.message
|
|
30
33
|
end
|
|
31
34
|
|
|
32
|
-
# @return [Parser::Base]
|
|
35
|
+
# @return [::Parser::Base]
|
|
33
36
|
def parser
|
|
34
37
|
# @todo Consider setting an instance variable. We might not need to
|
|
35
38
|
# recreate the parser every time we use it.
|
|
@@ -39,19 +42,30 @@ module Solargraph
|
|
|
39
42
|
parser
|
|
40
43
|
end
|
|
41
44
|
|
|
45
|
+
# @param source [Source]
|
|
46
|
+
# @return [Array(Array<Pin::Base>, Array<Pin::Base>)]
|
|
42
47
|
def map source
|
|
43
48
|
NodeProcessor.process(source.node, Region.new(source: source))
|
|
44
49
|
end
|
|
45
50
|
|
|
51
|
+
# @param node [Parser::AST::Node]
|
|
52
|
+
# @return [Array<Parser::AST::Node>]
|
|
46
53
|
def returns_from node
|
|
47
54
|
NodeMethods.returns_from(node)
|
|
48
55
|
end
|
|
49
56
|
|
|
57
|
+
# @param source [Source]
|
|
58
|
+
# @param name [String]
|
|
59
|
+
# @return [Array<Location>]
|
|
50
60
|
def references source, name
|
|
51
61
|
if name.end_with?("=")
|
|
52
62
|
reg = /#{Regexp.escape name[0..-2]}\s*=/
|
|
63
|
+
# @param code [String]
|
|
64
|
+
# @param offset [Integer]
|
|
53
65
|
extract_offset = ->(code, offset) { reg.match(code, offset).offset(0) }
|
|
54
66
|
else
|
|
67
|
+
# @param code [String]
|
|
68
|
+
# @param offset [Integer]
|
|
55
69
|
extract_offset = ->(code, offset) { [soff = code.index(name, offset), soff + name.length] }
|
|
56
70
|
end
|
|
57
71
|
inner_node_references(name, source.node).map do |n|
|
|
@@ -80,36 +94,48 @@ module Solargraph
|
|
|
80
94
|
result
|
|
81
95
|
end
|
|
82
96
|
|
|
97
|
+
# @return [Source::Chain]
|
|
83
98
|
def chain *args
|
|
84
99
|
NodeChainer.chain *args
|
|
85
100
|
end
|
|
86
101
|
|
|
102
|
+
# @return [Source::Chain]
|
|
87
103
|
def chain_string *args
|
|
88
104
|
NodeChainer.load_string *args
|
|
89
105
|
end
|
|
90
106
|
|
|
107
|
+
# @return [Array(Array<Pin::Base>, Array<Pin::Base>)]
|
|
91
108
|
def process_node *args
|
|
92
109
|
Solargraph::Parser::NodeProcessor.process *args
|
|
93
110
|
end
|
|
94
111
|
|
|
112
|
+
# @param node [Parser::AST::Node]
|
|
113
|
+
# @return [String, nil]
|
|
95
114
|
def infer_literal_node_type node
|
|
96
115
|
NodeMethods.infer_literal_node_type node
|
|
97
116
|
end
|
|
98
117
|
|
|
118
|
+
# @return [void]
|
|
99
119
|
def version
|
|
100
120
|
parser.version
|
|
101
121
|
end
|
|
102
122
|
|
|
123
|
+
# @param node [BasicObject]
|
|
124
|
+
# @return [Boolean]
|
|
103
125
|
def is_ast_node? node
|
|
104
126
|
node.is_a?(::Parser::AST::Node)
|
|
105
127
|
end
|
|
106
128
|
|
|
129
|
+
# @param node [Parser::AST::Node]
|
|
130
|
+
# @return [Range]
|
|
107
131
|
def node_range node
|
|
108
132
|
st = Position.new(node.loc.line, node.loc.column)
|
|
109
133
|
en = Position.new(node.loc.last_line, node.loc.last_column)
|
|
110
134
|
Range.new(st, en)
|
|
111
135
|
end
|
|
112
136
|
|
|
137
|
+
# @param node [Parser::AST::Node]
|
|
138
|
+
# @return [Array<Range>]
|
|
113
139
|
def string_ranges node
|
|
114
140
|
return [] unless is_ast_node?(node)
|
|
115
141
|
result = []
|
|
@@ -128,7 +154,7 @@ module Solargraph
|
|
|
128
154
|
end
|
|
129
155
|
end
|
|
130
156
|
result
|
|
131
|
-
end
|
|
157
|
+
end
|
|
132
158
|
end
|
|
133
159
|
end
|
|
134
160
|
end
|
|
@@ -2,11 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
module Solargraph
|
|
4
4
|
module Parser
|
|
5
|
-
module
|
|
5
|
+
module ParserGem
|
|
6
6
|
# A custom builder for source parsers that ignores character encoding
|
|
7
7
|
# issues in literal strings.
|
|
8
8
|
#
|
|
9
9
|
class FlawedBuilder < ::Parser::Builders::Default
|
|
10
|
+
# @param token [::Parser::AST::Node]
|
|
11
|
+
# @return [String]
|
|
10
12
|
def string_value(token)
|
|
11
13
|
value(token)
|
|
12
14
|
end
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
module Solargraph
|
|
4
4
|
module Parser
|
|
5
|
-
module
|
|
5
|
+
module ParserGem
|
|
6
6
|
# A factory for generating chains from nodes.
|
|
7
7
|
#
|
|
8
8
|
class NodeChainer
|
|
@@ -10,11 +10,12 @@ module Solargraph
|
|
|
10
10
|
Chain = Source::Chain
|
|
11
11
|
|
|
12
12
|
# @param node [Parser::AST::Node]
|
|
13
|
-
# @param filename [String]
|
|
14
|
-
|
|
13
|
+
# @param filename [String, nil]
|
|
14
|
+
# @param parent [Parser::AST::Node, nil]
|
|
15
|
+
def initialize node, filename = nil, parent = nil
|
|
15
16
|
@node = node
|
|
16
17
|
@filename = filename
|
|
17
|
-
@
|
|
18
|
+
@parent = parent
|
|
18
19
|
end
|
|
19
20
|
|
|
20
21
|
# @return [Source::Chain]
|
|
@@ -25,10 +26,11 @@ module Solargraph
|
|
|
25
26
|
|
|
26
27
|
class << self
|
|
27
28
|
# @param node [Parser::AST::Node]
|
|
28
|
-
# @param filename [String]
|
|
29
|
+
# @param filename [String, nil]
|
|
30
|
+
# @param parent [Parser::AST::Node, nil]
|
|
29
31
|
# @return [Source::Chain]
|
|
30
|
-
def chain node, filename = nil,
|
|
31
|
-
NodeChainer.new(node, filename,
|
|
32
|
+
def chain node, filename = nil, parent = nil
|
|
33
|
+
NodeChainer.new(node, filename, parent).chain
|
|
32
34
|
end
|
|
33
35
|
|
|
34
36
|
# @param code [String]
|
|
@@ -47,54 +49,43 @@ module Solargraph
|
|
|
47
49
|
# @return [Array<Chain::Link>]
|
|
48
50
|
def generate_links n
|
|
49
51
|
return [] unless n.is_a?(::Parser::AST::Node)
|
|
50
|
-
return generate_links(n.children[0]) if n.type == :begin
|
|
51
52
|
return generate_links(n.children[0]) if n.type == :splat
|
|
53
|
+
# @type [Array<Chain::Link>]
|
|
52
54
|
result = []
|
|
53
55
|
if n.type == :block
|
|
54
|
-
@
|
|
55
|
-
result.concat generate_links(n.children[0])
|
|
56
|
-
@in_block -= 1
|
|
56
|
+
result.concat NodeChainer.chain(n.children[0], @filename, n).links
|
|
57
57
|
elsif n.type == :send
|
|
58
58
|
if n.children[0].is_a?(::Parser::AST::Node)
|
|
59
59
|
result.concat generate_links(n.children[0])
|
|
60
|
-
|
|
61
|
-
n.children[2..-1].each do |c|
|
|
62
|
-
args.push NodeChainer.chain(c)
|
|
63
|
-
end
|
|
64
|
-
result.push Chain::Call.new(n.children[1].to_s, args, @in_block > 0 || block_passed?(n))
|
|
60
|
+
result.push Chain::Call.new(n.children[1].to_s, node_args(n), passed_block(n))
|
|
65
61
|
elsif n.children[0].nil?
|
|
66
62
|
args = []
|
|
67
63
|
n.children[2..-1].each do |c|
|
|
68
|
-
args.push NodeChainer.chain(c)
|
|
64
|
+
args.push NodeChainer.chain(c, @filename, n)
|
|
69
65
|
end
|
|
70
|
-
result.push Chain::Call.new(n.children[1].to_s,
|
|
66
|
+
result.push Chain::Call.new(n.children[1].to_s, node_args(n), passed_block(n))
|
|
71
67
|
else
|
|
72
68
|
raise "No idea what to do with #{n}"
|
|
73
69
|
end
|
|
74
70
|
elsif n.type == :csend
|
|
75
71
|
if n.children[0].is_a?(::Parser::AST::Node)
|
|
76
72
|
result.concat generate_links(n.children[0])
|
|
77
|
-
|
|
78
|
-
n.children[2..-1].each do |c|
|
|
79
|
-
args.push NodeChainer.chain(c)
|
|
80
|
-
end
|
|
81
|
-
result.push Chain::QCall.new(n.children[1].to_s, args, @in_block > 0 || block_passed?(n))
|
|
73
|
+
result.push Chain::QCall.new(n.children[1].to_s, node_args(n))
|
|
82
74
|
elsif n.children[0].nil?
|
|
83
|
-
|
|
84
|
-
n.children[2..-1].each do |c|
|
|
85
|
-
args.push NodeChainer.chain(c)
|
|
86
|
-
end
|
|
87
|
-
result.push Chain::QCall.new(n.children[1].to_s, args, @in_block > 0 || block_passed?(n))
|
|
75
|
+
result.push Chain::QCall.new(n.children[1].to_s, node_args(n))
|
|
88
76
|
else
|
|
89
77
|
raise "No idea what to do with #{n}"
|
|
90
78
|
end
|
|
91
79
|
elsif n.type == :self
|
|
92
80
|
result.push Chain::Head.new('self')
|
|
93
81
|
elsif n.type == :zsuper
|
|
94
|
-
result.push Chain::ZSuper.new('super'
|
|
82
|
+
result.push Chain::ZSuper.new('super')
|
|
95
83
|
elsif n.type == :super
|
|
96
|
-
args = n.children.map { |c| NodeChainer.chain(c) }
|
|
97
|
-
result.push Chain::Call.new('super', args
|
|
84
|
+
args = n.children.map { |c| NodeChainer.chain(c, @filename, n) }
|
|
85
|
+
result.push Chain::Call.new('super', args)
|
|
86
|
+
elsif n.type == :yield
|
|
87
|
+
args = n.children.map { |c| NodeChainer.chain(c, @filename, n) }
|
|
88
|
+
result.push Chain::Call.new('yield', args)
|
|
98
89
|
elsif n.type == :const
|
|
99
90
|
const = unpack_name(n)
|
|
100
91
|
result.push Chain::Constant.new(const)
|
|
@@ -114,24 +105,37 @@ module Solargraph
|
|
|
114
105
|
elsif n.type == :and
|
|
115
106
|
result.concat generate_links(n.children.last)
|
|
116
107
|
elsif n.type == :or
|
|
117
|
-
result.push Chain::Or.new([NodeChainer.chain(n.children[0], @filename), NodeChainer.chain(n.children[1], @filename)])
|
|
108
|
+
result.push Chain::Or.new([NodeChainer.chain(n.children[0], @filename), NodeChainer.chain(n.children[1], @filename, n)])
|
|
109
|
+
elsif n.type == :if
|
|
110
|
+
result.push Chain::If.new([NodeChainer.chain(n.children[1], @filename), NodeChainer.chain(n.children[2], @filename, n)])
|
|
118
111
|
elsif [:begin, :kwbegin].include?(n.type)
|
|
119
|
-
result.concat generate_links(n.children
|
|
112
|
+
result.concat generate_links(n.children.last)
|
|
120
113
|
elsif n.type == :block_pass
|
|
121
|
-
|
|
114
|
+
block_variable_name_node = n.children[0]
|
|
115
|
+
if block_variable_name_node.nil?
|
|
116
|
+
# anonymous block forwarding (e.g., "&")
|
|
117
|
+
# added in Ruby 3.1 - https://bugs.ruby-lang.org/issues/11256
|
|
118
|
+
result.push Chain::BlockVariable.new(nil)
|
|
119
|
+
else
|
|
120
|
+
if block_variable_name_node.type == :sym
|
|
121
|
+
result.push Chain::BlockSymbol.new("#{block_variable_name_node.children[0].to_s}")
|
|
122
|
+
else
|
|
123
|
+
result.push Chain::BlockVariable.new("&#{block_variable_name_node.children[0].to_s}")
|
|
124
|
+
end
|
|
125
|
+
end
|
|
122
126
|
elsif n.type == :hash
|
|
123
127
|
result.push Chain::Hash.new('::Hash', hash_is_splatted?(n))
|
|
128
|
+
elsif n.type == :array
|
|
129
|
+
chained_children = n.children.map { |c| NodeChainer.chain(c) }
|
|
130
|
+
result.push Source::Chain::Array.new(chained_children)
|
|
124
131
|
else
|
|
125
132
|
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
|
|
133
|
+
result.push (lit ? Chain::Literal.new(lit) : Chain::Link.new)
|
|
131
134
|
end
|
|
132
135
|
result
|
|
133
136
|
end
|
|
134
137
|
|
|
138
|
+
# @param node [Parser::AST::Node]
|
|
135
139
|
def hash_is_splatted? node
|
|
136
140
|
return false unless Parser.is_ast_node?(node) && node.type == :hash
|
|
137
141
|
return false unless Parser.is_ast_node?(node.children.last) && node.children.last.type == :kwsplat
|
|
@@ -139,8 +143,20 @@ module Solargraph
|
|
|
139
143
|
true
|
|
140
144
|
end
|
|
141
145
|
|
|
142
|
-
|
|
143
|
-
|
|
146
|
+
# @param node [Parser::AST::Node]
|
|
147
|
+
# @return [Source::Chain, nil]
|
|
148
|
+
def passed_block node
|
|
149
|
+
return unless node == @node && @parent&.type == :block
|
|
150
|
+
|
|
151
|
+
NodeChainer.chain(@parent.children[2], @filename)
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
# @param node [Parser::AST::Node]
|
|
155
|
+
# @return [Array<Source::Chain>]
|
|
156
|
+
def node_args node
|
|
157
|
+
node.children[2..-1].map do |child|
|
|
158
|
+
NodeChainer.chain(child, @filename, node)
|
|
159
|
+
end
|
|
144
160
|
end
|
|
145
161
|
end
|
|
146
162
|
end
|