solargraph 0.52.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 +1 -3
- data/.github/workflows/typecheck.yml +34 -0
- data/CHANGELOG.md +30 -0
- data/README.md +13 -16
- data/SPONSORS.md +1 -7
- data/lib/solargraph/api_map/cache.rb +59 -21
- data/lib/solargraph/api_map/store.rb +45 -9
- data/lib/solargraph/api_map.rb +152 -93
- data/lib/solargraph/bench.rb +2 -2
- data/lib/solargraph/cache.rb +29 -5
- data/lib/solargraph/complex_type/type_methods.rb +53 -8
- data/lib/solargraph/complex_type/unique_type.rb +149 -59
- data/lib/solargraph/complex_type.rb +62 -9
- data/lib/solargraph/convention.rb +0 -1
- 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 +15 -6
- 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 +5 -2
- data/lib/solargraph/language_server/message/text_document/hover.rb +2 -0
- data/lib/solargraph/language_server/message/text_document.rb +0 -1
- data/lib/solargraph/language_server/message/workspace/did_change_configuration.rb +5 -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 +58 -11
- data/lib/solargraph/location.rb +1 -0
- data/lib/solargraph/parser/comment_ripper.rb +3 -0
- data/lib/solargraph/parser/node_methods.rb +47 -8
- data/lib/solargraph/parser/node_processor/base.rb +9 -0
- data/lib/solargraph/parser/{legacy → parser_gem}/class_methods.rb +29 -3
- data/lib/solargraph/parser/{legacy → parser_gem}/flawed_builder.rb +3 -1
- data/lib/solargraph/parser/{legacy → parser_gem}/node_chainer.rb +42 -34
- data/lib/solargraph/parser/{legacy → parser_gem}/node_methods.rb +201 -29
- data/lib/solargraph/parser/{rubyvm → parser_gem}/node_processors/alias_node.rb +1 -1
- data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/args_node.rb +4 -1
- 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/{legacy → 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/{legacy → 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/snippet.rb +2 -0
- data/lib/solargraph/parser.rb +8 -11
- data/lib/solargraph/pin/base.rb +63 -8
- data/lib/solargraph/pin/base_variable.rb +6 -2
- data/lib/solargraph/pin/block.rb +11 -6
- 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/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 +109 -15
- data/lib/solargraph/pin/namespace.rb +16 -10
- data/lib/solargraph/pin/parameter.rb +41 -10
- data/lib/solargraph/pin/reference/override.rb +2 -2
- data/lib/solargraph/pin/reference.rb +8 -0
- data/lib/solargraph/pin/search.rb +3 -3
- data/lib/solargraph/pin/signature.rb +114 -2
- data/lib/solargraph/pin.rb +0 -1
- data/lib/solargraph/range.rb +2 -2
- data/lib/solargraph/rbs_map/conversions.rb +212 -25
- data/lib/solargraph/rbs_map/core_fills.rb +4 -26
- data/lib/solargraph/rbs_map/core_map.rb +1 -0
- data/lib/solargraph/rbs_map/core_signs.rb +2 -0
- data/lib/solargraph/rbs_map/stdlib_map.rb +2 -8
- data/lib/solargraph/rbs_map.rb +19 -9
- data/lib/solargraph/shell.rb +62 -59
- data/lib/solargraph/source/chain/array.rb +4 -1
- data/lib/solargraph/source/chain/block_symbol.rb +13 -0
- data/lib/solargraph/source/chain/call.rb +95 -26
- 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 +7 -1
- data/lib/solargraph/source/chain/or.rb +1 -1
- data/lib/solargraph/source/chain/z_super.rb +2 -2
- data/lib/solargraph/source/chain.rb +20 -4
- data/lib/solargraph/source/change.rb +3 -0
- data/lib/solargraph/source/cursor.rb +2 -0
- data/lib/solargraph/source/source_chainer.rb +6 -5
- data/lib/solargraph/source.rb +15 -16
- data/lib/solargraph/source_map/clip.rb +11 -7
- data/lib/solargraph/source_map/mapper.rb +10 -0
- data/lib/solargraph/source_map.rb +13 -3
- data/lib/solargraph/type_checker/checks.rb +10 -2
- data/lib/solargraph/type_checker.rb +74 -19
- data/lib/solargraph/version.rb +1 -1
- data/lib/solargraph/workspace/config.rb +8 -6
- data/lib/solargraph/workspace.rb +1 -1
- 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/to_method.rb +11 -4
- data/lib/solargraph/yard_map.rb +0 -292
- data/lib/solargraph/yardoc.rb +52 -0
- data/lib/solargraph.rb +4 -1
- data/solargraph.gemspec +2 -2
- metadata +35 -57
- data/lib/solargraph/api_map/bundler_methods.rb +0 -22
- data/lib/solargraph/documentor.rb +0 -76
- data/lib/solargraph/parser/legacy/node_processors/alias_node.rb +0 -23
- data/lib/solargraph/parser/legacy/node_processors/begin_node.rb +0 -15
- data/lib/solargraph/parser/legacy/node_processors/sym_node.rb +0 -18
- data/lib/solargraph/parser/legacy/node_processors.rb +0 -55
- data/lib/solargraph/parser/legacy.rb +0 -12
- data/lib/solargraph/parser/rubyvm/class_methods.rb +0 -151
- data/lib/solargraph/parser/rubyvm/node_chainer.rb +0 -163
- data/lib/solargraph/parser/rubyvm/node_methods.rb +0 -317
- 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/cvasgn_node.rb +0 -23
- 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/gvasgn_node.rb +0 -23
- 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 -51
- 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 -64
- data/lib/solargraph/parser/rubyvm/node_wrapper.rb +0 -47
- data/lib/solargraph/parser/rubyvm.rb +0 -40
@@ -1,23 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Solargraph
|
4
|
-
module Parser
|
5
|
-
module Legacy
|
6
|
-
module NodeProcessors
|
7
|
-
class AliasNode < Parser::NodeProcessor::Base
|
8
|
-
def process
|
9
|
-
loc = get_node_location(node)
|
10
|
-
pins.push Solargraph::Pin::MethodAlias.new(
|
11
|
-
location: loc,
|
12
|
-
closure: region.closure,
|
13
|
-
name: node.children[0].children[0].to_s,
|
14
|
-
original: node.children[1].children[0].to_s,
|
15
|
-
scope: region.scope || :instance
|
16
|
-
)
|
17
|
-
process_children
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Solargraph
|
4
|
-
module Parser
|
5
|
-
module Legacy
|
6
|
-
module NodeProcessors
|
7
|
-
class SymNode < Parser::NodeProcessor::Base
|
8
|
-
def process
|
9
|
-
pins.push Solargraph::Pin::Symbol.new(
|
10
|
-
get_node_location(node),
|
11
|
-
":#{node.children[0]}"
|
12
|
-
)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
@@ -1,55 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'solargraph/parser/node_processor'
|
4
|
-
|
5
|
-
module Solargraph
|
6
|
-
module Parser
|
7
|
-
module Legacy
|
8
|
-
module NodeProcessors
|
9
|
-
autoload :BeginNode, 'solargraph/parser/legacy/node_processors/begin_node'
|
10
|
-
autoload :DefNode, 'solargraph/parser/legacy/node_processors/def_node'
|
11
|
-
autoload :DefsNode, 'solargraph/parser/legacy/node_processors/defs_node'
|
12
|
-
autoload :SendNode, 'solargraph/parser/legacy/node_processors/send_node'
|
13
|
-
autoload :NamespaceNode, 'solargraph/parser/legacy/node_processors/namespace_node'
|
14
|
-
autoload :SclassNode, 'solargraph/parser/legacy/node_processors/sclass_node'
|
15
|
-
autoload :ModuleNode, 'solargraph/parser/legacy/node_processors/module_node'
|
16
|
-
autoload :IvasgnNode, 'solargraph/parser/legacy/node_processors/ivasgn_node'
|
17
|
-
autoload :CvasgnNode, 'solargraph/parser/legacy/node_processors/cvasgn_node'
|
18
|
-
autoload :LvasgnNode, 'solargraph/parser/legacy/node_processors/lvasgn_node'
|
19
|
-
autoload :GvasgnNode, 'solargraph/parser/legacy/node_processors/gvasgn_node'
|
20
|
-
autoload :CasgnNode, 'solargraph/parser/legacy/node_processors/casgn_node'
|
21
|
-
autoload :AliasNode, 'solargraph/parser/legacy/node_processors/alias_node'
|
22
|
-
autoload :ArgsNode, 'solargraph/parser/legacy/node_processors/args_node'
|
23
|
-
autoload :BlockNode, 'solargraph/parser/legacy/node_processors/block_node'
|
24
|
-
autoload :OrasgnNode, 'solargraph/parser/legacy/node_processors/orasgn_node'
|
25
|
-
autoload :SymNode, 'solargraph/parser/legacy/node_processors/sym_node'
|
26
|
-
autoload :ResbodyNode, 'solargraph/parser/legacy/node_processors/resbody_node'
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
module NodeProcessor
|
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
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
@@ -1,12 +0,0 @@
|
|
1
|
-
module Solargraph
|
2
|
-
module Parser
|
3
|
-
module Legacy
|
4
|
-
autoload :FlawedBuilder, 'solargraph/parser/legacy/flawed_builder'
|
5
|
-
autoload :ClassMethods, 'solargraph/parser/legacy/class_methods'
|
6
|
-
autoload :NodeMethods, 'solargraph/parser/legacy/node_methods'
|
7
|
-
autoload :NodeChainer, 'solargraph/parser/legacy/node_chainer'
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
require 'solargraph/parser/legacy/node_processors'
|
@@ -1,151 +0,0 @@
|
|
1
|
-
require 'solargraph/parser/rubyvm/node_processors'
|
2
|
-
require 'solargraph/parser/rubyvm/node_wrapper'
|
3
|
-
|
4
|
-
module Solargraph
|
5
|
-
module Parser
|
6
|
-
module Rubyvm
|
7
|
-
module ClassMethods
|
8
|
-
# @param code [String]
|
9
|
-
# @param filename [String, nil]
|
10
|
-
# @return [Array(Parser::AST::Node, Array<Parser::Source::Comment>)]
|
11
|
-
def parse_with_comments code, filename = nil
|
12
|
-
node = RubyVM::AbstractSyntaxTree.parse(code).children[2]
|
13
|
-
node &&= RubyVM::AbstractSyntaxTree::NodeWrapper.from(node, code.lines)
|
14
|
-
comments = CommentRipper.new(code).parse
|
15
|
-
[node, comments]
|
16
|
-
rescue ::SyntaxError => e
|
17
|
-
raise Parser::SyntaxError, e.message
|
18
|
-
end
|
19
|
-
|
20
|
-
# @param code [String]
|
21
|
-
# @param filename [String, nil]
|
22
|
-
# @param line [Integer]
|
23
|
-
# @return [Parser::AST::Node]
|
24
|
-
def parse code, filename = nil, line = 0
|
25
|
-
node = RubyVM::AbstractSyntaxTree.parse(code).children[2]
|
26
|
-
node and RubyVM::AbstractSyntaxTree::NodeWrapper.from(node, code.lines)
|
27
|
-
rescue ::SyntaxError => e
|
28
|
-
raise Parser::SyntaxError, e.message
|
29
|
-
end
|
30
|
-
|
31
|
-
def map source
|
32
|
-
NodeProcessor.process(source.node, Region.new(source: source))
|
33
|
-
end
|
34
|
-
|
35
|
-
def references source, name
|
36
|
-
if name.end_with?("=")
|
37
|
-
reg = /#{Regexp.escape name[0..-2]}\s*=/
|
38
|
-
extract_offset = ->(code, offset) { reg.match(code, offset).offset(0) }
|
39
|
-
else
|
40
|
-
extract_offset = ->(code, offset) { [soff = code.index(name, offset), soff + name.length] }
|
41
|
-
end
|
42
|
-
inner_node_references(name, source.node).map do |n|
|
43
|
-
rng = Range.from_node(n)
|
44
|
-
offset = Position.to_offset(source.code, rng.start)
|
45
|
-
soff, eoff = extract_offset[source.code, offset]
|
46
|
-
Location.new(
|
47
|
-
source.filename,
|
48
|
-
Range.new(
|
49
|
-
Position.from_offset(source.code, soff),
|
50
|
-
Position.from_offset(source.code, eoff)
|
51
|
-
)
|
52
|
-
)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
# @param name [String]
|
57
|
-
# @param top [AST::Node]
|
58
|
-
# @return [Array<AST::Node>]
|
59
|
-
def inner_node_references name, top
|
60
|
-
result = []
|
61
|
-
if Parser.rubyvm?
|
62
|
-
if Parser.is_ast_node?(top)
|
63
|
-
result.push top if match_rubyvm_node_to_ref(top, name)
|
64
|
-
top.children.each { |c| result.concat inner_node_references(name, c) }
|
65
|
-
end
|
66
|
-
else
|
67
|
-
if Parser.is_ast_node?(top) && top.to_s.include?(":#{name}")
|
68
|
-
result.push top if top.children.any? { |c| c.to_s == name }
|
69
|
-
top.children.each { |c| result.concat inner_node_references(name, c) }
|
70
|
-
end
|
71
|
-
end
|
72
|
-
result
|
73
|
-
end
|
74
|
-
|
75
|
-
def match_rubyvm_node_to_ref(top, name)
|
76
|
-
top.children.select { |c| c.is_a?(Symbol) }.any? { |c| c.to_s == name } ||
|
77
|
-
top.children.select { |c| c.is_a?(Array) }.any? { |c| c.include?(name.to_sym) }
|
78
|
-
end
|
79
|
-
|
80
|
-
def chain *args
|
81
|
-
NodeChainer.chain *args
|
82
|
-
end
|
83
|
-
|
84
|
-
def chain_string *args
|
85
|
-
NodeChainer.load_string *args
|
86
|
-
end
|
87
|
-
|
88
|
-
def process_node *args
|
89
|
-
Solargraph::Parser::NodeProcessor.process *args
|
90
|
-
end
|
91
|
-
|
92
|
-
def infer_literal_node_type node
|
93
|
-
NodeMethods.infer_literal_node_type node
|
94
|
-
end
|
95
|
-
|
96
|
-
def version
|
97
|
-
Ruby::VERSION
|
98
|
-
end
|
99
|
-
|
100
|
-
def is_ast_node? node
|
101
|
-
if Parser.rubyvm?
|
102
|
-
node.is_a?(RubyVM::AbstractSyntaxTree::Node)
|
103
|
-
else
|
104
|
-
node.is_a?(::Parser::AST::Node)
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
def node_range node
|
109
|
-
if node.nil?
|
110
|
-
nil
|
111
|
-
else
|
112
|
-
st = Position.new(node.first_lineno - 1, node.first_column)
|
113
|
-
en = Position.new(node.last_lineno - 1, node.last_column)
|
114
|
-
Range.new(st, en)
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
def recipient_node tree
|
119
|
-
tree.each_with_index do |node, idx|
|
120
|
-
return tree[idx + 1] if [:ARRAY, :ZARRAY, :LIST].include?(node.type) && tree[idx + 1] && [:FCALL, :VCALL, :CALL].include?(tree[idx + 1].type)
|
121
|
-
end
|
122
|
-
nil
|
123
|
-
end
|
124
|
-
|
125
|
-
def string_ranges node
|
126
|
-
return [] unless is_ast_node?(node)
|
127
|
-
result = []
|
128
|
-
if node.type == :STR
|
129
|
-
result.push Range.from_node(node)
|
130
|
-
elsif node.type == :DSTR
|
131
|
-
here = Range.from_node(node)
|
132
|
-
there = Range.from_node(node.children[1])
|
133
|
-
result.push Range.new(here.start, there&.start || here.ending)
|
134
|
-
end
|
135
|
-
node.children.each do |child|
|
136
|
-
result.concat string_ranges(child)
|
137
|
-
end
|
138
|
-
if node.type == :DSTR && node.children.last.nil?
|
139
|
-
last = node.children[-2]
|
140
|
-
unless last.nil?
|
141
|
-
rng = Range.from_node(last)
|
142
|
-
pos = Position.new(rng.ending.line, rng.ending.column - 1)
|
143
|
-
result.push Range.new(pos, pos)
|
144
|
-
end
|
145
|
-
end
|
146
|
-
result
|
147
|
-
end
|
148
|
-
end
|
149
|
-
end
|
150
|
-
end
|
151
|
-
end
|
@@ -1,163 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Solargraph
|
4
|
-
module Parser
|
5
|
-
module Rubyvm
|
6
|
-
# A factory for generating chains from nodes.
|
7
|
-
#
|
8
|
-
class NodeChainer
|
9
|
-
include Rubyvm::NodeMethods
|
10
|
-
|
11
|
-
Chain = Source::Chain
|
12
|
-
|
13
|
-
# @param node [Parser::AST::Node]
|
14
|
-
# @param filename [String, nil]
|
15
|
-
def initialize node, filename = nil, in_block = false
|
16
|
-
@node = node
|
17
|
-
@filename = filename
|
18
|
-
@in_block = in_block ? 1 : 0
|
19
|
-
end
|
20
|
-
|
21
|
-
# @return [Source::Chain]
|
22
|
-
def chain
|
23
|
-
links = generate_links(@node)
|
24
|
-
Chain.new(links, @node, (Parser.is_ast_node?(@node) && @node.type == :SPLAT))
|
25
|
-
end
|
26
|
-
|
27
|
-
class << self
|
28
|
-
# @param node [Parser::AST::Node]
|
29
|
-
# @param filename [String, nil]
|
30
|
-
# @return [Source::Chain]
|
31
|
-
def chain node, filename = nil, in_block = false
|
32
|
-
NodeChainer.new(node, filename, in_block).chain
|
33
|
-
end
|
34
|
-
|
35
|
-
# @param code [String]
|
36
|
-
# @return [Source::Chain]
|
37
|
-
def load_string(code)
|
38
|
-
node = Parser.parse(code.sub(/\.$/, ''))
|
39
|
-
chain = NodeChainer.new(node).chain
|
40
|
-
chain.links.push(Chain::Link.new) if code.end_with?('.')
|
41
|
-
chain
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
private
|
46
|
-
|
47
|
-
# @param n [Parser::AST::Node]
|
48
|
-
# @return [Array<Chain::Link>]
|
49
|
-
def generate_links n
|
50
|
-
return [] unless Parser.is_ast_node?(n)
|
51
|
-
return generate_links(n.children[2]) if n.type == :SCOPE
|
52
|
-
return generate_links(n.children[0]) if n.type == :SPLAT
|
53
|
-
result = []
|
54
|
-
if n.type == :ITER
|
55
|
-
@in_block += 1
|
56
|
-
result.concat generate_links(n.children[0])
|
57
|
-
@in_block -= 1
|
58
|
-
elsif n.type == :CALL || n.type == :OPCALL
|
59
|
-
n.children[0..-3].each do |c|
|
60
|
-
result.concat generate_links(c)
|
61
|
-
end
|
62
|
-
result.push Chain::Call.new(n.children[-2].to_s, node_to_argchains(n.children.last), @in_block > 0 || block_passed?(n))
|
63
|
-
elsif n.type == :QCALL
|
64
|
-
n.children[0..-3].each do |c|
|
65
|
-
result.concat generate_links(c)
|
66
|
-
end
|
67
|
-
result.push Chain::QCall.new(n.children[-2].to_s, node_to_argchains(n.children.last), @in_block > 0 || block_passed?(n))
|
68
|
-
elsif n.type == :ATTRASGN
|
69
|
-
result.concat generate_links(n.children[0])
|
70
|
-
result.push Chain::Call.new(n.children[1].to_s, node_to_argchains(n.children[2]), @in_block > 0 || block_passed?(n))
|
71
|
-
elsif n.type == :VCALL
|
72
|
-
result.push Chain::Call.new(n.children[0].to_s, [], @in_block > 0 || block_passed?(n))
|
73
|
-
elsif n.type == :FCALL
|
74
|
-
result.push Chain::Call.new(n.children[0].to_s, node_to_argchains(n.children[1]), @in_block > 0 || block_passed?(n))
|
75
|
-
elsif n.type == :SELF
|
76
|
-
result.push Chain::Head.new('self')
|
77
|
-
elsif n.type == :ZSUPER
|
78
|
-
result.push Chain::ZSuper.new('super', @in_block > 0 || block_passed?(n))
|
79
|
-
elsif n.type == :SUPER
|
80
|
-
result.push Chain::Call.new('super', node_to_argchains(n.children.last), @in_block > 0 || block_passed?(n))
|
81
|
-
elsif [:COLON2, :COLON3, :CONST].include?(n.type)
|
82
|
-
const = unpack_name(n)
|
83
|
-
result.push Chain::Constant.new(const)
|
84
|
-
elsif [:LVAR, :LASGN, :DVAR].include?(n.type)
|
85
|
-
result.push Chain::Call.new(n.children[0].to_s)
|
86
|
-
elsif [:IVAR, :IASGN].include?(n.type)
|
87
|
-
result.push Chain::InstanceVariable.new(n.children[0].to_s)
|
88
|
-
elsif [:CVAR, :CVASGN].include?(n.type)
|
89
|
-
result.push Chain::ClassVariable.new(n.children[0].to_s)
|
90
|
-
elsif [:GVAR, :GASGN].include?(n.type)
|
91
|
-
result.push Chain::GlobalVariable.new(n.children[0].to_s)
|
92
|
-
elsif n.type == :OP_ASGN_OR
|
93
|
-
result.concat generate_links n.children[2]
|
94
|
-
elsif [:class, :module, :def, :defs].include?(n.type)
|
95
|
-
# @todo Undefined or what?
|
96
|
-
result.push Chain::UNDEFINED_CALL
|
97
|
-
elsif n.type == :AND
|
98
|
-
result.concat generate_links(n.children.last)
|
99
|
-
elsif n.type == :OR
|
100
|
-
result.push Chain::Or.new([NodeChainer.chain(n.children[0], @filename), NodeChainer.chain(n.children[1], @filename)])
|
101
|
-
elsif n.type == :BEGIN
|
102
|
-
result.concat generate_links(n.children[0])
|
103
|
-
elsif n.type == :BLOCK_PASS
|
104
|
-
result.push Chain::BlockVariable.new("&#{n.children[1].children[0].to_s}")
|
105
|
-
elsif n.type == :HASH
|
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)
|
110
|
-
else
|
111
|
-
lit = infer_literal_node_type(n)
|
112
|
-
if lit
|
113
|
-
if lit == '::Hash'
|
114
|
-
result.push Chain::Hash.new(lit, hash_is_splatted?(n))
|
115
|
-
else
|
116
|
-
result.push Chain::Literal.new(lit)
|
117
|
-
end
|
118
|
-
else
|
119
|
-
result.push Chain::Link.new
|
120
|
-
end
|
121
|
-
# result.push (lit ? Chain::Literal.new(lit) : Chain::Link.new)
|
122
|
-
end
|
123
|
-
result
|
124
|
-
end
|
125
|
-
|
126
|
-
def hash_is_splatted? node
|
127
|
-
return false unless Parser.is_ast_node?(node.children[0]) && node.children[0].type == :LIST
|
128
|
-
list = node.children[0].children
|
129
|
-
eol = list.rindex(&:nil?)
|
130
|
-
eol && Parser.is_ast_node?(list[eol + 1])
|
131
|
-
end
|
132
|
-
|
133
|
-
def block_passed? node
|
134
|
-
node.children.last.is_a?(RubyVM::AbstractSyntaxTree::Node) && node.children.last.type == :BLOCK_PASS
|
135
|
-
end
|
136
|
-
|
137
|
-
def node_to_argchains node
|
138
|
-
return [] unless Parser.is_ast_node?(node)
|
139
|
-
if [:ZARRAY, :ARRAY, :LIST].include?(node.type)
|
140
|
-
node.children[0..-2].map { |c| NodeChainer.chain(c) }
|
141
|
-
elsif node.type == :SPLAT
|
142
|
-
[NodeChainer.chain(node)]
|
143
|
-
elsif node.type == :ARGSPUSH
|
144
|
-
result = node_to_argchains(node.children[0])
|
145
|
-
result.push NodeChainer.chain(node.children[1]) if Parser.is_ast_node?(node.children[1])
|
146
|
-
elsif node.type == :ARGSCAT
|
147
|
-
result = node.children[0].children[0..-2].map { |c| NodeChainer.chain(c) }
|
148
|
-
result.push NodeChainer.chain(node.children[1])
|
149
|
-
# @todo Smelly instance variable access
|
150
|
-
result.last.instance_variable_set(:@splat, true)
|
151
|
-
result
|
152
|
-
elsif node.type == :BLOCK_PASS
|
153
|
-
result = node_to_argchains(node.children[0])
|
154
|
-
result.push Chain.new([Chain::BlockVariable.new("&#{node.children[1].children[0].to_s}")])
|
155
|
-
result
|
156
|
-
else
|
157
|
-
[]
|
158
|
-
end
|
159
|
-
end
|
160
|
-
end
|
161
|
-
end
|
162
|
-
end
|
163
|
-
end
|