rucoa 0.2.0 → 0.5.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 (80) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +6 -0
  3. data/Gemfile +1 -0
  4. data/Gemfile.lock +11 -2
  5. data/README.md +39 -6
  6. data/data/definitions_ruby_3_1 +0 -0
  7. data/images/diagnostics.gif +0 -0
  8. data/images/document-formatting.gif +0 -0
  9. data/images/document-symbol.gif +0 -0
  10. data/images/selection-ranges.gif +0 -0
  11. data/lib/rucoa/cli.rb +2 -2
  12. data/lib/rucoa/configuration.rb +97 -0
  13. data/lib/rucoa/definition_archiver.rb +29 -0
  14. data/lib/rucoa/definition_builders/rbs_constant_definition_builder.rb +44 -0
  15. data/lib/rucoa/definition_builders/rbs_method_definition_builder.rb +106 -0
  16. data/lib/rucoa/definition_builders/yard_method_definition_builder.rb +191 -0
  17. data/lib/rucoa/definition_builders.rb +9 -0
  18. data/lib/rucoa/definition_store.rb +63 -0
  19. data/lib/rucoa/definitions/base.rb +12 -0
  20. data/lib/rucoa/definitions/constant_definition.rb +51 -0
  21. data/lib/rucoa/definitions/method_definition.rb +126 -0
  22. data/lib/rucoa/definitions/method_parameter_definition.rb +30 -0
  23. data/lib/rucoa/definitions.rb +9 -0
  24. data/lib/rucoa/handler_concerns/configuration_requestable.rb +35 -0
  25. data/lib/rucoa/handler_concerns/diagnostics_publishable.rb +172 -0
  26. data/lib/rucoa/handler_concerns.rb +8 -0
  27. data/lib/rucoa/handlers/base.rb +69 -0
  28. data/lib/rucoa/handlers/exit_handler.rb +11 -0
  29. data/lib/rucoa/handlers/initialize_handler.rb +29 -0
  30. data/lib/rucoa/handlers/initialized_handler.rb +23 -0
  31. data/lib/rucoa/handlers/shutdown_handler.rb +12 -0
  32. data/lib/rucoa/handlers/text_document_code_action_handler.rb +104 -0
  33. data/lib/rucoa/handlers/text_document_did_change_handler.rb +12 -0
  34. data/lib/rucoa/handlers/text_document_did_open_handler.rb +38 -0
  35. data/lib/rucoa/handlers/text_document_document_symbol_handler.rb +241 -0
  36. data/lib/rucoa/handlers/text_document_formatting_handler.rb +64 -0
  37. data/lib/rucoa/handlers/text_document_range_formatting_handler.rb +76 -0
  38. data/lib/rucoa/handlers/text_document_selection_range_handler.rb +141 -0
  39. data/lib/rucoa/handlers/text_document_signature_help_handler.rb +68 -0
  40. data/lib/rucoa/handlers/workspace_did_change_configuration_handler.rb +13 -0
  41. data/lib/rucoa/handlers.rb +20 -0
  42. data/lib/rucoa/message_reader.rb +3 -1
  43. data/lib/rucoa/message_writer.rb +3 -0
  44. data/lib/rucoa/node_concerns/name_full_qualifiable.rb +20 -0
  45. data/lib/rucoa/node_concerns.rb +7 -0
  46. data/lib/rucoa/node_inspector.rb +109 -0
  47. data/lib/rucoa/nodes/base.rb +43 -0
  48. data/lib/rucoa/nodes/casgn_node.rb +14 -0
  49. data/lib/rucoa/nodes/class_node.rb +8 -0
  50. data/lib/rucoa/nodes/const_node.rb +12 -0
  51. data/lib/rucoa/nodes/def_node.rb +71 -0
  52. data/lib/rucoa/nodes/defs_node.rb +12 -0
  53. data/lib/rucoa/nodes/lvar_node.rb +25 -0
  54. data/lib/rucoa/nodes/module_node.rb +21 -0
  55. data/lib/rucoa/nodes/sclass_node.rb +8 -0
  56. data/lib/rucoa/nodes/send_node.rb +60 -0
  57. data/lib/rucoa/nodes/str_node.rb +4 -0
  58. data/lib/rucoa/nodes/sym_node.rb +12 -0
  59. data/lib/rucoa/nodes.rb +10 -0
  60. data/lib/rucoa/parser_builder.rb +20 -10
  61. data/lib/rucoa/range.rb +89 -13
  62. data/lib/rucoa/rbs_document_loader.rb +43 -0
  63. data/lib/rucoa/rubocop_autocorrector.rb +1 -1
  64. data/lib/rucoa/rubocop_configuration_checker.rb +42 -0
  65. data/lib/rucoa/rubocop_investigator.rb +1 -1
  66. data/lib/rucoa/server.rb +96 -122
  67. data/lib/rucoa/source.rb +56 -6
  68. data/lib/rucoa/source_store.rb +11 -9
  69. data/lib/rucoa/types/method_type.rb +23 -0
  70. data/lib/rucoa/types.rb +7 -0
  71. data/lib/rucoa/version.rb +1 -1
  72. data/lib/rucoa/yard_glob_document_loader.rb +47 -0
  73. data/lib/rucoa/yard_string_document_loader.rb +70 -0
  74. data/lib/rucoa.rb +14 -4
  75. data/rucoa.gemspec +1 -0
  76. metadata +70 -6
  77. data/lib/rucoa/code_action_provider.rb +0 -102
  78. data/lib/rucoa/diagnostic_provider.rb +0 -159
  79. data/lib/rucoa/formatting_provider.rb +0 -52
  80. data/lib/rucoa/selection_range_provider.rb +0 -97
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 76603729adc41973a6692fa067867eefa24f1724afa9d972f224dc34338cf925
4
- data.tar.gz: d5c4a1c8001121bafbb9a768f8c5d91d6ae66a737e8b415572756772450d9ba1
3
+ metadata.gz: '05869f9180ae7dbf00c359ad9d0b89fe3b126c8f9a6171b8b8155c7ad683f95f'
4
+ data.tar.gz: 429c84f3e305a90bcc1b7c39fbb14af894a95e24117c91d6914681ae8c53624c
5
5
  SHA512:
6
- metadata.gz: de17db3774a60396fa40a307cf1d34c73db06b55afa9a3e2e2cae2085f1aeef07e459ace8149cf668e0cee47ca940a29066c963e599633e6c647dee31c36b1a0
7
- data.tar.gz: c309425209a6146a1ea4031f57b752bcef0ce7fe25f965704d6a334194000e8aa96a94aaad992bed04ddc200397ee9790349e0d5e94998703eaeafa4fd8f3558
6
+ metadata.gz: db443ae921e01609343392377664bf625bb4c2a057dc9d41ec1d611a7723807e6499d6669f097fb7d903b706110b6a34d83c09539612aba9d7b0e2fbd2302cf0
7
+ data.tar.gz: a6dabfb0fb1ac3228cb7217c9f9360fe6f32de32b65642492f00dbdc628d4578ed1c3a4f799c94c42ca8fe2553b3426c2105582569f9acd3e9971d68cc6722ec
data/.rubocop.yml CHANGED
@@ -20,12 +20,18 @@ RSpec/ExampleLength:
20
20
  RSpec/ImplicitSubject:
21
21
  Enabled: false
22
22
 
23
+ RSpec/MultipleExpectations:
24
+ Enabled: false
25
+
23
26
  RSpec/MultipleMemoizedHelpers:
24
27
  Enabled: false
25
28
 
26
29
  RSpec/NamedSubject:
27
30
  Enabled: false
28
31
 
32
+ Security/MarshalLoad:
33
+ Enabled: false
34
+
29
35
  Sevencop/HashLiteralOrder:
30
36
  Enabled: true
31
37
 
data/Gemfile CHANGED
@@ -11,3 +11,4 @@ gem 'rubocop-performance'
11
11
  gem 'rubocop-rake'
12
12
  gem 'rubocop-rspec'
13
13
  gem 'sevencop'
14
+ gem 'yardspec'
data/Gemfile.lock CHANGED
@@ -1,8 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rucoa (0.2.0)
4
+ rucoa (0.5.0)
5
5
  parser
6
+ rbs
6
7
  rubocop
7
8
 
8
9
  GEM
@@ -16,6 +17,7 @@ GEM
16
17
  ast (~> 2.4.1)
17
18
  rainbow (3.1.1)
18
19
  rake (13.0.6)
20
+ rbs (2.6.0)
19
21
  regexp_parser (2.5.0)
20
22
  rexml (3.2.5)
21
23
  rspec (3.11.0)
@@ -51,9 +53,15 @@ GEM
51
53
  rubocop-rspec (2.12.1)
52
54
  rubocop (~> 1.31)
53
55
  ruby-progressbar (1.11.0)
54
- sevencop (0.9.3)
56
+ sevencop (0.10.0)
55
57
  rubocop
56
58
  unicode-display_width (2.2.0)
59
+ webrick (1.7.0)
60
+ yard (0.9.28)
61
+ webrick (~> 1.7.0)
62
+ yardspec (0.2.0)
63
+ rspec
64
+ yard
57
65
 
58
66
  PLATFORMS
59
67
  x86_64-linux
@@ -67,6 +75,7 @@ DEPENDENCIES
67
75
  rubocop-rspec
68
76
  rucoa!
69
77
  sevencop
78
+ yardspec
70
79
 
71
80
  BUNDLED WITH
72
81
  2.3.21
data/README.md CHANGED
@@ -6,7 +6,7 @@ Language server for Ruby.
6
6
 
7
7
  ## Usage
8
8
 
9
- Install both rucoa gem and [vscode-rucoa](https://github.com/r7kamura/vscode-rucoa) extension, then open your Ruby project in VSCode.
9
+ Install both rucoa gem and [vscode-rucoa](https://marketplace.visualstudio.com/items?itemName=r7kamura.vscode-rucoa) extension, then open your Ruby project in VSCode.
10
10
 
11
11
  To install rucoa gem, if your project is managed by bundler, add to your Gemfile:
12
12
 
@@ -32,14 +32,47 @@ gem install rucoa
32
32
 
33
33
  ## Features
34
34
 
35
- - Diagnostics
36
- - Formatting
37
- - Quick Fix
38
- - Selection Ranges (experimental)
35
+ ### Diagnostics
36
+
37
+ Displays RuboCop offenses and provides Quick Fix action for autocorrection.
38
+
39
+ ![demo](images/diagnostics.gif)
40
+
41
+ ### Formatting
42
+
43
+ Run "Format Document" command or enable "Format On Save" in the settings to autocorrect RuboCop offenses.
44
+
45
+ ![demo](images/document-formatting.gif)
46
+
47
+ ### Selection
48
+
49
+ Run "Expand Selection" command to select appropriate ranges.
50
+
51
+ ![demo](images/selection-ranges.gif)
52
+
53
+ ### Symbol
54
+
55
+ See Outline section in the explorer panel to see document symbols in the current file, or run "Go to Symbol" command to search for symbols.
56
+
57
+ This extension supports the folowiing types of symbols:
58
+
59
+ - class
60
+ - module
61
+ - constant
62
+ - instance method
63
+ - singleton method (a.k.a. class method)
64
+ - attribute (attr_accessor, attr_reader, and attr_writer)
65
+
66
+ ![demo](images/document-symbol.gif)
67
+
68
+ ### Signature help (experimental)
69
+
70
+ Shows method signature help when you start to type method arguments like `"100".to_i(`.
39
71
 
40
72
  ### Coming soon
41
73
 
42
74
  - Completion
43
75
  - Documentation
44
- - Highlight
45
76
  - Go to Definition
77
+ - Highlight
78
+ - Semantic Tokens
Binary file
Binary file
Binary file
Binary file
Binary file
data/lib/rucoa/cli.rb CHANGED
@@ -16,8 +16,8 @@ module Rucoa
16
16
  # @return [void]
17
17
  def call
18
18
  Server.new(
19
- reader: $stdin,
20
- writer: $stdout
19
+ input: $stdin,
20
+ output: $stdout
21
21
  ).start
22
22
  end
23
23
  end
@@ -0,0 +1,97 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rucoa
4
+ class Configuration
5
+ def initialize
6
+ @settings = {}
7
+ end
8
+
9
+ # @return [Boolean]
10
+ def disable_code_action
11
+ disable('codeAction')
12
+ end
13
+
14
+ # @return [Boolean]
15
+ def disable_diagnostics
16
+ disable('diagnostics')
17
+ end
18
+
19
+ # @return [Boolean]
20
+ def disable_document_symbol
21
+ disable('documentSymbol')
22
+ end
23
+
24
+ # @return [Boolean]
25
+ def disable_formatting
26
+ disable('formatting')
27
+ end
28
+
29
+ # @return [Boolean]
30
+ def disable_selection_range
31
+ disable('selectionRange')
32
+ end
33
+
34
+ # @return [Boolean]
35
+ def disable_signature_help
36
+ disable('signatureHelp')
37
+ end
38
+
39
+ # @return [Boolean]
40
+ def enables_code_action?
41
+ enables?('codeAction')
42
+ end
43
+
44
+ # @return [Boolean]
45
+ def enables_diagnostics?
46
+ enables?('diagnostics')
47
+ end
48
+
49
+ # @return [Boolean]
50
+ def enables_document_symbol?
51
+ enables?('documentSymbol')
52
+ end
53
+
54
+ # @return [Boolean]
55
+ def enables_formatting?
56
+ enables?('formatting')
57
+ end
58
+
59
+ # @return [Boolean]
60
+ def enables_selection_range?
61
+ enables?('selectionRange')
62
+ end
63
+
64
+ # @return [Boolean]
65
+ def enables_signature_help?
66
+ enables?('signatureHelp')
67
+ end
68
+
69
+ # @param settings [Hash]
70
+ # @return [void]
71
+ def update(settings)
72
+ @settings = settings
73
+ end
74
+
75
+ private
76
+
77
+ # @param feature [String]
78
+ # @return [void]
79
+ def disable(feature)
80
+ @settings ||= {}
81
+ @settings['feature'] ||= {}
82
+ @settings['feature'][feature] ||= {}
83
+ @settings['feature'][feature]['enable'] = false
84
+ end
85
+
86
+ # @param feature [String]
87
+ # @return [Boolean]
88
+ def enables?(feature)
89
+ value = @settings.dig('feature', feature, 'enable')
90
+ if value.nil?
91
+ true
92
+ else
93
+ value
94
+ end
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'pathname'
4
+
5
+ module Rucoa
6
+ class DefinitionArchiver
7
+ RUBY_DEFINITIONS_DUMP_PATH = ::File.expand_path('../../data/definitions_ruby_3_1', __dir__).freeze
8
+ private_constant :RUBY_DEFINITIONS_DUMP_PATH
9
+
10
+ class << self
11
+ # @param definitions [Array<Rucoa::Definition::Base>]
12
+ # @return [void]
13
+ def dump(definitions)
14
+ pathname = ::Pathname.new(RUBY_DEFINITIONS_DUMP_PATH)
15
+ pathname.parent.mkpath
16
+ pathname.write(
17
+ ::Marshal.dump(definitions)
18
+ )
19
+ end
20
+
21
+ # @return [Array<Rucoa::Definition::Base>]
22
+ def load
23
+ ::Marshal.load(
24
+ ::File.binread(RUBY_DEFINITIONS_DUMP_PATH)
25
+ )
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rucoa
4
+ module DefinitionBuilders
5
+ # Build Rucoa contant definition from RBS constant declaration.
6
+ class RbsConstantDefinitionBuilder
7
+ class << self
8
+ # @param declaration [RBS::AST::Declarations::Constant]
9
+ # @return [Rucoa::Definitions::ConstantDefinition]
10
+ def call(declaration:)
11
+ new(
12
+ declaration: declaration
13
+ ).call
14
+ end
15
+ end
16
+
17
+ # @param declaration [RBS::AST::Declarations::Constant]
18
+ # @return [Rucoa::Definitions::ConstantDefinition]
19
+ def initialize(declaration:)
20
+ @declaration = declaration
21
+ end
22
+
23
+ # @return [Rucoa::Definitions::ConstantDefinition]
24
+ def call
25
+ ::Rucoa::Definitions::ConstantDefinition.new(
26
+ full_qualified_name: full_qualified_name,
27
+ source_path: source_path
28
+ )
29
+ end
30
+
31
+ private
32
+
33
+ # @return [String]
34
+ def full_qualified_name
35
+ @declaration.name.to_s.delete_prefix('::')
36
+ end
37
+
38
+ # @return [String]
39
+ def source_path
40
+ @declaration.location.name
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,106 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rbs'
4
+
5
+ module Rucoa
6
+ module DefinitionBuilders
7
+ # Build Rucoa method definition from RBS method definition.
8
+ class RbsMethodDefinitionBuilder
9
+ class << self
10
+ # @param declaration [RBS::AST::Declarations::Class, RBS::AST::Declarations::Module]
11
+ # @param method_definition [RBS::AST::Members::MethodDefinition]
12
+ # @return [Rucoa::Definitions::MethodDefinition]
13
+ def call(declaration:, method_definition:)
14
+ new(
15
+ declaration: declaration,
16
+ method_definition: method_definition
17
+ ).call
18
+ end
19
+ end
20
+
21
+ # @param declaration [RBS::AST::Declarations::Class, RBS::AST::Declarations::Module]
22
+ # @param method_definition [RBS::AST::Members::MethodDefinition]
23
+ def initialize(declaration:, method_definition:)
24
+ @declaration = declaration
25
+ @method_definition = method_definition
26
+ end
27
+
28
+ # @return [Rucoa::Definitions::MethodDefinition]
29
+ def call
30
+ Definitions::MethodDefinition.new(
31
+ description: description,
32
+ kind: kind,
33
+ method_name: method_name,
34
+ namespace: namespace,
35
+ source_path: source_path,
36
+ types: types
37
+ )
38
+ end
39
+
40
+ private
41
+
42
+ # @return [Array<Rucoa::Types::MethodType>]
43
+ def types
44
+ @method_definition.types.map do |method_type|
45
+ RbsMethodTypeToRucoaMethodTypeMapper.call(
46
+ method_type: method_type
47
+ )
48
+ end
49
+ end
50
+
51
+ # @return [String, nil]
52
+ def description
53
+ @method_definition.comment&.string&.sub(/\A\s*<!--.*-->\s*/m, '')
54
+ end
55
+
56
+ # @return [String]
57
+ def namespace
58
+ @declaration.name.to_s.delete_prefix('::')
59
+ end
60
+
61
+ # @return [String]
62
+ def method_name
63
+ @method_definition.name.to_s
64
+ end
65
+
66
+ # @return [Symbol]
67
+ def kind
68
+ @method_definition.kind
69
+ end
70
+
71
+ # @return [String]
72
+ def source_path
73
+ @declaration.location.name
74
+ end
75
+
76
+ class RbsMethodTypeToRucoaMethodTypeMapper
77
+ class << self
78
+ # @param method_type [RBS::Types::MethodType]
79
+ # @return [Rucoa::Types::MethodType]
80
+ def call(method_type:)
81
+ new(method_type: method_type).call
82
+ end
83
+
84
+ # @param type [RBS::Types::Base]
85
+ # @return [String]
86
+ def stringify(type)
87
+ type.to_s.delete_prefix('::')
88
+ end
89
+ end
90
+
91
+ # @param method_type [RBS::Types::MethodType]
92
+ def initialize(method_type:)
93
+ @method_type = method_type
94
+ end
95
+
96
+ # @return [Rucoa::Types::MethodType]
97
+ def call
98
+ Types::MethodType.new(
99
+ parameters_string: @method_type.type.param_to_s,
100
+ return_type: self.class.stringify(@method_type.type.return_type)
101
+ )
102
+ end
103
+ end
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,191 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'yard'
4
+
5
+ module Rucoa
6
+ module DefinitionBuilders
7
+ class YardMethodDefinitionBuilder
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
17
+ end
18
+ end
19
+
20
+ # @param code_object [YARD::CodeObjects::Base]
21
+ # @param path [String]
22
+ def initialize(code_object:, path:)
23
+ @code_object = code_object
24
+ @path = path
25
+ end
26
+
27
+ # @return [Rucoa::Definitions::Base]
28
+ def call
29
+ ::Rucoa::Definitions::MethodDefinition.new(
30
+ description: description,
31
+ kind: kind,
32
+ method_name: method_name,
33
+ namespace: namespace,
34
+ source_path: @path,
35
+ types: types
36
+ )
37
+ end
38
+
39
+ private
40
+
41
+ # @return [String]
42
+ def description
43
+ @code_object.docstring.to_s
44
+ end
45
+
46
+ # @return [Symbol]
47
+ def kind
48
+ if @code_object.scope == :instance
49
+ :instance
50
+ else
51
+ :singleton
52
+ end
53
+ end
54
+
55
+ # @return [String
56
+ def method_name
57
+ @code_object.name
58
+ end
59
+
60
+ # @return [String]
61
+ def namespace
62
+ @code_object.namespace.to_s
63
+ end
64
+
65
+ # @return [Array<Rucoa::Types::MethodType>]
66
+ def types
67
+ return_types.map do |return_type|
68
+ ::Rucoa::Types::MethodType.new(
69
+ parameters_string: parameters_string,
70
+ return_type: return_type
71
+ )
72
+ end
73
+ end
74
+
75
+ # @return [String]
76
+ # @example
77
+ # definitions = Rucoa::YardStringDocumentLoader.call(
78
+ # content: <<~RUBY,
79
+ # class Foo
80
+ # def bar(
81
+ # argument1,
82
+ # argument2 = nil,
83
+ # *arguments,
84
+ # keyword1:,
85
+ # keyword2: nil,
86
+ # **keywords,
87
+ # &block
88
+ # )
89
+ # end
90
+ # end
91
+ # RUBY
92
+ # path: '/path/to/foo.rb'
93
+ # )
94
+ # expect(definitions.first.signatures).to eq(
95
+ # [
96
+ # 'Foo#bar(argument1, argument2 = nil, *arguments, keyword1:, keyword2: nil, **keywords, &block) -> Object'
97
+ # ]
98
+ # )
99
+ def parameters_string
100
+ @code_object.parameters.map do |parameter_name, default_value|
101
+ default_value_part =
102
+ if default_value.nil?
103
+ nil
104
+ elsif parameter_name.end_with?(':')
105
+ " #{default_value}"
106
+ else
107
+ " = #{default_value}"
108
+ end
109
+ [
110
+ parameter_name,
111
+ default_value_part
112
+ ].join
113
+ end.join(', ')
114
+ end
115
+
116
+ # @return [Array<Rucoa::Definitions::MethodParameterDefinition>]
117
+ def parameters
118
+ parameter_tags.map do |parameter_tag|
119
+ ::Rucoa::Definitions::MethodParameterDefinition.new(
120
+ name: parameter_tag.name,
121
+ types: parameter_tag.types
122
+ )
123
+ end
124
+ end
125
+
126
+ # @return [Array<YARD::Tags::Tag>]
127
+ def parameter_tags
128
+ @code_object.tags(:param) + @code_object.tags(:overload).flat_map do |overload_tag|
129
+ overload_tag.tags(:param)
130
+ end
131
+ end
132
+
133
+ # @return [Array<String>]
134
+ def return_types
135
+ return %w[Object] if return_tags.empty?
136
+
137
+ return_tags.flat_map(&:types).map do |type|
138
+ YardType.new(type).to_rucoa_type
139
+ end
140
+ end
141
+
142
+ # @return [YARD::Tags::Tag]
143
+ def return_tags
144
+ @code_object.tags(:return) + @code_object.tags(:overload).flat_map do |overload_tag|
145
+ overload_tag.tags(:return)
146
+ end
147
+ end
148
+
149
+ class YardType
150
+ # @param type [String]
151
+ def initialize(type)
152
+ @type = type
153
+ end
154
+
155
+ # @return [String]
156
+ # @example scrubs "Array<String>" to "Array"
157
+ # yard_type = Rucoa::DefinitionBuilders::YardMethodDefinitionBuilder::YardType.new(
158
+ # 'Array<String>'
159
+ # )
160
+ # expect(yard_type.to_rucoa_type).to eq('Array')
161
+ # @example scrubs "Array(String, Integer)" to "Array"
162
+ # yard_type = Rucoa::DefinitionBuilders::YardMethodDefinitionBuilder::YardType.new(
163
+ # 'Array(String, Integer)'
164
+ # )
165
+ # expect(yard_type.to_rucoa_type).to eq('Array')
166
+ # @example scrubs "::Array" to "Array"
167
+ # yard_type = Rucoa::DefinitionBuilders::YardMethodDefinitionBuilder::YardType.new(
168
+ # '::Array'
169
+ # )
170
+ # expect(yard_type.to_rucoa_type).to eq('Array')
171
+ # @example scrubs "Hash{Symbol => Object}" to "Hash"
172
+ # yard_type = Rucoa::DefinitionBuilders::YardMethodDefinitionBuilder::YardType.new(
173
+ # 'Hash{Symbol => Object}'
174
+ # )
175
+ # expect(yard_type.to_rucoa_type).to eq('Hash')
176
+ # @exampel scrubs "Array<Array<Integer>>" to "Array"
177
+ # yard_type = Rucoa::DefinitionBuilders::YardMethodDefinitionBuilder::YardType.new(
178
+ # 'Array<Array<Integer>>'
179
+ # )
180
+ # expect(yard_type.to_rucoa_type).to eq('Array')
181
+ def to_rucoa_type
182
+ @type
183
+ .delete_prefix('::')
184
+ .gsub(/<.+>/, '')
185
+ .gsub(/\{.+\}/, '')
186
+ .gsub(/\(.+\)/, '')
187
+ end
188
+ end
189
+ end
190
+ end
191
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rucoa
4
+ module DefinitionBuilders
5
+ autoload :RbsConstantDefinitionBuilder, 'rucoa/definition_builders/rbs_constant_definition_builder'
6
+ autoload :RbsMethodDefinitionBuilder, 'rucoa/definition_builders/rbs_method_definition_builder'
7
+ autoload :YardMethodDefinitionBuilder, 'rucoa/definition_builders/yard_method_definition_builder'
8
+ end
9
+ end