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.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +6 -0
  3. data/Gemfile.lock +8 -8
  4. data/data/definitions_ruby_3_1 +0 -0
  5. data/lib/rucoa/configuration.rb +4 -1
  6. data/lib/rucoa/definition_store.rb +216 -83
  7. data/lib/rucoa/definitions/base.rb +14 -3
  8. data/lib/rucoa/definitions/class_definition.rb +14 -64
  9. data/lib/rucoa/definitions/constant_definition.rb +31 -19
  10. data/lib/rucoa/definitions/method_definition.rb +44 -52
  11. data/lib/rucoa/definitions/method_parameter_definition.rb +4 -1
  12. data/lib/rucoa/definitions/module_definition.rb +39 -0
  13. data/lib/rucoa/handler_concerns/diagnostics_publishable.rb +14 -3
  14. data/lib/rucoa/handlers/base.rb +12 -3
  15. data/lib/rucoa/handlers/text_document_definition_handler.rb +3 -99
  16. data/lib/rucoa/handlers/text_document_hover_handler.rb +21 -13
  17. data/lib/rucoa/handlers/text_document_selection_range_handler.rb +8 -2
  18. data/lib/rucoa/location.rb +37 -0
  19. data/lib/rucoa/node_concerns/body.rb +24 -0
  20. data/lib/rucoa/node_concerns/{name_fully_qualifiable.rb → qualified_name.rb} +2 -2
  21. data/lib/rucoa/node_concerns.rb +2 -1
  22. data/lib/rucoa/node_inspector.rb +17 -22
  23. data/lib/rucoa/nodes/base.rb +22 -6
  24. data/lib/rucoa/nodes/begin_node.rb +8 -0
  25. data/lib/rucoa/nodes/casgn_node.rb +1 -1
  26. data/lib/rucoa/nodes/class_node.rb +2 -1
  27. data/lib/rucoa/nodes/const_node.rb +33 -15
  28. data/lib/rucoa/nodes/def_node.rb +2 -2
  29. data/lib/rucoa/nodes/defs_node.rb +1 -1
  30. data/lib/rucoa/nodes/module_node.rb +2 -1
  31. data/lib/rucoa/nodes.rb +2 -1
  32. data/lib/rucoa/parser.rb +14 -14
  33. data/lib/rucoa/parser_builder.rb +6 -1
  34. data/lib/rucoa/position.rb +10 -1
  35. data/lib/rucoa/range.rb +11 -1
  36. data/lib/rucoa/rbs/class_definition_mapper.rb +13 -28
  37. data/lib/rucoa/rbs/constant_definition_mapper.rb +12 -6
  38. data/lib/rucoa/rbs/method_definition_mapper.rb +12 -6
  39. data/lib/rucoa/rbs/module_definition_mapper.rb +34 -6
  40. data/lib/rucoa/rubocop/investigator.rb +4 -1
  41. data/lib/rucoa/server.rb +8 -2
  42. data/lib/rucoa/source.rb +19 -4
  43. data/lib/rucoa/unqualified_name.rb +9 -0
  44. data/lib/rucoa/version.rb +1 -1
  45. data/lib/rucoa/yard/definition_generators/attribute_reader_definition_generator.rb +60 -0
  46. data/lib/rucoa/yard/definition_generators/attribute_writer_definition_generator.rb +60 -0
  47. data/lib/rucoa/yard/definition_generators/base.rb +117 -0
  48. data/lib/rucoa/yard/definition_generators/class_definition_generator.rb +66 -0
  49. data/lib/rucoa/yard/definition_generators/constant_assignment_definition_generator.rb +29 -0
  50. data/lib/rucoa/yard/definition_generators/method_definition_generator.rb +47 -0
  51. data/lib/rucoa/yard/definition_generators/module_definition_generator.rb +62 -0
  52. data/lib/rucoa/yard/definition_generators.rb +15 -0
  53. data/lib/rucoa/yard/definitions_loader.rb +1 -271
  54. data/lib/rucoa/yard.rb +1 -0
  55. data/lib/rucoa.rb +4 -2
  56. metadata +15 -3
@@ -39,6 +39,7 @@ module Rucoa
39
39
  ].flat_map do |node|
40
40
  [
41
41
  DefinitionGenerators::ClassDefinitionGenerator,
42
+ DefinitionGenerators::ConstantAssignmentDefinitionGenerator,
42
43
  DefinitionGenerators::MethodDefinitionGenerator,
43
44
  DefinitionGenerators::ModuleDefinitionGenerator,
44
45
  DefinitionGenerators::AttributeReaderDefinitionGenerator,
@@ -58,277 +59,6 @@ module Rucoa
58
59
  parser_comment.text.gsub(/^#\s*/m, '')
59
60
  end.join("\n")
60
61
  end
61
-
62
- module DefinitionGenerators
63
- class Base
64
- class << self
65
- # @param comment [String]
66
- # @param node [Rucoa::Nodes::Base]
67
- # @return [Array<Rucoa::Definitions::Base>]
68
- def call(
69
- comment:,
70
- node:
71
- )
72
- new(
73
- comment: comment,
74
- node: node
75
- ).call
76
- end
77
- end
78
-
79
- # @param comment [String]
80
- # @param node [Rucoa::Nodes::Base]
81
- def initialize(
82
- comment:,
83
- node:
84
- )
85
- @comment = comment
86
- @node = node
87
- end
88
-
89
- # @return [Array<Rucoa::Definitions::Base>]
90
- def call
91
- raise ::NotImplementedError
92
- end
93
-
94
- private
95
-
96
- # @return [YARD::DocstringParser]
97
- def docstring_parser
98
- @docstring_parser ||= ::YARD::Logger.instance.enter_level(::Logger::FATAL) do
99
- ::YARD::Docstring.parser.parse(
100
- @comment,
101
- ::YARD::CodeObjects::Base.new(:root, 'stub')
102
- )
103
- end
104
- end
105
-
106
- # @return [Array<String>]
107
- # @example returns annotated return types if return tag is provided
108
- # definitions = Rucoa::Source.new(
109
- # content: <<~RUBY,
110
- # # @return [String]
111
- # def foo
112
- # end
113
- # RUBY
114
- # uri: '/path/to/foo.rb'
115
- # ).definitions
116
- # expect(definitions[0].return_types).to eq(%w[String])
117
- # @example returns Object if no return tag is provided
118
- # definitions = Rucoa::Source.new(
119
- # content: <<~RUBY,
120
- # def foo
121
- # end
122
- # RUBY
123
- # uri: '/path/to/foo.rb'
124
- # ).definitions
125
- # expect(definitions[0].return_types).to eq(%w[Object])
126
- def return_types
127
- types = docstring_parser.tags.select do |tag|
128
- tag.tag_name == 'return'
129
- end.flat_map(&:types).compact.map do |yard_type|
130
- Type.new(yard_type).to_rucoa_type
131
- end
132
- if types.empty?
133
- %w[Object]
134
- else
135
- types
136
- end
137
- end
138
- end
139
-
140
- class ClassDefinitionGenerator < Base
141
- # @example returns class definition for class node
142
- # definitions = Rucoa::Source.new(
143
- # content: <<~RUBY,
144
- # class Foo
145
- # end
146
- # RUBY
147
- # uri: '/path/to/foo.rb'
148
- # ).definitions
149
- # expect(definitions[0]).to be_a(Rucoa::Definitions::ClassDefinition)
150
- def call
151
- return [] unless @node.is_a?(Nodes::ClassNode)
152
-
153
- [
154
- Definitions::ClassDefinition.new(
155
- fully_qualified_name: @node.fully_qualified_name,
156
- module_nesting: @node.module_nesting,
157
- source_path: @node.location.expression.source_buffer.name,
158
- super_class_chained_name: @node.super_class_chained_name
159
- )
160
- ]
161
- end
162
- end
163
-
164
- class ModuleDefinitionGenerator < Base
165
- # @example returns module definition for module node
166
- # definitions = Rucoa::Source.new(
167
- # content: <<~RUBY,
168
- # module Foo
169
- # end
170
- # RUBY
171
- # uri: '/path/to/foo.rb'
172
- # ).definitions
173
- # expect(definitions[0]).to be_a(Rucoa::Definitions::ModuleDefinition)
174
- def call
175
- return [] unless @node.is_a?(Nodes::ModuleNode)
176
-
177
- [
178
- Definitions::ModuleDefinition.new(
179
- fully_qualified_name: @node.fully_qualified_name,
180
- source_path: @node.location.expression.source_buffer.name
181
- )
182
- ]
183
- end
184
- end
185
-
186
- class MethodDefinitionGenerator < Base
187
- # @example returns method definition for def node
188
- # definitions = Rucoa::Source.new(
189
- # content: <<~RUBY,
190
- # def foo
191
- # end
192
- # RUBY
193
- # uri: '/path/to/foo.rb'
194
- # ).definitions
195
- # expect(definitions[0]).to be_a(Rucoa::Definitions::MethodDefinition)
196
- # @example returns method definition for defs node
197
- # definitions = Rucoa::Source.new(
198
- # content: <<~RUBY,
199
- # def self.foo
200
- # end
201
- # RUBY
202
- # uri: '/path/to/foo.rb'
203
- # ).definitions
204
- # expect(definitions[0]).to be_a(Rucoa::Definitions::MethodDefinition)
205
- def call
206
- return [] unless @node.is_a?(Nodes::DefNode) || @node.is_a?(Nodes::DefsNode)
207
-
208
- [
209
- Definitions::MethodDefinition.new(
210
- description: docstring_parser.to_docstring.to_s,
211
- kind: @node.singleton? ? :singleton : :instance,
212
- method_name: @node.name,
213
- namespace: @node.namespace,
214
- source_path: @node.location.expression.source_buffer.name,
215
- types: return_types.map do |type|
216
- Types::MethodType.new(
217
- parameters_string: '', # TODO
218
- return_type: type
219
- )
220
- end
221
- )
222
- ]
223
- end
224
- end
225
-
226
- class AttributeReaderDefinitionGenerator < Base
227
- READER_METHOD_NAMES = ::Set[
228
- 'attr_accessor',
229
- 'attr_reader'
230
- ].freeze
231
-
232
- # @example returns method definition for attr_reader node
233
- # definitions = Rucoa::Source.new(
234
- # content: <<~RUBY,
235
- # class Foo
236
- # attr_reader :bar
237
- # end
238
- # RUBY
239
- # uri: '/path/to/foo.rb'
240
- # ).definitions
241
- # expect(definitions[1]).to be_a(Rucoa::Definitions::MethodDefinition)
242
- # @example returns method definition for attr_accessor node
243
- # definitions = Rucoa::Source.new(
244
- # content: <<~RUBY,
245
- # class Foo
246
- # attr_accessor :bar
247
- # end
248
- # RUBY
249
- # uri: '/path/to/foo.rb'
250
- # ).definitions
251
- # expect(definitions.map(&:fully_qualified_name)).to eq(
252
- # %w[
253
- # Foo
254
- # Foo#bar
255
- # Foo#bar=
256
- # ]
257
- # )
258
- def call
259
- return [] unless @node.is_a?(Nodes::SendNode) && READER_METHOD_NAMES.include?(@node.name)
260
-
261
- @node.arguments.map do |argument|
262
- Definitions::MethodDefinition.new(
263
- description: docstring_parser.to_docstring.to_s,
264
- kind: :instance,
265
- method_name: argument.value.to_s,
266
- namespace: @node.namespace,
267
- source_path: @node.location.expression.source_buffer.name,
268
- types: return_types.map do |type|
269
- Types::MethodType.new(
270
- parameters_string: '', # TODO
271
- return_type: type
272
- )
273
- end
274
- )
275
- end
276
- end
277
- end
278
-
279
- class AttributeWriterDefinitionGenerator < Base
280
- WRITER_METHOD_NAMES = ::Set[
281
- 'attr_accessor',
282
- 'attr_writer'
283
- ].freeze
284
-
285
- # @example returns method definition for attr_writer node
286
- # definitions = Rucoa::Source.new(
287
- # content: <<~RUBY,
288
- # class Foo
289
- # attr_writer :bar
290
- # end
291
- # RUBY
292
- # uri: '/path/to/foo.rb'
293
- # ).definitions
294
- # expect(definitions[1]).to be_a(Rucoa::Definitions::MethodDefinition)
295
- # @example returns method definition for attr_accessor node
296
- # definitions = Rucoa::Source.new(
297
- # content: <<~RUBY,
298
- # class Foo
299
- # attr_accessor :bar
300
- # end
301
- # RUBY
302
- # uri: '/path/to/foo.rb'
303
- # ).definitions
304
- # expect(definitions.map(&:fully_qualified_name)).to eq(
305
- # %w[
306
- # Foo
307
- # Foo#bar
308
- # Foo#bar=
309
- # ]
310
- # )
311
- def call
312
- return [] unless @node.is_a?(Nodes::SendNode) && WRITER_METHOD_NAMES.include?(@node.name)
313
-
314
- @node.arguments.map do |argument|
315
- Definitions::MethodDefinition.new(
316
- description: docstring_parser.to_docstring.to_s,
317
- kind: :instance,
318
- method_name: "#{argument.value}=",
319
- namespace: @node.namespace,
320
- source_path: @node.location.expression.source_buffer.name,
321
- types: return_types.map do |type|
322
- Types::MethodType.new(
323
- parameters_string: 'value', # TODO
324
- return_type: type
325
- )
326
- end
327
- )
328
- end
329
- end
330
- end
331
- end
332
62
  end
333
63
  end
334
64
  end
data/lib/rucoa/yard.rb CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  module Rucoa
4
4
  module Yard
5
+ autoload :DefinitionGenerators, 'rucoa/yard/definition_generators'
5
6
  autoload :DefinitionsLoader, 'rucoa/yard/definitions_loader'
6
7
  autoload :Type, 'rucoa/yard/type'
7
8
  end
data/lib/rucoa.rb CHANGED
@@ -6,19 +6,20 @@ module Rucoa
6
6
  autoload :Cli, 'rucoa/cli'
7
7
  autoload :Configuration, 'rucoa/configuration'
8
8
  autoload :DefinitionArchiver, 'rucoa/definition_archiver'
9
- autoload :Definitions, 'rucoa/definitions'
10
9
  autoload :DefinitionStore, 'rucoa/definition_store'
10
+ autoload :Definitions, 'rucoa/definitions'
11
11
  autoload :Errors, 'rucoa/errors'
12
12
  autoload :HandlerConcerns, 'rucoa/handler_concerns'
13
13
  autoload :Handlers, 'rucoa/handlers'
14
+ autoload :Location, 'rucoa/location'
14
15
  autoload :MessageReader, 'rucoa/message_reader'
15
16
  autoload :MessageWriter, 'rucoa/message_writer'
16
17
  autoload :NodeConcerns, 'rucoa/node_concerns'
17
18
  autoload :NodeInspector, 'rucoa/node_inspector'
18
19
  autoload :Nodes, 'rucoa/nodes'
20
+ autoload :ParseResult, 'rucoa/parse_result'
19
21
  autoload :Parser, 'rucoa/parser'
20
22
  autoload :ParserBuilder, 'rucoa/parser_builder'
21
- autoload :ParseResult, 'rucoa/parse_result'
22
23
  autoload :Position, 'rucoa/position'
23
24
  autoload :Range, 'rucoa/range'
24
25
  autoload :Rbs, 'rucoa/rbs'
@@ -27,5 +28,6 @@ module Rucoa
27
28
  autoload :Source, 'rucoa/source'
28
29
  autoload :SourceStore, 'rucoa/source_store'
29
30
  autoload :Types, 'rucoa/types'
31
+ autoload :UnqualifiedName, 'rucoa/unqualified_name'
30
32
  autoload :Yard, 'rucoa/yard'
31
33
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rucoa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryo Nakamura
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-09-21 00:00:00.000000000 Z
11
+ date: 2022-09-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parser
@@ -123,13 +123,16 @@ files:
123
123
  - lib/rucoa/handlers/text_document_selection_range_handler.rb
124
124
  - lib/rucoa/handlers/text_document_signature_help_handler.rb
125
125
  - lib/rucoa/handlers/workspace_did_change_configuration_handler.rb
126
+ - lib/rucoa/location.rb
126
127
  - lib/rucoa/message_reader.rb
127
128
  - lib/rucoa/message_writer.rb
128
129
  - lib/rucoa/node_concerns.rb
129
- - lib/rucoa/node_concerns/name_fully_qualifiable.rb
130
+ - lib/rucoa/node_concerns/body.rb
131
+ - lib/rucoa/node_concerns/qualified_name.rb
130
132
  - lib/rucoa/node_inspector.rb
131
133
  - lib/rucoa/nodes.rb
132
134
  - lib/rucoa/nodes/base.rb
135
+ - lib/rucoa/nodes/begin_node.rb
133
136
  - lib/rucoa/nodes/casgn_node.rb
134
137
  - lib/rucoa/nodes/cbase_node.rb
135
138
  - lib/rucoa/nodes/class_node.rb
@@ -162,8 +165,17 @@ files:
162
165
  - lib/rucoa/source_store.rb
163
166
  - lib/rucoa/types.rb
164
167
  - lib/rucoa/types/method_type.rb
168
+ - lib/rucoa/unqualified_name.rb
165
169
  - lib/rucoa/version.rb
166
170
  - lib/rucoa/yard.rb
171
+ - lib/rucoa/yard/definition_generators.rb
172
+ - lib/rucoa/yard/definition_generators/attribute_reader_definition_generator.rb
173
+ - lib/rucoa/yard/definition_generators/attribute_writer_definition_generator.rb
174
+ - lib/rucoa/yard/definition_generators/base.rb
175
+ - lib/rucoa/yard/definition_generators/class_definition_generator.rb
176
+ - lib/rucoa/yard/definition_generators/constant_assignment_definition_generator.rb
177
+ - lib/rucoa/yard/definition_generators/method_definition_generator.rb
178
+ - lib/rucoa/yard/definition_generators/module_definition_generator.rb
167
179
  - lib/rucoa/yard/definitions_loader.rb
168
180
  - lib/rucoa/yard/type.rb
169
181
  - rucoa.gemspec