solargraph 0.60.4 → 0.62.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 +24 -2
- data/.github/workflows/plugins.yml +19 -1
- data/.github/workflows/rspec.yml +17 -2
- data/.github/workflows/typecheck.yml +6 -0
- data/CHANGELOG.md +54 -0
- data/Gemfile +0 -3
- data/lib/solargraph/api_map/index.rb +28 -4
- data/lib/solargraph/api_map/store.rb +19 -0
- data/lib/solargraph/api_map.rb +91 -80
- data/lib/solargraph/cache_dir.rb +58 -0
- data/lib/solargraph/collection/base.rb +50 -0
- data/lib/solargraph/collection/core.rb +17 -0
- data/lib/solargraph/collection/gem.rb +59 -0
- data/lib/solargraph/collection/stdlib.rb +25 -0
- data/lib/solargraph/collection.rb +30 -0
- data/lib/solargraph/complex_type/unique_type.rb +13 -0
- data/lib/solargraph/complex_type.rb +23 -3
- data/lib/solargraph/convention.rb +5 -7
- data/lib/solargraph/diagnostics/require_not_found.rb +0 -4
- data/lib/solargraph/diagnostics/type_check.rb +0 -1
- data/lib/solargraph/external.rb +187 -0
- data/lib/solargraph/language_server/host/diagnoser.rb +1 -1
- data/lib/solargraph/language_server/host/dispatch.rb +4 -2
- data/lib/solargraph/language_server/host.rb +10 -2
- data/lib/solargraph/language_server/message/completion_item/resolve.rb +10 -3
- data/lib/solargraph/language_server/message/text_document/definition.rb +5 -2
- data/lib/solargraph/language_server/message/text_document/hover.rb +1 -2
- data/lib/solargraph/library.rb +26 -53
- data/lib/solargraph/metagem.rb +80 -0
- data/lib/solargraph/parser/node_processor/base.rb +6 -0
- data/lib/solargraph/parser/parser_gem/node_chainer.rb +22 -3
- data/lib/solargraph/parser/parser_gem/node_methods.rb +29 -6
- data/lib/solargraph/parser/parser_gem/node_processors/class_definition/class_assignment_node.rb +98 -0
- data/lib/solargraph/parser/parser_gem/node_processors/class_definition.rb +54 -0
- data/lib/solargraph/parser/parser_gem/node_processors/cvasgn_node.rb +1 -0
- data/lib/solargraph/parser/parser_gem/node_processors/data_definition/data_assignment_node.rb +65 -0
- data/lib/solargraph/parser/parser_gem/node_processors/data_definition/data_definition_node.rb +97 -0
- data/lib/solargraph/parser/parser_gem/node_processors/data_definition.rb +110 -0
- data/lib/solargraph/parser/parser_gem/node_processors/gvasgn_node.rb +1 -0
- data/lib/solargraph/parser/parser_gem/node_processors/ivasgn_node.rb +2 -0
- data/lib/solargraph/parser/parser_gem/node_processors/lvasgn_node.rb +1 -0
- data/lib/solargraph/parser/parser_gem/node_processors/send_node.rb +185 -0
- data/lib/solargraph/parser/parser_gem/node_processors/struct_definition/struct_assignment_node.rb +66 -0
- data/lib/solargraph/parser/parser_gem/node_processors/struct_definition/struct_definition_node.rb +108 -0
- data/lib/solargraph/parser/parser_gem/node_processors/struct_definition.rb +170 -0
- data/lib/solargraph/parser/parser_gem/node_processors.rb +33 -29
- data/lib/solargraph/pin/base.rb +25 -1
- data/lib/solargraph/pin/base_variable.rb +31 -1
- data/lib/solargraph/pin/callable.rb +11 -2
- data/lib/solargraph/pin/closure.rb +17 -0
- data/lib/solargraph/pin/delegated_method.rb +5 -0
- data/lib/solargraph/pin/duck_method.rb +36 -16
- data/lib/solargraph/pin/factory_parameter.rb +84 -0
- data/lib/solargraph/pin/instance_variable.rb +45 -0
- data/lib/solargraph/pin/method.rb +10 -0
- data/lib/solargraph/pin/method_alias.rb +4 -0
- data/lib/solargraph/pin/parameter.rb +1 -1
- data/lib/solargraph/pin/reference/included_mixin.rb +22 -0
- data/lib/solargraph/pin/reference.rb +1 -0
- data/lib/solargraph/pin.rb +1 -0
- data/lib/solargraph/plugin/active_support.rb +100 -0
- data/lib/solargraph/plugin/addon.rb +16 -0
- data/lib/solargraph/plugin/base.rb +25 -0
- data/lib/solargraph/plugin/panel.rb +37 -0
- data/lib/solargraph/plugin.rb +26 -0
- data/lib/solargraph/rbs_collection.rb +119 -0
- data/lib/solargraph/rbs_map/base.rb +31 -0
- data/lib/solargraph/rbs_map/conversions.rb +109 -48
- data/lib/solargraph/rbs_map/{core_map.rb → core.rb} +18 -39
- data/lib/solargraph/rbs_map/core_fills.rb +1 -1
- data/lib/solargraph/rbs_map/gem.rb +16 -0
- data/lib/solargraph/rbs_map/helpers.rb +61 -0
- data/lib/solargraph/rbs_map/path.rb +19 -0
- data/lib/solargraph/rbs_map/stdlib.rb +24 -0
- data/lib/solargraph/rbs_map.rb +7 -198
- data/lib/solargraph/rbs_translator.rb +105 -70
- data/lib/solargraph/repo.rb +177 -0
- data/lib/solargraph/shell.rb +49 -99
- data/lib/solargraph/source/chain/call.rb +58 -14
- data/lib/solargraph/source/chain/literal.rb +17 -17
- data/lib/solargraph/source/chain/parameter.rb +79 -0
- data/lib/solargraph/source/chain.rb +8 -0
- data/lib/solargraph/source/node_map.rb +27 -0
- data/lib/solargraph/source/source_chainer.rb +40 -44
- data/lib/solargraph/source.rb +17 -0
- data/lib/solargraph/source_map/call.rb +18 -0
- data/lib/solargraph/source_map/clip.rb +5 -3
- data/lib/solargraph/source_map/mapper.rb +6 -2
- data/lib/solargraph/source_map.rb +28 -9
- data/lib/solargraph/type_checker/rules.rb +3 -2
- data/lib/solargraph/type_checker.rb +4 -1
- data/lib/solargraph/version.rb +1 -1
- data/lib/solargraph/workspace.rb +0 -1
- data/lib/solargraph/yard_map/cache.rb +1 -1
- data/lib/solargraph/yard_map/directives/attribute_directive.rb +1 -1
- data/lib/solargraph/yard_map/directives/domain_directive.rb +1 -1
- data/lib/solargraph/yard_map/directives/method_directive.rb +1 -1
- data/lib/solargraph/yard_map/directives/override_directive.rb +1 -1
- data/lib/solargraph/yard_map/directives/parse_directive.rb +1 -1
- data/lib/solargraph/yard_map/directives/scope_directive.rb +178 -0
- data/lib/solargraph/yard_map/directives/visibility_directive.rb +1 -1
- data/lib/solargraph/yard_map/directives.rb +5 -2
- data/lib/solargraph/yard_map/helpers.rb +1 -1
- data/lib/solargraph/yard_map/macro.rb +85 -6
- data/lib/solargraph/yard_map/mapper/to_constant.rb +1 -1
- data/lib/solargraph/yard_map/mapper/to_method.rb +1 -1
- data/lib/solargraph/yard_map/mapper/to_namespace.rb +1 -1
- data/lib/solargraph/yard_map/mapper.rb +2 -2
- data/lib/solargraph/yard_map.rb +1 -1
- data/lib/solargraph/yardoc.rb +43 -60
- data/lib/solargraph.rb +8 -3
- data/rbs/fills/boolean/0/boolean.rbs +12 -0
- data/solargraph.gemspec +2 -2
- metadata +41 -18
- data/lib/solargraph/convention/active_support_concern.rb +0 -111
- data/lib/solargraph/convention/data_definition/data_assignment_node.rb +0 -61
- data/lib/solargraph/convention/data_definition/data_definition_node.rb +0 -93
- data/lib/solargraph/convention/data_definition.rb +0 -108
- data/lib/solargraph/convention/struct_definition/struct_assignment_node.rb +0 -62
- data/lib/solargraph/convention/struct_definition/struct_definition_node.rb +0 -103
- data/lib/solargraph/convention/struct_definition.rb +0 -168
- data/lib/solargraph/doc_map.rb +0 -439
- data/lib/solargraph/gem_pins.rb +0 -87
- data/lib/solargraph/pin_cache.rb +0 -248
- data/lib/solargraph/rbs_map/stdlib_map.rb +0 -71
- data/lib/solargraph/workspace/gemspecs.rb +0 -373
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Solargraph
|
|
4
|
-
module Convention
|
|
5
|
-
module DataDefinition
|
|
6
|
-
autoload :DataDefintionNode, 'solargraph/convention/data_definition/data_definition_node'
|
|
7
|
-
autoload :DataAssignmentNode, 'solargraph/convention/data_definition/data_assignment_node'
|
|
8
|
-
|
|
9
|
-
module NodeProcessors
|
|
10
|
-
class DataNode < Parser::NodeProcessor::Base
|
|
11
|
-
# @return [Boolean] continue processing the next processor of the same node.
|
|
12
|
-
def process
|
|
13
|
-
return true if data_definition_node.nil?
|
|
14
|
-
|
|
15
|
-
loc = get_node_location(node)
|
|
16
|
-
nspin = Solargraph::Pin::Namespace.new(
|
|
17
|
-
type: :class,
|
|
18
|
-
location: loc,
|
|
19
|
-
closure: region.closure,
|
|
20
|
-
# @sg-ignore flow sensitive typing needs to handle attrs
|
|
21
|
-
name: data_definition_node.class_name,
|
|
22
|
-
comments: comments_for(node),
|
|
23
|
-
visibility: :public,
|
|
24
|
-
gates: region.closure.gates.freeze
|
|
25
|
-
)
|
|
26
|
-
pins.push nspin
|
|
27
|
-
|
|
28
|
-
# define initialize method
|
|
29
|
-
initialize_method_pin = Pin::Method.new(
|
|
30
|
-
name: 'initialize',
|
|
31
|
-
parameters: [],
|
|
32
|
-
scope: :instance,
|
|
33
|
-
location: get_node_location(node),
|
|
34
|
-
closure: nspin,
|
|
35
|
-
visibility: :private,
|
|
36
|
-
comments: comments_for(node)
|
|
37
|
-
)
|
|
38
|
-
|
|
39
|
-
# @todo Support both arg and kwarg initializers for Data.define
|
|
40
|
-
# Solargraph::SourceMap::Clip#complete_keyword_parameters does not seem to currently take into account [Pin::Method#signatures] hence we only one for :kwarg
|
|
41
|
-
pins.push initialize_method_pin
|
|
42
|
-
|
|
43
|
-
# @sg-ignore flow sensitive typing needs to handle attrs
|
|
44
|
-
data_definition_node.attributes.map do |attribute_node, attribute_name|
|
|
45
|
-
initialize_method_pin.parameters.push(
|
|
46
|
-
Pin::Parameter.new(
|
|
47
|
-
name: attribute_name,
|
|
48
|
-
decl: :kwarg,
|
|
49
|
-
location: get_node_location(attribute_node),
|
|
50
|
-
closure: initialize_method_pin
|
|
51
|
-
)
|
|
52
|
-
)
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
# define attribute readers and instance variables
|
|
56
|
-
# @sg-ignore flow sensitive typing needs to handle attrs
|
|
57
|
-
data_definition_node.attributes.each do |attribute_node, attribute_name|
|
|
58
|
-
name = attribute_name.to_s
|
|
59
|
-
method_pin = Pin::Method.new(
|
|
60
|
-
name: name,
|
|
61
|
-
parameters: [],
|
|
62
|
-
scope: :instance,
|
|
63
|
-
location: get_node_location(attribute_node),
|
|
64
|
-
closure: nspin,
|
|
65
|
-
comments: attribute_comments(attribute_node, attribute_name),
|
|
66
|
-
visibility: :public
|
|
67
|
-
)
|
|
68
|
-
|
|
69
|
-
pins.push method_pin
|
|
70
|
-
|
|
71
|
-
pins.push Pin::InstanceVariable.new(name: "@#{attribute_name}",
|
|
72
|
-
closure: method_pin,
|
|
73
|
-
location: get_node_location(attribute_node),
|
|
74
|
-
comments: attribute_comments(attribute_node, attribute_name))
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
process_children region.update(closure: nspin, visibility: :public)
|
|
78
|
-
|
|
79
|
-
false
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
private
|
|
83
|
-
|
|
84
|
-
# @return [DataDefinition::DataDefintionNode, DataDefinition::DataAssignmentNode, nil]
|
|
85
|
-
def data_definition_node
|
|
86
|
-
@data_definition_node ||= if DataDefintionNode.match?(node)
|
|
87
|
-
DataDefintionNode.new(node)
|
|
88
|
-
elsif DataAssignmentNode.match?(node)
|
|
89
|
-
DataAssignmentNode.new(node)
|
|
90
|
-
end
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
# @param attribute_node [Parser::AST::Node]
|
|
94
|
-
# @param attribute_name [String]
|
|
95
|
-
# @return [String, nil]
|
|
96
|
-
def attribute_comments attribute_node, attribute_name
|
|
97
|
-
data_comments = comments_for(attribute_node)
|
|
98
|
-
return if data_comments.nil? || data_comments.empty?
|
|
99
|
-
|
|
100
|
-
data_comments.split("\n").find do |row|
|
|
101
|
-
row.include?(attribute_name)
|
|
102
|
-
end&.gsub('@param', '@return')&.gsub(attribute_name, '')
|
|
103
|
-
end
|
|
104
|
-
end
|
|
105
|
-
end
|
|
106
|
-
end
|
|
107
|
-
end
|
|
108
|
-
end
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Solargraph
|
|
4
|
-
module Convention
|
|
5
|
-
module StructDefinition
|
|
6
|
-
# A node wrapper for a Struct definition via const assignment.
|
|
7
|
-
# @example
|
|
8
|
-
# MyStruct = Struct.new(:bar, :baz) do
|
|
9
|
-
# def foo
|
|
10
|
-
# end
|
|
11
|
-
# end
|
|
12
|
-
class StructAssignmentNode < StructDefintionNode
|
|
13
|
-
class << self
|
|
14
|
-
# @example
|
|
15
|
-
# s(:casgn, nil, :Foo,
|
|
16
|
-
# s(:block,
|
|
17
|
-
# s(:send,
|
|
18
|
-
# s(:const, nil, :Struct), :new,
|
|
19
|
-
# s(:sym, :bar),
|
|
20
|
-
# s(:sym, :baz)),
|
|
21
|
-
# s(:args),
|
|
22
|
-
# s(:def, :foo,
|
|
23
|
-
# s(:args),
|
|
24
|
-
# s(:send, nil, :bar))))
|
|
25
|
-
#
|
|
26
|
-
# @param node [Parser::AST::Node]
|
|
27
|
-
def match? node
|
|
28
|
-
return false unless node&.type == :casgn
|
|
29
|
-
return false if node.children[2].nil?
|
|
30
|
-
|
|
31
|
-
struct_node = if node.children[2].type == :block
|
|
32
|
-
node.children[2].children[0]
|
|
33
|
-
else
|
|
34
|
-
node.children[2]
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
struct_definition_node?(struct_node)
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
def class_name
|
|
42
|
-
if node.children[0]
|
|
43
|
-
Parser::NodeMethods.unpack_name(node.children[0]) + "::#{node.children[1]}"
|
|
44
|
-
else
|
|
45
|
-
node.children[1].to_s
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
private
|
|
50
|
-
|
|
51
|
-
# @return [Parser::AST::Node]
|
|
52
|
-
def struct_node
|
|
53
|
-
if node.children[2].type == :block
|
|
54
|
-
node.children[2].children[0]
|
|
55
|
-
else
|
|
56
|
-
node.children[2]
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
end
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Solargraph
|
|
4
|
-
module Convention
|
|
5
|
-
module StructDefinition
|
|
6
|
-
# A node wrapper for a Struct definition via inheritance.
|
|
7
|
-
# @example
|
|
8
|
-
# class MyStruct < Struct.new(:bar, :baz)
|
|
9
|
-
# def foo
|
|
10
|
-
# end
|
|
11
|
-
# end
|
|
12
|
-
class StructDefintionNode
|
|
13
|
-
class << self
|
|
14
|
-
# @example
|
|
15
|
-
# s(:class,
|
|
16
|
-
# s(:const, nil, :Foo),
|
|
17
|
-
# s(:send,
|
|
18
|
-
# s(:const, nil, :Struct), :new,
|
|
19
|
-
# s(:sym, :bar),
|
|
20
|
-
# s(:sym, :baz)),
|
|
21
|
-
# s(:hash,
|
|
22
|
-
# s(:pair,
|
|
23
|
-
# s(:sym, :keyword_init),
|
|
24
|
-
# s(:true)))),
|
|
25
|
-
# s(:def, :foo,
|
|
26
|
-
# s(:args),
|
|
27
|
-
# s(:send, nil, :bar)))
|
|
28
|
-
#
|
|
29
|
-
# @param node [Parser::AST::Node]
|
|
30
|
-
def match? node
|
|
31
|
-
return false unless node&.type == :class
|
|
32
|
-
|
|
33
|
-
struct_definition_node?(node.children[1])
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
private
|
|
37
|
-
|
|
38
|
-
# @param struct_node [Parser::AST::Node]
|
|
39
|
-
# @return [Boolean]
|
|
40
|
-
def struct_definition_node? struct_node
|
|
41
|
-
return false unless struct_node.is_a?(::Parser::AST::Node)
|
|
42
|
-
return false unless struct_node&.type == :send
|
|
43
|
-
return false unless struct_node.children[0]&.type == :const
|
|
44
|
-
return false unless struct_node.children[0].children[1] == :Struct
|
|
45
|
-
return false unless struct_node.children[1] == :new
|
|
46
|
-
|
|
47
|
-
true
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
# @param node [Parser::AST::Node]
|
|
52
|
-
def initialize node
|
|
53
|
-
@node = node
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
# @return [String]
|
|
57
|
-
def class_name
|
|
58
|
-
Parser::NodeMethods.unpack_name(node)
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
# @return [Array<Array(Parser::AST::Node, String)>]
|
|
62
|
-
def attributes
|
|
63
|
-
struct_attribute_nodes.map do |struct_def_param|
|
|
64
|
-
next unless struct_def_param.type == :sym
|
|
65
|
-
[struct_def_param, struct_def_param.children[0].to_s]
|
|
66
|
-
end.compact
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
def keyword_init?
|
|
70
|
-
keyword_init_param = struct_attribute_nodes.find do |struct_def_param|
|
|
71
|
-
struct_def_param.type == :hash && struct_def_param.children[0].type == :pair &&
|
|
72
|
-
struct_def_param.children[0].children[0].children[0] == :keyword_init
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
return false if keyword_init_param.nil?
|
|
76
|
-
|
|
77
|
-
keyword_init_param.children[0].children[1].type == :true
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
# @return [Parser::AST::Node]
|
|
81
|
-
def body_node
|
|
82
|
-
node.children[2]
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
private
|
|
86
|
-
|
|
87
|
-
# @return [Parser::AST::Node]
|
|
88
|
-
attr_reader :node
|
|
89
|
-
|
|
90
|
-
# @return [Parser::AST::Node]
|
|
91
|
-
def struct_node
|
|
92
|
-
node.children[1]
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
# @sg-ignore Need to add nil check here
|
|
96
|
-
# @return [Array<Parser::AST::Node>]
|
|
97
|
-
def struct_attribute_nodes
|
|
98
|
-
struct_node.children[2..-1]
|
|
99
|
-
end
|
|
100
|
-
end
|
|
101
|
-
end
|
|
102
|
-
end
|
|
103
|
-
end
|
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Solargraph
|
|
4
|
-
module Convention
|
|
5
|
-
module StructDefinition
|
|
6
|
-
autoload :StructDefintionNode, 'solargraph/convention/struct_definition/struct_definition_node'
|
|
7
|
-
autoload :StructAssignmentNode, 'solargraph/convention/struct_definition/struct_assignment_node'
|
|
8
|
-
|
|
9
|
-
module NodeProcessors
|
|
10
|
-
class StructNode < Parser::NodeProcessor::Base
|
|
11
|
-
# @return [Boolean] continue processing the next processor of the same node.
|
|
12
|
-
def process
|
|
13
|
-
return true if struct_definition_node.nil?
|
|
14
|
-
|
|
15
|
-
loc = get_node_location(node)
|
|
16
|
-
nspin = Solargraph::Pin::Namespace.new(
|
|
17
|
-
type: :class,
|
|
18
|
-
location: loc,
|
|
19
|
-
closure: region.closure,
|
|
20
|
-
# @sg-ignore flow sensitive typing needs to handle attrs
|
|
21
|
-
name: struct_definition_node.class_name,
|
|
22
|
-
docstring: docstring,
|
|
23
|
-
visibility: :public,
|
|
24
|
-
gates: region.closure.gates.freeze,
|
|
25
|
-
source: :struct_definition
|
|
26
|
-
)
|
|
27
|
-
pins.push nspin
|
|
28
|
-
|
|
29
|
-
# define initialize method
|
|
30
|
-
initialize_method_pin = Pin::Method.new(
|
|
31
|
-
name: 'initialize',
|
|
32
|
-
parameters: [],
|
|
33
|
-
scope: :instance,
|
|
34
|
-
location: get_node_location(node),
|
|
35
|
-
closure: nspin,
|
|
36
|
-
visibility: :private,
|
|
37
|
-
docstring: docstring,
|
|
38
|
-
source: :struct_definition
|
|
39
|
-
)
|
|
40
|
-
|
|
41
|
-
pins.push initialize_method_pin
|
|
42
|
-
|
|
43
|
-
# @sg-ignore flow sensitive typing needs to handle attrs
|
|
44
|
-
struct_definition_node.attributes.map do |attribute_node, attribute_name|
|
|
45
|
-
initialize_method_pin.parameters.push(
|
|
46
|
-
Pin::Parameter.new(
|
|
47
|
-
name: attribute_name,
|
|
48
|
-
decl: struct_definition_node.keyword_init? ? :kwarg : :arg,
|
|
49
|
-
location: get_node_location(attribute_node),
|
|
50
|
-
closure: initialize_method_pin,
|
|
51
|
-
source: :struct_definition
|
|
52
|
-
)
|
|
53
|
-
)
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
# define attribute accessors and instance variables
|
|
57
|
-
# @sg-ignore flow sensitive typing needs to handle attrs
|
|
58
|
-
struct_definition_node.attributes.each do |attribute_node, attribute_name|
|
|
59
|
-
[attribute_name, "#{attribute_name}="].each do |name|
|
|
60
|
-
docs = docstring.tags.find { |t| t.tag_name == 'param' && t.name == attribute_name }
|
|
61
|
-
|
|
62
|
-
attribute_type = ComplexType.parse(tag_string(docs))
|
|
63
|
-
return_type_comment = attribute_comment(docs, false)
|
|
64
|
-
param_comment = attribute_comment(docs, true)
|
|
65
|
-
|
|
66
|
-
method_pin = Pin::Method.new(
|
|
67
|
-
name: name,
|
|
68
|
-
parameters: [],
|
|
69
|
-
scope: :instance,
|
|
70
|
-
location: get_node_location(attribute_node),
|
|
71
|
-
closure: nspin,
|
|
72
|
-
docstring: YARD::Docstring.new(return_type_comment),
|
|
73
|
-
# even assignments return the value
|
|
74
|
-
comments: return_type_comment,
|
|
75
|
-
return_type: attribute_type,
|
|
76
|
-
visibility: :public,
|
|
77
|
-
source: :struct_definition
|
|
78
|
-
)
|
|
79
|
-
|
|
80
|
-
if name.end_with?('=')
|
|
81
|
-
method_pin.parameters << Pin::Parameter.new(
|
|
82
|
-
name: attribute_name,
|
|
83
|
-
location: get_node_location(attribute_node),
|
|
84
|
-
closure: method_pin,
|
|
85
|
-
return_type: attribute_type,
|
|
86
|
-
comments: param_comment,
|
|
87
|
-
source: :struct_definition
|
|
88
|
-
)
|
|
89
|
-
|
|
90
|
-
pins.push Pin::InstanceVariable.new(name: "@#{attribute_name}",
|
|
91
|
-
closure: method_pin,
|
|
92
|
-
location: get_node_location(attribute_node),
|
|
93
|
-
return_type: attribute_type,
|
|
94
|
-
comments: "@type [#{attribute_type.rooted_tags}]",
|
|
95
|
-
source: :struct_definition)
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
pins.push method_pin
|
|
99
|
-
end
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
process_children region.update(closure: nspin, visibility: :public)
|
|
103
|
-
false
|
|
104
|
-
end
|
|
105
|
-
|
|
106
|
-
private
|
|
107
|
-
|
|
108
|
-
# @return [StructDefinition::StructDefintionNode, StructDefinition::StructAssignmentNode, nil]
|
|
109
|
-
def struct_definition_node
|
|
110
|
-
@struct_definition_node ||= if StructDefintionNode.match?(node)
|
|
111
|
-
StructDefintionNode.new(node)
|
|
112
|
-
elsif StructAssignmentNode.match?(node)
|
|
113
|
-
StructAssignmentNode.new(node)
|
|
114
|
-
end
|
|
115
|
-
end
|
|
116
|
-
|
|
117
|
-
# Gets/generates the relevant docstring for this struct & it's attributes
|
|
118
|
-
# @return [YARD::Docstring]
|
|
119
|
-
def docstring
|
|
120
|
-
@docstring ||= parse_comments
|
|
121
|
-
end
|
|
122
|
-
|
|
123
|
-
# Parses any relevant comments for a struct int a yard docstring
|
|
124
|
-
# @return [YARD::Docstring]
|
|
125
|
-
def parse_comments
|
|
126
|
-
struct_comments = comments_for(node) || ''
|
|
127
|
-
# @sg-ignore Need to add nil check here
|
|
128
|
-
struct_definition_node.attributes.each do |attr_node, attr_name|
|
|
129
|
-
comment = comments_for(attr_node)
|
|
130
|
-
next if comment.nil?
|
|
131
|
-
|
|
132
|
-
# We should support specific comments for an attribute, and that can be either a @return on an @param
|
|
133
|
-
# But since we merge into the struct_comments, then we should interpret either as a param
|
|
134
|
-
comment = "@param #{attr_name}#{comment[7..]}" if comment.start_with?('@return')
|
|
135
|
-
|
|
136
|
-
struct_comments += "\n#{comment}"
|
|
137
|
-
end
|
|
138
|
-
|
|
139
|
-
Solargraph::Source.parse_docstring(struct_comments).to_docstring
|
|
140
|
-
end
|
|
141
|
-
|
|
142
|
-
# @param tag [YARD::Tags::Tag, nil] The param tag for this attribute.xtract_
|
|
143
|
-
#
|
|
144
|
-
# @return [String]
|
|
145
|
-
def tag_string tag
|
|
146
|
-
tag&.types&.join(',') || 'undefined'
|
|
147
|
-
end
|
|
148
|
-
|
|
149
|
-
# @param tag [YARD::Tags::Tag, nil] The param tag for this attribute. If nil, this method is a no-op
|
|
150
|
-
# @param for_setter [Boolean] If true, will return a @param tag instead of a @return tag
|
|
151
|
-
#
|
|
152
|
-
# @return [String] The formatted comment for the attribute
|
|
153
|
-
def attribute_comment tag, for_setter
|
|
154
|
-
return '' if tag.nil?
|
|
155
|
-
|
|
156
|
-
suffix = "[#{tag_string(tag)}] #{tag.text}"
|
|
157
|
-
|
|
158
|
-
if for_setter
|
|
159
|
-
"@param #{tag.name} #{suffix}"
|
|
160
|
-
else
|
|
161
|
-
"@return #{suffix}"
|
|
162
|
-
end
|
|
163
|
-
end
|
|
164
|
-
end
|
|
165
|
-
end
|
|
166
|
-
end
|
|
167
|
-
end
|
|
168
|
-
end
|