solargraph 0.54.0 → 0.55.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/CHANGELOG.md +58 -0
- data/lib/solargraph/api_map/cache.rb +10 -1
- data/lib/solargraph/api_map/index.rb +167 -0
- data/lib/solargraph/api_map/store.rb +75 -122
- data/lib/solargraph/api_map.rb +109 -41
- data/lib/solargraph/bench.rb +17 -1
- data/lib/solargraph/complex_type/type_methods.rb +17 -11
- data/lib/solargraph/complex_type/unique_type.rb +181 -17
- data/lib/solargraph/complex_type.rb +103 -24
- data/lib/solargraph/convention/struct_definition/struct_assignment_node.rb +51 -0
- data/lib/solargraph/convention/struct_definition/struct_definition_node.rb +100 -0
- data/lib/solargraph/convention/struct_definition.rb +101 -0
- data/lib/solargraph/convention.rb +2 -0
- data/lib/solargraph/doc_map.rb +43 -18
- data/lib/solargraph/equality.rb +33 -0
- data/lib/solargraph/language_server/host/message_worker.rb +51 -5
- data/lib/solargraph/language_server/host.rb +13 -11
- data/lib/solargraph/language_server/message/base.rb +19 -12
- data/lib/solargraph/language_server/message/initialize.rb +3 -1
- data/lib/solargraph/language_server/message/text_document/completion.rb +0 -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/formatting.rb +4 -0
- 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 +31 -41
- data/lib/solargraph/location.rb +29 -1
- data/lib/solargraph/parser/comment_ripper.rb +11 -6
- data/lib/solargraph/parser/flow_sensitive_typing.rb +226 -0
- data/lib/solargraph/parser/node_methods.rb +15 -1
- data/lib/solargraph/parser/parser_gem/class_methods.rb +11 -6
- data/lib/solargraph/parser/parser_gem/node_chainer.rb +10 -10
- data/lib/solargraph/parser/parser_gem/node_methods.rb +6 -4
- data/lib/solargraph/parser/parser_gem/node_processors/and_node.rb +21 -0
- data/lib/solargraph/parser/parser_gem/node_processors/args_node.rb +23 -19
- data/lib/solargraph/parser/parser_gem/node_processors/casgn_node.rb +21 -1
- data/lib/solargraph/parser/parser_gem/node_processors/if_node.rb +21 -0
- data/lib/solargraph/parser/parser_gem/node_processors/masgn_node.rb +8 -2
- data/lib/solargraph/parser/parser_gem/node_processors/namespace_node.rb +26 -5
- data/lib/solargraph/parser/parser_gem/node_processors/opasgn_node.rb +41 -0
- data/lib/solargraph/parser/parser_gem/node_processors/send_node.rb +1 -1
- data/lib/solargraph/parser/parser_gem/node_processors/until_node.rb +28 -0
- data/lib/solargraph/parser/parser_gem/node_processors/while_node.rb +28 -0
- data/lib/solargraph/parser/parser_gem/node_processors.rb +10 -0
- data/lib/solargraph/parser.rb +3 -5
- data/lib/solargraph/pin/base.rb +47 -17
- data/lib/solargraph/pin/base_variable.rb +11 -4
- data/lib/solargraph/pin/block.rb +8 -26
- data/lib/solargraph/pin/breakable.rb +9 -0
- 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/local_variable.rb +7 -1
- data/lib/solargraph/pin/method.rb +76 -48
- data/lib/solargraph/pin/namespace.rb +14 -11
- data/lib/solargraph/pin/parameter.rb +24 -17
- data/lib/solargraph/pin/proxy_type.rb +13 -7
- data/lib/solargraph/pin/signature.rb +3 -129
- data/lib/solargraph/pin/until.rb +18 -0
- data/lib/solargraph/pin/while.rb +18 -0
- data/lib/solargraph/pin.rb +7 -1
- data/lib/solargraph/position.rb +7 -0
- data/lib/solargraph/range.rb +9 -4
- data/lib/solargraph/rbs_map/conversions.rb +84 -45
- data/lib/solargraph/rbs_map/core_fills.rb +16 -9
- data/lib/solargraph/rbs_map.rb +1 -0
- data/lib/solargraph/shell.rb +19 -2
- data/lib/solargraph/source/chain/array.rb +10 -8
- 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 +125 -61
- data/lib/solargraph/source/chain/constant.rb +1 -1
- data/lib/solargraph/source/chain/hash.rb +8 -2
- data/lib/solargraph/source/chain/if.rb +5 -0
- data/lib/solargraph/source/chain/link.rb +28 -5
- data/lib/solargraph/source/chain/literal.rb +27 -2
- data/lib/solargraph/source/chain/or.rb +1 -1
- data/lib/solargraph/source/chain/z_super.rb +1 -1
- data/lib/solargraph/source/chain.rb +131 -63
- data/lib/solargraph/source/cursor.rb +3 -2
- data/lib/solargraph/source/source_chainer.rb +2 -2
- data/lib/solargraph/source.rb +104 -86
- data/lib/solargraph/source_map/clip.rb +8 -6
- data/lib/solargraph/source_map/data.rb +30 -0
- data/lib/solargraph/source_map.rb +28 -16
- data/lib/solargraph/type_checker/checks.rb +4 -0
- data/lib/solargraph/type_checker/rules.rb +6 -1
- data/lib/solargraph/type_checker.rb +48 -21
- data/lib/solargraph/version.rb +1 -1
- data/lib/solargraph/views/environment.erb +3 -5
- data/lib/solargraph/workspace/config.rb +7 -3
- data/lib/solargraph/workspace.rb +1 -1
- data/lib/solargraph/yard_map/mapper/to_constant.rb +1 -0
- data/lib/solargraph/yard_map/mapper/to_method.rb +42 -15
- data/lib/solargraph/yard_map/mapper/to_namespace.rb +1 -0
- data/lib/solargraph/yard_map/mapper.rb +1 -0
- data/lib/solargraph/yardoc.rb +1 -1
- data/lib/solargraph.rb +1 -0
- data/solargraph.gemspec +5 -5
- metadata +41 -25
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Solargraph
|
|
4
|
+
module Parser
|
|
5
|
+
module ParserGem
|
|
6
|
+
module NodeProcessors
|
|
7
|
+
class AndNode < Parser::NodeProcessor::Base
|
|
8
|
+
include ParserGem::NodeMethods
|
|
9
|
+
|
|
10
|
+
def process
|
|
11
|
+
process_children
|
|
12
|
+
|
|
13
|
+
position = get_node_start_position(node)
|
|
14
|
+
enclosing_breakable_pin = pins.select{|pin| pin.is_a?(Pin::Breakable) && pin.location.range.contain?(position)}.last
|
|
15
|
+
FlowSensitiveTyping.new(locals, enclosing_breakable_pin).process_and(node)
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -6,22 +6,25 @@ module Solargraph
|
|
|
6
6
|
module NodeProcessors
|
|
7
7
|
class ArgsNode < Parser::NodeProcessor::Base
|
|
8
8
|
def process
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
9
|
+
callable = region.closure
|
|
10
|
+
if callable.is_a? Pin::Callable
|
|
11
|
+
if node.type == :forward_args
|
|
12
|
+
forward(callable)
|
|
13
|
+
else
|
|
14
|
+
node.children.each do |u|
|
|
15
|
+
loc = get_node_location(u)
|
|
16
|
+
locals.push Solargraph::Pin::Parameter.new(
|
|
17
|
+
location: loc,
|
|
18
|
+
closure: callable,
|
|
19
|
+
comments: comments_for(node),
|
|
20
|
+
name: u.children[0].to_s,
|
|
21
|
+
assignment: u.children[1],
|
|
22
|
+
asgn_code: u.children[1] ? region.code_for(u.children[1]) : nil,
|
|
23
|
+
presence: callable.location.range,
|
|
24
|
+
decl: get_decl(u)
|
|
25
|
+
)
|
|
26
|
+
callable.parameters.push locals.last
|
|
27
|
+
end
|
|
25
28
|
end
|
|
26
29
|
end
|
|
27
30
|
process_children
|
|
@@ -29,16 +32,17 @@ module Solargraph
|
|
|
29
32
|
|
|
30
33
|
private
|
|
31
34
|
|
|
35
|
+
# @param callable [Pin::Callable]
|
|
32
36
|
# @return [void]
|
|
33
|
-
def forward
|
|
37
|
+
def forward(callable)
|
|
34
38
|
loc = get_node_location(node)
|
|
35
39
|
locals.push Solargraph::Pin::Parameter.new(
|
|
36
40
|
location: loc,
|
|
37
|
-
closure:
|
|
41
|
+
closure: callable,
|
|
38
42
|
presence: region.closure.location.range,
|
|
39
43
|
decl: get_decl(node)
|
|
40
44
|
)
|
|
41
|
-
|
|
45
|
+
callable.parameters.push locals.last
|
|
42
46
|
end
|
|
43
47
|
|
|
44
48
|
# @param node [AST::Node]
|
|
@@ -8,6 +8,17 @@ module Solargraph
|
|
|
8
8
|
include ParserGem::NodeMethods
|
|
9
9
|
|
|
10
10
|
def process
|
|
11
|
+
if Convention::StructDefinition::StructAssignmentNode.valid?(node)
|
|
12
|
+
process_struct_assignment
|
|
13
|
+
else
|
|
14
|
+
process_constant_assignment
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
private
|
|
19
|
+
|
|
20
|
+
# @return [void]
|
|
21
|
+
def process_constant_assignment
|
|
11
22
|
pins.push Solargraph::Pin::Constant.new(
|
|
12
23
|
location: get_node_location(node),
|
|
13
24
|
closure: region.closure,
|
|
@@ -18,7 +29,16 @@ module Solargraph
|
|
|
18
29
|
process_children
|
|
19
30
|
end
|
|
20
31
|
|
|
21
|
-
|
|
32
|
+
# TODO: Move this out of [CasgnNode] once [Solargraph::Parser::NodeProcessor] supports
|
|
33
|
+
# multiple processors.
|
|
34
|
+
def process_struct_assignment
|
|
35
|
+
processor_klass = Convention::StructDefinition::NodeProcessors::StructNode
|
|
36
|
+
processor = processor_klass.new(node, region, pins, locals)
|
|
37
|
+
processor.process
|
|
38
|
+
|
|
39
|
+
@pins = processor.pins
|
|
40
|
+
@locals = processor.locals
|
|
41
|
+
end
|
|
22
42
|
|
|
23
43
|
# @return [String]
|
|
24
44
|
def const_name
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Solargraph
|
|
4
|
+
module Parser
|
|
5
|
+
module ParserGem
|
|
6
|
+
module NodeProcessors
|
|
7
|
+
class IfNode < Parser::NodeProcessor::Base
|
|
8
|
+
include ParserGem::NodeMethods
|
|
9
|
+
|
|
10
|
+
def process
|
|
11
|
+
process_children
|
|
12
|
+
|
|
13
|
+
position = get_node_start_position(node)
|
|
14
|
+
enclosing_breakable_pin = pins.select{|pin| pin.is_a?(Pin::Breakable) && pin.location.range.contain?(position)}.last
|
|
15
|
+
FlowSensitiveTyping.new(locals, enclosing_breakable_pin).process_if(node)
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -30,11 +30,17 @@ module Solargraph
|
|
|
30
30
|
|
|
31
31
|
lhs_arr.each_with_index do |lhs, i|
|
|
32
32
|
location = get_node_location(lhs)
|
|
33
|
+
pin = if lhs.type == :lvasgn
|
|
34
|
+
# lvasgn is a local variable
|
|
35
|
+
locals.find { |l| l.location == location }
|
|
36
|
+
else
|
|
37
|
+
# e.g., ivasgn is an instance variable, etc
|
|
38
|
+
pins.find { |iv| iv.location == location && iv.is_a?(Pin::BaseVariable) }
|
|
39
|
+
end
|
|
33
40
|
# @todo in line below, nothing in typechecking alerts
|
|
34
41
|
# when a non-existant method is called on 'l'
|
|
35
|
-
pin = locals.find { |l| l.location == location }
|
|
36
42
|
if pin.nil?
|
|
37
|
-
Solargraph.logger.debug "Could not find
|
|
43
|
+
Solargraph.logger.debug { "Could not find local for masgn= value in location #{location.inspect} in #{lhs_arr} - masgn = #{masgn}, lhs.type = #{lhs.type}" }
|
|
38
44
|
next
|
|
39
45
|
end
|
|
40
46
|
pin.mass_assignment = [mass_rhs, i]
|
|
@@ -8,10 +8,20 @@ module Solargraph
|
|
|
8
8
|
include ParserGem::NodeMethods
|
|
9
9
|
|
|
10
10
|
def process
|
|
11
|
-
|
|
12
|
-
if node.type == :class
|
|
13
|
-
|
|
11
|
+
superclass_name = nil
|
|
12
|
+
superclass_name = unpack_name(node.children[1]) if node.type == :class && node.children[1]&.type == :const
|
|
13
|
+
|
|
14
|
+
if Convention::StructDefinition::StructDefintionNode.valid?(node)
|
|
15
|
+
process_struct_definition
|
|
16
|
+
else
|
|
17
|
+
process_namespace(superclass_name)
|
|
14
18
|
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
private
|
|
22
|
+
|
|
23
|
+
# @param superclass_name [String, nil]
|
|
24
|
+
def process_namespace(superclass_name)
|
|
15
25
|
loc = get_node_location(node)
|
|
16
26
|
nspin = Solargraph::Pin::Namespace.new(
|
|
17
27
|
type: node.type,
|
|
@@ -23,15 +33,26 @@ module Solargraph
|
|
|
23
33
|
gates: region.closure.gates.freeze
|
|
24
34
|
)
|
|
25
35
|
pins.push nspin
|
|
26
|
-
unless
|
|
36
|
+
unless superclass_name.nil?
|
|
27
37
|
pins.push Pin::Reference::Superclass.new(
|
|
28
38
|
location: loc,
|
|
29
39
|
closure: pins.last,
|
|
30
|
-
name:
|
|
40
|
+
name: superclass_name
|
|
31
41
|
)
|
|
32
42
|
end
|
|
33
43
|
process_children region.update(closure: nspin, visibility: :public)
|
|
34
44
|
end
|
|
45
|
+
|
|
46
|
+
# TODO: Move this out of [NamespaceNode] once [Solargraph::Parser::NodeProcessor] supports
|
|
47
|
+
# multiple processors.
|
|
48
|
+
def process_struct_definition
|
|
49
|
+
processor_klass = Convention::StructDefinition::NodeProcessors::StructNode
|
|
50
|
+
processor = processor_klass.new(node, region, pins, locals)
|
|
51
|
+
processor.process
|
|
52
|
+
|
|
53
|
+
@pins = processor.pins
|
|
54
|
+
@locals = processor.locals
|
|
55
|
+
end
|
|
35
56
|
end
|
|
36
57
|
end
|
|
37
58
|
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'parser'
|
|
4
|
+
|
|
5
|
+
module Solargraph
|
|
6
|
+
module Parser
|
|
7
|
+
module ParserGem
|
|
8
|
+
module NodeProcessors
|
|
9
|
+
class OpasgnNode < Parser::NodeProcessor::Base
|
|
10
|
+
def process
|
|
11
|
+
# Parser::CurrentRuby.parse("a += 2")
|
|
12
|
+
# => s(:op_asgn,
|
|
13
|
+
# s(:lvasgn, :a), :+,
|
|
14
|
+
# s(:int, 2))
|
|
15
|
+
asgn = node.children[0]
|
|
16
|
+
variable_name = asgn.children[0]
|
|
17
|
+
operator = node.children[1]
|
|
18
|
+
argument = node.children[2]
|
|
19
|
+
# for lvasgn, gvasgn, cvasgn, convert to lvar, gvar, cvar
|
|
20
|
+
# [6] pry(main)> Parser::CurrentRuby.parse("a = a + 1")
|
|
21
|
+
# => s(:lvasgn, :a,
|
|
22
|
+
# s(:send,
|
|
23
|
+
# s(:lvar, :a), :+,
|
|
24
|
+
# s(:int, 1)))
|
|
25
|
+
# [7] pry(main)>
|
|
26
|
+
variable_reference_type = asgn.type.to_s.sub(/vasgn$/, 'var').to_sym
|
|
27
|
+
variable_reference = node.updated(variable_reference_type, asgn.children)
|
|
28
|
+
send_children = [
|
|
29
|
+
variable_reference,
|
|
30
|
+
operator,
|
|
31
|
+
argument
|
|
32
|
+
]
|
|
33
|
+
send_node = node.updated(:send, send_children)
|
|
34
|
+
new_asgn = node.updated(asgn.type, [variable_name, send_node])
|
|
35
|
+
NodeProcessor.process(new_asgn, region, pins, locals)
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -92,7 +92,7 @@ module Solargraph
|
|
|
92
92
|
pins.push method_pin
|
|
93
93
|
method_pin.parameters.push Pin::Parameter.new(name: 'value', decl: :arg, closure: pins.last)
|
|
94
94
|
if method_pin.return_type.defined?
|
|
95
|
-
pins.last.docstring.add_tag YARD::Tags::Tag.new(:param, '', pins.last.return_type.
|
|
95
|
+
pins.last.docstring.add_tag YARD::Tags::Tag.new(:param, '', pins.last.return_type.items.map(&:rooted_tags), 'value')
|
|
96
96
|
end
|
|
97
97
|
end
|
|
98
98
|
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Solargraph
|
|
4
|
+
module Parser
|
|
5
|
+
module ParserGem
|
|
6
|
+
module NodeProcessors
|
|
7
|
+
class UntilNode < Parser::NodeProcessor::Base
|
|
8
|
+
include ParserGem::NodeMethods
|
|
9
|
+
|
|
10
|
+
def process
|
|
11
|
+
location = get_node_location(node)
|
|
12
|
+
# Note - this should not be considered a block, as the
|
|
13
|
+
# until statement doesn't create a closure - e.g.,
|
|
14
|
+
# variables created inside can be seen from outside as
|
|
15
|
+
# well
|
|
16
|
+
pins.push Solargraph::Pin::Until.new(
|
|
17
|
+
location: location,
|
|
18
|
+
closure: region.closure,
|
|
19
|
+
node: node,
|
|
20
|
+
comments: comments_for(node),
|
|
21
|
+
)
|
|
22
|
+
process_children region
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Solargraph
|
|
4
|
+
module Parser
|
|
5
|
+
module ParserGem
|
|
6
|
+
module NodeProcessors
|
|
7
|
+
class WhileNode < Parser::NodeProcessor::Base
|
|
8
|
+
include ParserGem::NodeMethods
|
|
9
|
+
|
|
10
|
+
def process
|
|
11
|
+
location = get_node_location(node)
|
|
12
|
+
# Note - this should not be considered a block, as the
|
|
13
|
+
# while statement doesn't create a closure - e.g.,
|
|
14
|
+
# variables created inside can be seen from outside as
|
|
15
|
+
# well
|
|
16
|
+
pins.push Solargraph::Pin::While.new(
|
|
17
|
+
location: location,
|
|
18
|
+
closure: region.closure,
|
|
19
|
+
node: node,
|
|
20
|
+
comments: comments_for(node),
|
|
21
|
+
)
|
|
22
|
+
process_children region
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -13,6 +13,7 @@ module Solargraph
|
|
|
13
13
|
autoload :NamespaceNode, 'solargraph/parser/parser_gem/node_processors/namespace_node'
|
|
14
14
|
autoload :SclassNode, 'solargraph/parser/parser_gem/node_processors/sclass_node'
|
|
15
15
|
autoload :IvasgnNode, 'solargraph/parser/parser_gem/node_processors/ivasgn_node'
|
|
16
|
+
autoload :IfNode, 'solargraph/parser/parser_gem/node_processors/if_node'
|
|
16
17
|
autoload :CvasgnNode, 'solargraph/parser/parser_gem/node_processors/cvasgn_node'
|
|
17
18
|
autoload :LvasgnNode, 'solargraph/parser/parser_gem/node_processors/lvasgn_node'
|
|
18
19
|
autoload :GvasgnNode, 'solargraph/parser/parser_gem/node_processors/gvasgn_node'
|
|
@@ -22,8 +23,12 @@ module Solargraph
|
|
|
22
23
|
autoload :ArgsNode, 'solargraph/parser/parser_gem/node_processors/args_node'
|
|
23
24
|
autoload :BlockNode, 'solargraph/parser/parser_gem/node_processors/block_node'
|
|
24
25
|
autoload :OrasgnNode, 'solargraph/parser/parser_gem/node_processors/orasgn_node'
|
|
26
|
+
autoload :OpasgnNode, 'solargraph/parser/parser_gem/node_processors/opasgn_node'
|
|
25
27
|
autoload :SymNode, 'solargraph/parser/parser_gem/node_processors/sym_node'
|
|
26
28
|
autoload :ResbodyNode, 'solargraph/parser/parser_gem/node_processors/resbody_node'
|
|
29
|
+
autoload :UntilNode, 'solargraph/parser/parser_gem/node_processors/until_node'
|
|
30
|
+
autoload :WhileNode, 'solargraph/parser/parser_gem/node_processors/while_node'
|
|
31
|
+
autoload :AndNode, 'solargraph/parser/parser_gem/node_processors/and_node'
|
|
27
32
|
end
|
|
28
33
|
end
|
|
29
34
|
|
|
@@ -35,6 +40,7 @@ module Solargraph
|
|
|
35
40
|
register :resbody, ParserGem::NodeProcessors::ResbodyNode
|
|
36
41
|
register :def, ParserGem::NodeProcessors::DefNode
|
|
37
42
|
register :defs, ParserGem::NodeProcessors::DefsNode
|
|
43
|
+
register :if, ParserGem::NodeProcessors::IfNode
|
|
38
44
|
register :send, ParserGem::NodeProcessors::SendNode
|
|
39
45
|
register :class, ParserGem::NodeProcessors::NamespaceNode
|
|
40
46
|
register :module, ParserGem::NodeProcessors::NamespaceNode
|
|
@@ -50,7 +56,11 @@ module Solargraph
|
|
|
50
56
|
register :forward_args, ParserGem::NodeProcessors::ArgsNode
|
|
51
57
|
register :block, ParserGem::NodeProcessors::BlockNode
|
|
52
58
|
register :or_asgn, ParserGem::NodeProcessors::OrasgnNode
|
|
59
|
+
register :op_asgn, ParserGem::NodeProcessors::OpasgnNode
|
|
53
60
|
register :sym, ParserGem::NodeProcessors::SymNode
|
|
61
|
+
register :until, ParserGem::NodeProcessors::UntilNode
|
|
62
|
+
register :while, ParserGem::NodeProcessors::WhileNode
|
|
63
|
+
register :and, ParserGem::NodeProcessors::AndNode
|
|
54
64
|
end
|
|
55
65
|
end
|
|
56
66
|
end
|
data/lib/solargraph/parser.rb
CHANGED
|
@@ -4,20 +4,18 @@ module Solargraph
|
|
|
4
4
|
autoload :ParserGem, 'solargraph/parser/parser_gem'
|
|
5
5
|
autoload :Region, 'solargraph/parser/region'
|
|
6
6
|
autoload :NodeProcessor, 'solargraph/parser/node_processor'
|
|
7
|
+
autoload :FlowSensitiveTyping, 'solargraph/parser/flow_sensitive_typing'
|
|
7
8
|
autoload :Snippet, 'solargraph/parser/snippet'
|
|
8
9
|
|
|
9
10
|
class SyntaxError < StandardError
|
|
10
11
|
end
|
|
11
12
|
|
|
12
|
-
def self.rubyvm?
|
|
13
|
-
false
|
|
14
|
-
end
|
|
15
|
-
|
|
16
13
|
# @deprecated
|
|
17
14
|
Legacy = ParserGem
|
|
18
15
|
|
|
19
16
|
ClassMethods = ParserGem::ClassMethods
|
|
20
|
-
|
|
17
|
+
# @todo should be able to just 'extend ClassMethods' here and
|
|
18
|
+
# typecheck things off it in strict mode
|
|
21
19
|
extend ParserGem::ClassMethods
|
|
22
20
|
|
|
23
21
|
NodeMethods = ParserGem::NodeMethods
|
data/lib/solargraph/pin/base.rb
CHANGED
|
@@ -15,6 +15,9 @@ module Solargraph
|
|
|
15
15
|
# @return [Solargraph::Location]
|
|
16
16
|
attr_reader :location
|
|
17
17
|
|
|
18
|
+
# @return [Solargraph::Location]
|
|
19
|
+
attr_reader :type_location
|
|
20
|
+
|
|
18
21
|
# @return [String]
|
|
19
22
|
attr_reader :name
|
|
20
23
|
|
|
@@ -24,15 +27,23 @@ module Solargraph
|
|
|
24
27
|
# @return [::Symbol]
|
|
25
28
|
attr_accessor :source
|
|
26
29
|
|
|
30
|
+
def presence_certain?
|
|
31
|
+
true
|
|
32
|
+
end
|
|
33
|
+
|
|
27
34
|
# @param location [Solargraph::Location, nil]
|
|
35
|
+
# @param type_location [Solargraph::Location, nil]
|
|
28
36
|
# @param closure [Solargraph::Pin::Closure, nil]
|
|
29
37
|
# @param name [String]
|
|
30
38
|
# @param comments [String]
|
|
31
|
-
def initialize location: nil, closure: nil, name: '', comments: ''
|
|
39
|
+
def initialize location: nil, type_location: nil, closure: nil, source: nil, name: '', comments: ''
|
|
32
40
|
@location = location
|
|
41
|
+
@type_location = type_location
|
|
33
42
|
@closure = closure
|
|
34
43
|
@name = name
|
|
44
|
+
@source = source
|
|
35
45
|
@comments = comments
|
|
46
|
+
@source = source
|
|
36
47
|
end
|
|
37
48
|
|
|
38
49
|
# @return [String]
|
|
@@ -66,11 +77,14 @@ module Solargraph
|
|
|
66
77
|
# @param context_type [ComplexType] The receiver type
|
|
67
78
|
# @return [self]
|
|
68
79
|
def resolve_generics definitions, context_type
|
|
69
|
-
|
|
70
|
-
|
|
80
|
+
transform_types { |t| t.resolve_generics(definitions, context_type) if t }
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def all_rooted?
|
|
84
|
+
!return_type || return_type.all_rooted?
|
|
71
85
|
end
|
|
72
86
|
|
|
73
|
-
# @param generics_to_erase [
|
|
87
|
+
# @param generics_to_erase [::Array<String>]
|
|
74
88
|
# @return [self]
|
|
75
89
|
def erase_generics(generics_to_erase)
|
|
76
90
|
return self if generics_to_erase.empty?
|
|
@@ -94,7 +108,7 @@ module Solargraph
|
|
|
94
108
|
end
|
|
95
109
|
|
|
96
110
|
def to_s
|
|
97
|
-
|
|
111
|
+
desc
|
|
98
112
|
end
|
|
99
113
|
|
|
100
114
|
# @return [Boolean]
|
|
@@ -102,12 +116,9 @@ module Solargraph
|
|
|
102
116
|
false
|
|
103
117
|
end
|
|
104
118
|
|
|
105
|
-
#
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
def == other
|
|
109
|
-
return false unless nearly? other
|
|
110
|
-
comments == other.comments and location == other.location
|
|
119
|
+
# @return [Location, nil]
|
|
120
|
+
def best_location
|
|
121
|
+
location || type_location
|
|
111
122
|
end
|
|
112
123
|
|
|
113
124
|
# True if the specified pin is a near match to this one. A near match
|
|
@@ -126,6 +137,14 @@ module Solargraph
|
|
|
126
137
|
)
|
|
127
138
|
end
|
|
128
139
|
|
|
140
|
+
# Pin equality is determined using the #nearly? method and also
|
|
141
|
+
# requiring both pins to have the same location.
|
|
142
|
+
#
|
|
143
|
+
def == other
|
|
144
|
+
return false unless nearly? other
|
|
145
|
+
comments == other.comments && location == other.location
|
|
146
|
+
end
|
|
147
|
+
|
|
129
148
|
# The pin's return type.
|
|
130
149
|
#
|
|
131
150
|
# @return [ComplexType]
|
|
@@ -252,9 +271,10 @@ module Solargraph
|
|
|
252
271
|
result
|
|
253
272
|
end
|
|
254
273
|
|
|
274
|
+
# @deprecated
|
|
255
275
|
# @return [String]
|
|
256
276
|
def identity
|
|
257
|
-
@identity ||= "#{closure
|
|
277
|
+
@identity ||= "#{closure&.path}|#{name}|#{location}"
|
|
258
278
|
end
|
|
259
279
|
|
|
260
280
|
# @return [String, nil]
|
|
@@ -262,19 +282,29 @@ module Solargraph
|
|
|
262
282
|
return_type.to_rbs
|
|
263
283
|
end
|
|
264
284
|
|
|
265
|
-
# @return [String
|
|
266
|
-
def
|
|
285
|
+
# @return [String]
|
|
286
|
+
def type_desc
|
|
287
|
+
rbs = to_rbs
|
|
288
|
+
# RBS doesn't have a way to represent a Class<x> type
|
|
289
|
+
rbs = return_type.rooted_tags if return_type.name == 'Class'
|
|
267
290
|
if path
|
|
268
|
-
if
|
|
269
|
-
path + ' ' +
|
|
291
|
+
if rbs
|
|
292
|
+
path + ' ' + rbs
|
|
270
293
|
else
|
|
271
294
|
path
|
|
272
295
|
end
|
|
273
296
|
else
|
|
274
|
-
|
|
297
|
+
rbs
|
|
275
298
|
end
|
|
276
299
|
end
|
|
277
300
|
|
|
301
|
+
# @return [String]
|
|
302
|
+
def desc
|
|
303
|
+
closure_info = closure&.desc
|
|
304
|
+
binder_info = binder&.desc
|
|
305
|
+
"[name=#{name.inspect} return_type=#{type_desc}, context=#{context.rooted_tags}, closure=#{closure_info}, binder=#{binder_info}]"
|
|
306
|
+
end
|
|
307
|
+
|
|
278
308
|
def inspect
|
|
279
309
|
"#<#{self.class} `#{self.desc}` at #{self.location.inspect}>"
|
|
280
310
|
end
|
|
@@ -11,12 +11,14 @@ module Solargraph
|
|
|
11
11
|
|
|
12
12
|
attr_accessor :mass_assignment
|
|
13
13
|
|
|
14
|
+
# @param return_type [ComplexType, nil]
|
|
14
15
|
# @param assignment [Parser::AST::Node, nil]
|
|
15
|
-
def initialize assignment: nil, **splat
|
|
16
|
+
def initialize assignment: nil, return_type: nil, **splat
|
|
16
17
|
super(**splat)
|
|
17
18
|
@assignment = assignment
|
|
18
19
|
# @type [nil, ::Array(Parser::AST::Node, Integer)]
|
|
19
20
|
@mass_assignment = nil
|
|
21
|
+
@return_type = return_type
|
|
20
22
|
end
|
|
21
23
|
|
|
22
24
|
def completion_item_kind
|
|
@@ -32,7 +34,10 @@ module Solargraph
|
|
|
32
34
|
@return_type ||= generate_complex_type
|
|
33
35
|
end
|
|
34
36
|
|
|
37
|
+
# @sg-ignore
|
|
35
38
|
def nil_assignment?
|
|
39
|
+
# this will always be false - should it be return_type ==
|
|
40
|
+
# ComplexType::NIL or somesuch?
|
|
36
41
|
return_type.nil?
|
|
37
42
|
end
|
|
38
43
|
|
|
@@ -57,7 +62,7 @@ module Solargraph
|
|
|
57
62
|
# Use the return node for inference. The clip might infer from the
|
|
58
63
|
# first node in a method call instead of the entire call.
|
|
59
64
|
chain = Parser.chain(node, nil, nil)
|
|
60
|
-
result = chain.infer(api_map, closure, clip.locals).
|
|
65
|
+
result = chain.infer(api_map, closure, clip.locals).self_to_type(closure.context)
|
|
61
66
|
types.push result unless result.undefined?
|
|
62
67
|
end
|
|
63
68
|
end
|
|
@@ -88,11 +93,13 @@ module Solargraph
|
|
|
88
93
|
ComplexType::UNDEFINED
|
|
89
94
|
end
|
|
90
95
|
|
|
96
|
+
# @param other [Object]
|
|
91
97
|
def == other
|
|
92
98
|
return false unless super
|
|
93
99
|
assignment == other.assignment
|
|
94
100
|
end
|
|
95
101
|
|
|
102
|
+
# @param pin [self]
|
|
96
103
|
def try_merge! pin
|
|
97
104
|
return false unless super
|
|
98
105
|
@assignment = pin.assignment
|
|
@@ -100,8 +107,8 @@ module Solargraph
|
|
|
100
107
|
true
|
|
101
108
|
end
|
|
102
109
|
|
|
103
|
-
def
|
|
104
|
-
"#{
|
|
110
|
+
def type_desc
|
|
111
|
+
"#{super} = #{assignment&.type.inspect}"
|
|
105
112
|
end
|
|
106
113
|
|
|
107
114
|
private
|