rucoa 0.5.1 → 0.7.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 (40) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/README.md +12 -13
  4. data/data/definitions_ruby_3_1 +0 -0
  5. data/lib/rucoa/cli.rb +3 -2
  6. data/lib/rucoa/configuration.rb +69 -16
  7. data/lib/rucoa/handler_concerns/diagnostics_publishable.rb +14 -2
  8. data/lib/rucoa/handlers/initialize_handler.rb +7 -0
  9. data/lib/rucoa/handlers/initialized_handler.rb +1 -1
  10. data/lib/rucoa/handlers/text_document_completion_handler.rb +223 -0
  11. data/lib/rucoa/handlers/text_document_did_close_handler.rb +20 -0
  12. data/lib/rucoa/handlers/text_document_formatting_handler.rb +2 -2
  13. data/lib/rucoa/handlers/text_document_hover_handler.rb +76 -0
  14. data/lib/rucoa/handlers/text_document_range_formatting_handler.rb +2 -2
  15. data/lib/rucoa/handlers.rb +3 -0
  16. data/lib/rucoa/node_inspector.rb +13 -1
  17. data/lib/rucoa/position.rb +12 -1
  18. data/lib/rucoa/{definition_builders/rbs_constant_definition_builder.rb → rbs/constant_definition_mapper.rb} +4 -8
  19. data/lib/rucoa/{definition_builders/rbs_method_definition_builder.rb → rbs/method_definition_mapper.rb} +4 -7
  20. data/lib/rucoa/rbs/ruby_definitions_loader.rb +78 -0
  21. data/lib/rucoa/rbs.rb +9 -0
  22. data/lib/rucoa/rubocop/autocorrector.rb +40 -0
  23. data/lib/rucoa/rubocop/configuration_checker.rb +44 -0
  24. data/lib/rucoa/rubocop/investigator.rb +50 -0
  25. data/lib/rucoa/rubocop.rb +9 -0
  26. data/lib/rucoa/server.rb +45 -12
  27. data/lib/rucoa/source.rb +6 -1
  28. data/lib/rucoa/version.rb +1 -1
  29. data/lib/rucoa/{definition_builders/yard_method_definition_builder.rb → yard/definition_mapper.rb} +20 -21
  30. data/lib/rucoa/yard/definitions_loader.rb +62 -0
  31. data/lib/rucoa/yard.rb +8 -0
  32. data/lib/rucoa.rb +3 -7
  33. metadata +16 -12
  34. data/lib/rucoa/definition_builders.rb +0 -9
  35. data/lib/rucoa/rbs_document_loader.rb +0 -43
  36. data/lib/rucoa/rubocop_autocorrector.rb +0 -38
  37. data/lib/rucoa/rubocop_configuration_checker.rb +0 -42
  38. data/lib/rucoa/rubocop_investigator.rb +0 -48
  39. data/lib/rucoa/yard_glob_document_loader.rb +0 -47
  40. data/lib/rucoa/yard_string_document_loader.rb +0 -70
@@ -21,7 +21,7 @@ module Rucoa
21
21
  )
22
22
  end
23
23
 
24
- # @param hash [Hash{Symbol => Integer}]
24
+ # @param hash [Hash{String => Integer}]
25
25
  # @return [Rucoa::Position]
26
26
  def from_vscode_position(hash)
27
27
  new(
@@ -44,6 +44,17 @@ module Rucoa
44
44
  @line = line
45
45
  end
46
46
 
47
+ # @param text [String]
48
+ # @return [Integer]
49
+ def to_index_of(text)
50
+ text.each_line.take(@line - 1).sum(&:length) + @column
51
+ end
52
+
53
+ # @return [Rucoa::Range]
54
+ def to_range
55
+ Range.new(self, self)
56
+ end
57
+
47
58
  # @return [Hash]
48
59
  def to_vscode_position
49
60
  {
@@ -1,28 +1,24 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Rucoa
4
- module DefinitionBuilders
5
- # Build Rucoa contant definition from RBS constant declaration.
6
- class RbsConstantDefinitionBuilder
4
+ module Rbs
5
+ class ConstantDefinitionMapper
7
6
  class << self
8
7
  # @param declaration [RBS::AST::Declarations::Constant]
9
8
  # @return [Rucoa::Definitions::ConstantDefinition]
10
9
  def call(declaration:)
11
- new(
12
- declaration: declaration
13
- ).call
10
+ new(declaration: declaration).call
14
11
  end
15
12
  end
16
13
 
17
14
  # @param declaration [RBS::AST::Declarations::Constant]
18
- # @return [Rucoa::Definitions::ConstantDefinition]
19
15
  def initialize(declaration:)
20
16
  @declaration = declaration
21
17
  end
22
18
 
23
19
  # @return [Rucoa::Definitions::ConstantDefinition]
24
20
  def call
25
- ::Rucoa::Definitions::ConstantDefinition.new(
21
+ Definitions::ConstantDefinition.new(
26
22
  full_qualified_name: full_qualified_name,
27
23
  source_path: source_path
28
24
  )
@@ -1,11 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rbs'
4
-
5
3
  module Rucoa
6
- module DefinitionBuilders
7
- # Build Rucoa method definition from RBS method definition.
8
- class RbsMethodDefinitionBuilder
4
+ module Rbs
5
+ class MethodDefinitionMapper
9
6
  class << self
10
7
  # @param declaration [RBS::AST::Declarations::Class, RBS::AST::Declarations::Module]
11
8
  # @param method_definition [RBS::AST::Members::MethodDefinition]
@@ -42,7 +39,7 @@ module Rucoa
42
39
  # @return [Array<Rucoa::Types::MethodType>]
43
40
  def types
44
41
  @method_definition.types.map do |method_type|
45
- RbsMethodTypeToRucoaMethodTypeMapper.call(
42
+ MethodTypeMapper.call(
46
43
  method_type: method_type
47
44
  )
48
45
  end
@@ -73,7 +70,7 @@ module Rucoa
73
70
  @declaration.location.name
74
71
  end
75
72
 
76
- class RbsMethodTypeToRucoaMethodTypeMapper
73
+ class MethodTypeMapper
77
74
  class << self
78
75
  # @param method_type [RBS::Types::MethodType]
79
76
  # @return [Rucoa::Types::MethodType]
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rbs'
4
+
5
+ module Rucoa
6
+ module Rbs
7
+ # Load definitions for Ruby core and standard libraries.
8
+ class RubyDefinitionsLoader
9
+ class << self
10
+ # @return [Array<Rucoa::Definitions::Base>]
11
+ def call
12
+ new.call
13
+ end
14
+ end
15
+
16
+ # @return [Array<Rucoa::Definitions::Base>]
17
+ def call
18
+ declarations.flat_map do |declaration|
19
+ case declaration
20
+ when ::RBS::AST::Declarations::Constant
21
+ [
22
+ ConstantDefinitionMapper.call(declaration: declaration)
23
+ ]
24
+ when ::RBS::AST::Declarations::Class, ::RBS::AST::Declarations::Module
25
+ [
26
+ ConstantDefinitionMapper.call(declaration: declaration)
27
+ ] +
28
+ declaration.members.grep(::RBS::AST::Members::MethodDefinition).map do |method_definition|
29
+ MethodDefinitionMapper.call(
30
+ declaration: declaration,
31
+ method_definition: method_definition
32
+ )
33
+ end
34
+ else
35
+ []
36
+ end
37
+ end
38
+ end
39
+
40
+ private
41
+
42
+ # @return [Array<RBS::AST::Declarations::Base>]
43
+ def declarations
44
+ class_declarations + constant_declarations
45
+ end
46
+
47
+ # @return [Array<RBS::AST::Declarations::Class>]
48
+ def class_declarations
49
+ environment.class_decls.values.flat_map do |multi_entry|
50
+ multi_entry.decls.map(&:decl)
51
+ end
52
+ end
53
+
54
+ # @return [Array<RBS::AST::Declarations::Constant>]
55
+ def constant_declarations
56
+ environment.constant_decls.values.map(&:decl)
57
+ end
58
+
59
+ # @return [RBS::Environment]
60
+ def environment
61
+ @environment ||= ::RBS::Environment.from_loader(
62
+ environment_loader
63
+ ).resolve_type_names
64
+ end
65
+
66
+ # @return [RBS::EnvironmentLoader]
67
+ def environment_loader
68
+ loader = ::RBS::EnvironmentLoader.new
69
+ ::RBS::Repository::DEFAULT_STDLIB_ROOT.children.sort.each do |pathname|
70
+ loader.add(
71
+ library: pathname.basename.to_s
72
+ )
73
+ end
74
+ loader
75
+ end
76
+ end
77
+ end
78
+ end
data/lib/rucoa/rbs.rb ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rucoa
4
+ module Rbs
5
+ autoload :ConstantDefinitionMapper, 'rucoa/rbs/constant_definition_mapper'
6
+ autoload :MethodDefinitionMapper, 'rucoa/rbs/method_definition_mapper'
7
+ autoload :RubyDefinitionsLoader, 'rucoa/rbs/ruby_definitions_loader'
8
+ end
9
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rubocop'
4
+
5
+ module Rucoa
6
+ module Rubocop
7
+ class Autocorrector < ::RuboCop::Runner
8
+ class << self
9
+ # @param source [Rucoa::Source]
10
+ # @return [String]
11
+ def call(source:)
12
+ new(source: source).call
13
+ end
14
+ end
15
+
16
+ # @param source [Rucoa::Source]
17
+ def initialize(source:)
18
+ @source = source
19
+ super(
20
+ ::RuboCop::Options.new.parse(
21
+ %w[
22
+ --stderr
23
+ --force-exclusion
24
+ --format RuboCop::Formatter::BaseFormatter
25
+ -A
26
+ ]
27
+ ).first,
28
+ ::RuboCop::ConfigStore.new
29
+ )
30
+ end
31
+
32
+ # @return [String]
33
+ def call
34
+ @options[:stdin] = @source.content
35
+ run([@source.path || 'untitled'])
36
+ @options[:stdin]
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'pathname'
4
+
5
+ module Rucoa
6
+ module Rubocop
7
+ class ConfigurationChecker
8
+ class << self
9
+ # @return [Boolean]
10
+ def call
11
+ new.call
12
+ end
13
+ end
14
+
15
+ # @return [Boolean]
16
+ def call
17
+ rubocop_configured_for_current_directory?
18
+ end
19
+
20
+ private
21
+
22
+ # @return [Boolean]
23
+ def rubocop_configured_for_current_directory?
24
+ each_current_and_ancestor_pathname.any? do |pathname|
25
+ pathname.join('.rubocop.yml').exist?
26
+ end
27
+ end
28
+
29
+ # @return [Enumerable<Pathname>]
30
+ def each_current_and_ancestor_pathname
31
+ return to_enum(__method__) unless block_given?
32
+
33
+ pathname = ::Pathname.pwd
34
+ loop do
35
+ yield pathname
36
+ break if pathname.root?
37
+
38
+ pathname = pathname.parent
39
+ end
40
+ self
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rubocop'
4
+
5
+ module Rucoa
6
+ module Rubocop
7
+ class Investigator < ::RuboCop::Runner
8
+ class << self
9
+ # @param source [Rucoa::Source]
10
+ # @return [Array<RuboCop::Cop::Offense>]
11
+ def call(source:)
12
+ new(source: source).call
13
+ end
14
+ end
15
+
16
+ # @param source [Rucoa::Source]
17
+ def initialize(source:)
18
+ @source = source
19
+ @offenses = []
20
+ super(
21
+ ::RuboCop::Options.new.parse(
22
+ %w[
23
+ --stderr
24
+ --force-exclusion
25
+ --format RuboCop::Formatter::BaseFormatter
26
+ ]
27
+ ).first,
28
+ ::RuboCop::ConfigStore.new
29
+ )
30
+ end
31
+
32
+ # @return [Array<RuboCop::Cop::Offense>]
33
+ def call
34
+ @options[:stdin] = @source.content
35
+ run([@source.path || 'untitled'])
36
+ @offenses
37
+ end
38
+
39
+ private
40
+
41
+ # @param file [String]
42
+ # @param offenses [Array<RuboCop::Cop::Offense>]
43
+ # @return [void]
44
+ def file_finished(file, offenses)
45
+ @offenses = offenses
46
+ super
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rucoa
4
+ module Rubocop
5
+ autoload :Autocorrector, 'rucoa/rubocop/autocorrector'
6
+ autoload :ConfigurationChecker, 'rucoa/rubocop/configuration_checker'
7
+ autoload :Investigator, 'rucoa/rubocop/investigator'
8
+ end
9
+ end
data/lib/rucoa/server.rb CHANGED
@@ -1,5 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'logger'
4
+ require 'stringio'
5
+
3
6
  module Rucoa
4
7
  class Server
5
8
  # @return [Hash{String => Class}]
@@ -9,10 +12,13 @@ module Rucoa
9
12
  'initialized' => Handlers::InitializedHandler,
10
13
  'shutdown' => Handlers::ShutdownHandler,
11
14
  'textDocument/codeAction' => Handlers::TextDocumentCodeActionHandler,
15
+ 'textDocument/completion' => Handlers::TextDocumentCompletionHandler,
12
16
  'textDocument/didChange' => Handlers::TextDocumentDidChangeHandler,
17
+ 'textDocument/didClose' => Handlers::TextDocumentDidCloseHandler,
13
18
  'textDocument/didOpen' => Handlers::TextDocumentDidOpenHandler,
14
19
  'textDocument/documentSymbol' => Handlers::TextDocumentDocumentSymbolHandler,
15
20
  'textDocument/formatting' => Handlers::TextDocumentFormattingHandler,
21
+ 'textDocument/hover' => Handlers::TextDocumentHoverHandler,
16
22
  'textDocument/rangeFormatting' => Handlers::TextDocumentRangeFormattingHandler,
17
23
  'textDocument/selectionRange' => Handlers::TextDocumentSelectionRangeHandler,
18
24
  'textDocument/signatureHelp' => Handlers::TextDocumentSignatureHelpHandler,
@@ -32,11 +38,18 @@ module Rucoa
32
38
  # @return [Rucoa::SourceStore]
33
39
  attr_reader :source_store
34
40
 
35
- # @param input [IO]
36
- # @param output [IO]
37
- def initialize(input:, output:)
38
- @reader = MessageReader.new(input)
39
- @writer = MessageWriter.new(output)
41
+ # @param io_log [IO]
42
+ # @param io_in [IO]
43
+ # @param io_out [IO]
44
+ def initialize(
45
+ io_log: ::StringIO.new,
46
+ io_in: ::StringIO.new,
47
+ io_out: ::StringIO.new
48
+ )
49
+ @logger = ::Logger.new(io_log)
50
+ @logger.level = ::Logger::DEBUG
51
+ @reader = MessageReader.new(io_in)
52
+ @writer = MessageWriter.new(io_out)
40
53
 
41
54
  @client_response_handlers = {}
42
55
  @configuration = Configuration.new
@@ -50,8 +63,14 @@ module Rucoa
50
63
 
51
64
  # @return [void]
52
65
  def start
53
- @reader.read do |request|
54
- handle(request)
66
+ @reader.read do |message|
67
+ debug do
68
+ {
69
+ kind: :read,
70
+ message: message
71
+ }
72
+ end
73
+ handle(message)
55
74
  end
56
75
  end
57
76
 
@@ -91,6 +110,11 @@ module Rucoa
91
110
  end
92
111
  end
93
112
 
113
+ # @yieldparam log [String]
114
+ def debug(&block)
115
+ @logger.debug(&block) if configuration.enables_debug?
116
+ end
117
+
94
118
  # @param request [Hash]
95
119
  # @return [void]
96
120
  def handle_client_request(request)
@@ -115,11 +139,14 @@ module Rucoa
115
139
  # @param message [Hash]
116
140
  # @return [void]
117
141
  def write_server_request(message, &block)
118
- @writer.write(
119
- message.merge(
120
- id: @server_request_id
121
- )
122
- )
142
+ message = message.merge('id' => @server_request_id)
143
+ debug do
144
+ {
145
+ kind: :write,
146
+ message: message
147
+ }
148
+ end
149
+ @writer.write(message)
123
150
  @client_response_handlers[@server_request_id] = block
124
151
  @server_request_id += 1
125
152
  end
@@ -127,6 +154,12 @@ module Rucoa
127
154
  # @param message [Hash]
128
155
  # @return [void]
129
156
  def write_server_response(message)
157
+ debug do
158
+ {
159
+ kind: :write,
160
+ message: message
161
+ }
162
+ end
130
163
  @writer.write(message)
131
164
  end
132
165
  end
data/lib/rucoa/source.rb CHANGED
@@ -33,7 +33,7 @@ module Rucoa
33
33
  # ]
34
34
  # )
35
35
  def definitions
36
- @definitions ||= YardStringDocumentLoader.call(
36
+ @definitions ||= Yard::DefinitionsLoader.load_string(
37
37
  content: @content,
38
38
  path: path
39
39
  )
@@ -78,6 +78,11 @@ module Rucoa
78
78
  nil
79
79
  end
80
80
 
81
+ # @return [Boolean]
82
+ def syntax_error?
83
+ root_node.nil?
84
+ end
85
+
81
86
  private
82
87
 
83
88
  # @return [Array<Rucoa::Nodes::Base>]
data/lib/rucoa/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Rucoa
4
- VERSION = '0.5.1'
4
+ VERSION = '0.7.0'
5
5
  end
@@ -3,30 +3,29 @@
3
3
  require 'yard'
4
4
 
5
5
  module Rucoa
6
- module DefinitionBuilders
7
- class YardMethodDefinitionBuilder
6
+ module Yard
7
+ class DefinitionMapper
8
8
  class << self
9
- # @param code_object [YARD::CodeObjects::MethodObject]
10
- # @param path [String]
11
- # @return [Rucoa::Definitions::Base]
12
- def call(code_object:, path:)
13
- new(
14
- code_object: code_object,
15
- path: path
16
- ).call
9
+ # @param code_object [YARD::CodeObjects::Base]
10
+ # @param path [String] This must be passed if the path is not available from code object.
11
+ # @return [Rucoa::Definitions::Base, nil]
12
+ def call(code_object, path: code_object.file)
13
+ new(code_object, path: path).call
17
14
  end
18
15
  end
19
16
 
20
17
  # @param code_object [YARD::CodeObjects::Base]
21
18
  # @param path [String]
22
- def initialize(code_object:, path:)
19
+ def initialize(code_object, path:)
23
20
  @code_object = code_object
24
21
  @path = path
25
22
  end
26
23
 
27
- # @return [Rucoa::Definitions::Base]
24
+ # @return [Rucoa::Definitions::Base, nil]
28
25
  def call
29
- ::Rucoa::Definitions::MethodDefinition.new(
26
+ return unless @code_object.is_a?(::YARD::CodeObjects::MethodObject)
27
+
28
+ Definitions::MethodDefinition.new(
30
29
  description: description,
31
30
  kind: kind,
32
31
  method_name: method_name,
@@ -74,7 +73,7 @@ module Rucoa
74
73
 
75
74
  # @return [String]
76
75
  # @example
77
- # definitions = Rucoa::YardStringDocumentLoader.call(
76
+ # definitions = Rucoa::Yard::DefinitionsLoader.load_string(
78
77
  # content: <<~RUBY,
79
78
  # class Foo
80
79
  # def bar(
@@ -133,7 +132,7 @@ module Rucoa
133
132
  # @return [Array<String>]
134
133
  # @return [String]
135
134
  # @example returns return type annotated by YARD @return tags
136
- # definitions = Rucoa::YardStringDocumentLoader.call(
135
+ # definitions = Rucoa::Yard::DefinitionsLoader.load_string(
137
136
  # content: <<~RUBY,
138
137
  # # @return [String]
139
138
  # def foo
@@ -148,7 +147,7 @@ module Rucoa
148
147
  # ]
149
148
  # )
150
149
  # @example ignores empty @return tags
151
- # definitions = Rucoa::YardStringDocumentLoader.call(
150
+ # definitions = Rucoa::Yard::DefinitionsLoader.load_string(
152
151
  # content: <<~RUBY,
153
152
  # # @return []
154
153
  # def foo
@@ -181,27 +180,27 @@ module Rucoa
181
180
 
182
181
  # @return [String]
183
182
  # @example scrubs "Array<String>" to "Array"
184
- # yard_type = Rucoa::DefinitionBuilders::YardMethodDefinitionBuilder::YardType.new(
183
+ # yard_type = Rucoa::Yard::DefinitionMapper::YardType.new(
185
184
  # 'Array<String>'
186
185
  # )
187
186
  # expect(yard_type.to_rucoa_type).to eq('Array')
188
187
  # @example scrubs "Array(String, Integer)" to "Array"
189
- # yard_type = Rucoa::DefinitionBuilders::YardMethodDefinitionBuilder::YardType.new(
188
+ # yard_type = Rucoa::Yard::DefinitionMapper::YardType.new(
190
189
  # 'Array(String, Integer)'
191
190
  # )
192
191
  # expect(yard_type.to_rucoa_type).to eq('Array')
193
192
  # @example scrubs "::Array" to "Array"
194
- # yard_type = Rucoa::DefinitionBuilders::YardMethodDefinitionBuilder::YardType.new(
193
+ # yard_type = Rucoa::Yard::DefinitionMapper::YardType.new(
195
194
  # '::Array'
196
195
  # )
197
196
  # expect(yard_type.to_rucoa_type).to eq('Array')
198
197
  # @example scrubs "Hash{Symbol => Object}" to "Hash"
199
- # yard_type = Rucoa::DefinitionBuilders::YardMethodDefinitionBuilder::YardType.new(
198
+ # yard_type = Rucoa::Yard::DefinitionMapper::YardType.new(
200
199
  # 'Hash{Symbol => Object}'
201
200
  # )
202
201
  # expect(yard_type.to_rucoa_type).to eq('Hash')
203
202
  # @example scrubs "Array<Array<Integer>>" to "Array"
204
- # yard_type = Rucoa::DefinitionBuilders::YardMethodDefinitionBuilder::YardType.new(
203
+ # yard_type = Rucoa::Yard::DefinitionMapper::YardType.new(
205
204
  # 'Array<Array<Integer>>'
206
205
  # )
207
206
  # expect(yard_type.to_rucoa_type).to eq('Array')
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'logger'
4
+ require 'yard'
5
+
6
+ module Rucoa
7
+ module Yard
8
+ class DefinitionsLoader
9
+ class << self
10
+ # @param content [String]
11
+ # @return [Array<Rucoa::Definitions::Base>]
12
+ # @example returns method definitions from Ruby source code
13
+ # content = <<~RUBY
14
+ # class Foo
15
+ # # Return given argument as an Integer.
16
+ # # @param bar [String]
17
+ # # @return [Integer]
18
+ # def foo(bar)
19
+ # bar.to_i
20
+ # end
21
+ # end
22
+ # RUBY
23
+ # definitions = Rucoa::Yard::DefinitionsLoader.load_string(
24
+ # content: content,
25
+ # path: '/path/to/foo.rb'
26
+ # )
27
+ # expect(definitions.size).to eq(1)
28
+ # expect(definitions.first.full_qualified_name).to eq('Foo#foo')
29
+ # expect(definitions.first.source_path).to eq('/path/to/foo.rb')
30
+ # expect(definitions.first.description).to eq('Return given argument as an Integer.')
31
+ # expect(definitions.first.return_types).to eq(%w[Integer])
32
+ def load_string(content:, path:)
33
+ ::YARD::Registry.clear
34
+ quietly do
35
+ ::YARD.parse_string(content)
36
+ end
37
+ ::YARD::Registry.all.filter_map do |code_object|
38
+ DefinitionMapper.call(code_object, path: path)
39
+ end
40
+ end
41
+
42
+ # @param globs [String]
43
+ # @return [Array<Rucoa::Definitions::Base>]
44
+ def load_globs(globs:)
45
+ ::YARD::Registry.clear
46
+ quietly do
47
+ ::YARD.parse(globs)
48
+ end
49
+ ::YARD::Registry.all.filter_map do |code_object|
50
+ DefinitionMapper.call(code_object)
51
+ end
52
+ end
53
+
54
+ private
55
+
56
+ def quietly(&block)
57
+ ::YARD::Logger.instance.enter_level(::Logger::FATAL, &block)
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
data/lib/rucoa/yard.rb ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rucoa
4
+ module Yard
5
+ autoload :DefinitionMapper, 'rucoa/yard/definition_mapper'
6
+ autoload :DefinitionsLoader, 'rucoa/yard/definitions_loader'
7
+ end
8
+ end
data/lib/rucoa.rb CHANGED
@@ -6,7 +6,6 @@ module Rucoa
6
6
  autoload :Cli, 'rucoa/cli'
7
7
  autoload :Configuration, 'rucoa/configuration'
8
8
  autoload :DefinitionArchiver, 'rucoa/definition_archiver'
9
- autoload :DefinitionBuilders, 'rucoa/definition_builders'
10
9
  autoload :Definitions, 'rucoa/definitions'
11
10
  autoload :DefinitionStore, 'rucoa/definition_store'
12
11
  autoload :Errors, 'rucoa/errors'
@@ -21,14 +20,11 @@ module Rucoa
21
20
  autoload :ParserBuilder, 'rucoa/parser_builder'
22
21
  autoload :Position, 'rucoa/position'
23
22
  autoload :Range, 'rucoa/range'
24
- autoload :RbsDocumentLoader, 'rucoa/rbs_document_loader'
25
- autoload :RubocopAutocorrector, 'rucoa/rubocop_autocorrector'
26
- autoload :RubocopConfigurationChecker, 'rucoa/rubocop_configuration_checker'
27
- autoload :RubocopInvestigator, 'rucoa/rubocop_investigator'
23
+ autoload :Rbs, 'rucoa/rbs'
24
+ autoload :Rubocop, 'rucoa/rubocop'
28
25
  autoload :Server, 'rucoa/server'
29
26
  autoload :Source, 'rucoa/source'
30
27
  autoload :SourceStore, 'rucoa/source_store'
31
28
  autoload :Types, 'rucoa/types'
32
- autoload :YardGlobDocumentLoader, 'rucoa/yard_glob_document_loader'
33
- autoload :YardStringDocumentLoader, 'rucoa/yard_string_document_loader'
29
+ autoload :Yard, 'rucoa/yard'
34
30
  end