rucoa 0.8.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/data/definitions_ruby_3_1 +0 -0
- data/lib/rucoa/definition_store.rb +114 -54
- data/lib/rucoa/definitions/class_definition.rb +70 -4
- data/lib/rucoa/definitions/constant_definition.rb +7 -7
- data/lib/rucoa/definitions/method_definition.rb +4 -4
- data/lib/rucoa/handlers/initialized_handler.rb +33 -5
- data/lib/rucoa/handlers/text_document_completion_handler.rb +1 -1
- data/lib/rucoa/handlers/text_document_definition_handler.rb +7 -7
- data/lib/rucoa/handlers/text_document_did_open_handler.rb +1 -4
- data/lib/rucoa/node_concerns/{name_full_qualifiable.rb → name_fully_qualifiable.rb} +2 -2
- data/lib/rucoa/node_concerns.rb +1 -1
- data/lib/rucoa/node_inspector.rb +18 -17
- data/lib/rucoa/nodes/base.rb +30 -5
- data/lib/rucoa/nodes/casgn_node.rb +1 -1
- data/lib/rucoa/nodes/cbase_node.rb +8 -0
- data/lib/rucoa/nodes/class_node.rb +62 -1
- data/lib/rucoa/nodes/const_node.rb +46 -5
- data/lib/rucoa/nodes/def_node.rb +11 -9
- data/lib/rucoa/nodes/defs_node.rb +21 -0
- data/lib/rucoa/nodes/lvar_node.rb +2 -1
- data/lib/rucoa/nodes/module_node.rb +1 -1
- data/lib/rucoa/nodes/send_node.rb +14 -10
- data/lib/rucoa/nodes.rb +1 -0
- data/lib/rucoa/parse_result.rb +29 -0
- data/lib/rucoa/parser.rb +40 -8
- data/lib/rucoa/parser_builder.rb +1 -0
- data/lib/rucoa/rbs/class_definition_mapper.rb +4 -4
- data/lib/rucoa/rbs/constant_definition_mapper.rb +2 -2
- data/lib/rucoa/rbs/module_definition_mapper.rb +2 -2
- data/lib/rucoa/rubocop/autocorrector.rb +2 -2
- data/lib/rucoa/rubocop/investigator.rb +2 -2
- data/lib/rucoa/server.rb +1 -1
- data/lib/rucoa/source.rb +42 -27
- data/lib/rucoa/source_store.rb +0 -13
- data/lib/rucoa/version.rb +1 -1
- data/lib/rucoa/yard/definitions_loader.rb +308 -59
- data/lib/rucoa/yard/type.rb +46 -0
- data/lib/rucoa/yard.rb +1 -1
- data/lib/rucoa.rb +1 -0
- metadata +6 -4
- data/lib/rucoa/yard/method_definition_mapper.rb +0 -215
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 237fa68185426d66437c43fc2a3f34f7f85ee7309eb4ed6bb6ce4e31b5dfbb6e
|
4
|
+
data.tar.gz: e9f96daf65c7ccef564b2e06756497fd4d98bd946911487ca2fdd32740436e4b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3698e9db246d46ce64314df9b4a7418278a6e9f65cc2e80dfece624b547c5ab238af42b456370d1096e872f6e30aefdb132b5b2bd435ec03d1e6cccdac0a908a
|
7
|
+
data.tar.gz: 5088d4dcc1fa5ad6e053a155246da87602071fa8283b4f42e1b4e9040b222be5f82622343ad2467b5cdf8003b02293e70ea8d391dc99f478ee36a1389311a9d4
|
data/Gemfile.lock
CHANGED
data/data/definitions_ruby_3_1
CHANGED
Binary file
|
@@ -2,26 +2,69 @@
|
|
2
2
|
|
3
3
|
module Rucoa
|
4
4
|
class DefinitionStore
|
5
|
-
# @return [Array<Rucoa::Definition::Base>]
|
6
|
-
attr_accessor :definitions
|
7
|
-
|
8
5
|
def initialize
|
9
|
-
@
|
6
|
+
@definition_by_full_qualified_name = {}
|
7
|
+
@fully_qualified_names_by_uri = ::Hash.new { |hash, key| hash[key] = [] }
|
10
8
|
end
|
11
9
|
|
12
|
-
# @param
|
13
|
-
# @return [
|
14
|
-
def
|
15
|
-
|
16
|
-
|
10
|
+
# @param definitions [Array<Rucoa::Definition::Base>]
|
11
|
+
# @return [void]
|
12
|
+
def bulk_add(definitions)
|
13
|
+
definitions.each do |definition|
|
14
|
+
@fully_qualified_names_by_uri["file://#{definition.source_path}"] << definition.fully_qualified_name
|
15
|
+
@definition_by_full_qualified_name[definition.fully_qualified_name] = definition
|
16
|
+
end
|
17
17
|
end
|
18
18
|
|
19
|
-
# @param
|
20
|
-
# @return [
|
21
|
-
|
22
|
-
|
23
|
-
|
19
|
+
# @param source [Rucoa::Source]
|
20
|
+
# @return [void]
|
21
|
+
# @example resolves super class name correctly by using existent definitions
|
22
|
+
# definition_store = Rucoa::DefinitionStore.new
|
23
|
+
# foo = Rucoa::Source.new(
|
24
|
+
# content: <<~RUBY,
|
25
|
+
# module A
|
26
|
+
# class Foo
|
27
|
+
# end
|
28
|
+
# end
|
29
|
+
# RUBY
|
30
|
+
# uri: 'file:///path/to/a/foo.rb',
|
31
|
+
# )
|
32
|
+
# definition_store.update_from(foo)
|
33
|
+
# bar = Rucoa::Source.new(
|
34
|
+
# content: <<~RUBY,
|
35
|
+
# module A
|
36
|
+
# class Bar < Foo
|
37
|
+
# end
|
38
|
+
# end
|
39
|
+
# RUBY
|
40
|
+
# uri: 'file:///path/to/a/bar.rb',
|
41
|
+
# )
|
42
|
+
# definition_store.update_from(bar)
|
43
|
+
# definition = definition_store.find_definition_by_fully_qualified_name('A::Bar')
|
44
|
+
# expect(definition.super_class_fully_qualified_name).to eq('A::Foo')
|
45
|
+
def update_from(source)
|
46
|
+
delete_definitions_about(source)
|
47
|
+
|
48
|
+
# Need to store definitions before super class resolution.
|
49
|
+
source.definitions.group_by(&:source_path).each do |source_path, definitions|
|
50
|
+
@fully_qualified_names_by_uri["file://#{source_path}"] += definitions.map(&:fully_qualified_name)
|
51
|
+
definitions.each do |definition|
|
52
|
+
@definition_by_full_qualified_name[definition.fully_qualified_name] = definition
|
53
|
+
end
|
24
54
|
end
|
55
|
+
|
56
|
+
source.definitions.each do |definition|
|
57
|
+
next unless definition.is_a?(Definitions::ClassDefinition)
|
58
|
+
next if definition.super_class_resolved?
|
59
|
+
|
60
|
+
definition.super_class_fully_qualified_name = resolve_super_class_of(definition)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
# @param fully_qualified_name [String]
|
65
|
+
# @return [Rucoa::Definitions::Base, nil]
|
66
|
+
def find_definition_by_fully_qualified_name(fully_qualified_name)
|
67
|
+
@definition_by_full_qualified_name[fully_qualified_name]
|
25
68
|
end
|
26
69
|
|
27
70
|
# @param method_name [String]
|
@@ -30,20 +73,29 @@ module Rucoa
|
|
30
73
|
# @return [Rucoa::Definition::MethodDefinition, nil]
|
31
74
|
# @example has the ability to find `IO.write` from `File.write`
|
32
75
|
# definition_store = Rucoa::DefinitionStore.new
|
33
|
-
# definition_store.
|
76
|
+
# definition_store.bulk_add(Rucoa::DefinitionArchiver.load)
|
34
77
|
# subject = definition_store.find_method_definition_by(
|
35
78
|
# method_name: 'write',
|
36
79
|
# namespace: 'File',
|
37
80
|
# singleton: true
|
38
81
|
# )
|
39
|
-
# expect(subject.
|
82
|
+
# expect(subject.fully_qualified_name).to eq('IO.write')
|
40
83
|
def find_method_definition_by(method_name:, namespace:, singleton: false)
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
84
|
+
definition = find_definition_by_fully_qualified_name(namespace)
|
85
|
+
return unless definition
|
86
|
+
|
87
|
+
[
|
88
|
+
namespace,
|
89
|
+
*ancestor_definitions_of(definition).map(&:fully_qualified_name)
|
90
|
+
].find do |fully_qualified_name|
|
91
|
+
method_marker = singleton ? '.' : '#'
|
92
|
+
fully_qualified_method_name = [
|
93
|
+
fully_qualified_name,
|
94
|
+
method_marker,
|
95
|
+
method_name
|
96
|
+
].join
|
97
|
+
definition = find_definition_by_fully_qualified_name(fully_qualified_method_name)
|
98
|
+
break definition if definition
|
47
99
|
end
|
48
100
|
end
|
49
101
|
|
@@ -51,28 +103,28 @@ module Rucoa
|
|
51
103
|
# @return [Array<Rucoa::Definitions::MethodDefinition>]
|
52
104
|
# @example includes ancestors' methods
|
53
105
|
# definition_store = Rucoa::DefinitionStore.new
|
54
|
-
# definition_store.
|
106
|
+
# definition_store.bulk_add(Rucoa::DefinitionArchiver.load)
|
55
107
|
# subject = definition_store.instance_method_definitions_of('File')
|
56
|
-
# expect(subject.map(&:
|
108
|
+
# expect(subject.map(&:fully_qualified_name)).to include('IO#raw')
|
57
109
|
# @example responds to `singleton<File>`
|
58
110
|
# definition_store = Rucoa::DefinitionStore.new
|
59
|
-
# definition_store.
|
111
|
+
# definition_store.bulk_add(Rucoa::DefinitionArchiver.load)
|
60
112
|
# subject = definition_store.instance_method_definitions_of('singleton<File>')
|
61
|
-
# expect(subject.map(&:
|
113
|
+
# expect(subject.map(&:fully_qualified_name)).to include('IO.write')
|
62
114
|
def instance_method_definitions_of(type)
|
63
115
|
singleton_class_name = singleton_class_name_from(type)
|
64
116
|
return singleton_method_definitions_of(singleton_class_name) if singleton_class_name
|
65
117
|
|
66
|
-
class_or_module_definition =
|
118
|
+
class_or_module_definition = find_definition_by_fully_qualified_name(type)
|
67
119
|
return [] unless class_or_module_definition
|
68
120
|
|
69
121
|
definitions = instance_method_definitions
|
70
122
|
[
|
71
123
|
class_or_module_definition,
|
72
124
|
*ancestor_definitions_of(class_or_module_definition)
|
73
|
-
].map(&:
|
125
|
+
].map(&:fully_qualified_name).flat_map do |fully_qualified_type_name|
|
74
126
|
definitions.select do |definition|
|
75
|
-
definition.namespace ==
|
127
|
+
definition.namespace == fully_qualified_type_name
|
76
128
|
end
|
77
129
|
end
|
78
130
|
end
|
@@ -81,29 +133,24 @@ module Rucoa
|
|
81
133
|
# @return [Array<Rucoa::Definitions::MethodDefinition>]
|
82
134
|
# @example returns singleton method definitions of File
|
83
135
|
# definition_store = Rucoa::DefinitionStore.new
|
84
|
-
# definition_store.
|
136
|
+
# definition_store.bulk_add(Rucoa::DefinitionArchiver.load)
|
85
137
|
# subject = definition_store.singleton_method_definitions_of('File')
|
86
|
-
# expect(subject.map(&:
|
138
|
+
# expect(subject.map(&:fully_qualified_name)).to include('IO.write')
|
87
139
|
def singleton_method_definitions_of(type)
|
88
|
-
class_or_module_definition =
|
140
|
+
class_or_module_definition = find_definition_by_fully_qualified_name(type)
|
89
141
|
return [] unless class_or_module_definition
|
90
142
|
|
91
143
|
definitions = singleton_method_definitions
|
92
144
|
[
|
93
145
|
class_or_module_definition,
|
94
146
|
*ancestor_definitions_of(class_or_module_definition)
|
95
|
-
].map(&:
|
147
|
+
].map(&:fully_qualified_name).flat_map do |fully_qualified_type_name|
|
96
148
|
definitions.select do |definition|
|
97
|
-
definition.namespace ==
|
149
|
+
definition.namespace == fully_qualified_type_name
|
98
150
|
end
|
99
151
|
end
|
100
152
|
end
|
101
153
|
|
102
|
-
# @return [Array<Rucoa::Definition::ConstantDefinition>]
|
103
|
-
def constant_definitions
|
104
|
-
@definitions.grep(Definitions::ConstantDefinition)
|
105
|
-
end
|
106
|
-
|
107
154
|
# @param namespace [String]
|
108
155
|
# @return [Array<Rucoa::Definitions::ConstantDefinition>] e.g. File::Separator, File::SEPARATOR, etc.
|
109
156
|
def constant_definitions_under(namespace)
|
@@ -114,6 +161,15 @@ module Rucoa
|
|
114
161
|
|
115
162
|
private
|
116
163
|
|
164
|
+
# @param source [Rucoa::Source]
|
165
|
+
# @return [void]
|
166
|
+
def delete_definitions_about(source)
|
167
|
+
@fully_qualified_names_by_uri[source.uri].each do |fully_qualified_name|
|
168
|
+
@definition_by_full_qualified_name.delete(fully_qualified_name)
|
169
|
+
end
|
170
|
+
@fully_qualified_names_by_uri.delete(source.uri)
|
171
|
+
end
|
172
|
+
|
117
173
|
# @param type [String]
|
118
174
|
# @return [String, nil]
|
119
175
|
def singleton_class_name_from(type)
|
@@ -127,8 +183,8 @@ module Rucoa
|
|
127
183
|
|
128
184
|
result = []
|
129
185
|
class_definition = class_or_module_definition
|
130
|
-
while (
|
131
|
-
class_definition =
|
186
|
+
while (super_class_fully_qualified_name = class_definition.super_class_fully_qualified_name)
|
187
|
+
class_definition = find_definition_by_fully_qualified_name(super_class_fully_qualified_name)
|
132
188
|
break unless class_definition
|
133
189
|
|
134
190
|
result << class_definition
|
@@ -136,17 +192,14 @@ module Rucoa
|
|
136
192
|
result
|
137
193
|
end
|
138
194
|
|
139
|
-
# @
|
140
|
-
|
141
|
-
|
142
|
-
@definitions.find do |definition|
|
143
|
-
definition.full_qualified_name == type
|
144
|
-
end
|
195
|
+
# @return [Array<Rucoa::Definitions::Base>]
|
196
|
+
def definitions
|
197
|
+
@definition_by_full_qualified_name.values
|
145
198
|
end
|
146
199
|
|
147
200
|
# @return [Array<Rucoa::Definition::MethodDefinition>]
|
148
201
|
def method_definitions
|
149
|
-
|
202
|
+
definitions.grep(Definitions::MethodDefinition)
|
150
203
|
end
|
151
204
|
|
152
205
|
# @return [Array<Rucoa::Definition::MethodDefinition>]
|
@@ -159,12 +212,19 @@ module Rucoa
|
|
159
212
|
method_definitions.select(&:singleton_method?)
|
160
213
|
end
|
161
214
|
|
162
|
-
# @
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
215
|
+
# @return [Array<Rucoa::Definition::ConstantDefinition>]
|
216
|
+
def constant_definitions
|
217
|
+
definitions.grep(Definitions::ConstantDefinition)
|
218
|
+
end
|
219
|
+
|
220
|
+
# @param class_definition [Rucoa::Definitions::ClassDefinition]
|
221
|
+
# @return [String]
|
222
|
+
def resolve_super_class_of(class_definition)
|
223
|
+
return 'Object' unless class_definition.super_class_chained_name
|
224
|
+
|
225
|
+
class_definition.super_class_candidates.find do |candidate|
|
226
|
+
find_definition_by_fully_qualified_name(candidate)
|
227
|
+
end || class_definition.super_class_chained_name
|
168
228
|
end
|
169
229
|
end
|
170
230
|
end
|
@@ -3,13 +3,79 @@
|
|
3
3
|
module Rucoa
|
4
4
|
module Definitions
|
5
5
|
class ClassDefinition < ModuleDefinition
|
6
|
+
# @return [Arra<String>, nil]
|
7
|
+
attr_reader :module_nesting
|
8
|
+
|
9
|
+
# @return [String, nil]
|
10
|
+
attr_reader :super_class_chained_name
|
11
|
+
|
6
12
|
# @return [String, nil]
|
7
|
-
|
13
|
+
attr_accessor :super_class_fully_qualified_name
|
8
14
|
|
9
|
-
# @param
|
10
|
-
|
15
|
+
# @param module_nesting [Array<String>, nil]
|
16
|
+
# @param super_class_chained_name [String, nil]
|
17
|
+
# @param super_class_fully_qualified_name [String, nil]
|
18
|
+
def initialize(
|
19
|
+
module_nesting: nil,
|
20
|
+
super_class_chained_name: nil,
|
21
|
+
super_class_fully_qualified_name: nil,
|
22
|
+
**keyword_arguments
|
23
|
+
)
|
11
24
|
super(**keyword_arguments)
|
12
|
-
@
|
25
|
+
@module_nesting = module_nesting
|
26
|
+
@super_class_chained_name = super_class_chained_name
|
27
|
+
@super_class_fully_qualified_name = super_class_fully_qualified_name
|
28
|
+
end
|
29
|
+
|
30
|
+
# @return [Boolean]
|
31
|
+
# @example returns false on not-resolved case
|
32
|
+
# definition = Rucoa::Definitions::ClassDefinition.new(
|
33
|
+
# fully_qualified_name: 'Foo',
|
34
|
+
# source_path: '/path/to/foo.rb',
|
35
|
+
# super_class_chained_name: 'Bar'
|
36
|
+
# )
|
37
|
+
# expect(definition).not_to be_super_class_resolved
|
38
|
+
# @example returns true on resolved case
|
39
|
+
# definition = Rucoa::Definitions::ClassDefinition.new(
|
40
|
+
# fully_qualified_name: 'Foo',
|
41
|
+
# source_path: '/path/to/foo.rb',
|
42
|
+
# super_class_chained_name: 'Bar',
|
43
|
+
# super_class_fully_qualified_name: 'Bar'
|
44
|
+
# )
|
45
|
+
# expect(definition).to be_super_class_resolved
|
46
|
+
def super_class_resolved?
|
47
|
+
!@super_class_fully_qualified_name.nil?
|
48
|
+
end
|
49
|
+
|
50
|
+
# @return [Array<String>]
|
51
|
+
# @example returns candidates of super class fully qualified name
|
52
|
+
# class_definition = Rucoa::Definitions::ClassDefinition.new(
|
53
|
+
# fully_qualified_name: nil,
|
54
|
+
# module_nesting: %w[B::A B],
|
55
|
+
# source_path: '/path/to/b/a/c.rb',
|
56
|
+
# super_class_chained_name: 'C'
|
57
|
+
# )
|
58
|
+
# expect(class_definition.super_class_candidates).to eq(
|
59
|
+
# %w[B::A::C B::C C]
|
60
|
+
# )
|
61
|
+
# @example returns only correct answer if it's already resolved
|
62
|
+
# class_definition = Rucoa::Definitions::ClassDefinition.new(
|
63
|
+
# fully_qualified_name: 'B::A::C',
|
64
|
+
# source_path: '/path/to/b/a/c.rb',
|
65
|
+
# super_class_fully_qualified_name: 'B::A::C'
|
66
|
+
# )
|
67
|
+
# expect(class_definition.super_class_candidates).to eq(
|
68
|
+
# %w[B::A::C]
|
69
|
+
# )
|
70
|
+
def super_class_candidates
|
71
|
+
return [super_class_fully_qualified_name] if super_class_resolved?
|
72
|
+
|
73
|
+
module_nesting.map do |chained_name|
|
74
|
+
[
|
75
|
+
chained_name,
|
76
|
+
super_class_chained_name
|
77
|
+
].join('::')
|
78
|
+
end + [super_class_chained_name]
|
13
79
|
end
|
14
80
|
end
|
15
81
|
end
|
@@ -5,23 +5,23 @@ 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 :fully_qualified_name
|
9
9
|
|
10
10
|
# @return [String]
|
11
11
|
attr_reader :source_path
|
12
12
|
|
13
|
-
# @param
|
13
|
+
# @param fully_qualified_name [String]
|
14
14
|
# @param source_path [String]
|
15
|
-
def initialize(
|
15
|
+
def initialize(fully_qualified_name:, source_path:)
|
16
16
|
super()
|
17
|
-
@
|
17
|
+
@fully_qualified_name = fully_qualified_name
|
18
18
|
@source_path = source_path
|
19
19
|
end
|
20
20
|
|
21
21
|
# @return [String]
|
22
22
|
# @example returns non-full-qualified name
|
23
23
|
# definition = Rucoa::Definitions::ConstantDefinition.new(
|
24
|
-
#
|
24
|
+
# fully_qualified_name: 'Foo::Bar::Baz',
|
25
25
|
# source_path: '/path/to/foo/bar/baz.rb'
|
26
26
|
# )
|
27
27
|
# expect(definition.name).to eq('Baz')
|
@@ -32,7 +32,7 @@ module Rucoa
|
|
32
32
|
# @return [String]
|
33
33
|
# @example returns namespace
|
34
34
|
# definition = Rucoa::Definitions::ConstantDefinition.new(
|
35
|
-
#
|
35
|
+
# fully_qualified_name: 'Foo::Bar::Baz',
|
36
36
|
# source_path: '/path/to/foo/bar/baz.rb'
|
37
37
|
# )
|
38
38
|
# expect(definition.namespace).to eq('Foo::Bar')
|
@@ -44,7 +44,7 @@ module Rucoa
|
|
44
44
|
|
45
45
|
# @return [Array<String>]
|
46
46
|
def names
|
47
|
-
@names ||=
|
47
|
+
@names ||= fully_qualified_name.split('::')
|
48
48
|
end
|
49
49
|
end
|
50
50
|
end
|
@@ -51,8 +51,8 @@ module Rucoa
|
|
51
51
|
# source_path: '/path/to/foo/bar.rb',
|
52
52
|
# types: []
|
53
53
|
# )
|
54
|
-
# expect(method_definition.
|
55
|
-
def
|
54
|
+
# expect(method_definition.fully_qualified_name).to eq('Foo::Bar#foo')
|
55
|
+
def fully_qualified_name
|
56
56
|
[
|
57
57
|
@namespace,
|
58
58
|
method_kind_symbol,
|
@@ -105,8 +105,8 @@ module Rucoa
|
|
105
105
|
def signatures
|
106
106
|
@types.map do |type|
|
107
107
|
format(
|
108
|
-
'%<
|
109
|
-
|
108
|
+
'%<fully_qualified_name>s(%<parameters>s) -> %<return_types>s',
|
109
|
+
fully_qualified_name: fully_qualified_name,
|
110
110
|
parameters: type.parameters_string,
|
111
111
|
return_types: type.return_type
|
112
112
|
)
|
@@ -7,16 +7,44 @@ module Rucoa
|
|
7
7
|
|
8
8
|
def call
|
9
9
|
request_workspace_configuration
|
10
|
-
|
10
|
+
update_source_store
|
11
|
+
update_definition_store
|
11
12
|
end
|
12
13
|
|
13
14
|
private
|
14
15
|
|
15
16
|
# @return [void]
|
16
|
-
def
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
def update_definition_store
|
18
|
+
sources.each do |source|
|
19
|
+
definition_store.update_from(source)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# @return [void]
|
24
|
+
def update_source_store
|
25
|
+
sources.each do |source|
|
26
|
+
source_store.update(source)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# @return [Array<Rucoa::Source>]
|
31
|
+
def sources
|
32
|
+
@sources ||= pathnames.map do |pathname|
|
33
|
+
Source.new(
|
34
|
+
content: pathname.read,
|
35
|
+
uri: "file://#{pathname}"
|
36
|
+
)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
# @return [Array<Pathname>]
|
41
|
+
def pathnames
|
42
|
+
::Pathname.glob(glob)
|
43
|
+
end
|
44
|
+
|
45
|
+
# @return [String]
|
46
|
+
def glob
|
47
|
+
::File.expand_path('{app,lib}/**/*.rb')
|
20
48
|
end
|
21
49
|
end
|
22
50
|
end
|
@@ -94,8 +94,8 @@ module Rucoa
|
|
94
94
|
|
95
95
|
# @return [Rucoa::Nodes::ClassNode, nil]
|
96
96
|
def find_class_node
|
97
|
-
|
98
|
-
|
97
|
+
find_by_fully_qualified_name(
|
98
|
+
fully_qualified_name: definition.fully_qualified_name,
|
99
99
|
klass: Nodes::ClassNode
|
100
100
|
) || find_by_name(
|
101
101
|
klass: Nodes::ClassNode,
|
@@ -105,8 +105,8 @@ module Rucoa
|
|
105
105
|
|
106
106
|
# @return [Rucoa::Nodes::ModuleNode, nil]
|
107
107
|
def find_module_node
|
108
|
-
|
109
|
-
|
108
|
+
find_by_fully_qualified_name(
|
109
|
+
fully_qualified_name: definition.fully_qualified_name,
|
110
110
|
klass: Nodes::ModuleNode
|
111
111
|
) || find_by_name(
|
112
112
|
klass: Nodes::ModuleNode,
|
@@ -123,13 +123,13 @@ module Rucoa
|
|
123
123
|
end
|
124
124
|
end
|
125
125
|
|
126
|
-
# @param
|
126
|
+
# @param fully_qualified_name [String]
|
127
127
|
# @param klass [Class]
|
128
128
|
# @return [Rucoa::Nodes::Base, nil]
|
129
|
-
def
|
129
|
+
def find_by_fully_qualified_name(fully_qualified_name:, klass:)
|
130
130
|
location_root_or_descendant_nodes.reverse.find do |node|
|
131
131
|
node.is_a?(klass) &&
|
132
|
-
node.
|
132
|
+
node.fully_qualified_name == fully_qualified_name
|
133
133
|
end
|
134
134
|
end
|
135
135
|
|
data/lib/rucoa/node_concerns.rb
CHANGED
data/lib/rucoa/node_inspector.rb
CHANGED
@@ -90,20 +90,20 @@ module Rucoa
|
|
90
90
|
def constant_definition
|
91
91
|
return unless @node.is_a?(Nodes::ConstNode)
|
92
92
|
|
93
|
-
|
94
|
-
|
93
|
+
module_nesting = @node.module_nesting
|
94
|
+
candidate_fully_qualified_names = module_nesting.flat_map do |module_nesting_fully_qualified_name|
|
95
95
|
[
|
96
|
-
|
97
|
-
# TODO: *ancestors_of(
|
98
|
-
].map do |
|
96
|
+
module_nesting_fully_qualified_name
|
97
|
+
# TODO: *ancestors_of(module_nesting_fully_qualified_name)
|
98
|
+
].map do |fully_qualified_name|
|
99
99
|
[
|
100
|
-
|
100
|
+
fully_qualified_name,
|
101
101
|
@node.chained_name
|
102
102
|
].join('::')
|
103
103
|
end
|
104
104
|
end + [@node.chained_name]
|
105
|
-
|
106
|
-
definition = @definition_store.
|
105
|
+
candidate_fully_qualified_names.find do |candidate_fully_qualified_name|
|
106
|
+
definition = @definition_store.find_definition_by_fully_qualified_name(candidate_fully_qualified_name)
|
107
107
|
break definition if definition
|
108
108
|
end
|
109
109
|
end
|
@@ -114,20 +114,21 @@ module Rucoa
|
|
114
114
|
end
|
115
115
|
|
116
116
|
# @return [String, nil]
|
117
|
-
def
|
118
|
-
@node.each_ancestor(:def).first&.
|
117
|
+
def nearest_def_fully_qualified_name
|
118
|
+
@node.each_ancestor(:def).first&.fully_qualified_name
|
119
119
|
end
|
120
120
|
|
121
121
|
# @return [Array<String>]
|
122
122
|
def return_types_for_lvar
|
123
|
-
|
124
|
-
return [] unless
|
123
|
+
fully_qualified_name = nearest_def_fully_qualified_name
|
124
|
+
return [] unless fully_qualified_name
|
125
125
|
|
126
|
-
@definition_store.
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
126
|
+
definition = @definition_store.find_definition_by_fully_qualified_name(fully_qualified_name)
|
127
|
+
return [] unless definition
|
128
|
+
|
129
|
+
definition.parameters.select do |parameter|
|
130
|
+
parameter.name == @node.name
|
131
|
+
end.flat_map(&:types)
|
131
132
|
end
|
132
133
|
|
133
134
|
# @return [Array<String>]
|