solargraph 0.54.4 → 0.57.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/linting.yml +125 -0
- data/.github/workflows/plugins.yml +149 -5
- data/.github/workflows/rspec.yml +39 -4
- data/.github/workflows/typecheck.yml +8 -3
- data/.gitignore +7 -0
- data/.overcommit.yml +72 -0
- data/.rspec +1 -0
- data/.rubocop.yml +66 -0
- data/.rubocop_todo.yml +2627 -0
- data/.yardopts +1 -0
- data/CHANGELOG.md +104 -0
- data/README.md +20 -6
- data/Rakefile +125 -13
- data/lib/solargraph/api_map/cache.rb +3 -2
- data/lib/solargraph/api_map/constants.rb +218 -0
- data/lib/solargraph/api_map/index.rb +44 -42
- data/lib/solargraph/api_map/source_to_yard.rb +10 -4
- data/lib/solargraph/api_map/store.rb +165 -32
- data/lib/solargraph/api_map.rb +319 -243
- data/lib/solargraph/bench.rb +18 -1
- data/lib/solargraph/complex_type/type_methods.rb +7 -1
- data/lib/solargraph/complex_type/unique_type.rb +105 -16
- data/lib/solargraph/complex_type.rb +40 -7
- data/lib/solargraph/convention/active_support_concern.rb +111 -0
- data/lib/solargraph/convention/base.rb +20 -3
- data/lib/solargraph/convention/data_definition/data_assignment_node.rb +61 -0
- data/lib/solargraph/convention/data_definition/data_definition_node.rb +91 -0
- data/lib/solargraph/convention/data_definition.rb +105 -0
- data/lib/solargraph/convention/gemspec.rb +3 -2
- data/lib/solargraph/convention/struct_definition/struct_assignment_node.rb +61 -0
- data/lib/solargraph/convention/struct_definition/struct_definition_node.rb +102 -0
- data/lib/solargraph/convention/struct_definition.rb +164 -0
- data/lib/solargraph/convention.rb +35 -4
- data/lib/solargraph/diagnostics/rubocop.rb +6 -1
- data/lib/solargraph/diagnostics/rubocop_helpers.rb +1 -1
- data/lib/solargraph/doc_map.rb +313 -65
- data/lib/solargraph/environ.rb +9 -2
- data/lib/solargraph/gem_pins.rb +60 -38
- data/lib/solargraph/language_server/host/dispatch.rb +2 -0
- data/lib/solargraph/language_server/host/message_worker.rb +13 -7
- data/lib/solargraph/language_server/host.rb +14 -3
- data/lib/solargraph/language_server/message/base.rb +2 -1
- data/lib/solargraph/language_server/message/extended/check_gem_version.rb +2 -0
- data/lib/solargraph/language_server/message/extended/document.rb +5 -2
- data/lib/solargraph/language_server/message/extended/document_gems.rb +3 -3
- data/lib/solargraph/language_server/message/text_document/definition.rb +2 -0
- data/lib/solargraph/language_server/message/text_document/formatting.rb +16 -2
- data/lib/solargraph/language_server/message/text_document/type_definition.rb +1 -0
- data/lib/solargraph/language_server/message/workspace/did_change_workspace_folders.rb +2 -0
- data/lib/solargraph/language_server/progress.rb +8 -0
- data/lib/solargraph/language_server/request.rb +1 -0
- data/lib/solargraph/library.rb +53 -32
- data/lib/solargraph/location.rb +23 -0
- data/lib/solargraph/logging.rb +12 -2
- data/lib/solargraph/page.rb +4 -0
- data/lib/solargraph/parser/comment_ripper.rb +20 -7
- data/lib/solargraph/parser/flow_sensitive_typing.rb +255 -0
- data/lib/solargraph/parser/node_methods.rb +16 -2
- data/lib/solargraph/parser/node_processor/base.rb +10 -5
- data/lib/solargraph/parser/node_processor.rb +26 -9
- data/lib/solargraph/parser/parser_gem/class_methods.rb +17 -15
- data/lib/solargraph/parser/parser_gem/flawed_builder.rb +1 -0
- data/lib/solargraph/parser/parser_gem/node_chainer.rb +13 -11
- data/lib/solargraph/parser/parser_gem/node_methods.rb +8 -4
- data/lib/solargraph/parser/parser_gem/node_processors/alias_node.rb +2 -1
- data/lib/solargraph/parser/parser_gem/node_processors/and_node.rb +21 -0
- data/lib/solargraph/parser/parser_gem/node_processors/args_node.rb +4 -2
- data/lib/solargraph/parser/parser_gem/node_processors/block_node.rb +7 -4
- data/lib/solargraph/parser/parser_gem/node_processors/casgn_node.rb +2 -1
- data/lib/solargraph/parser/parser_gem/node_processors/cvasgn_node.rb +2 -1
- data/lib/solargraph/parser/parser_gem/node_processors/def_node.rb +6 -3
- data/lib/solargraph/parser/parser_gem/node_processors/defs_node.rb +2 -1
- data/lib/solargraph/parser/parser_gem/node_processors/gvasgn_node.rb +2 -1
- data/lib/solargraph/parser/parser_gem/node_processors/if_node.rb +23 -0
- data/lib/solargraph/parser/parser_gem/node_processors/ivasgn_node.rb +4 -2
- data/lib/solargraph/parser/parser_gem/node_processors/lvasgn_node.rb +2 -1
- data/lib/solargraph/parser/parser_gem/node_processors/masgn_node.rb +7 -1
- data/lib/solargraph/parser/parser_gem/node_processors/namespace_node.rb +8 -7
- data/lib/solargraph/parser/parser_gem/node_processors/opasgn_node.rb +42 -0
- data/lib/solargraph/parser/parser_gem/node_processors/orasgn_node.rb +1 -0
- data/lib/solargraph/parser/parser_gem/node_processors/resbody_node.rb +3 -1
- data/lib/solargraph/parser/parser_gem/node_processors/sclass_node.rb +4 -3
- data/lib/solargraph/parser/parser_gem/node_processors/send_node.rb +63 -30
- data/lib/solargraph/parser/parser_gem/node_processors/sym_node.rb +3 -1
- data/lib/solargraph/parser/parser_gem/node_processors/until_node.rb +29 -0
- data/lib/solargraph/parser/parser_gem/node_processors/while_node.rb +29 -0
- data/lib/solargraph/parser/parser_gem/node_processors.rb +14 -0
- data/lib/solargraph/parser/region.rb +4 -1
- data/lib/solargraph/parser/snippet.rb +2 -0
- data/lib/solargraph/parser.rb +1 -0
- data/lib/solargraph/pin/base.rb +360 -30
- data/lib/solargraph/pin/base_variable.rb +16 -10
- data/lib/solargraph/pin/block.rb +2 -0
- data/lib/solargraph/pin/breakable.rb +9 -0
- data/lib/solargraph/pin/callable.rb +83 -3
- data/lib/solargraph/pin/closure.rb +20 -1
- data/lib/solargraph/pin/common.rb +10 -1
- data/lib/solargraph/pin/constant.rb +2 -0
- data/lib/solargraph/pin/delegated_method.rb +21 -1
- data/lib/solargraph/pin/documenting.rb +16 -0
- data/lib/solargraph/pin/keyword.rb +7 -2
- data/lib/solargraph/pin/local_variable.rb +18 -6
- data/lib/solargraph/pin/method.rb +175 -46
- data/lib/solargraph/pin/method_alias.rb +3 -0
- data/lib/solargraph/pin/namespace.rb +17 -9
- data/lib/solargraph/pin/parameter.rb +78 -19
- data/lib/solargraph/pin/proxy_type.rb +13 -6
- data/lib/solargraph/pin/reference/override.rb +24 -6
- data/lib/solargraph/pin/reference/require.rb +2 -2
- data/lib/solargraph/pin/reference/superclass.rb +5 -0
- data/lib/solargraph/pin/reference.rb +26 -0
- data/lib/solargraph/pin/search.rb +3 -1
- data/lib/solargraph/pin/signature.rb +44 -0
- data/lib/solargraph/pin/singleton.rb +1 -1
- data/lib/solargraph/pin/symbol.rb +8 -2
- data/lib/solargraph/pin/until.rb +18 -0
- data/lib/solargraph/pin/while.rb +18 -0
- data/lib/solargraph/pin.rb +4 -1
- data/lib/solargraph/pin_cache.rb +245 -0
- data/lib/solargraph/position.rb +11 -0
- data/lib/solargraph/range.rb +10 -0
- data/lib/solargraph/rbs_map/conversions.rb +226 -70
- data/lib/solargraph/rbs_map/core_fills.rb +32 -16
- data/lib/solargraph/rbs_map/core_map.rb +37 -11
- data/lib/solargraph/rbs_map/stdlib_map.rb +15 -5
- data/lib/solargraph/rbs_map.rb +88 -18
- data/lib/solargraph/shell.rb +20 -18
- data/lib/solargraph/source/chain/array.rb +11 -7
- 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 +53 -23
- data/lib/solargraph/source/chain/constant.rb +1 -1
- data/lib/solargraph/source/chain/hash.rb +4 -3
- data/lib/solargraph/source/chain/head.rb +1 -1
- data/lib/solargraph/source/chain/if.rb +1 -1
- data/lib/solargraph/source/chain/link.rb +12 -1
- data/lib/solargraph/source/chain/literal.rb +22 -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 +84 -47
- data/lib/solargraph/source/change.rb +2 -2
- data/lib/solargraph/source/cursor.rb +2 -3
- data/lib/solargraph/source/source_chainer.rb +3 -3
- data/lib/solargraph/source.rb +5 -2
- data/lib/solargraph/source_map/clip.rb +4 -2
- data/lib/solargraph/source_map/data.rb +4 -0
- data/lib/solargraph/source_map/mapper.rb +13 -7
- data/lib/solargraph/source_map.rb +21 -31
- data/lib/solargraph/type_checker/checks.rb +4 -0
- data/lib/solargraph/type_checker/param_def.rb +2 -0
- data/lib/solargraph/type_checker/rules.rb +8 -0
- data/lib/solargraph/type_checker.rb +208 -128
- data/lib/solargraph/version.rb +1 -1
- data/lib/solargraph/views/_method.erb +10 -10
- data/lib/solargraph/views/_namespace.erb +3 -3
- data/lib/solargraph/views/document.erb +10 -10
- data/lib/solargraph/workspace/config.rb +1 -3
- data/lib/solargraph/workspace/require_paths.rb +98 -0
- data/lib/solargraph/workspace.rb +38 -52
- data/lib/solargraph/yard_map/helpers.rb +29 -1
- data/lib/solargraph/yard_map/mapper/to_constant.rb +7 -5
- data/lib/solargraph/yard_map/mapper/to_method.rb +53 -18
- data/lib/solargraph/yard_map/mapper/to_namespace.rb +9 -7
- data/lib/solargraph/yard_map/mapper.rb +4 -3
- data/lib/solargraph/yard_map/to_method.rb +4 -2
- data/lib/solargraph/yardoc.rb +22 -10
- data/lib/solargraph.rb +34 -1
- data/rbs/fills/tuple.rbs +149 -0
- data/rbs_collection.yaml +19 -0
- data/sig/shims/parser/3.2.0.1/builders/default.rbs +195 -0
- data/sig/shims/thor/1.2.0.1/.rbs_meta.yaml +9 -0
- data/sig/shims/thor/1.2.0.1/manifest.yaml +7 -0
- data/sig/shims/thor/1.2.0.1/thor.rbs +17 -0
- data/solargraph.gemspec +15 -4
- metadata +157 -15
- data/lib/.rubocop.yml +0 -22
- data/lib/solargraph/cache.rb +0 -77
@@ -13,20 +13,23 @@ module Solargraph
|
|
13
13
|
Solargraph::Pin::Namespace.new(
|
14
14
|
location: location,
|
15
15
|
type: :class,
|
16
|
-
name: unpack_name(node.children[0].children[0])
|
16
|
+
name: unpack_name(node.children[0].children[0]),
|
17
|
+
source: :parser,
|
17
18
|
)
|
18
19
|
else
|
19
20
|
region.closure
|
20
21
|
end
|
21
|
-
|
22
|
+
block_pin = Solargraph::Pin::Block.new(
|
22
23
|
location: location,
|
23
24
|
closure: parent,
|
24
25
|
node: node,
|
25
26
|
receiver: node.children[0],
|
26
27
|
comments: comments_for(node),
|
27
|
-
scope: region.scope || region.closure.context.scope
|
28
|
+
scope: region.scope || region.closure.context.scope,
|
29
|
+
source: :parser
|
28
30
|
)
|
29
|
-
|
31
|
+
pins.push block_pin
|
32
|
+
process_children region.update(closure: block_pin)
|
30
33
|
end
|
31
34
|
|
32
35
|
private
|
@@ -15,7 +15,8 @@ module Solargraph
|
|
15
15
|
comments: comments_for(node),
|
16
16
|
scope: scope,
|
17
17
|
visibility: scope == :instance && name == 'initialize' ? :private : region.visibility,
|
18
|
-
node: node
|
18
|
+
node: node,
|
19
|
+
source: :parser,
|
19
20
|
)
|
20
21
|
if region.visibility == :module_function
|
21
22
|
pins.push Solargraph::Pin::Method.new(
|
@@ -26,7 +27,8 @@ module Solargraph
|
|
26
27
|
scope: :class,
|
27
28
|
visibility: :public,
|
28
29
|
parameters: methpin.parameters,
|
29
|
-
node: methpin.node
|
30
|
+
node: methpin.node,
|
31
|
+
source: :parser,
|
30
32
|
)
|
31
33
|
pins.push Solargraph::Pin::Method.new(
|
32
34
|
location: methpin.location,
|
@@ -36,7 +38,8 @@ module Solargraph
|
|
36
38
|
scope: :instance,
|
37
39
|
visibility: :private,
|
38
40
|
parameters: methpin.parameters,
|
39
|
-
node: methpin.node
|
41
|
+
node: methpin.node,
|
42
|
+
source: :parser,
|
40
43
|
)
|
41
44
|
else
|
42
45
|
pins.push methpin
|
@@ -0,0 +1,23 @@
|
|
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
|
+
# @sg-ignore
|
15
|
+
# @type [Solargraph::Pin::Breakable, nil]
|
16
|
+
enclosing_breakable_pin = pins.select{|pin| pin.is_a?(Pin::Breakable) && pin.location.range.contain?(position)}.last
|
17
|
+
FlowSensitiveTyping.new(locals, enclosing_breakable_pin).process_if(node)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -14,7 +14,8 @@ module Solargraph
|
|
14
14
|
closure: region.closure,
|
15
15
|
name: node.children[0].to_s,
|
16
16
|
comments: comments_for(node),
|
17
|
-
assignment: node.children[1]
|
17
|
+
assignment: node.children[1],
|
18
|
+
source: :parser
|
18
19
|
)
|
19
20
|
if region.visibility == :module_function
|
20
21
|
here = get_node_start_position(node)
|
@@ -25,7 +26,8 @@ module Solargraph
|
|
25
26
|
closure: Pin::Namespace.new(type: :module, closure: region.closure.closure, name: region.closure.name),
|
26
27
|
name: node.children[0].to_s,
|
27
28
|
comments: comments_for(node),
|
28
|
-
assignment: node.children[1]
|
29
|
+
assignment: node.children[1],
|
30
|
+
source: :parser
|
29
31
|
)
|
30
32
|
end
|
31
33
|
end
|
@@ -7,6 +7,7 @@ module Solargraph
|
|
7
7
|
class MasgnNode < Parser::NodeProcessor::Base
|
8
8
|
include ParserGem::NodeMethods
|
9
9
|
|
10
|
+
# @return [void]
|
10
11
|
def process
|
11
12
|
# Example:
|
12
13
|
#
|
@@ -21,8 +22,11 @@ module Solargraph
|
|
21
22
|
# s(:int, 2),
|
22
23
|
# s(:int, 3)))
|
23
24
|
masgn = node
|
25
|
+
# @type [Parser::AST::Node]
|
24
26
|
mlhs = masgn.children.fetch(0)
|
27
|
+
# @type [Array<Parser::AST::Node>]
|
25
28
|
lhs_arr = mlhs.children
|
29
|
+
# @type [Parser::AST::Node]
|
26
30
|
mass_rhs = node.children.fetch(1)
|
27
31
|
|
28
32
|
# Get pins created for the mlhs node
|
@@ -40,7 +44,9 @@ module Solargraph
|
|
40
44
|
# @todo in line below, nothing in typechecking alerts
|
41
45
|
# when a non-existant method is called on 'l'
|
42
46
|
if pin.nil?
|
43
|
-
Solargraph.logger.debug
|
47
|
+
Solargraph.logger.debug do
|
48
|
+
"Could not find local for masgn= value in location #{location.inspect} in #{lhs_arr} - masgn = #{masgn}, lhs.type = #{lhs.type}"
|
49
|
+
end
|
44
50
|
next
|
45
51
|
end
|
46
52
|
pin.mass_assignment = [mass_rhs, i]
|
@@ -8,10 +8,9 @@ module Solargraph
|
|
8
8
|
include ParserGem::NodeMethods
|
9
9
|
|
10
10
|
def process
|
11
|
-
|
12
|
-
if node.type == :class
|
13
|
-
|
14
|
-
end
|
11
|
+
superclass_name = nil
|
12
|
+
superclass_name = unpack_name(node.children[1]) if node.type == :class && node.children[1]&.type == :const
|
13
|
+
|
15
14
|
loc = get_node_location(node)
|
16
15
|
nspin = Solargraph::Pin::Namespace.new(
|
17
16
|
type: node.type,
|
@@ -20,14 +19,16 @@ module Solargraph
|
|
20
19
|
name: unpack_name(node.children[0]),
|
21
20
|
comments: comments_for(node),
|
22
21
|
visibility: :public,
|
23
|
-
gates: region.closure.gates.freeze
|
22
|
+
gates: region.closure.gates.freeze,
|
23
|
+
source: :parser
|
24
24
|
)
|
25
25
|
pins.push nspin
|
26
|
-
unless
|
26
|
+
unless superclass_name.nil?
|
27
27
|
pins.push Pin::Reference::Superclass.new(
|
28
28
|
location: loc,
|
29
29
|
closure: pins.last,
|
30
|
-
name:
|
30
|
+
name: superclass_name,
|
31
|
+
source: :parser
|
31
32
|
)
|
32
33
|
end
|
33
34
|
process_children region.update(closure: nspin, visibility: :public)
|
@@ -0,0 +1,42 @@
|
|
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
|
+
# @return [void]
|
11
|
+
def process
|
12
|
+
# Parser::CurrentRuby.parse("a += 2")
|
13
|
+
# => s(:op_asgn,
|
14
|
+
# s(:lvasgn, :a), :+,
|
15
|
+
# s(:int, 2))
|
16
|
+
asgn = node.children[0]
|
17
|
+
variable_name = asgn.children[0]
|
18
|
+
operator = node.children[1]
|
19
|
+
argument = node.children[2]
|
20
|
+
# for lvasgn, gvasgn, cvasgn, convert to lvar, gvar, cvar
|
21
|
+
# [6] pry(main)> Parser::CurrentRuby.parse("a = a + 1")
|
22
|
+
# => s(:lvasgn, :a,
|
23
|
+
# s(:send,
|
24
|
+
# s(:lvar, :a), :+,
|
25
|
+
# s(:int, 1)))
|
26
|
+
# [7] pry(main)>
|
27
|
+
variable_reference_type = asgn.type.to_s.sub(/vasgn$/, 'var').to_sym
|
28
|
+
variable_reference = node.updated(variable_reference_type, asgn.children)
|
29
|
+
send_children = [
|
30
|
+
variable_reference,
|
31
|
+
operator,
|
32
|
+
argument
|
33
|
+
]
|
34
|
+
send_node = node.updated(:send, send_children)
|
35
|
+
new_asgn = node.updated(asgn.type, [variable_name, send_node])
|
36
|
+
NodeProcessor.process(new_asgn, region, pins, locals)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -5,6 +5,7 @@ module Solargraph
|
|
5
5
|
module ParserGem
|
6
6
|
module NodeProcessors
|
7
7
|
class OrasgnNode < Parser::NodeProcessor::Base
|
8
|
+
# @return [void]
|
8
9
|
def process
|
9
10
|
new_node = node.updated(node.children[0].type, node.children[0].children + [node.children[1]])
|
10
11
|
NodeProcessor.process(new_node, region, pins, locals)
|
@@ -7,6 +7,7 @@ module Solargraph
|
|
7
7
|
class ResbodyNode < Parser::NodeProcessor::Base
|
8
8
|
include ParserGem::NodeMethods
|
9
9
|
|
10
|
+
# @return [void]
|
10
11
|
def process
|
11
12
|
if node.children[1] # Exception local variable name
|
12
13
|
here = get_node_start_position(node.children[1])
|
@@ -24,7 +25,8 @@ module Solargraph
|
|
24
25
|
closure: region.closure,
|
25
26
|
name: node.children[1].children[0].to_s,
|
26
27
|
comments: "@type [#{types.join(',')}]",
|
27
|
-
presence: presence
|
28
|
+
presence: presence,
|
29
|
+
source: :parser
|
28
30
|
)
|
29
31
|
end
|
30
32
|
NodeProcessor.process(node.children[2], region, pins, locals)
|
@@ -17,7 +17,7 @@ module Solargraph
|
|
17
17
|
names.concat [NodeMethods.unpack_name(sclass.children[0]), sclass.children[1].to_s]
|
18
18
|
end
|
19
19
|
name = names.reject(&:empty?).join('::')
|
20
|
-
closure = Solargraph::Pin::Namespace.new(name: name, location: region.closure.location)
|
20
|
+
closure = Solargraph::Pin::Namespace.new(name: name, location: region.closure.location, source: :parser)
|
21
21
|
elsif sclass.is_a?(AST::Node) && sclass.type == :const
|
22
22
|
names = [region.closure.namespace, region.closure.name]
|
23
23
|
also = NodeMethods.unpack_name(sclass)
|
@@ -25,13 +25,14 @@ module Solargraph
|
|
25
25
|
names << also
|
26
26
|
end
|
27
27
|
name = names.reject(&:empty?).join('::')
|
28
|
-
closure = Solargraph::Pin::Namespace.new(name: name, location: region.closure.location)
|
28
|
+
closure = Solargraph::Pin::Namespace.new(name: name, location: region.closure.location, source: :parser)
|
29
29
|
else
|
30
30
|
return
|
31
31
|
end
|
32
32
|
pins.push Solargraph::Pin::Singleton.new(
|
33
33
|
location: get_node_location(node),
|
34
|
-
closure: closure
|
34
|
+
closure: closure,
|
35
|
+
source: :parser,
|
35
36
|
)
|
36
37
|
process_children region.update(visibility: :public, scope: :class, closure: pins.last)
|
37
38
|
end
|
@@ -8,33 +8,45 @@ module Solargraph
|
|
8
8
|
include ParserGem::NodeMethods
|
9
9
|
|
10
10
|
def process
|
11
|
+
# @sg-ignore Variable type could not be inferred for method_name
|
12
|
+
# @type [Symbol]
|
13
|
+
method_name = node.children[1]
|
14
|
+
# :nocov:
|
15
|
+
unless method_name.instance_of?(Symbol)
|
16
|
+
Solargraph.assert_or_log(:parser_method_name, "Expected method name to be a Symbol, got #{method_name.class} for node #{node.inspect}")
|
17
|
+
return process_children
|
18
|
+
end
|
19
|
+
# :nocov:
|
11
20
|
if node.children[0].nil?
|
12
|
-
if [:private, :public, :protected].include?(
|
21
|
+
if [:private, :public, :protected].include?(method_name)
|
13
22
|
process_visibility
|
14
|
-
elsif
|
23
|
+
elsif method_name == :module_function
|
15
24
|
process_module_function
|
16
|
-
elsif [:attr_reader, :attr_writer, :attr_accessor].include?(
|
25
|
+
elsif [:attr_reader, :attr_writer, :attr_accessor].include?(method_name)
|
17
26
|
process_attribute
|
18
|
-
elsif
|
27
|
+
elsif method_name == :include
|
19
28
|
process_include
|
20
|
-
elsif
|
29
|
+
elsif method_name == :extend
|
21
30
|
process_extend
|
22
|
-
elsif
|
31
|
+
elsif method_name == :prepend
|
23
32
|
process_prepend
|
24
|
-
elsif
|
33
|
+
elsif method_name == :require
|
25
34
|
process_require
|
26
|
-
elsif
|
35
|
+
elsif method_name == :autoload
|
27
36
|
process_autoload
|
28
|
-
elsif
|
37
|
+
elsif method_name == :private_constant
|
29
38
|
process_private_constant
|
30
|
-
|
39
|
+
# @sg-ignore
|
40
|
+
elsif method_name == :alias_method && node.children[2] && node.children[2] && node.children[2].type == :sym && node.children[3] && node.children[3].type == :sym
|
31
41
|
process_alias_method
|
32
|
-
|
42
|
+
# @sg-ignore
|
43
|
+
elsif method_name == :private_class_method && node.children[2].is_a?(AST::Node)
|
33
44
|
# Processing a private class can potentially handle children on its own
|
34
45
|
return if process_private_class_method
|
35
46
|
end
|
36
|
-
|
37
|
-
|
47
|
+
# @sg-ignore
|
48
|
+
elsif method_name == :require && node.children[0].to_s == '(const nil :Bundler)'
|
49
|
+
pins.push Pin::Reference::Require.new(Solargraph::Location.new(region.filename, Solargraph::Range.from_to(0, 0, 0, 0)), 'bundler/require', source: :parser)
|
38
50
|
end
|
39
51
|
process_children
|
40
52
|
end
|
@@ -45,15 +57,24 @@ module Solargraph
|
|
45
57
|
def process_visibility
|
46
58
|
if (node.children.length > 2)
|
47
59
|
node.children[2..-1].each do |child|
|
60
|
+
# @sg-ignore Variable type could not be inferred for method_name
|
61
|
+
# @type [Symbol]
|
62
|
+
visibility = node.children[1]
|
63
|
+
# :nocov:
|
64
|
+
unless visibility.instance_of?(Symbol)
|
65
|
+
Solargraph.assert_or_log(:parser_visibility, "Expected visibility name to be a Symbol, got #{visibility.class} for node #{node.inspect}")
|
66
|
+
return process_children
|
67
|
+
end
|
68
|
+
# :nocov:
|
48
69
|
if child.is_a?(AST::Node) && (child.type == :sym || child.type == :str)
|
49
70
|
name = child.children[0].to_s
|
50
71
|
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)}
|
51
72
|
matches.each do |pin|
|
52
73
|
# @todo Smelly instance variable access
|
53
|
-
pin.instance_variable_set(:@visibility,
|
74
|
+
pin.instance_variable_set(:@visibility, visibility)
|
54
75
|
end
|
55
76
|
else
|
56
|
-
process_children region.update(visibility:
|
77
|
+
process_children region.update(visibility: visibility)
|
57
78
|
end
|
58
79
|
end
|
59
80
|
else
|
@@ -76,7 +97,8 @@ module Solargraph
|
|
76
97
|
comments: cmnt,
|
77
98
|
scope: region.scope || :instance,
|
78
99
|
visibility: region.visibility,
|
79
|
-
attribute: true
|
100
|
+
attribute: true,
|
101
|
+
source: :parser
|
80
102
|
)
|
81
103
|
end
|
82
104
|
if node.children[1] == :attr_writer || node.children[1] == :attr_accessor
|
@@ -87,10 +109,11 @@ module Solargraph
|
|
87
109
|
comments: cmnt,
|
88
110
|
scope: region.scope || :instance,
|
89
111
|
visibility: region.visibility,
|
90
|
-
attribute: true
|
112
|
+
attribute: true,
|
113
|
+
source: :parser
|
91
114
|
)
|
92
115
|
pins.push method_pin
|
93
|
-
method_pin.parameters.push Pin::Parameter.new(name: 'value', decl: :arg, closure: pins.last)
|
116
|
+
method_pin.parameters.push Pin::Parameter.new(name: 'value', decl: :arg, closure: pins.last, source: :parser)
|
94
117
|
if method_pin.return_type.defined?
|
95
118
|
pins.last.docstring.add_tag YARD::Tags::Tag.new(:param, '', pins.last.return_type.items.map(&:rooted_tags), 'value')
|
96
119
|
end
|
@@ -107,7 +130,8 @@ module Solargraph
|
|
107
130
|
pins.push type.new(
|
108
131
|
location: get_node_location(i),
|
109
132
|
closure: cp,
|
110
|
-
name: unpack_name(i)
|
133
|
+
name: unpack_name(i),
|
134
|
+
source: :parser
|
111
135
|
)
|
112
136
|
end
|
113
137
|
end
|
@@ -121,7 +145,8 @@ module Solargraph
|
|
121
145
|
pins.push Pin::Reference::Prepend.new(
|
122
146
|
location: get_node_location(i),
|
123
147
|
closure: cp,
|
124
|
-
name: unpack_name(i)
|
148
|
+
name: unpack_name(i),
|
149
|
+
source: :parser
|
125
150
|
)
|
126
151
|
end
|
127
152
|
end
|
@@ -135,13 +160,15 @@ module Solargraph
|
|
135
160
|
pins.push Pin::Reference::Extend.new(
|
136
161
|
location: loc,
|
137
162
|
closure: region.closure,
|
138
|
-
name: region.closure.full_context.namespace
|
163
|
+
name: region.closure.full_context.namespace,
|
164
|
+
source: :parser
|
139
165
|
)
|
140
166
|
else
|
141
167
|
pins.push Pin::Reference::Extend.new(
|
142
168
|
location: loc,
|
143
169
|
closure: region.closure,
|
144
|
-
name: unpack_name(i)
|
170
|
+
name: unpack_name(i),
|
171
|
+
source: :parser
|
145
172
|
)
|
146
173
|
end
|
147
174
|
end
|
@@ -151,7 +178,7 @@ module Solargraph
|
|
151
178
|
def process_require
|
152
179
|
if node.children[2].is_a?(AST::Node) && node.children[2].type == :str
|
153
180
|
path = node.children[2].children[0].to_s
|
154
|
-
pins.push Pin::Reference::Require.new(get_node_location(node), path)
|
181
|
+
pins.push Pin::Reference::Require.new(get_node_location(node), path, source: :parser)
|
155
182
|
end
|
156
183
|
end
|
157
184
|
|
@@ -159,7 +186,7 @@ module Solargraph
|
|
159
186
|
def process_autoload
|
160
187
|
if node.children[3].is_a?(AST::Node) && node.children[3].type == :str
|
161
188
|
path = node.children[3].children[0].to_s
|
162
|
-
pins.push Pin::Reference::Require.new(get_node_location(node), path)
|
189
|
+
pins.push Pin::Reference::Require.new(get_node_location(node), path, source: :parser)
|
163
190
|
end
|
164
191
|
end
|
165
192
|
|
@@ -171,7 +198,8 @@ module Solargraph
|
|
171
198
|
elsif node.children[2].type == :sym || node.children[2].type == :str
|
172
199
|
node.children[2..-1].each do |x|
|
173
200
|
cn = x.children[0].to_s
|
174
|
-
|
201
|
+
# @type [Pin::Method]
|
202
|
+
ref = pins.find { |p| p.is_a?(Pin::Method) && p.namespace == region.closure.full_context.namespace && p.name == cn }
|
175
203
|
unless ref.nil?
|
176
204
|
pins.delete ref
|
177
205
|
mm = Solargraph::Pin::Method.new(
|
@@ -182,7 +210,8 @@ module Solargraph
|
|
182
210
|
comments: ref.comments,
|
183
211
|
scope: :class,
|
184
212
|
visibility: :public,
|
185
|
-
node: ref.node
|
213
|
+
node: ref.node,
|
214
|
+
source: :parser
|
186
215
|
)
|
187
216
|
cm = Solargraph::Pin::Method.new(
|
188
217
|
location: ref.location,
|
@@ -192,7 +221,8 @@ module Solargraph
|
|
192
221
|
comments: ref.comments,
|
193
222
|
scope: :instance,
|
194
223
|
visibility: :private,
|
195
|
-
node: ref.node
|
224
|
+
node: ref.node,
|
225
|
+
source: :parser)
|
196
226
|
pins.push mm, cm
|
197
227
|
pins.select{|pin| pin.is_a?(Pin::InstanceVariable) && pin.closure.path == ref.path}.each do |ivar|
|
198
228
|
pins.delete ivar
|
@@ -201,14 +231,16 @@ module Solargraph
|
|
201
231
|
closure: cm,
|
202
232
|
name: ivar.name,
|
203
233
|
comments: ivar.comments,
|
204
|
-
assignment: ivar.assignment
|
234
|
+
assignment: ivar.assignment,
|
235
|
+
source: :parser
|
205
236
|
)
|
206
237
|
pins.push Solargraph::Pin::InstanceVariable.new(
|
207
238
|
location: ivar.location,
|
208
239
|
closure: mm,
|
209
240
|
name: ivar.name,
|
210
241
|
comments: ivar.comments,
|
211
|
-
assignment: ivar.assignment
|
242
|
+
assignment: ivar.assignment,
|
243
|
+
source: :parser
|
212
244
|
)
|
213
245
|
end
|
214
246
|
end
|
@@ -236,7 +268,8 @@ module Solargraph
|
|
236
268
|
closure: region.closure,
|
237
269
|
name: node.children[2].children[0].to_s,
|
238
270
|
original: node.children[3].children[0].to_s,
|
239
|
-
scope: region.scope || :instance
|
271
|
+
scope: region.scope || :instance,
|
272
|
+
source: :parser
|
240
273
|
)
|
241
274
|
end
|
242
275
|
|
@@ -5,10 +5,12 @@ module Solargraph
|
|
5
5
|
module ParserGem
|
6
6
|
module NodeProcessors
|
7
7
|
class SymNode < Parser::NodeProcessor::Base
|
8
|
+
# @return [void]
|
8
9
|
def process
|
9
10
|
pins.push Solargraph::Pin::Symbol.new(
|
10
11
|
get_node_location(node),
|
11
|
-
":#{node.children[0]}"
|
12
|
+
":#{node.children[0]}",
|
13
|
+
source: :parser
|
12
14
|
)
|
13
15
|
end
|
14
16
|
end
|
@@ -0,0 +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
|
@@ -0,0 +1,29 @@
|
|
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
|
+
source: :parser,
|
22
|
+
)
|
23
|
+
process_children region
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|