solargraph 0.58.2 → 0.59.0.dev.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/.envrc +3 -0
- data/.github/workflows/linting.yml +4 -5
- data/.github/workflows/plugins.yml +41 -34
- data/.github/workflows/rspec.yml +44 -23
- data/.github/workflows/typecheck.yml +2 -2
- data/.rubocop.yml +32 -5
- data/.rubocop_todo.yml +50 -966
- data/Gemfile +3 -1
- data/README.md +3 -3
- data/Rakefile +26 -23
- data/bin/solargraph +2 -1
- data/lib/solargraph/api_map/cache.rb +3 -3
- data/lib/solargraph/api_map/constants.rb +13 -3
- data/lib/solargraph/api_map/index.rb +23 -18
- data/lib/solargraph/api_map/source_to_yard.rb +22 -9
- data/lib/solargraph/api_map/store.rb +33 -28
- data/lib/solargraph/api_map.rb +150 -82
- data/lib/solargraph/bench.rb +44 -45
- data/lib/solargraph/complex_type/conformance.rb +176 -0
- data/lib/solargraph/complex_type/type_methods.rb +28 -17
- data/lib/solargraph/complex_type/unique_type.rb +218 -57
- data/lib/solargraph/complex_type.rb +170 -57
- data/lib/solargraph/convention/data_definition/data_assignment_node.rb +61 -61
- data/lib/solargraph/convention/data_definition/data_definition_node.rb +7 -5
- data/lib/solargraph/convention/data_definition.rb +5 -2
- data/lib/solargraph/convention/gemfile.rb +15 -15
- data/lib/solargraph/convention/gemspec.rb +23 -23
- data/lib/solargraph/convention/rakefile.rb +17 -17
- data/lib/solargraph/convention/struct_definition/struct_assignment_node.rb +2 -1
- data/lib/solargraph/convention/struct_definition/struct_definition_node.rb +4 -3
- data/lib/solargraph/convention/struct_definition.rb +8 -4
- data/lib/solargraph/convention.rb +78 -78
- data/lib/solargraph/converters/dd.rb +19 -17
- data/lib/solargraph/converters/dl.rb +17 -15
- data/lib/solargraph/converters/dt.rb +17 -15
- data/lib/solargraph/converters/misc.rb +3 -1
- data/lib/solargraph/diagnostics/require_not_found.rb +1 -0
- data/lib/solargraph/diagnostics/rubocop.rb +11 -10
- data/lib/solargraph/diagnostics/rubocop_helpers.rb +5 -3
- data/lib/solargraph/diagnostics/type_check.rb +11 -10
- data/lib/solargraph/diagnostics/update_errors.rb +37 -41
- data/lib/solargraph/doc_map.rb +133 -373
- data/lib/solargraph/equality.rb +4 -4
- data/lib/solargraph/gem_pins.rb +21 -20
- data/lib/solargraph/language_server/error_codes.rb +20 -20
- data/lib/solargraph/language_server/host/diagnoser.rb +1 -1
- data/lib/solargraph/language_server/host/dispatch.rb +3 -3
- data/lib/solargraph/language_server/host/message_worker.rb +4 -3
- data/lib/solargraph/language_server/host/sources.rb +2 -1
- data/lib/solargraph/language_server/host.rb +30 -22
- data/lib/solargraph/language_server/message/base.rb +97 -97
- data/lib/solargraph/language_server/message/client/register_capability.rb +13 -15
- data/lib/solargraph/language_server/message/completion_item/resolve.rb +58 -60
- data/lib/solargraph/language_server/message/extended/check_gem_version.rb +12 -18
- data/lib/solargraph/language_server/message/extended/document.rb +1 -0
- data/lib/solargraph/language_server/message/extended/document_gems.rb +32 -32
- data/lib/solargraph/language_server/message/extended/download_core.rb +20 -19
- data/lib/solargraph/language_server/message/extended/search.rb +20 -20
- data/lib/solargraph/language_server/message/initialize.rb +197 -191
- data/lib/solargraph/language_server/message/text_document/completion.rb +10 -8
- data/lib/solargraph/language_server/message/text_document/definition.rb +41 -32
- data/lib/solargraph/language_server/message/text_document/document_highlight.rb +23 -16
- data/lib/solargraph/language_server/message/text_document/document_symbol.rb +29 -19
- data/lib/solargraph/language_server/message/text_document/formatting.rb +8 -6
- data/lib/solargraph/language_server/message/text_document/hover.rb +5 -5
- data/lib/solargraph/language_server/message/text_document/prepare_rename.rb +18 -11
- data/lib/solargraph/language_server/message/text_document/references.rb +23 -16
- data/lib/solargraph/language_server/message/text_document/rename.rb +26 -19
- data/lib/solargraph/language_server/message/text_document/signature_help.rb +3 -2
- data/lib/solargraph/language_server/message/text_document/type_definition.rb +25 -17
- data/lib/solargraph/language_server/message/workspace/did_change_configuration.rb +41 -35
- data/lib/solargraph/language_server/message/workspace/did_change_watched_files.rb +48 -40
- data/lib/solargraph/language_server/message/workspace/did_change_workspace_folders.rb +32 -26
- data/lib/solargraph/language_server/message/workspace/workspace_symbol.rb +27 -17
- data/lib/solargraph/language_server/message.rb +94 -94
- data/lib/solargraph/language_server/request.rb +29 -27
- data/lib/solargraph/language_server/transport/data_reader.rb +72 -74
- data/lib/solargraph/language_server/uri_helpers.rb +49 -49
- data/lib/solargraph/library.rb +85 -44
- data/lib/solargraph/location.rb +17 -14
- data/lib/solargraph/logging.rb +24 -4
- data/lib/solargraph/page.rb +92 -92
- data/lib/solargraph/parser/comment_ripper.rb +19 -4
- data/lib/solargraph/parser/flow_sensitive_typing.rb +326 -108
- data/lib/solargraph/parser/node_processor/base.rb +34 -4
- data/lib/solargraph/parser/node_processor.rb +8 -7
- data/lib/solargraph/parser/parser_gem/class_methods.rb +32 -14
- data/lib/solargraph/parser/parser_gem/flawed_builder.rb +19 -19
- data/lib/solargraph/parser/parser_gem/node_chainer.rb +50 -25
- data/lib/solargraph/parser/parser_gem/node_methods.rb +91 -70
- data/lib/solargraph/parser/parser_gem/node_processors/and_node.rb +4 -4
- data/lib/solargraph/parser/parser_gem/node_processors/args_node.rb +13 -11
- data/lib/solargraph/parser/parser_gem/node_processors/begin_node.rb +9 -0
- data/lib/solargraph/parser/parser_gem/node_processors/block_node.rb +12 -12
- data/lib/solargraph/parser/parser_gem/node_processors/def_node.rb +10 -3
- data/lib/solargraph/parser/parser_gem/node_processors/defs_node.rb +38 -37
- data/lib/solargraph/parser/parser_gem/node_processors/if_node.rb +36 -6
- data/lib/solargraph/parser/parser_gem/node_processors/ivasgn_node.rb +5 -3
- data/lib/solargraph/parser/parser_gem/node_processors/lvasgn_node.rb +1 -0
- data/lib/solargraph/parser/parser_gem/node_processors/masgn_node.rb +3 -1
- data/lib/solargraph/parser/parser_gem/node_processors/opasgn_node.rb +3 -3
- data/lib/solargraph/parser/parser_gem/node_processors/or_node.rb +22 -0
- data/lib/solargraph/parser/parser_gem/node_processors/orasgn_node.rb +1 -1
- data/lib/solargraph/parser/parser_gem/node_processors/resbody_node.rb +2 -1
- data/lib/solargraph/parser/parser_gem/node_processors/sclass_node.rb +4 -5
- data/lib/solargraph/parser/parser_gem/node_processors/send_node.rb +124 -113
- data/lib/solargraph/parser/parser_gem/node_processors/until_node.rb +29 -29
- data/lib/solargraph/parser/parser_gem/node_processors/when_node.rb +23 -0
- data/lib/solargraph/parser/parser_gem/node_processors/while_node.rb +6 -2
- data/lib/solargraph/parser/parser_gem/node_processors.rb +4 -0
- data/lib/solargraph/parser/parser_gem.rb +14 -12
- data/lib/solargraph/parser/region.rb +9 -3
- data/lib/solargraph/parser/snippet.rb +3 -1
- data/lib/solargraph/parser.rb +25 -23
- data/lib/solargraph/pin/base.rb +126 -80
- data/lib/solargraph/pin/base_variable.rb +273 -24
- data/lib/solargraph/pin/block.rb +29 -6
- data/lib/solargraph/pin/breakable.rb +7 -1
- data/lib/solargraph/pin/callable.rb +65 -21
- data/lib/solargraph/pin/closure.rb +7 -10
- data/lib/solargraph/pin/common.rb +24 -6
- data/lib/solargraph/pin/compound_statement.rb +55 -0
- data/lib/solargraph/pin/constant.rb +43 -45
- data/lib/solargraph/pin/conversions.rb +10 -4
- data/lib/solargraph/pin/delegated_method.rb +19 -8
- data/lib/solargraph/pin/documenting.rb +4 -2
- data/lib/solargraph/pin/instance_variable.rb +5 -1
- data/lib/solargraph/pin/keyword.rb +0 -4
- data/lib/solargraph/pin/local_variable.rb +15 -59
- data/lib/solargraph/pin/method.rb +153 -104
- data/lib/solargraph/pin/method_alias.rb +8 -0
- data/lib/solargraph/pin/namespace.rb +19 -12
- data/lib/solargraph/pin/parameter.rb +100 -36
- data/lib/solargraph/pin/proxy_type.rb +4 -1
- data/lib/solargraph/pin/reference/override.rb +1 -1
- data/lib/solargraph/pin/reference/superclass.rb +2 -0
- data/lib/solargraph/pin/reference.rb +19 -0
- data/lib/solargraph/pin/search.rb +3 -2
- data/lib/solargraph/pin/signature.rb +15 -12
- data/lib/solargraph/pin/symbol.rb +2 -1
- data/lib/solargraph/pin/until.rb +2 -4
- data/lib/solargraph/pin/while.rb +2 -4
- data/lib/solargraph/pin.rb +2 -0
- data/lib/solargraph/pin_cache.rb +490 -73
- data/lib/solargraph/position.rb +14 -10
- data/lib/solargraph/range.rb +16 -15
- data/lib/solargraph/rbs_map/conversions.rb +343 -214
- data/lib/solargraph/rbs_map/core_fills.rb +91 -84
- data/lib/solargraph/rbs_map/core_map.rb +24 -17
- data/lib/solargraph/rbs_map/stdlib_map.rb +33 -5
- data/lib/solargraph/rbs_map.rb +77 -32
- data/lib/solargraph/server_methods.rb +16 -16
- data/lib/solargraph/shell.rb +128 -73
- data/lib/solargraph/source/chain/array.rb +39 -37
- data/lib/solargraph/source/chain/call.rb +96 -56
- data/lib/solargraph/source/chain/class_variable.rb +13 -13
- data/lib/solargraph/source/chain/constant.rb +5 -1
- data/lib/solargraph/source/chain/global_variable.rb +13 -13
- data/lib/solargraph/source/chain/hash.rb +8 -5
- data/lib/solargraph/source/chain/if.rb +12 -10
- data/lib/solargraph/source/chain/instance_variable.rb +24 -1
- data/lib/solargraph/source/chain/link.rb +99 -109
- data/lib/solargraph/source/chain/literal.rb +9 -6
- data/lib/solargraph/source/chain/or.rb +10 -4
- data/lib/solargraph/source/chain/q_call.rb +13 -11
- data/lib/solargraph/source/chain/variable.rb +15 -13
- data/lib/solargraph/source/chain/z_super.rb +28 -30
- data/lib/solargraph/source/chain.rb +49 -38
- data/lib/solargraph/source/change.rb +12 -5
- data/lib/solargraph/source/cursor.rb +23 -17
- data/lib/solargraph/source/encoding_fixes.rb +6 -7
- data/lib/solargraph/source/source_chainer.rb +56 -32
- data/lib/solargraph/source/updater.rb +5 -1
- data/lib/solargraph/source.rb +59 -35
- data/lib/solargraph/source_map/clip.rb +48 -29
- data/lib/solargraph/source_map/data.rb +4 -1
- data/lib/solargraph/source_map/mapper.rb +71 -42
- data/lib/solargraph/source_map.rb +21 -9
- data/lib/solargraph/type_checker/problem.rb +3 -1
- data/lib/solargraph/type_checker/rules.rb +81 -8
- data/lib/solargraph/type_checker.rb +195 -120
- data/lib/solargraph/version.rb +1 -1
- data/lib/solargraph/workspace/config.rb +13 -10
- data/lib/solargraph/workspace/gemspecs.rb +367 -0
- data/lib/solargraph/workspace/require_paths.rb +1 -0
- data/lib/solargraph/workspace.rb +149 -30
- data/lib/solargraph/yard_map/helpers.rb +8 -3
- data/lib/solargraph/yard_map/mapper/to_method.rb +13 -7
- data/lib/solargraph/yard_map/mapper/to_namespace.rb +2 -1
- data/lib/solargraph/yard_map/mapper.rb +13 -8
- data/lib/solargraph/yard_tags.rb +20 -20
- data/lib/solargraph/yardoc.rb +33 -23
- data/lib/solargraph.rb +29 -8
- data/rbs/fills/rubygems/0/dependency.rbs +193 -0
- data/rbs/fills/tuple/tuple.rbs +28 -0
- data/rbs/shims/ast/0/node.rbs +1 -1
- data/rbs/shims/diff-lcs/1.5/diff-lcs.rbs +11 -0
- data/solargraph.gemspec +36 -34
- metadata +38 -33
- data/lib/solargraph/type_checker/checks.rb +0 -124
- data/lib/solargraph/type_checker/param_def.rb +0 -37
- data/lib/solargraph/yard_map/to_method.rb +0 -89
|
@@ -9,7 +9,7 @@ module Solargraph
|
|
|
9
9
|
|
|
10
10
|
def process
|
|
11
11
|
loc = get_node_location(node)
|
|
12
|
-
|
|
12
|
+
ivars.push Solargraph::Pin::InstanceVariable.new(
|
|
13
13
|
location: loc,
|
|
14
14
|
closure: region.closure,
|
|
15
15
|
name: node.children[0].to_s,
|
|
@@ -19,11 +19,13 @@ module Solargraph
|
|
|
19
19
|
)
|
|
20
20
|
if region.visibility == :module_function
|
|
21
21
|
here = get_node_start_position(node)
|
|
22
|
+
# @type [Pin::Closure, nil]
|
|
22
23
|
named_path = named_path_pin(here)
|
|
23
24
|
if named_path.is_a?(Pin::Method)
|
|
24
|
-
|
|
25
|
+
ivars.push Solargraph::Pin::InstanceVariable.new(
|
|
25
26
|
location: loc,
|
|
26
|
-
closure: Pin::Namespace.new(type: :module, closure: region.closure.closure,
|
|
27
|
+
closure: Pin::Namespace.new(type: :module, closure: region.closure.closure,
|
|
28
|
+
name: region.closure.name),
|
|
27
29
|
name: node.children[0].to_s,
|
|
28
30
|
comments: comments_for(node),
|
|
29
31
|
assignment: node.children[1],
|
|
@@ -9,6 +9,7 @@ module Solargraph
|
|
|
9
9
|
|
|
10
10
|
def process
|
|
11
11
|
here = get_node_start_position(node)
|
|
12
|
+
# @sg-ignore Need to add nil check here
|
|
12
13
|
presence = Range.new(here, region.closure.location.range.ending)
|
|
13
14
|
loc = get_node_location(node)
|
|
14
15
|
locals.push Solargraph::Pin::LocalVariable.new(
|
|
@@ -37,8 +37,10 @@ module Solargraph
|
|
|
37
37
|
pin = if lhs.type == :lvasgn
|
|
38
38
|
# lvasgn is a local variable
|
|
39
39
|
locals.find { |l| l.location == location }
|
|
40
|
+
elsif lhs.type == :ivasgn
|
|
41
|
+
# ivasgn is an instance variable assignment
|
|
42
|
+
ivars.find { |iv| iv.location == location }
|
|
40
43
|
else
|
|
41
|
-
# e.g., ivasgn is an instance variable, etc
|
|
42
44
|
pins.find { |iv| iv.location == location && iv.is_a?(Pin::BaseVariable) }
|
|
43
45
|
end
|
|
44
46
|
# @todo in line below, nothing in typechecking alerts
|
|
@@ -57,7 +57,7 @@ module Solargraph
|
|
|
57
57
|
[callee,
|
|
58
58
|
asgn_method,
|
|
59
59
|
node.updated(:send, [call, operator, argument])])
|
|
60
|
-
NodeProcessor.process(new_send, region, pins, locals)
|
|
60
|
+
NodeProcessor.process(new_send, region, pins, locals, ivars)
|
|
61
61
|
end
|
|
62
62
|
|
|
63
63
|
# @param asgn [Parser::AST::Node] the target of the assignment
|
|
@@ -88,8 +88,8 @@ module Solargraph
|
|
|
88
88
|
argument
|
|
89
89
|
]
|
|
90
90
|
send_node = node.updated(:send, send_children)
|
|
91
|
-
new_asgn = node.updated(asgn.type, [variable_name,
|
|
92
|
-
NodeProcessor.process(new_asgn, region, pins, locals)
|
|
91
|
+
new_asgn = node.updated(asgn.type, [variable_name, send_node])
|
|
92
|
+
NodeProcessor.process(new_asgn, region, pins, locals, ivars)
|
|
93
93
|
end
|
|
94
94
|
end
|
|
95
95
|
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Solargraph
|
|
4
|
+
module Parser
|
|
5
|
+
module ParserGem
|
|
6
|
+
module NodeProcessors
|
|
7
|
+
class OrNode < Parser::NodeProcessor::Base
|
|
8
|
+
include ParserGem::NodeMethods
|
|
9
|
+
|
|
10
|
+
def process
|
|
11
|
+
process_children
|
|
12
|
+
|
|
13
|
+
FlowSensitiveTyping.new(locals,
|
|
14
|
+
ivars,
|
|
15
|
+
enclosing_breakable_pin,
|
|
16
|
+
enclosing_compound_statement_pin).process_or(node)
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -8,7 +8,7 @@ module Solargraph
|
|
|
8
8
|
# @return [void]
|
|
9
9
|
def process
|
|
10
10
|
new_node = node.updated(node.children[0].type, node.children[0].children + [node.children[1]])
|
|
11
|
-
NodeProcessor.process(new_node, region, pins, locals)
|
|
11
|
+
NodeProcessor.process(new_node, region, pins, locals, ivars)
|
|
12
12
|
end
|
|
13
13
|
end
|
|
14
14
|
end
|
|
@@ -11,6 +11,7 @@ module Solargraph
|
|
|
11
11
|
def process
|
|
12
12
|
if node.children[1] # Exception local variable name
|
|
13
13
|
here = get_node_start_position(node.children[1])
|
|
14
|
+
# @sg-ignore Need to add nil check here
|
|
14
15
|
presence = Range.new(here, region.closure.location.range.ending)
|
|
15
16
|
loc = get_node_location(node.children[1])
|
|
16
17
|
types = if node.children[0].nil?
|
|
@@ -29,7 +30,7 @@ module Solargraph
|
|
|
29
30
|
source: :parser
|
|
30
31
|
)
|
|
31
32
|
end
|
|
32
|
-
NodeProcessor.process(node.children[2], region, pins, locals)
|
|
33
|
+
NodeProcessor.process(node.children[2], region, pins, locals, ivars)
|
|
33
34
|
end
|
|
34
35
|
end
|
|
35
36
|
end
|
|
@@ -5,6 +5,7 @@ module Solargraph
|
|
|
5
5
|
module ParserGem
|
|
6
6
|
module NodeProcessors
|
|
7
7
|
class SclassNode < Parser::NodeProcessor::Base
|
|
8
|
+
# @sg-ignore @override is adding, not overriding
|
|
8
9
|
def process
|
|
9
10
|
sclass = node.children[0]
|
|
10
11
|
# @todo Changing Parser::AST::Node to AST::Node below will
|
|
@@ -23,16 +24,14 @@ module Solargraph
|
|
|
23
24
|
if sclass.children[0].nil? && names.last != sclass.children[1].to_s
|
|
24
25
|
names << sclass.children[1].to_s
|
|
25
26
|
else
|
|
26
|
-
names.
|
|
27
|
+
names.push NodeMethods.unpack_name(sclass.children[0]), sclass.children[1].to_s
|
|
27
28
|
end
|
|
28
29
|
name = names.reject(&:empty?).join('::')
|
|
29
30
|
closure = Solargraph::Pin::Namespace.new(name: name, location: region.closure.location, source: :parser)
|
|
30
31
|
elsif sclass.is_a?(::Parser::AST::Node) && sclass.type == :const
|
|
31
32
|
names = [region.closure.namespace, region.closure.name]
|
|
32
33
|
also = NodeMethods.unpack_name(sclass)
|
|
33
|
-
if also != region.closure.name
|
|
34
|
-
names << also
|
|
35
|
-
end
|
|
34
|
+
names << also if also != region.closure.name
|
|
36
35
|
name = names.reject(&:empty?).join('::')
|
|
37
36
|
closure = Solargraph::Pin::Namespace.new(name: name, location: region.closure.location, source: :parser)
|
|
38
37
|
else
|
|
@@ -41,7 +40,7 @@ module Solargraph
|
|
|
41
40
|
pins.push Solargraph::Pin::Singleton.new(
|
|
42
41
|
location: get_node_location(node),
|
|
43
42
|
closure: closure,
|
|
44
|
-
source: :parser
|
|
43
|
+
source: :parser
|
|
45
44
|
)
|
|
46
45
|
process_children region.update(visibility: :public, scope: :class, closure: pins.last)
|
|
47
46
|
end
|
|
@@ -7,22 +7,24 @@ module Solargraph
|
|
|
7
7
|
class SendNode < Parser::NodeProcessor::Base
|
|
8
8
|
include ParserGem::NodeMethods
|
|
9
9
|
|
|
10
|
+
# @sg-ignore @override is adding, not overriding
|
|
10
11
|
def process
|
|
11
12
|
# @sg-ignore Variable type could not be inferred for method_name
|
|
12
13
|
# @type [Symbol]
|
|
13
14
|
method_name = node.children[1]
|
|
14
15
|
# :nocov:
|
|
15
16
|
unless method_name.instance_of?(Symbol)
|
|
16
|
-
Solargraph.assert_or_log(:parser_method_name,
|
|
17
|
+
Solargraph.assert_or_log(:parser_method_name,
|
|
18
|
+
"Expected method name to be a Symbol, got #{method_name.class} for node #{node.inspect}")
|
|
17
19
|
return process_children
|
|
18
20
|
end
|
|
19
21
|
# :nocov:
|
|
20
22
|
if node.children[0].nil?
|
|
21
|
-
if [
|
|
23
|
+
if %i[private public protected].include?(method_name)
|
|
22
24
|
process_visibility
|
|
23
25
|
elsif method_name == :module_function
|
|
24
26
|
process_module_function
|
|
25
|
-
elsif [
|
|
27
|
+
elsif %i[attr_reader attr_writer attr_accessor].include?(method_name)
|
|
26
28
|
process_attribute
|
|
27
29
|
elsif method_name == :include
|
|
28
30
|
process_include
|
|
@@ -43,7 +45,10 @@ module Solargraph
|
|
|
43
45
|
return if process_private_class_method
|
|
44
46
|
end
|
|
45
47
|
elsif method_name == :require && node.children[0].to_s == '(const nil :Bundler)'
|
|
46
|
-
pins.push Pin::Reference::Require.new(
|
|
48
|
+
pins.push Pin::Reference::Require.new(
|
|
49
|
+
Solargraph::Location.new(region.filename,
|
|
50
|
+
Solargraph::Range.from_to(0, 0, 0, 0)), 'bundler/require', source: :parser
|
|
51
|
+
)
|
|
47
52
|
end
|
|
48
53
|
process_children
|
|
49
54
|
end
|
|
@@ -52,20 +57,22 @@ module Solargraph
|
|
|
52
57
|
|
|
53
58
|
# @return [void]
|
|
54
59
|
def process_visibility
|
|
55
|
-
if
|
|
56
|
-
|
|
60
|
+
if node.children.length > 2
|
|
61
|
+
# @sg-ignore Need to add nil check here
|
|
62
|
+
node.children[2..].each do |child|
|
|
57
63
|
# @sg-ignore Variable type could not be inferred for method_name
|
|
58
64
|
# @type [Symbol]
|
|
59
65
|
visibility = node.children[1]
|
|
60
66
|
# :nocov:
|
|
61
67
|
unless visibility.instance_of?(Symbol)
|
|
62
|
-
Solargraph.assert_or_log(:parser_visibility,
|
|
68
|
+
Solargraph.assert_or_log(:parser_visibility,
|
|
69
|
+
"Expected visibility name to be a Symbol, got #{visibility.class} for node #{node.inspect}")
|
|
63
70
|
return process_children
|
|
64
71
|
end
|
|
65
72
|
# :nocov:
|
|
66
|
-
if child.is_a?(::Parser::AST::Node) &&
|
|
73
|
+
if child.is_a?(::Parser::AST::Node) && %i[sym str].include?(child.type)
|
|
67
74
|
name = child.children[0].to_s
|
|
68
|
-
matches = pins.select{ |pin| pin.is_a?(Pin::Method) && pin.name == name && pin.namespace == region.closure.full_context.namespace && pin.context.scope == (region.scope || :instance)}
|
|
75
|
+
matches = pins.select { |pin| pin.is_a?(Pin::Method) && pin.name == name && pin.namespace == region.closure.full_context.namespace && pin.context.scope == (region.scope || :instance) }
|
|
69
76
|
matches.each do |pin|
|
|
70
77
|
# @todo Smelly instance variable access
|
|
71
78
|
pin.instance_variable_set(:@visibility, visibility)
|
|
@@ -82,11 +89,12 @@ module Solargraph
|
|
|
82
89
|
|
|
83
90
|
# @return [void]
|
|
84
91
|
def process_attribute
|
|
85
|
-
|
|
92
|
+
# @sg-ignore Need to add nil check here
|
|
93
|
+
node.children[2..].each do |a|
|
|
86
94
|
loc = get_node_location(node)
|
|
87
95
|
clos = region.closure
|
|
88
96
|
cmnt = comments_for(node)
|
|
89
|
-
if
|
|
97
|
+
if %i[attr_reader attr_accessor].include?(node.children[1])
|
|
90
98
|
pins.push Solargraph::Pin::Method.new(
|
|
91
99
|
location: loc,
|
|
92
100
|
closure: clos,
|
|
@@ -98,60 +106,62 @@ module Solargraph
|
|
|
98
106
|
source: :parser
|
|
99
107
|
)
|
|
100
108
|
end
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
109
|
+
next unless %i[attr_writer attr_accessor].include?(node.children[1])
|
|
110
|
+
method_pin = Solargraph::Pin::Method.new(
|
|
111
|
+
location: loc,
|
|
112
|
+
closure: clos,
|
|
113
|
+
name: "#{a.children[0]}=",
|
|
114
|
+
comments: cmnt,
|
|
115
|
+
scope: region.scope || :instance,
|
|
116
|
+
visibility: region.visibility,
|
|
117
|
+
attribute: true,
|
|
118
|
+
source: :parser
|
|
119
|
+
)
|
|
120
|
+
pins.push method_pin
|
|
121
|
+
method_pin.parameters.push Pin::Parameter.new(name: 'value', decl: :arg, closure: pins.last,
|
|
122
|
+
source: :parser)
|
|
123
|
+
if method_pin.return_type.defined?
|
|
124
|
+
pins.last.docstring.add_tag YARD::Tags::Tag.new(:param, '',
|
|
125
|
+
pins.last.return_type.items.map(&:rooted_tags), 'value')
|
|
117
126
|
end
|
|
118
127
|
end
|
|
119
128
|
end
|
|
120
129
|
|
|
121
130
|
# @return [void]
|
|
122
131
|
def process_include
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
132
|
+
return unless node.children[2].is_a?(AST::Node) && node.children[2].type == :const
|
|
133
|
+
cp = region.closure
|
|
134
|
+
# @sg-ignore Need to add nil check here
|
|
135
|
+
node.children[2..].each do |i|
|
|
136
|
+
type = region.scope == :class ? Pin::Reference::Extend : Pin::Reference::Include
|
|
137
|
+
pins.push type.new(
|
|
138
|
+
location: get_node_location(i),
|
|
139
|
+
closure: cp,
|
|
140
|
+
name: unpack_name(i),
|
|
141
|
+
source: :parser
|
|
142
|
+
)
|
|
134
143
|
end
|
|
135
144
|
end
|
|
136
145
|
|
|
137
146
|
# @return [void]
|
|
138
147
|
def process_prepend
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
148
|
+
return unless node.children[2].is_a?(AST::Node) && node.children[2].type == :const
|
|
149
|
+
cp = region.closure
|
|
150
|
+
# @sg-ignore Need to add nil check here
|
|
151
|
+
node.children[2..].each do |i|
|
|
152
|
+
pins.push Pin::Reference::Prepend.new(
|
|
153
|
+
location: get_node_location(i),
|
|
154
|
+
closure: cp,
|
|
155
|
+
name: unpack_name(i),
|
|
156
|
+
source: :parser
|
|
157
|
+
)
|
|
149
158
|
end
|
|
150
159
|
end
|
|
151
160
|
|
|
152
161
|
# @return [void]
|
|
153
162
|
def process_extend
|
|
154
|
-
|
|
163
|
+
# @sg-ignore Need to add nil check here
|
|
164
|
+
node.children[2..].each do |i|
|
|
155
165
|
loc = get_node_location(node)
|
|
156
166
|
if i.type == :self
|
|
157
167
|
pins.push Pin::Reference::Extend.new(
|
|
@@ -173,18 +183,16 @@ module Solargraph
|
|
|
173
183
|
|
|
174
184
|
# @return [void]
|
|
175
185
|
def process_require
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
end
|
|
186
|
+
return unless node.children[2].is_a?(AST::Node) && node.children[2].type == :str
|
|
187
|
+
path = node.children[2].children[0].to_s
|
|
188
|
+
pins.push Pin::Reference::Require.new(get_node_location(node), path, source: :parser)
|
|
180
189
|
end
|
|
181
190
|
|
|
182
191
|
# @return [void]
|
|
183
192
|
def process_autoload
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
end
|
|
193
|
+
return unless node.children[3].is_a?(AST::Node) && node.children[3].type == :str
|
|
194
|
+
path = node.children[3].children[0].to_s
|
|
195
|
+
pins.push Pin::Reference::Require.new(get_node_location(node), path, source: :parser)
|
|
188
196
|
end
|
|
189
197
|
|
|
190
198
|
# @return [void]
|
|
@@ -192,76 +200,77 @@ module Solargraph
|
|
|
192
200
|
if node.children[2].nil?
|
|
193
201
|
# @todo Smelly instance variable access
|
|
194
202
|
region.instance_variable_set(:@visibility, :module_function)
|
|
195
|
-
elsif
|
|
196
|
-
|
|
203
|
+
elsif %i[sym str].include?(node.children[2].type)
|
|
204
|
+
# @sg-ignore Need to add nil check here
|
|
205
|
+
node.children[2..].each do |x|
|
|
197
206
|
cn = x.children[0].to_s
|
|
198
207
|
# @type [Pin::Method, nil]
|
|
199
208
|
ref = pins.find { |p| p.is_a?(Pin::Method) && p.namespace == region.closure.full_context.namespace && p.name == cn }
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
209
|
+
next if ref.nil?
|
|
210
|
+
pins.delete ref
|
|
211
|
+
mm = Solargraph::Pin::Method.new(
|
|
212
|
+
location: ref.location,
|
|
213
|
+
closure: ref.closure,
|
|
214
|
+
name: ref.name,
|
|
215
|
+
parameters: ref.parameters,
|
|
216
|
+
comments: ref.comments,
|
|
217
|
+
scope: :class,
|
|
218
|
+
visibility: :public,
|
|
219
|
+
node: ref.node,
|
|
220
|
+
source: :parser
|
|
221
|
+
)
|
|
222
|
+
cm = Solargraph::Pin::Method.new(
|
|
223
|
+
location: ref.location,
|
|
224
|
+
closure: ref.closure,
|
|
225
|
+
name: ref.name,
|
|
226
|
+
parameters: ref.parameters,
|
|
227
|
+
comments: ref.comments,
|
|
228
|
+
scope: :instance,
|
|
229
|
+
visibility: :private,
|
|
230
|
+
node: ref.node,
|
|
231
|
+
source: :parser
|
|
232
|
+
)
|
|
233
|
+
pins.push mm, cm
|
|
234
|
+
ivars.select { |pin| pin.is_a?(Pin::InstanceVariable) && pin.closure.path == ref.path }.each do |ivar|
|
|
235
|
+
ivars.delete ivar
|
|
236
|
+
ivars.push Solargraph::Pin::InstanceVariable.new(
|
|
237
|
+
location: ivar.location,
|
|
238
|
+
closure: cm,
|
|
239
|
+
name: ivar.name,
|
|
240
|
+
comments: ivar.comments,
|
|
241
|
+
assignment: ivar.assignment,
|
|
242
|
+
source: :parser
|
|
243
|
+
)
|
|
244
|
+
ivars.push Solargraph::Pin::InstanceVariable.new(
|
|
245
|
+
location: ivar.location,
|
|
246
|
+
closure: mm,
|
|
247
|
+
name: ivar.name,
|
|
248
|
+
comments: ivar.comments,
|
|
249
|
+
assignment: ivar.assignment,
|
|
211
250
|
source: :parser
|
|
212
251
|
)
|
|
213
|
-
cm = Solargraph::Pin::Method.new(
|
|
214
|
-
location: ref.location,
|
|
215
|
-
closure: ref.closure,
|
|
216
|
-
name: ref.name,
|
|
217
|
-
parameters: ref.parameters,
|
|
218
|
-
comments: ref.comments,
|
|
219
|
-
scope: :instance,
|
|
220
|
-
visibility: :private,
|
|
221
|
-
node: ref.node,
|
|
222
|
-
source: :parser)
|
|
223
|
-
pins.push mm, cm
|
|
224
|
-
pins.select{|pin| pin.is_a?(Pin::InstanceVariable) && pin.closure.path == ref.path}.each do |ivar|
|
|
225
|
-
pins.delete ivar
|
|
226
|
-
pins.push Solargraph::Pin::InstanceVariable.new(
|
|
227
|
-
location: ivar.location,
|
|
228
|
-
closure: cm,
|
|
229
|
-
name: ivar.name,
|
|
230
|
-
comments: ivar.comments,
|
|
231
|
-
# @sg-ignore https://github.com/castwide/solargraph/pull/1114
|
|
232
|
-
assignment: ivar.assignment,
|
|
233
|
-
source: :parser
|
|
234
|
-
)
|
|
235
|
-
pins.push Solargraph::Pin::InstanceVariable.new(
|
|
236
|
-
location: ivar.location,
|
|
237
|
-
closure: mm,
|
|
238
|
-
name: ivar.name,
|
|
239
|
-
comments: ivar.comments,
|
|
240
|
-
# @sg-ignore https://github.com/castwide/solargraph/pull/1114
|
|
241
|
-
assignment: ivar.assignment,
|
|
242
|
-
source: :parser
|
|
243
|
-
)
|
|
244
|
-
end
|
|
245
252
|
end
|
|
246
253
|
end
|
|
247
254
|
elsif node.children[2].type == :def
|
|
248
|
-
NodeProcessor.process node.children[2], region.update(visibility: :module_function), pins, locals
|
|
255
|
+
NodeProcessor.process node.children[2], region.update(visibility: :module_function), pins, locals, ivars
|
|
249
256
|
end
|
|
250
257
|
end
|
|
251
258
|
|
|
252
259
|
# @return [void]
|
|
253
260
|
def process_private_constant
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
end
|
|
261
|
+
return unless node.children[2] && %i[sym str].include?(node.children[2].type)
|
|
262
|
+
cn = node.children[2].children[0].to_s
|
|
263
|
+
ref = pins.select do |p|
|
|
264
|
+
[Solargraph::Pin::Namespace,
|
|
265
|
+
Solargraph::Pin::Constant].include?(p.class) && p.namespace == region.closure.full_context.namespace && p.name == cn
|
|
266
|
+
end.first
|
|
267
|
+
# HACK: Smelly instance variable access
|
|
268
|
+
ref&.instance_variable_set(:@visibility, :private)
|
|
260
269
|
end
|
|
261
270
|
|
|
262
271
|
# @return [void]
|
|
263
272
|
def process_alias_method
|
|
264
|
-
|
|
273
|
+
get_node_location(node)
|
|
265
274
|
pins.push Solargraph::Pin::MethodAlias.new(
|
|
266
275
|
location: get_node_location(node),
|
|
267
276
|
closure: region.closure,
|
|
@@ -274,10 +283,12 @@ module Solargraph
|
|
|
274
283
|
|
|
275
284
|
# @return [Boolean]
|
|
276
285
|
def process_private_class_method
|
|
277
|
-
if
|
|
278
|
-
ref = pins.select
|
|
286
|
+
if %i[sym str].include?(node.children[2].type)
|
|
287
|
+
ref = pins.select do |p|
|
|
288
|
+
p.is_a?(Pin::Method) && p.namespace == region.closure.full_context.namespace && p.name == node.children[2].children[0].to_s
|
|
289
|
+
end.first
|
|
279
290
|
# HACK: Smelly instance variable access
|
|
280
|
-
ref
|
|
291
|
+
ref&.instance_variable_set(:@visibility, :private)
|
|
281
292
|
false
|
|
282
293
|
else
|
|
283
294
|
process_children region.update(scope: :class, visibility: :private)
|
|
@@ -1,29 +1,29 @@
|
|
|
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
|
-
source: :parser
|
|
22
|
-
)
|
|
23
|
-
process_children region
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
end
|
|
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
|
+
source: :parser
|
|
22
|
+
)
|
|
23
|
+
process_children region
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Solargraph
|
|
4
|
+
module Parser
|
|
5
|
+
module ParserGem
|
|
6
|
+
module NodeProcessors
|
|
7
|
+
class WhenNode < Parser::NodeProcessor::Base
|
|
8
|
+
include ParserGem::NodeMethods
|
|
9
|
+
|
|
10
|
+
def process
|
|
11
|
+
pins.push Solargraph::Pin::CompoundStatement.new(
|
|
12
|
+
location: get_node_location(node),
|
|
13
|
+
closure: region.closure,
|
|
14
|
+
node: node,
|
|
15
|
+
source: :parser
|
|
16
|
+
)
|
|
17
|
+
process_children
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -8,7 +8,11 @@ module Solargraph
|
|
|
8
8
|
include ParserGem::NodeMethods
|
|
9
9
|
|
|
10
10
|
def process
|
|
11
|
-
|
|
11
|
+
FlowSensitiveTyping.new(locals,
|
|
12
|
+
ivars,
|
|
13
|
+
enclosing_breakable_pin,
|
|
14
|
+
enclosing_compound_statement_pin).process_while(node)
|
|
15
|
+
|
|
12
16
|
# Note - this should not be considered a block, as the
|
|
13
17
|
# while statement doesn't create a closure - e.g.,
|
|
14
18
|
# variables created inside can be seen from outside as
|
|
@@ -18,7 +22,7 @@ module Solargraph
|
|
|
18
22
|
closure: region.closure,
|
|
19
23
|
node: node,
|
|
20
24
|
comments: comments_for(node),
|
|
21
|
-
source: :parser
|
|
25
|
+
source: :parser
|
|
22
26
|
)
|
|
23
27
|
process_children region
|
|
24
28
|
end
|
|
@@ -27,8 +27,10 @@ module Solargraph
|
|
|
27
27
|
autoload :SymNode, 'solargraph/parser/parser_gem/node_processors/sym_node'
|
|
28
28
|
autoload :ResbodyNode, 'solargraph/parser/parser_gem/node_processors/resbody_node'
|
|
29
29
|
autoload :UntilNode, 'solargraph/parser/parser_gem/node_processors/until_node'
|
|
30
|
+
autoload :WhenNode, 'solargraph/parser/parser_gem/node_processors/when_node'
|
|
30
31
|
autoload :WhileNode, 'solargraph/parser/parser_gem/node_processors/while_node'
|
|
31
32
|
autoload :AndNode, 'solargraph/parser/parser_gem/node_processors/and_node'
|
|
33
|
+
autoload :OrNode, 'solargraph/parser/parser_gem/node_processors/or_node'
|
|
32
34
|
end
|
|
33
35
|
end
|
|
34
36
|
|
|
@@ -63,8 +65,10 @@ module Solargraph
|
|
|
63
65
|
register :op_asgn, ParserGem::NodeProcessors::OpasgnNode
|
|
64
66
|
register :sym, ParserGem::NodeProcessors::SymNode
|
|
65
67
|
register :until, ParserGem::NodeProcessors::UntilNode
|
|
68
|
+
register :when, ParserGem::NodeProcessors::WhenNode
|
|
66
69
|
register :while, ParserGem::NodeProcessors::WhileNode
|
|
67
70
|
register :and, ParserGem::NodeProcessors::AndNode
|
|
71
|
+
register :or, ParserGem::NodeProcessors::OrNode
|
|
68
72
|
end
|
|
69
73
|
end
|
|
70
74
|
end
|