rucoa 0.9.0 → 0.10.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/.rubocop.yml +6 -0
- data/Gemfile.lock +8 -8
- data/data/definitions_ruby_3_1 +0 -0
- data/lib/rucoa/configuration.rb +4 -1
- data/lib/rucoa/definition_store.rb +216 -83
- data/lib/rucoa/definitions/base.rb +14 -3
- data/lib/rucoa/definitions/class_definition.rb +14 -64
- data/lib/rucoa/definitions/constant_definition.rb +31 -19
- data/lib/rucoa/definitions/method_definition.rb +44 -52
- data/lib/rucoa/definitions/method_parameter_definition.rb +4 -1
- data/lib/rucoa/definitions/module_definition.rb +39 -0
- data/lib/rucoa/handler_concerns/diagnostics_publishable.rb +14 -3
- data/lib/rucoa/handlers/base.rb +12 -3
- data/lib/rucoa/handlers/text_document_definition_handler.rb +3 -99
- data/lib/rucoa/handlers/text_document_hover_handler.rb +21 -13
- data/lib/rucoa/handlers/text_document_selection_range_handler.rb +8 -2
- data/lib/rucoa/location.rb +37 -0
- data/lib/rucoa/node_concerns/body.rb +24 -0
- data/lib/rucoa/node_concerns/{name_fully_qualifiable.rb → qualified_name.rb} +2 -2
- data/lib/rucoa/node_concerns.rb +2 -1
- data/lib/rucoa/node_inspector.rb +17 -22
- data/lib/rucoa/nodes/base.rb +22 -6
- data/lib/rucoa/nodes/begin_node.rb +8 -0
- data/lib/rucoa/nodes/casgn_node.rb +1 -1
- data/lib/rucoa/nodes/class_node.rb +2 -1
- data/lib/rucoa/nodes/const_node.rb +33 -15
- data/lib/rucoa/nodes/def_node.rb +2 -2
- data/lib/rucoa/nodes/defs_node.rb +1 -1
- data/lib/rucoa/nodes/module_node.rb +2 -1
- data/lib/rucoa/nodes.rb +2 -1
- data/lib/rucoa/parser.rb +14 -14
- data/lib/rucoa/parser_builder.rb +6 -1
- data/lib/rucoa/position.rb +10 -1
- data/lib/rucoa/range.rb +11 -1
- data/lib/rucoa/rbs/class_definition_mapper.rb +13 -28
- data/lib/rucoa/rbs/constant_definition_mapper.rb +12 -6
- data/lib/rucoa/rbs/method_definition_mapper.rb +12 -6
- data/lib/rucoa/rbs/module_definition_mapper.rb +34 -6
- data/lib/rucoa/rubocop/investigator.rb +4 -1
- data/lib/rucoa/server.rb +8 -2
- data/lib/rucoa/source.rb +19 -4
- data/lib/rucoa/unqualified_name.rb +9 -0
- data/lib/rucoa/version.rb +1 -1
- data/lib/rucoa/yard/definition_generators/attribute_reader_definition_generator.rb +60 -0
- data/lib/rucoa/yard/definition_generators/attribute_writer_definition_generator.rb +60 -0
- data/lib/rucoa/yard/definition_generators/base.rb +117 -0
- data/lib/rucoa/yard/definition_generators/class_definition_generator.rb +66 -0
- data/lib/rucoa/yard/definition_generators/constant_assignment_definition_generator.rb +29 -0
- data/lib/rucoa/yard/definition_generators/method_definition_generator.rb +47 -0
- data/lib/rucoa/yard/definition_generators/module_definition_generator.rb +62 -0
- data/lib/rucoa/yard/definition_generators.rb +15 -0
- data/lib/rucoa/yard/definitions_loader.rb +1 -271
- data/lib/rucoa/yard.rb +1 -0
- data/lib/rucoa.rb +4 -2
- metadata +15 -3
@@ -5,25 +5,30 @@ module Rucoa
|
|
5
5
|
# Represents class definition, module definition, or constant assignment.
|
6
6
|
class ConstantDefinition < Base
|
7
7
|
# @return [String]
|
8
|
-
attr_reader :
|
8
|
+
attr_reader :qualified_name
|
9
9
|
|
10
|
-
# @
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
@fully_qualified_name = fully_qualified_name
|
18
|
-
@source_path = source_path
|
10
|
+
# @param qualified_name [String]
|
11
|
+
def initialize(
|
12
|
+
qualified_name:,
|
13
|
+
**keyword_arguments
|
14
|
+
)
|
15
|
+
super(**keyword_arguments)
|
16
|
+
@qualified_name = qualified_name
|
19
17
|
end
|
20
18
|
|
21
19
|
# @return [String]
|
22
20
|
# @example returns non-full-qualified name
|
23
|
-
# definition = Rucoa::
|
24
|
-
#
|
25
|
-
#
|
26
|
-
#
|
21
|
+
# definition = Rucoa::Source.new(
|
22
|
+
# content: <<~RUBY,
|
23
|
+
# module Foo
|
24
|
+
# module Bar
|
25
|
+
# class Baz
|
26
|
+
# end
|
27
|
+
# end
|
28
|
+
# end
|
29
|
+
# RUBY
|
30
|
+
# uri: 'file:///path/to/foo/bar/baz.rb',
|
31
|
+
# ).definitions[2]
|
27
32
|
# expect(definition.name).to eq('Baz')
|
28
33
|
def name
|
29
34
|
names.last
|
@@ -31,10 +36,17 @@ module Rucoa
|
|
31
36
|
|
32
37
|
# @return [String]
|
33
38
|
# @example returns namespace
|
34
|
-
# definition = Rucoa::
|
35
|
-
#
|
36
|
-
#
|
37
|
-
#
|
39
|
+
# definition = Rucoa::Source.new(
|
40
|
+
# content: <<~RUBY,
|
41
|
+
# module Foo
|
42
|
+
# module Bar
|
43
|
+
# class Baz
|
44
|
+
# end
|
45
|
+
# end
|
46
|
+
# end
|
47
|
+
# RUBY
|
48
|
+
# uri: 'file:///path/to/foo/bar/baz.rb',
|
49
|
+
# ).definitions[2]
|
38
50
|
# expect(definition.namespace).to eq('Foo::Bar')
|
39
51
|
def namespace
|
40
52
|
names[..-2].join('::')
|
@@ -44,7 +56,7 @@ module Rucoa
|
|
44
56
|
|
45
57
|
# @return [Array<String>]
|
46
58
|
def names
|
47
|
-
@names ||=
|
59
|
+
@names ||= qualified_name.split('::')
|
48
60
|
end
|
49
61
|
end
|
50
62
|
end
|
@@ -3,9 +3,6 @@
|
|
3
3
|
module Rucoa
|
4
4
|
module Definitions
|
5
5
|
class MethodDefinition < Base
|
6
|
-
# @return [String, nil]
|
7
|
-
attr_reader :description
|
8
|
-
|
9
6
|
# @return [Symbol]
|
10
7
|
attr_reader :kind
|
11
8
|
|
@@ -15,44 +12,39 @@ module Rucoa
|
|
15
12
|
# @return [String]
|
16
13
|
attr_reader :namespace
|
17
14
|
|
18
|
-
# @return [String]
|
19
|
-
attr_reader :source_path
|
20
|
-
|
21
|
-
# @param description [String, nil]
|
22
15
|
# @param kind [Symbol]
|
23
16
|
# @param method_name [String]
|
24
17
|
# @param namespace [String]
|
25
|
-
# @param source_path [String]
|
26
18
|
# @param types [Array<Rucoa::Types::MethodType>]
|
27
19
|
def initialize(
|
28
|
-
description:,
|
29
20
|
kind:,
|
30
21
|
method_name:,
|
31
22
|
namespace:,
|
32
|
-
|
33
|
-
|
23
|
+
types:,
|
24
|
+
**keyword_arguments
|
34
25
|
)
|
35
|
-
super()
|
36
|
-
@description = description
|
26
|
+
super(**keyword_arguments)
|
37
27
|
@kind = kind
|
38
28
|
@method_name = method_name
|
39
29
|
@namespace = namespace
|
40
|
-
@source_path = source_path
|
41
30
|
@types = types
|
42
31
|
end
|
43
32
|
|
44
33
|
# @return [String]
|
45
34
|
# @example returns qualified name of method
|
46
|
-
#
|
47
|
-
#
|
48
|
-
#
|
49
|
-
#
|
50
|
-
#
|
51
|
-
#
|
52
|
-
#
|
53
|
-
#
|
54
|
-
#
|
55
|
-
|
35
|
+
# definition = Rucoa::Source.new(
|
36
|
+
# content: <<~RUBY,
|
37
|
+
# module Foo
|
38
|
+
# module Bar
|
39
|
+
# def foo
|
40
|
+
# end
|
41
|
+
# end
|
42
|
+
# end
|
43
|
+
# RUBY
|
44
|
+
# uri: 'file:///path/to/foo/bar/baz.rb',
|
45
|
+
# ).definitions[2]
|
46
|
+
# expect(definition.qualified_name).to eq('Foo::Bar#foo')
|
47
|
+
def qualified_name
|
56
48
|
[
|
57
49
|
@namespace,
|
58
50
|
method_kind_symbol,
|
@@ -68,46 +60,46 @@ module Rucoa
|
|
68
60
|
|
69
61
|
# @return [Array<String>]
|
70
62
|
# @example returns return types
|
71
|
-
#
|
72
|
-
#
|
73
|
-
#
|
74
|
-
#
|
75
|
-
#
|
76
|
-
#
|
77
|
-
#
|
78
|
-
#
|
79
|
-
#
|
80
|
-
#
|
81
|
-
#
|
82
|
-
#
|
83
|
-
# )
|
84
|
-
# expect(method_definition.return_types).to eq(%w[String])
|
63
|
+
# definition = Rucoa::Source.new(
|
64
|
+
# content: <<~RUBY,
|
65
|
+
# module Foo
|
66
|
+
# module Bar
|
67
|
+
# # @return [String]
|
68
|
+
# def baz
|
69
|
+
# end
|
70
|
+
# end
|
71
|
+
# end
|
72
|
+
# RUBY
|
73
|
+
# uri: 'file:///path/to/foo/bar.rb',
|
74
|
+
# ).definitions[2]
|
75
|
+
# expect(definition.return_types).to eq(%w[String])
|
85
76
|
def return_types
|
86
77
|
@types.map(&:return_type)
|
87
78
|
end
|
88
79
|
|
89
80
|
# @return [Array<String>]
|
90
81
|
# @example returns signature
|
91
|
-
#
|
92
|
-
#
|
93
|
-
#
|
94
|
-
#
|
95
|
-
#
|
96
|
-
#
|
97
|
-
#
|
98
|
-
#
|
99
|
-
#
|
100
|
-
#
|
101
|
-
#
|
82
|
+
# definition = Rucoa::Source.new(
|
83
|
+
# content: <<~RUBY,
|
84
|
+
# module Foo
|
85
|
+
# module Bar
|
86
|
+
# attr_writer :baz
|
87
|
+
# end
|
88
|
+
# end
|
89
|
+
# RUBY
|
90
|
+
# uri: 'file:///path/to/foo/bar.rb',
|
91
|
+
# ).definitions[2]
|
92
|
+
# expect(definition.signatures).to eq(
|
93
|
+
# [
|
94
|
+
# 'Foo::Bar#baz=(value) -> Object'
|
102
95
|
# ]
|
103
96
|
# )
|
104
|
-
# expect(method_definition.signatures).to eq(['Foo::Bar#foo(?::int base) -> String'])
|
105
97
|
def signatures
|
106
98
|
@types.map do |type|
|
107
99
|
format(
|
108
|
-
'%<
|
109
|
-
fully_qualified_name: fully_qualified_name,
|
100
|
+
'%<qualified_name>s(%<parameters>s) -> %<return_types>s',
|
110
101
|
parameters: type.parameters_string,
|
102
|
+
qualified_name: qualified_name,
|
111
103
|
return_types: type.return_type
|
112
104
|
)
|
113
105
|
end
|
@@ -3,6 +3,45 @@
|
|
3
3
|
module Rucoa
|
4
4
|
module Definitions
|
5
5
|
class ModuleDefinition < ConstantDefinition
|
6
|
+
# @return [Array<String>]
|
7
|
+
attr_accessor :included_module_qualified_names
|
8
|
+
|
9
|
+
# @return [Array<Rucoa::UnqualifiedName>]
|
10
|
+
attr_accessor :included_module_unqualified_names
|
11
|
+
|
12
|
+
# @return [Array<String>]
|
13
|
+
attr_accessor :prepended_module_qualified_names
|
14
|
+
|
15
|
+
# @return [Array<Rucoa::UnqualifiedName>]
|
16
|
+
attr_accessor :prepended_module_unqualified_names
|
17
|
+
|
18
|
+
# @param included_module_qualified_names [Array<String>]
|
19
|
+
# @param included_module_unqualified_names [Array<String>]
|
20
|
+
# @param prepended_module_qualified_names [Array<String>]
|
21
|
+
# @param prepended_module_unqualified_names [Array<String>]
|
22
|
+
def initialize(
|
23
|
+
included_module_qualified_names: [],
|
24
|
+
included_module_unqualified_names: [],
|
25
|
+
prepended_module_qualified_names: [],
|
26
|
+
prepended_module_unqualified_names: [],
|
27
|
+
**keyword_arguments
|
28
|
+
)
|
29
|
+
super(**keyword_arguments)
|
30
|
+
@included_module_qualified_names = included_module_qualified_names
|
31
|
+
@included_module_unqualified_names = included_module_unqualified_names
|
32
|
+
@prepended_module_qualified_names = prepended_module_qualified_names
|
33
|
+
@prepended_module_unqualified_names = prepended_module_unqualified_names
|
34
|
+
end
|
35
|
+
|
36
|
+
# @param other [Rucoa::Definitions::ModuleDefinition]
|
37
|
+
# @return [Rucoa::Definitions::ModuleDefinition]
|
38
|
+
def merge!(other)
|
39
|
+
self.included_module_qualified_names |= other.included_module_qualified_names
|
40
|
+
self.included_module_unqualified_names |= other.included_module_unqualified_names
|
41
|
+
self.prepended_module_qualified_names |= other.prepended_module_qualified_names
|
42
|
+
self.prepended_module_unqualified_names |= other.prepended_module_unqualified_names
|
43
|
+
self
|
44
|
+
end
|
6
45
|
end
|
7
46
|
end
|
8
47
|
end
|
@@ -53,7 +53,10 @@ module Rucoa
|
|
53
53
|
|
54
54
|
# @param source [Rucoa::Source]
|
55
55
|
# @param uri [String]
|
56
|
-
def initialize(
|
56
|
+
def initialize(
|
57
|
+
source:,
|
58
|
+
uri:
|
59
|
+
)
|
57
60
|
@source = source
|
58
61
|
@uri = uri
|
59
62
|
end
|
@@ -102,7 +105,11 @@ module Rucoa
|
|
102
105
|
# @param source [Rucoa::Source]
|
103
106
|
# @param uri [String]
|
104
107
|
# @return [Hash]
|
105
|
-
def call(
|
108
|
+
def call(
|
109
|
+
offense,
|
110
|
+
source:,
|
111
|
+
uri:
|
112
|
+
)
|
106
113
|
new(
|
107
114
|
offense,
|
108
115
|
source: source,
|
@@ -114,7 +121,11 @@ module Rucoa
|
|
114
121
|
# @param offense [RuboCop::Cop::Offense]
|
115
122
|
# @param source [Rucoa::Source]
|
116
123
|
# @param uri [String]
|
117
|
-
def initialize(
|
124
|
+
def initialize(
|
125
|
+
offense,
|
126
|
+
source:,
|
127
|
+
uri:
|
128
|
+
)
|
118
129
|
@offense = offense
|
119
130
|
@source = source
|
120
131
|
@uri = uri
|
data/lib/rucoa/handlers/base.rb
CHANGED
@@ -7,7 +7,10 @@ module Rucoa
|
|
7
7
|
# @param server [Rucoa::Server]
|
8
8
|
# @param request [Hash]
|
9
9
|
# @return [void]
|
10
|
-
def call(
|
10
|
+
def call(
|
11
|
+
request:,
|
12
|
+
server:
|
13
|
+
)
|
11
14
|
new(
|
12
15
|
request: request,
|
13
16
|
server: server
|
@@ -17,7 +20,10 @@ module Rucoa
|
|
17
20
|
|
18
21
|
# @param request [Hash]
|
19
22
|
# @param server [Rucoa::Server]
|
20
|
-
def initialize(
|
23
|
+
def initialize(
|
24
|
+
request:,
|
25
|
+
server:
|
26
|
+
)
|
21
27
|
@request = request
|
22
28
|
@server = server
|
23
29
|
end
|
@@ -61,7 +67,10 @@ module Rucoa
|
|
61
67
|
|
62
68
|
# @param message [Hash]
|
63
69
|
# @return [void]
|
64
|
-
def write(
|
70
|
+
def write(
|
71
|
+
message,
|
72
|
+
&block
|
73
|
+
)
|
65
74
|
@server.write(message, &block)
|
66
75
|
end
|
67
76
|
end
|
@@ -14,52 +14,15 @@ module Rucoa
|
|
14
14
|
return unless reponsible?
|
15
15
|
|
16
16
|
{
|
17
|
-
range:
|
18
|
-
uri:
|
17
|
+
range: definition.location.range.to_vscode_range,
|
18
|
+
uri: definition.location.uri
|
19
19
|
}
|
20
20
|
end
|
21
21
|
|
22
22
|
# @return [Boolean]
|
23
23
|
def reponsible?
|
24
24
|
configuration.enables_definition? &&
|
25
|
-
!
|
26
|
-
!location_source.nil?
|
27
|
-
end
|
28
|
-
|
29
|
-
# @return [Rucoa::Range]
|
30
|
-
def location_range
|
31
|
-
return Range.from_parser_range(location_node.location.expression) if location_node
|
32
|
-
|
33
|
-
Position.new.to_range
|
34
|
-
end
|
35
|
-
|
36
|
-
# @return [String, nil]
|
37
|
-
def location_uri
|
38
|
-
return unless definition
|
39
|
-
|
40
|
-
if definition.source_path.start_with?('Untitled-')
|
41
|
-
"untitled:#{definition.source_path}"
|
42
|
-
else
|
43
|
-
"file://#{definition.source_path}"
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
# @return [Rucoa::Nodes::Base, nil]
|
48
|
-
def location_node
|
49
|
-
@location_node ||=
|
50
|
-
case definition
|
51
|
-
when Definitions::ClassDefinition
|
52
|
-
find_class_node
|
53
|
-
when Definitions::ModuleDefinition
|
54
|
-
find_module_node
|
55
|
-
when Definitions::MethodDefinition
|
56
|
-
find_method_node
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
# @return [Rucoa::Source, nil]
|
61
|
-
def location_source
|
62
|
-
source_store.get(location_uri)
|
25
|
+
!definition&.location.nil?
|
63
26
|
end
|
64
27
|
|
65
28
|
# @return [Rucoa::Position]
|
@@ -91,65 +54,6 @@ module Rucoa
|
|
91
54
|
node: node
|
92
55
|
).definitions.first
|
93
56
|
end
|
94
|
-
|
95
|
-
# @return [Rucoa::Nodes::ClassNode, nil]
|
96
|
-
def find_class_node
|
97
|
-
find_by_fully_qualified_name(
|
98
|
-
fully_qualified_name: definition.fully_qualified_name,
|
99
|
-
klass: Nodes::ClassNode
|
100
|
-
) || find_by_name(
|
101
|
-
klass: Nodes::ClassNode,
|
102
|
-
name: definition.name
|
103
|
-
)
|
104
|
-
end
|
105
|
-
|
106
|
-
# @return [Rucoa::Nodes::ModuleNode, nil]
|
107
|
-
def find_module_node
|
108
|
-
find_by_fully_qualified_name(
|
109
|
-
fully_qualified_name: definition.fully_qualified_name,
|
110
|
-
klass: Nodes::ModuleNode
|
111
|
-
) || find_by_name(
|
112
|
-
klass: Nodes::ModuleNode,
|
113
|
-
name: definition.name
|
114
|
-
)
|
115
|
-
end
|
116
|
-
|
117
|
-
# @return [Rucoa::Nodes::MethodNode, nil]
|
118
|
-
def find_method_node
|
119
|
-
location_root_or_descendant_nodes.reverse.find do |node|
|
120
|
-
node.is_a?(Nodes::DefNode) &&
|
121
|
-
node.name == definition.method_name &&
|
122
|
-
node.namespace == definition.namespace
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
# @param fully_qualified_name [String]
|
127
|
-
# @param klass [Class]
|
128
|
-
# @return [Rucoa::Nodes::Base, nil]
|
129
|
-
def find_by_fully_qualified_name(fully_qualified_name:, klass:)
|
130
|
-
location_root_or_descendant_nodes.reverse.find do |node|
|
131
|
-
node.is_a?(klass) &&
|
132
|
-
node.fully_qualified_name == fully_qualified_name
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
# @param name [String]
|
137
|
-
# @param klass [Class]
|
138
|
-
# @return [Rucoa::Nodes::Base, nil]
|
139
|
-
def find_by_name(klass:, name:)
|
140
|
-
location_root_or_descendant_nodes.reverse.find do |node|
|
141
|
-
node.is_a?(klass) &&
|
142
|
-
node.name == name
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
# @return [Array<Rucoa::Nodes::Base>]
|
147
|
-
def location_root_or_descendant_nodes
|
148
|
-
@location_root_or_descendant_nodes ||= [
|
149
|
-
location_source.root_node,
|
150
|
-
*location_source.root_node.descendants
|
151
|
-
]
|
152
|
-
end
|
153
57
|
end
|
154
58
|
end
|
155
59
|
end
|
@@ -22,18 +22,24 @@ module Rucoa
|
|
22
22
|
# @return [Boolean]
|
23
23
|
def responsible?
|
24
24
|
configuration.enables_hover? &&
|
25
|
-
!
|
26
|
-
!node.nil? &&
|
27
|
-
!method_definitions.empty?
|
25
|
+
!contents.nil?
|
28
26
|
end
|
29
27
|
|
30
28
|
# @return [String, nil]
|
31
29
|
def contents
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
30
|
+
@contents ||=
|
31
|
+
case definition
|
32
|
+
when Definitions::ClassDefinition, Definitions::ConstantDefinition, Definitions::ModuleDefinition
|
33
|
+
[
|
34
|
+
definition.qualified_name,
|
35
|
+
definition.description
|
36
|
+
].compact.join("\n")
|
37
|
+
when Definitions::MethodDefinition
|
38
|
+
[
|
39
|
+
definition.signatures.join("\n"),
|
40
|
+
definition.description
|
41
|
+
].join("\n\n")
|
42
|
+
end
|
37
43
|
end
|
38
44
|
|
39
45
|
# @return [Rucoa::Range]
|
@@ -43,7 +49,7 @@ module Rucoa
|
|
43
49
|
|
44
50
|
# @return [Rucoa::Nodes::Base, nil]
|
45
51
|
def node
|
46
|
-
@node ||= source
|
52
|
+
@node ||= source&.node_at(position)
|
47
53
|
end
|
48
54
|
|
49
55
|
# @return [Rucoa::Source, nil]
|
@@ -63,12 +69,14 @@ module Rucoa
|
|
63
69
|
)
|
64
70
|
end
|
65
71
|
|
66
|
-
# @return [
|
67
|
-
def
|
68
|
-
|
72
|
+
# @return [Rucoa::Definitions::Base, nil]
|
73
|
+
def definition
|
74
|
+
return unless node
|
75
|
+
|
76
|
+
@definition ||= NodeInspector.new(
|
69
77
|
definition_store: definition_store,
|
70
78
|
node: node
|
71
|
-
).
|
79
|
+
).definitions.first
|
72
80
|
end
|
73
81
|
end
|
74
82
|
end
|
@@ -46,7 +46,10 @@ module Rucoa
|
|
46
46
|
# @param source [Rucoa::Source]
|
47
47
|
# @param position [Rucoa::Position]
|
48
48
|
# @return [Hash, nil]
|
49
|
-
def call(
|
49
|
+
def call(
|
50
|
+
position:,
|
51
|
+
source:
|
52
|
+
)
|
50
53
|
new(
|
51
54
|
position: position,
|
52
55
|
source: source
|
@@ -56,7 +59,10 @@ module Rucoa
|
|
56
59
|
|
57
60
|
# @param position [Rucoa::Position]
|
58
61
|
# @param source [Rucoa::Source]
|
59
|
-
def initialize(
|
62
|
+
def initialize(
|
63
|
+
position:,
|
64
|
+
source:
|
65
|
+
)
|
60
66
|
@position = position
|
61
67
|
@source = source
|
62
68
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Rucoa
|
4
|
+
Location = ::Struct.new(
|
5
|
+
:range,
|
6
|
+
:uri,
|
7
|
+
keyword_init: true
|
8
|
+
) do
|
9
|
+
class << self
|
10
|
+
# @param location [RBS::Location]
|
11
|
+
# @return [Rucoa::Location]
|
12
|
+
def from_rbs_location(location)
|
13
|
+
new(
|
14
|
+
range: Range.new(
|
15
|
+
Position.new(
|
16
|
+
column: location.start_column,
|
17
|
+
line: location.start_line
|
18
|
+
),
|
19
|
+
Position.new(
|
20
|
+
column: location.end_column,
|
21
|
+
line: location.end_line
|
22
|
+
)
|
23
|
+
),
|
24
|
+
uri: "file://#{location.name}"
|
25
|
+
)
|
26
|
+
end
|
27
|
+
|
28
|
+
# @param node [Rucoa::Nodes::Base]
|
29
|
+
def from_rucoa_node(node)
|
30
|
+
new(
|
31
|
+
range: Range.from_parser_range(node.location.expression),
|
32
|
+
uri: node.location.expression.source_buffer.name
|
33
|
+
)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Rucoa
|
4
|
+
module NodeConcerns
|
5
|
+
module Body
|
6
|
+
# @return [Rucoa::Nodes::BeginNode, nil]
|
7
|
+
def body
|
8
|
+
children[2]
|
9
|
+
end
|
10
|
+
|
11
|
+
# @return [Array<Rucoa::Nodes::Base>]
|
12
|
+
def body_children
|
13
|
+
case body
|
14
|
+
when Nodes::BeginNode
|
15
|
+
body.children
|
16
|
+
when nil
|
17
|
+
[]
|
18
|
+
else
|
19
|
+
[body]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/rucoa/node_concerns.rb
CHANGED