solargraph 0.58.1 → 0.58.2
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/.gitignore +1 -0
- data/CHANGELOG.md +7 -1
- data/lib/solargraph/api_map/cache.rb +110 -110
- data/lib/solargraph/api_map/constants.rb +279 -279
- data/lib/solargraph/api_map/index.rb +193 -193
- data/lib/solargraph/api_map/source_to_yard.rb +97 -97
- data/lib/solargraph/api_map/store.rb +384 -384
- data/lib/solargraph/api_map.rb +945 -945
- data/lib/solargraph/complex_type/type_methods.rb +228 -228
- data/lib/solargraph/complex_type/unique_type.rb +482 -482
- data/lib/solargraph/complex_type.rb +444 -444
- data/lib/solargraph/convention/data_definition/data_definition_node.rb +91 -91
- data/lib/solargraph/convention/data_definition.rb +105 -105
- data/lib/solargraph/convention/struct_definition/struct_assignment_node.rb +61 -61
- data/lib/solargraph/convention/struct_definition/struct_definition_node.rb +102 -102
- data/lib/solargraph/convention/struct_definition.rb +164 -164
- data/lib/solargraph/diagnostics/require_not_found.rb +53 -53
- data/lib/solargraph/diagnostics/rubocop.rb +118 -118
- data/lib/solargraph/diagnostics/rubocop_helpers.rb +68 -68
- data/lib/solargraph/diagnostics/type_check.rb +55 -55
- data/lib/solargraph/doc_map.rb +439 -439
- data/lib/solargraph/equality.rb +34 -34
- data/lib/solargraph/gem_pins.rb +98 -98
- data/lib/solargraph/language_server/host/diagnoser.rb +89 -89
- data/lib/solargraph/language_server/host/dispatch.rb +130 -130
- data/lib/solargraph/language_server/host/message_worker.rb +112 -112
- data/lib/solargraph/language_server/host/sources.rb +99 -99
- data/lib/solargraph/language_server/host.rb +878 -878
- data/lib/solargraph/language_server/message/extended/check_gem_version.rb +114 -114
- data/lib/solargraph/language_server/message/extended/document.rb +23 -23
- data/lib/solargraph/language_server/message/text_document/completion.rb +56 -56
- data/lib/solargraph/language_server/message/text_document/definition.rb +40 -40
- data/lib/solargraph/language_server/message/text_document/document_symbol.rb +26 -26
- data/lib/solargraph/language_server/message/text_document/formatting.rb +148 -148
- data/lib/solargraph/language_server/message/text_document/hover.rb +58 -58
- data/lib/solargraph/language_server/message/text_document/signature_help.rb +24 -24
- data/lib/solargraph/language_server/message/text_document/type_definition.rb +25 -25
- data/lib/solargraph/language_server/message/workspace/workspace_symbol.rb +23 -23
- data/lib/solargraph/library.rb +683 -683
- data/lib/solargraph/location.rb +82 -82
- data/lib/solargraph/logging.rb +37 -37
- data/lib/solargraph/parser/comment_ripper.rb +69 -69
- data/lib/solargraph/parser/flow_sensitive_typing.rb +255 -255
- data/lib/solargraph/parser/node_processor/base.rb +92 -92
- data/lib/solargraph/parser/node_processor.rb +62 -62
- data/lib/solargraph/parser/parser_gem/class_methods.rb +149 -149
- data/lib/solargraph/parser/parser_gem/node_chainer.rb +166 -166
- data/lib/solargraph/parser/parser_gem/node_methods.rb +486 -486
- data/lib/solargraph/parser/parser_gem/node_processors/and_node.rb +22 -22
- data/lib/solargraph/parser/parser_gem/node_processors/args_node.rb +59 -59
- data/lib/solargraph/parser/parser_gem/node_processors/begin_node.rb +15 -15
- data/lib/solargraph/parser/parser_gem/node_processors/block_node.rb +46 -46
- data/lib/solargraph/parser/parser_gem/node_processors/def_node.rb +53 -53
- data/lib/solargraph/parser/parser_gem/node_processors/if_node.rb +23 -23
- data/lib/solargraph/parser/parser_gem/node_processors/ivasgn_node.rb +40 -40
- data/lib/solargraph/parser/parser_gem/node_processors/lvasgn_node.rb +29 -29
- data/lib/solargraph/parser/parser_gem/node_processors/masgn_node.rb +59 -59
- data/lib/solargraph/parser/parser_gem/node_processors/opasgn_node.rb +98 -98
- data/lib/solargraph/parser/parser_gem/node_processors/orasgn_node.rb +17 -17
- data/lib/solargraph/parser/parser_gem/node_processors/resbody_node.rb +38 -38
- data/lib/solargraph/parser/parser_gem/node_processors/sclass_node.rb +52 -52
- data/lib/solargraph/parser/parser_gem/node_processors/send_node.rb +291 -291
- data/lib/solargraph/parser/parser_gem/node_processors/while_node.rb +29 -29
- data/lib/solargraph/parser/parser_gem/node_processors.rb +70 -70
- data/lib/solargraph/parser/region.rb +69 -69
- data/lib/solargraph/parser/snippet.rb +17 -17
- data/lib/solargraph/pin/base.rb +729 -729
- data/lib/solargraph/pin/base_variable.rb +126 -126
- data/lib/solargraph/pin/block.rb +104 -104
- data/lib/solargraph/pin/breakable.rb +9 -9
- data/lib/solargraph/pin/callable.rb +231 -231
- data/lib/solargraph/pin/closure.rb +72 -72
- data/lib/solargraph/pin/common.rb +79 -79
- data/lib/solargraph/pin/conversions.rb +123 -123
- data/lib/solargraph/pin/delegated_method.rb +120 -120
- data/lib/solargraph/pin/documenting.rb +114 -114
- data/lib/solargraph/pin/instance_variable.rb +34 -34
- data/lib/solargraph/pin/keyword.rb +20 -20
- data/lib/solargraph/pin/local_variable.rb +75 -75
- data/lib/solargraph/pin/method.rb +672 -672
- data/lib/solargraph/pin/method_alias.rb +34 -34
- data/lib/solargraph/pin/namespace.rb +115 -115
- data/lib/solargraph/pin/parameter.rb +275 -275
- data/lib/solargraph/pin/proxy_type.rb +39 -39
- data/lib/solargraph/pin/reference/override.rb +47 -47
- data/lib/solargraph/pin/reference/superclass.rb +15 -15
- data/lib/solargraph/pin/reference.rb +39 -39
- data/lib/solargraph/pin/search.rb +61 -61
- data/lib/solargraph/pin/signature.rb +61 -61
- data/lib/solargraph/pin/symbol.rb +53 -53
- data/lib/solargraph/pin/until.rb +18 -18
- data/lib/solargraph/pin/while.rb +18 -18
- data/lib/solargraph/pin.rb +44 -44
- data/lib/solargraph/pin_cache.rb +245 -245
- data/lib/solargraph/position.rb +132 -119
- data/lib/solargraph/range.rb +112 -112
- data/lib/solargraph/rbs_map/conversions.rb +823 -823
- data/lib/solargraph/rbs_map/core_map.rb +58 -58
- data/lib/solargraph/rbs_map/stdlib_map.rb +43 -43
- data/lib/solargraph/rbs_map.rb +163 -163
- data/lib/solargraph/shell.rb +352 -352
- data/lib/solargraph/source/chain/call.rb +337 -337
- data/lib/solargraph/source/chain/constant.rb +26 -26
- data/lib/solargraph/source/chain/hash.rb +34 -34
- data/lib/solargraph/source/chain/if.rb +28 -28
- data/lib/solargraph/source/chain/instance_variable.rb +13 -13
- data/lib/solargraph/source/chain/literal.rb +48 -48
- data/lib/solargraph/source/chain/or.rb +23 -23
- data/lib/solargraph/source/chain.rb +291 -291
- data/lib/solargraph/source/change.rb +82 -82
- data/lib/solargraph/source/cursor.rb +166 -166
- data/lib/solargraph/source/source_chainer.rb +194 -194
- data/lib/solargraph/source/updater.rb +55 -55
- data/lib/solargraph/source.rb +498 -498
- data/lib/solargraph/source_map/clip.rb +226 -226
- data/lib/solargraph/source_map/data.rb +34 -34
- data/lib/solargraph/source_map/mapper.rb +259 -259
- data/lib/solargraph/source_map.rb +212 -212
- data/lib/solargraph/type_checker/checks.rb +124 -124
- data/lib/solargraph/type_checker/param_def.rb +37 -37
- data/lib/solargraph/type_checker/problem.rb +32 -32
- data/lib/solargraph/type_checker/rules.rb +84 -84
- data/lib/solargraph/type_checker.rb +814 -814
- data/lib/solargraph/version.rb +1 -1
- data/lib/solargraph/workspace/config.rb +255 -255
- data/lib/solargraph/workspace/require_paths.rb +97 -97
- data/lib/solargraph/workspace.rb +220 -220
- data/lib/solargraph/yard_map/helpers.rb +44 -44
- data/lib/solargraph/yard_map/mapper/to_method.rb +130 -130
- data/lib/solargraph/yard_map/mapper/to_namespace.rb +31 -31
- data/lib/solargraph/yard_map/mapper.rb +79 -79
- data/lib/solargraph/yard_map/to_method.rb +89 -89
- data/lib/solargraph/yardoc.rb +87 -87
- data/lib/solargraph.rb +105 -105
- data/rbs_collection.yaml +1 -1
- metadata +12 -12
- /data/{sig → rbs}/shims/ast/0/node.rbs +0 -0
- /data/{sig → rbs}/shims/ast/2.4/.rbs_meta.yaml +0 -0
- /data/{sig → rbs}/shims/ast/2.4/ast.rbs +0 -0
- /data/{sig → rbs}/shims/parser/3.2.0.1/builders/default.rbs +0 -0
- /data/{sig → rbs}/shims/parser/3.2.0.1/manifest.yaml +0 -0
- /data/{sig → rbs}/shims/parser/3.2.0.1/parser.rbs +0 -0
- /data/{sig → rbs}/shims/parser/3.2.0.1/polyfill.rbs +0 -0
- /data/{sig → rbs}/shims/thor/1.2.0.1/.rbs_meta.yaml +0 -0
- /data/{sig → rbs}/shims/thor/1.2.0.1/manifest.yaml +0 -0
- /data/{sig → rbs}/shims/thor/1.2.0.1/thor.rbs +0 -0
|
@@ -1,92 +1,92 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Solargraph
|
|
4
|
-
module Parser
|
|
5
|
-
module NodeProcessor
|
|
6
|
-
class Base
|
|
7
|
-
# @return [Parser::AST::Node]
|
|
8
|
-
attr_reader :node
|
|
9
|
-
|
|
10
|
-
# @return [Region]
|
|
11
|
-
attr_reader :region
|
|
12
|
-
|
|
13
|
-
# @return [Array<Pin::Base>]
|
|
14
|
-
attr_reader :pins
|
|
15
|
-
|
|
16
|
-
# @return [Array<Pin::LocalVariable>]
|
|
17
|
-
attr_reader :locals
|
|
18
|
-
|
|
19
|
-
# @param node [Parser::AST::Node]
|
|
20
|
-
# @param region [Region]
|
|
21
|
-
# @param pins [Array<Pin::Base>]
|
|
22
|
-
# @param locals [Array<Pin::LocalVariable>]
|
|
23
|
-
def initialize node, region, pins, locals
|
|
24
|
-
@node = node
|
|
25
|
-
@region = region
|
|
26
|
-
@pins = pins
|
|
27
|
-
@locals = locals
|
|
28
|
-
@processed_children = false
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
# Subclasses should override this method to generate new pins.
|
|
32
|
-
#
|
|
33
|
-
# @return [Boolean] continue processing the next processor of the same node type.
|
|
34
|
-
# @return [void] In case there is only one processor registered for the node type, it can be void.
|
|
35
|
-
def process
|
|
36
|
-
process_children
|
|
37
|
-
|
|
38
|
-
true
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
private
|
|
42
|
-
|
|
43
|
-
# @param subregion [Region]
|
|
44
|
-
# @return [void]
|
|
45
|
-
def process_children subregion = region
|
|
46
|
-
return if @processed_children
|
|
47
|
-
@processed_children = true
|
|
48
|
-
node.children.each do |child|
|
|
49
|
-
next unless Parser.is_ast_node?(child)
|
|
50
|
-
NodeProcessor.process(child, subregion, pins, locals)
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
# @param node [Parser::AST::Node]
|
|
55
|
-
# @return [Solargraph::Location]
|
|
56
|
-
def get_node_location(node)
|
|
57
|
-
range = Parser.node_range(node)
|
|
58
|
-
Location.new(region.filename, range)
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
# @param node [Parser::AST::Node]
|
|
62
|
-
# @return [String, nil]
|
|
63
|
-
def comments_for(node)
|
|
64
|
-
region.source.comments_for(node)
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
# @param position [Solargraph::Position]
|
|
68
|
-
# @return [Pin::Closure, nil]
|
|
69
|
-
def named_path_pin position
|
|
70
|
-
pins.select do |pin|
|
|
71
|
-
pin.is_a?(Pin::Closure) && pin.path && !pin.path.empty? && pin.location.range.contain?(position)
|
|
72
|
-
end.last
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
# @todo Candidate for deprecation
|
|
76
|
-
# @param position [Solargraph::Position]
|
|
77
|
-
# @return [Pin::Closure, nil]
|
|
78
|
-
def block_pin position
|
|
79
|
-
# @todo determine if this can return a Pin::Block
|
|
80
|
-
pins.select { |pin| pin.is_a?(Pin::Closure) && pin.location.range.contain?(position) }.last
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
# @todo Candidate for deprecation
|
|
84
|
-
# @param position [Solargraph::Position]
|
|
85
|
-
# @return [Pin::Closure, nil]
|
|
86
|
-
def closure_pin position
|
|
87
|
-
pins.select { |pin| pin.is_a?(Pin::Closure) && pin.location.range.contain?(position) }.last
|
|
88
|
-
end
|
|
89
|
-
end
|
|
90
|
-
end
|
|
91
|
-
end
|
|
92
|
-
end
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Solargraph
|
|
4
|
+
module Parser
|
|
5
|
+
module NodeProcessor
|
|
6
|
+
class Base
|
|
7
|
+
# @return [Parser::AST::Node]
|
|
8
|
+
attr_reader :node
|
|
9
|
+
|
|
10
|
+
# @return [Region]
|
|
11
|
+
attr_reader :region
|
|
12
|
+
|
|
13
|
+
# @return [Array<Pin::Base>]
|
|
14
|
+
attr_reader :pins
|
|
15
|
+
|
|
16
|
+
# @return [Array<Pin::LocalVariable>]
|
|
17
|
+
attr_reader :locals
|
|
18
|
+
|
|
19
|
+
# @param node [Parser::AST::Node]
|
|
20
|
+
# @param region [Region]
|
|
21
|
+
# @param pins [Array<Pin::Base>]
|
|
22
|
+
# @param locals [Array<Pin::LocalVariable>]
|
|
23
|
+
def initialize node, region, pins, locals
|
|
24
|
+
@node = node
|
|
25
|
+
@region = region
|
|
26
|
+
@pins = pins
|
|
27
|
+
@locals = locals
|
|
28
|
+
@processed_children = false
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Subclasses should override this method to generate new pins.
|
|
32
|
+
#
|
|
33
|
+
# @return [Boolean] continue processing the next processor of the same node type.
|
|
34
|
+
# @return [void] In case there is only one processor registered for the node type, it can be void.
|
|
35
|
+
def process
|
|
36
|
+
process_children
|
|
37
|
+
|
|
38
|
+
true
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
private
|
|
42
|
+
|
|
43
|
+
# @param subregion [Region]
|
|
44
|
+
# @return [void]
|
|
45
|
+
def process_children subregion = region
|
|
46
|
+
return if @processed_children
|
|
47
|
+
@processed_children = true
|
|
48
|
+
node.children.each do |child|
|
|
49
|
+
next unless Parser.is_ast_node?(child)
|
|
50
|
+
NodeProcessor.process(child, subregion, pins, locals)
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# @param node [Parser::AST::Node]
|
|
55
|
+
# @return [Solargraph::Location]
|
|
56
|
+
def get_node_location(node)
|
|
57
|
+
range = Parser.node_range(node)
|
|
58
|
+
Location.new(region.filename, range)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# @param node [Parser::AST::Node]
|
|
62
|
+
# @return [String, nil]
|
|
63
|
+
def comments_for(node)
|
|
64
|
+
region.source.comments_for(node)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# @param position [Solargraph::Position]
|
|
68
|
+
# @return [Pin::Closure, nil]
|
|
69
|
+
def named_path_pin position
|
|
70
|
+
pins.select do |pin|
|
|
71
|
+
pin.is_a?(Pin::Closure) && pin.path && !pin.path.empty? && pin.location.range.contain?(position)
|
|
72
|
+
end.last
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
# @todo Candidate for deprecation
|
|
76
|
+
# @param position [Solargraph::Position]
|
|
77
|
+
# @return [Pin::Closure, nil]
|
|
78
|
+
def block_pin position
|
|
79
|
+
# @todo determine if this can return a Pin::Block
|
|
80
|
+
pins.select { |pin| pin.is_a?(Pin::Closure) && pin.location.range.contain?(position) }.last
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
# @todo Candidate for deprecation
|
|
84
|
+
# @param position [Solargraph::Position]
|
|
85
|
+
# @return [Pin::Closure, nil]
|
|
86
|
+
def closure_pin position
|
|
87
|
+
pins.select { |pin| pin.is_a?(Pin::Closure) && pin.location.range.contain?(position) }.last
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
end
|
|
@@ -1,62 +1,62 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Solargraph
|
|
4
|
-
module Parser
|
|
5
|
-
# The processor classes used by SourceMap::Mapper to generate pins from
|
|
6
|
-
# parser nodes.
|
|
7
|
-
#
|
|
8
|
-
module NodeProcessor
|
|
9
|
-
autoload :Base, 'solargraph/parser/node_processor/base'
|
|
10
|
-
|
|
11
|
-
class << self
|
|
12
|
-
# @type [Hash{Symbol => Array<Class<NodeProcessor::Base>>}]
|
|
13
|
-
@@processors ||= {}
|
|
14
|
-
|
|
15
|
-
# Register a processor for a node type. You can register multiple processors for the same type.
|
|
16
|
-
# If a node processor returns true, it will skip the next processor of the same node type.
|
|
17
|
-
#
|
|
18
|
-
# @param type [Symbol]
|
|
19
|
-
# @param cls [Class<NodeProcessor::Base>]
|
|
20
|
-
# @return [Array<Class<NodeProcessor::Base>>]
|
|
21
|
-
def register type, cls
|
|
22
|
-
@@processors[type] ||= []
|
|
23
|
-
@@processors[type] << cls
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
# @param type [Symbol]
|
|
27
|
-
# @param cls [Class<NodeProcessor::Base>]
|
|
28
|
-
#
|
|
29
|
-
# @return [void]
|
|
30
|
-
def deregister type, cls
|
|
31
|
-
@@processors[type].delete(cls)
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
# @param node [Parser::AST::Node]
|
|
36
|
-
# @param region [Region]
|
|
37
|
-
# @param pins [Array<Pin::Base>]
|
|
38
|
-
# @param locals [Array<Pin::BaseVariable>]
|
|
39
|
-
# @return [Array(Array<Pin::Base>, Array<Pin::Base>)]
|
|
40
|
-
def self.process node, region = Region.new, pins = [], locals = []
|
|
41
|
-
if pins.empty?
|
|
42
|
-
pins.push Pin::Namespace.new(
|
|
43
|
-
location: region.source.location,
|
|
44
|
-
name: '',
|
|
45
|
-
source: :parser,
|
|
46
|
-
)
|
|
47
|
-
end
|
|
48
|
-
return [pins, locals] unless Parser.is_ast_node?(node)
|
|
49
|
-
node_processor_classes = @@processors[node.type] || [NodeProcessor::Base]
|
|
50
|
-
|
|
51
|
-
node_processor_classes.each do |klass|
|
|
52
|
-
processor = klass.new(node, region, pins, locals)
|
|
53
|
-
process_next = processor.process
|
|
54
|
-
|
|
55
|
-
break unless process_next
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
[pins, locals]
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
end
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Solargraph
|
|
4
|
+
module Parser
|
|
5
|
+
# The processor classes used by SourceMap::Mapper to generate pins from
|
|
6
|
+
# parser nodes.
|
|
7
|
+
#
|
|
8
|
+
module NodeProcessor
|
|
9
|
+
autoload :Base, 'solargraph/parser/node_processor/base'
|
|
10
|
+
|
|
11
|
+
class << self
|
|
12
|
+
# @type [Hash{Symbol => Array<Class<NodeProcessor::Base>>}]
|
|
13
|
+
@@processors ||= {}
|
|
14
|
+
|
|
15
|
+
# Register a processor for a node type. You can register multiple processors for the same type.
|
|
16
|
+
# If a node processor returns true, it will skip the next processor of the same node type.
|
|
17
|
+
#
|
|
18
|
+
# @param type [Symbol]
|
|
19
|
+
# @param cls [Class<NodeProcessor::Base>]
|
|
20
|
+
# @return [Array<Class<NodeProcessor::Base>>]
|
|
21
|
+
def register type, cls
|
|
22
|
+
@@processors[type] ||= []
|
|
23
|
+
@@processors[type] << cls
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# @param type [Symbol]
|
|
27
|
+
# @param cls [Class<NodeProcessor::Base>]
|
|
28
|
+
#
|
|
29
|
+
# @return [void]
|
|
30
|
+
def deregister type, cls
|
|
31
|
+
@@processors[type].delete(cls)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# @param node [Parser::AST::Node]
|
|
36
|
+
# @param region [Region]
|
|
37
|
+
# @param pins [Array<Pin::Base>]
|
|
38
|
+
# @param locals [Array<Pin::BaseVariable>]
|
|
39
|
+
# @return [Array(Array<Pin::Base>, Array<Pin::Base>)]
|
|
40
|
+
def self.process node, region = Region.new, pins = [], locals = []
|
|
41
|
+
if pins.empty?
|
|
42
|
+
pins.push Pin::Namespace.new(
|
|
43
|
+
location: region.source.location,
|
|
44
|
+
name: '',
|
|
45
|
+
source: :parser,
|
|
46
|
+
)
|
|
47
|
+
end
|
|
48
|
+
return [pins, locals] unless Parser.is_ast_node?(node)
|
|
49
|
+
node_processor_classes = @@processors[node.type] || [NodeProcessor::Base]
|
|
50
|
+
|
|
51
|
+
node_processor_classes.each do |klass|
|
|
52
|
+
processor = klass.new(node, region, pins, locals)
|
|
53
|
+
process_next = processor.process
|
|
54
|
+
|
|
55
|
+
break unless process_next
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
[pins, locals]
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
@@ -1,149 +1,149 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'prism'
|
|
4
|
-
|
|
5
|
-
module Solargraph
|
|
6
|
-
module Parser
|
|
7
|
-
module ParserGem
|
|
8
|
-
module ClassMethods
|
|
9
|
-
# @param code [String]
|
|
10
|
-
# @param filename [String, nil]
|
|
11
|
-
# @return [Array(Parser::AST::Node, Hash{Integer => Solargraph::Parser::Snippet})]
|
|
12
|
-
def parse_with_comments code, filename = nil
|
|
13
|
-
node = parse(code, filename)
|
|
14
|
-
comments = CommentRipper.new(code, filename, 0).parse
|
|
15
|
-
[node, comments]
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
# @param code [String]
|
|
19
|
-
# @param filename [String, nil]
|
|
20
|
-
# @param line [Integer]
|
|
21
|
-
# @return [Parser::AST::Node]
|
|
22
|
-
def parse code, filename = nil, line = 0
|
|
23
|
-
buffer = ::Parser::Source::Buffer.new(filename, line)
|
|
24
|
-
buffer.source = code
|
|
25
|
-
parser.parse(buffer)
|
|
26
|
-
rescue ::Parser::SyntaxError, ::Parser::UnknownEncodingInMagicComment => e
|
|
27
|
-
raise Parser::SyntaxError, e.message
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
# @return [::Parser::Base]
|
|
31
|
-
def parser
|
|
32
|
-
@parser ||= Prism::Translation::Parser.new(FlawedBuilder.new).tap do |parser|
|
|
33
|
-
parser.diagnostics.all_errors_are_fatal = true
|
|
34
|
-
parser.diagnostics.ignore_warnings = true
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
# @param source [Source]
|
|
39
|
-
# @return [Array(Array<Pin::Base>, Array<Pin::Base>)]
|
|
40
|
-
def map source
|
|
41
|
-
NodeProcessor.process(source.node, Region.new(source: source))
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
# @param source [Source]
|
|
45
|
-
# @param name [String]
|
|
46
|
-
# @return [Array<Location>]
|
|
47
|
-
def references source, name
|
|
48
|
-
if name.end_with?("=")
|
|
49
|
-
reg = /#{Regexp.escape name[0..-2]}\s*=/
|
|
50
|
-
# @param code [String]
|
|
51
|
-
# @param offset [Integer]
|
|
52
|
-
# @return [Array(Integer, Integer), Array(nil, nil)]
|
|
53
|
-
extract_offset = ->(code, offset) { reg.match(code, offset).offset(0) }
|
|
54
|
-
else
|
|
55
|
-
# @param code [String]
|
|
56
|
-
# @param offset [Integer]
|
|
57
|
-
# @return [Array(Integer, Integer), Array(nil, nil)]
|
|
58
|
-
extract_offset = ->(code, offset) { [soff = code.index(name, offset), soff + name.length] }
|
|
59
|
-
end
|
|
60
|
-
inner_node_references(name, source.node).map do |n|
|
|
61
|
-
rng = Range.from_node(n)
|
|
62
|
-
offset = Position.to_offset(source.code, rng.start)
|
|
63
|
-
soff, eoff = extract_offset[source.code, offset]
|
|
64
|
-
Location.new(
|
|
65
|
-
source.filename,
|
|
66
|
-
Range.new(
|
|
67
|
-
Position.from_offset(source.code, soff),
|
|
68
|
-
Position.from_offset(source.code, eoff)
|
|
69
|
-
)
|
|
70
|
-
)
|
|
71
|
-
end
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
# @param name [String]
|
|
75
|
-
# @param top [AST::Node]
|
|
76
|
-
# @return [Array<AST::Node>]
|
|
77
|
-
def inner_node_references name, top
|
|
78
|
-
# @type [Array<AST::Node>]
|
|
79
|
-
result = []
|
|
80
|
-
if top.is_a?(AST::Node) && top.to_s.include?(":#{name}")
|
|
81
|
-
result.push top if top.children.any? { |c| c.to_s == name }
|
|
82
|
-
top.children.each { |c| result.concat inner_node_references(name, c) }
|
|
83
|
-
end
|
|
84
|
-
result
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
# @return [Source::Chain]
|
|
88
|
-
def chain *args
|
|
89
|
-
NodeChainer.chain *args
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
# @return [Source::Chain]
|
|
93
|
-
def chain_string *args
|
|
94
|
-
NodeChainer.load_string *args
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
# @return [Array(Array<Pin::Base>, Array<Pin::Base>)]
|
|
98
|
-
def process_node *args
|
|
99
|
-
Solargraph::Parser::NodeProcessor.process *args
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
# @param node [Parser::AST::Node]
|
|
103
|
-
# @return [String, nil]
|
|
104
|
-
def infer_literal_node_type node
|
|
105
|
-
NodeMethods.infer_literal_node_type node
|
|
106
|
-
end
|
|
107
|
-
|
|
108
|
-
# @return [Integer]
|
|
109
|
-
def version
|
|
110
|
-
parser.version
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
# @param node [BasicObject]
|
|
114
|
-
# @return [Boolean]
|
|
115
|
-
def is_ast_node? node
|
|
116
|
-
node.is_a?(::Parser::AST::Node)
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
# @param node [Parser::AST::Node]
|
|
120
|
-
# @return [Range]
|
|
121
|
-
def node_range node
|
|
122
|
-
st = Position.new(node.loc.line, node.loc.column)
|
|
123
|
-
en = Position.new(node.loc.last_line, node.loc.last_column)
|
|
124
|
-
Range.new(st, en)
|
|
125
|
-
end
|
|
126
|
-
|
|
127
|
-
# @param node [Parser::AST::Node]
|
|
128
|
-
# @return [Array<Range>]
|
|
129
|
-
def string_ranges node
|
|
130
|
-
return [] unless is_ast_node?(node)
|
|
131
|
-
result = []
|
|
132
|
-
result.push Range.from_node(node) if node.type == :str
|
|
133
|
-
node.children.each do |child|
|
|
134
|
-
result.concat string_ranges(child)
|
|
135
|
-
end
|
|
136
|
-
if node.type == :dstr && node.children.last.nil?
|
|
137
|
-
last = node.children[-2]
|
|
138
|
-
unless last.nil?
|
|
139
|
-
rng = Range.from_node(last)
|
|
140
|
-
pos = Position.new(rng.ending.line, rng.ending.column - 1)
|
|
141
|
-
result.push Range.new(pos, pos)
|
|
142
|
-
end
|
|
143
|
-
end
|
|
144
|
-
result
|
|
145
|
-
end
|
|
146
|
-
end
|
|
147
|
-
end
|
|
148
|
-
end
|
|
149
|
-
end
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'prism'
|
|
4
|
+
|
|
5
|
+
module Solargraph
|
|
6
|
+
module Parser
|
|
7
|
+
module ParserGem
|
|
8
|
+
module ClassMethods
|
|
9
|
+
# @param code [String]
|
|
10
|
+
# @param filename [String, nil]
|
|
11
|
+
# @return [Array(Parser::AST::Node, Hash{Integer => Solargraph::Parser::Snippet})]
|
|
12
|
+
def parse_with_comments code, filename = nil
|
|
13
|
+
node = parse(code, filename)
|
|
14
|
+
comments = CommentRipper.new(code, filename, 0).parse
|
|
15
|
+
[node, comments]
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# @param code [String]
|
|
19
|
+
# @param filename [String, nil]
|
|
20
|
+
# @param line [Integer]
|
|
21
|
+
# @return [Parser::AST::Node]
|
|
22
|
+
def parse code, filename = nil, line = 0
|
|
23
|
+
buffer = ::Parser::Source::Buffer.new(filename, line)
|
|
24
|
+
buffer.source = code
|
|
25
|
+
parser.parse(buffer)
|
|
26
|
+
rescue ::Parser::SyntaxError, ::Parser::UnknownEncodingInMagicComment => e
|
|
27
|
+
raise Parser::SyntaxError, e.message
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# @return [::Parser::Base]
|
|
31
|
+
def parser
|
|
32
|
+
@parser ||= Prism::Translation::Parser.new(FlawedBuilder.new).tap do |parser|
|
|
33
|
+
parser.diagnostics.all_errors_are_fatal = true
|
|
34
|
+
parser.diagnostics.ignore_warnings = true
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# @param source [Source]
|
|
39
|
+
# @return [Array(Array<Pin::Base>, Array<Pin::Base>)]
|
|
40
|
+
def map source
|
|
41
|
+
NodeProcessor.process(source.node, Region.new(source: source))
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# @param source [Source]
|
|
45
|
+
# @param name [String]
|
|
46
|
+
# @return [Array<Location>]
|
|
47
|
+
def references source, name
|
|
48
|
+
if name.end_with?("=")
|
|
49
|
+
reg = /#{Regexp.escape name[0..-2]}\s*=/
|
|
50
|
+
# @param code [String]
|
|
51
|
+
# @param offset [Integer]
|
|
52
|
+
# @return [Array(Integer, Integer), Array(nil, nil)]
|
|
53
|
+
extract_offset = ->(code, offset) { reg.match(code, offset).offset(0) }
|
|
54
|
+
else
|
|
55
|
+
# @param code [String]
|
|
56
|
+
# @param offset [Integer]
|
|
57
|
+
# @return [Array(Integer, Integer), Array(nil, nil)]
|
|
58
|
+
extract_offset = ->(code, offset) { [soff = code.index(name, offset), soff + name.length] }
|
|
59
|
+
end
|
|
60
|
+
inner_node_references(name, source.node).map do |n|
|
|
61
|
+
rng = Range.from_node(n)
|
|
62
|
+
offset = Position.to_offset(source.code, rng.start)
|
|
63
|
+
soff, eoff = extract_offset[source.code, offset]
|
|
64
|
+
Location.new(
|
|
65
|
+
source.filename,
|
|
66
|
+
Range.new(
|
|
67
|
+
Position.from_offset(source.code, soff),
|
|
68
|
+
Position.from_offset(source.code, eoff)
|
|
69
|
+
)
|
|
70
|
+
)
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
# @param name [String]
|
|
75
|
+
# @param top [AST::Node]
|
|
76
|
+
# @return [Array<AST::Node>]
|
|
77
|
+
def inner_node_references name, top
|
|
78
|
+
# @type [Array<AST::Node>]
|
|
79
|
+
result = []
|
|
80
|
+
if top.is_a?(AST::Node) && top.to_s.include?(":#{name}")
|
|
81
|
+
result.push top if top.children.any? { |c| c.to_s == name }
|
|
82
|
+
top.children.each { |c| result.concat inner_node_references(name, c) }
|
|
83
|
+
end
|
|
84
|
+
result
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
# @return [Source::Chain]
|
|
88
|
+
def chain *args
|
|
89
|
+
NodeChainer.chain *args
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
# @return [Source::Chain]
|
|
93
|
+
def chain_string *args
|
|
94
|
+
NodeChainer.load_string *args
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
# @return [Array(Array<Pin::Base>, Array<Pin::Base>)]
|
|
98
|
+
def process_node *args
|
|
99
|
+
Solargraph::Parser::NodeProcessor.process *args
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
# @param node [Parser::AST::Node]
|
|
103
|
+
# @return [String, nil]
|
|
104
|
+
def infer_literal_node_type node
|
|
105
|
+
NodeMethods.infer_literal_node_type node
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
# @return [Integer]
|
|
109
|
+
def version
|
|
110
|
+
parser.version
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
# @param node [BasicObject]
|
|
114
|
+
# @return [Boolean]
|
|
115
|
+
def is_ast_node? node
|
|
116
|
+
node.is_a?(::Parser::AST::Node)
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
# @param node [Parser::AST::Node]
|
|
120
|
+
# @return [Range]
|
|
121
|
+
def node_range node
|
|
122
|
+
st = Position.new(node.loc.line, node.loc.column)
|
|
123
|
+
en = Position.new(node.loc.last_line, node.loc.last_column)
|
|
124
|
+
Range.new(st, en)
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
# @param node [Parser::AST::Node]
|
|
128
|
+
# @return [Array<Range>]
|
|
129
|
+
def string_ranges node
|
|
130
|
+
return [] unless is_ast_node?(node)
|
|
131
|
+
result = []
|
|
132
|
+
result.push Range.from_node(node) if node.type == :str
|
|
133
|
+
node.children.each do |child|
|
|
134
|
+
result.concat string_ranges(child)
|
|
135
|
+
end
|
|
136
|
+
if node.type == :dstr && node.children.last.nil?
|
|
137
|
+
last = node.children[-2]
|
|
138
|
+
unless last.nil?
|
|
139
|
+
rng = Range.from_node(last)
|
|
140
|
+
pos = Position.new(rng.ending.line, rng.ending.column - 1)
|
|
141
|
+
result.push Range.new(pos, pos)
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
result
|
|
145
|
+
end
|
|
146
|
+
end
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
end
|