rucoa 0.10.0 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +8 -2
  3. data/Gemfile.lock +3 -3
  4. data/README.md +4 -1
  5. data/data/definitions_ruby_3_1 +6594 -6594
  6. data/lib/rucoa/configuration.rb +22 -12
  7. data/lib/rucoa/definition_store.rb +270 -158
  8. data/lib/rucoa/definitions/method_definition.rb +11 -11
  9. data/lib/rucoa/definitions/module_definition.rb +14 -0
  10. data/lib/rucoa/handler_concerns/configuration_requestable.rb +7 -7
  11. data/lib/rucoa/handler_concerns/diagnostics_publishable.rb +11 -11
  12. data/lib/rucoa/handler_concerns/text_document_position_parameters.rb +29 -0
  13. data/lib/rucoa/handler_concerns/text_document_uri_parameters.rb +21 -0
  14. data/lib/rucoa/handler_concerns.rb +2 -0
  15. data/lib/rucoa/handlers/base.rb +9 -9
  16. data/lib/rucoa/handlers/initialize_handler.rb +1 -0
  17. data/lib/rucoa/handlers/initialized_handler.rb +16 -16
  18. data/lib/rucoa/handlers/text_document_code_action_handler.rb +12 -12
  19. data/lib/rucoa/handlers/text_document_completion_handler.rb +85 -99
  20. data/lib/rucoa/handlers/text_document_definition_handler.rb +11 -30
  21. data/lib/rucoa/handlers/text_document_did_close_handler.rb +2 -8
  22. data/lib/rucoa/handlers/text_document_did_open_handler.rb +3 -7
  23. data/lib/rucoa/handlers/text_document_document_highlight_handler.rb +256 -0
  24. data/lib/rucoa/handlers/text_document_document_symbol_handler.rb +47 -76
  25. data/lib/rucoa/handlers/text_document_formatting_handler.rb +15 -23
  26. data/lib/rucoa/handlers/text_document_hover_handler.rb +24 -43
  27. data/lib/rucoa/handlers/text_document_range_formatting_handler.rb +17 -25
  28. data/lib/rucoa/handlers/text_document_selection_range_handler.rb +11 -19
  29. data/lib/rucoa/handlers/text_document_signature_help_handler.rb +17 -36
  30. data/lib/rucoa/handlers.rb +1 -0
  31. data/lib/rucoa/node_concerns/body.rb +1 -1
  32. data/lib/rucoa/node_concerns/qualified_name.rb +5 -5
  33. data/lib/rucoa/node_concerns/rescue.rb +21 -0
  34. data/lib/rucoa/node_concerns.rb +1 -0
  35. data/lib/rucoa/node_inspector.rb +17 -6
  36. data/lib/rucoa/nodes/base.rb +48 -48
  37. data/lib/rucoa/nodes/begin_node.rb +2 -0
  38. data/lib/rucoa/nodes/block_node.rb +24 -0
  39. data/lib/rucoa/nodes/case_node.rb +24 -0
  40. data/lib/rucoa/nodes/const_node.rb +26 -26
  41. data/lib/rucoa/nodes/def_node.rb +14 -13
  42. data/lib/rucoa/nodes/ensure_node.rb +19 -0
  43. data/lib/rucoa/nodes/for_node.rb +8 -0
  44. data/lib/rucoa/nodes/if_node.rb +32 -0
  45. data/lib/rucoa/nodes/resbody_node.rb +8 -0
  46. data/lib/rucoa/nodes/rescue_node.rb +17 -0
  47. data/lib/rucoa/nodes/send_node.rb +40 -0
  48. data/lib/rucoa/nodes/until_node.rb +8 -0
  49. data/lib/rucoa/nodes/when_node.rb +8 -0
  50. data/lib/rucoa/nodes/while_node.rb +8 -0
  51. data/lib/rucoa/nodes.rb +10 -1
  52. data/lib/rucoa/parser_builder.rb +16 -2
  53. data/lib/rucoa/range.rb +9 -3
  54. data/lib/rucoa/rbs/class_definition_mapper.rb +1 -0
  55. data/lib/rucoa/rbs/constant_definition_mapper.rb +5 -5
  56. data/lib/rucoa/rbs/method_definition_mapper.rb +18 -18
  57. data/lib/rucoa/rbs/module_definition_mapper.rb +17 -12
  58. data/lib/rucoa/rbs/ruby_definitions_loader.rb +5 -5
  59. data/lib/rucoa/rubocop/configuration_checker.rb +7 -7
  60. data/lib/rucoa/server.rb +25 -24
  61. data/lib/rucoa/source.rb +5 -5
  62. data/lib/rucoa/source_store.rb +8 -8
  63. data/lib/rucoa/version.rb +1 -1
  64. data/lib/rucoa/yard/definition_generators/attribute_reader_definition_generator.rb +17 -1
  65. data/lib/rucoa/yard/definition_generators/attribute_writer_definition_generator.rb +17 -1
  66. data/lib/rucoa/yard/definition_generators/class_definition_generator.rb +1 -0
  67. data/lib/rucoa/yard/definition_generators/method_definition_generator.rb +14 -1
  68. data/lib/rucoa/yard/definition_generators/module_definition_generator.rb +6 -0
  69. metadata +16 -3
  70. data/lib/rucoa/nodes/defs_node.rb +0 -33
@@ -21,6 +21,39 @@ module Rucoa
21
21
  children[2..]
22
22
  end
23
23
 
24
+ # @return [Rucoa::Nodes::BlockNode, nil]
25
+ # @example returns nil for method call without block
26
+ # node = Rucoa::Source.new(
27
+ # content: <<~RUBY,
28
+ # foo
29
+ # RUBY
30
+ # uri: 'file:///path/to/example.rb'
31
+ # ).node_at(
32
+ # Rucoa::Position.new(
33
+ # column: 0,
34
+ # line: 1
35
+ # )
36
+ # )
37
+ # expect(node.block).to be_nil
38
+ # @example returns block
39
+ # node = Rucoa::Source.new(
40
+ # content: <<~RUBY,
41
+ # foo do
42
+ # bar
43
+ # end
44
+ # RUBY
45
+ # uri: 'file:///path/to/example.rb'
46
+ # ).node_at(
47
+ # Rucoa::Position.new(
48
+ # column: 0,
49
+ # line: 1
50
+ # )
51
+ # )
52
+ # expect(node.block).to be_a(Rucoa::Nodes::BlockNode)
53
+ def block
54
+ parent if called_with_block?
55
+ end
56
+
24
57
  # @return [String]
25
58
  # @example returns method name
26
59
  # node = Rucoa::Source.new(
@@ -59,6 +92,13 @@ module Rucoa
59
92
  def receiver
60
93
  children[0]
61
94
  end
95
+
96
+ private
97
+
98
+ # @return [Boolean]
99
+ def called_with_block?
100
+ parent.is_a?(Nodes::BlockNode) && eql?(parent.send_node)
101
+ end
62
102
  end
63
103
  end
64
104
  end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rucoa
4
+ module Nodes
5
+ class UntilNode < Base
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rucoa
4
+ module Nodes
5
+ class WhenNode < Base
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rucoa
4
+ module Nodes
5
+ class WhileNode < Base
6
+ end
7
+ end
8
+ end
data/lib/rucoa/nodes.rb CHANGED
@@ -4,17 +4,26 @@ module Rucoa
4
4
  module Nodes
5
5
  autoload :Base, 'rucoa/nodes/base'
6
6
  autoload :BeginNode, 'rucoa/nodes/begin_node'
7
+ autoload :BlockNode, 'rucoa/nodes/block_node'
8
+ autoload :CaseNode, 'rucoa/nodes/case_node'
7
9
  autoload :CasgnNode, 'rucoa/nodes/casgn_node'
8
10
  autoload :CbaseNode, 'rucoa/nodes/cbase_node'
9
11
  autoload :ClassNode, 'rucoa/nodes/class_node'
10
12
  autoload :ConstNode, 'rucoa/nodes/const_node'
11
13
  autoload :DefNode, 'rucoa/nodes/def_node'
12
- autoload :DefsNode, 'rucoa/nodes/defs_node'
14
+ autoload :EnsureNode, 'rucoa/nodes/ensure_node'
15
+ autoload :ForNode, 'rucoa/nodes/for_node'
16
+ autoload :IfNode, 'rucoa/nodes/if_node'
13
17
  autoload :LvarNode, 'rucoa/nodes/lvar_node'
14
18
  autoload :ModuleNode, 'rucoa/nodes/module_node'
19
+ autoload :ResbodyNode, 'rucoa/nodes/resbody_node'
20
+ autoload :RescueNode, 'rucoa/nodes/rescue_node'
15
21
  autoload :SclassNode, 'rucoa/nodes/sclass_node'
16
22
  autoload :SendNode, 'rucoa/nodes/send_node'
17
23
  autoload :StrNode, 'rucoa/nodes/str_node'
18
24
  autoload :SymNode, 'rucoa/nodes/sym_node'
25
+ autoload :UntilNode, 'rucoa/nodes/until_node'
26
+ autoload :WhenNode, 'rucoa/nodes/when_node'
27
+ autoload :WhileNode, 'rucoa/nodes/while_node'
19
28
  end
20
29
  end
@@ -6,18 +6,32 @@ module Rucoa
6
6
  class ParserBuilder < ::Parser::Builders::Default
7
7
  NODE_CLASS_BY_TYPE = {
8
8
  begin: Nodes::BeginNode,
9
+ block: Nodes::BlockNode,
10
+ case: Nodes::CaseNode,
9
11
  casgn: Nodes::CasgnNode,
10
12
  cbase: Nodes::CbaseNode,
11
13
  class: Nodes::ClassNode,
12
14
  const: Nodes::ConstNode,
15
+ csend: Nodes::SendNode,
13
16
  def: Nodes::DefNode,
14
- defs: Nodes::DefsNode,
17
+ defs: Nodes::DefNode,
18
+ ensure: Nodes::EnsureNode,
19
+ for: Nodes::ForNode,
20
+ if: Nodes::IfNode,
21
+ kwbegin: Nodes::BeginNode,
15
22
  lvar: Nodes::LvarNode,
16
23
  module: Nodes::ModuleNode,
24
+ resbody: Nodes::ResbodyNode,
25
+ rescue: Nodes::RescueNode,
17
26
  sclass: Nodes::SclassNode,
18
27
  send: Nodes::SendNode,
19
28
  str: Nodes::StrNode,
20
- sym: Nodes::SymNode
29
+ super: Nodes::SendNode,
30
+ sym: Nodes::SymNode,
31
+ until: Nodes::UntilNode,
32
+ when: Nodes::WhenNode,
33
+ while: Nodes::WhileNode,
34
+ zsuper: Nodes::SendNode
21
35
  }.freeze
22
36
 
23
37
  class << self
data/lib/rucoa/range.rb CHANGED
@@ -103,6 +103,12 @@ module Rucoa
103
103
  # )
104
104
  # expect(range).to include(
105
105
  # Rucoa::Position.new(
106
+ # column: 1,
107
+ # line: 1
108
+ # )
109
+ # )
110
+ # expect(range).to include(
111
+ # Rucoa::Position.new(
106
112
  # column: 0,
107
113
  # line: 2
108
114
  # )
@@ -116,9 +122,9 @@ module Rucoa
116
122
  def include?(position)
117
123
  return false if position.line > @ending.line
118
124
  return false if position.line < @beginning.line
119
- return false if position.column < @beginning.column
120
- return false if position.column > @ending.column
121
- return false if position.column == @ending.column && !@including_ending
125
+ return false if position.line == @beginning.line && position.column < @beginning.column
126
+ return false if position.line == @ending.line && position.column > @ending.column
127
+ return false if position.line == @ending.line && position.column == @ending.column && !@including_ending
122
128
 
123
129
  true
124
130
  end
@@ -12,6 +12,7 @@ module Rucoa
12
12
  def call
13
13
  Definitions::ClassDefinition.new(
14
14
  description: description,
15
+ extended_module_qualified_names: extended_module_qualified_names,
15
16
  included_module_qualified_names: included_module_qualified_names,
16
17
  location: location,
17
18
  prepended_module_qualified_names: prepended_module_qualified_names,
@@ -32,15 +32,15 @@ module Rucoa
32
32
  @declaration.comment&.string&.sub(/\A\s*<!--.*-->\s*/m, '')
33
33
  end
34
34
 
35
- # @return [String]
36
- def qualified_name
37
- @declaration.name.to_s.delete_prefix('::')
38
- end
39
-
40
35
  # @return [Rucoa::Location]
41
36
  def location
42
37
  Location.from_rbs_location(@declaration.location)
43
38
  end
39
+
40
+ # @return [String]
41
+ def qualified_name
42
+ @declaration.name.to_s.delete_prefix('::')
43
+ end
44
44
  end
45
45
  end
46
46
  end
@@ -42,23 +42,19 @@ module Rucoa
42
42
 
43
43
  private
44
44
 
45
- # @return [Array<Rucoa::Types::MethodType>]
46
- def types
47
- @method_definition.types.map do |method_type|
48
- MethodTypeMapper.call(
49
- method_type: method_type
50
- )
51
- end
52
- end
53
-
54
45
  # @return [String, nil]
55
46
  def description
56
47
  @method_definition.comment&.string&.sub(/\A\s*<!--.*-->\s*/m, '')
57
48
  end
58
49
 
59
- # @return [String]
60
- def namespace
61
- @declaration.name.to_s.delete_prefix('::')
50
+ # @return [Symbol]
51
+ def kind
52
+ @method_definition.kind
53
+ end
54
+
55
+ # @return [Rucoa::Location]
56
+ def location
57
+ Location.from_rbs_location(@method_definition.location)
62
58
  end
63
59
 
64
60
  # @return [String]
@@ -66,14 +62,18 @@ module Rucoa
66
62
  @method_definition.name.to_s
67
63
  end
68
64
 
69
- # @return [Symbol]
70
- def kind
71
- @method_definition.kind
65
+ # @return [String]
66
+ def namespace
67
+ @declaration.name.to_s.delete_prefix('::')
72
68
  end
73
69
 
74
- # @return [Rucoa::Location]
75
- def location
76
- Location.from_rbs_location(@method_definition.location)
70
+ # @return [Array<Rucoa::Types::MethodType>]
71
+ def types
72
+ @method_definition.types.map do |method_type|
73
+ MethodTypeMapper.call(
74
+ method_type: method_type
75
+ )
76
+ end
77
77
  end
78
78
 
79
79
  class MethodTypeMapper
@@ -20,6 +20,7 @@ module Rucoa
20
20
  def call
21
21
  Definitions::ModuleDefinition.new(
22
22
  description: description,
23
+ extended_module_qualified_names: extended_module_qualified_names,
23
24
  included_module_qualified_names: included_module_qualified_names,
24
25
  location: location,
25
26
  prepended_module_qualified_names: prepended_module_qualified_names,
@@ -34,9 +35,14 @@ module Rucoa
34
35
  @declaration.comment&.string&.sub(/\A\s*<!--.*-->\s*/m, '')
35
36
  end
36
37
 
37
- # @return [String]
38
- def qualified_name
39
- @declaration.name.to_s.delete_prefix('::')
38
+ # @return [Array<String>]
39
+ def extended_module_qualified_names
40
+ module_qualified_names_for(::RBS::AST::Members::Extend)
41
+ end
42
+
43
+ # @return [Array<String>]
44
+ def included_module_qualified_names
45
+ module_qualified_names_for(::RBS::AST::Members::Include)
40
46
  end
41
47
 
42
48
  # @return [Rucoa::Location]
@@ -44,11 +50,10 @@ module Rucoa
44
50
  Location.from_rbs_location(@declaration.location)
45
51
  end
46
52
 
47
- # @return [Array<String>]
48
- def included_module_qualified_names
53
+ def module_qualified_names_for(member_class)
49
54
  @declaration.members.filter_map do |member|
50
55
  case member
51
- when ::RBS::AST::Members::Include
56
+ when member_class
52
57
  member.name.to_s.delete_prefix('::')
53
58
  end
54
59
  end
@@ -56,12 +61,12 @@ module Rucoa
56
61
 
57
62
  # @return [Array<String>]
58
63
  def prepended_module_qualified_names
59
- @declaration.members.filter_map do |member|
60
- case member
61
- when ::RBS::AST::Members::Prepend
62
- member.name.to_s.delete_prefix('::')
63
- end
64
- end
64
+ module_qualified_names_for(::RBS::AST::Members::Prepend)
65
+ end
66
+
67
+ # @return [String]
68
+ def qualified_name
69
+ @declaration.name.to_s.delete_prefix('::')
65
70
  end
66
71
  end
67
72
  end
@@ -43,11 +43,6 @@ module Rucoa
43
43
 
44
44
  private
45
45
 
46
- # @return [Array<RBS::AST::Declarations::Base>]
47
- def declarations
48
- class_declarations + constant_declarations
49
- end
50
-
51
46
  # @return [Array<RBS::AST::Declarations::Class>]
52
47
  def class_declarations
53
48
  environment.class_decls.values.flat_map do |multi_entry|
@@ -60,6 +55,11 @@ module Rucoa
60
55
  environment.constant_decls.values.map(&:decl)
61
56
  end
62
57
 
58
+ # @return [Array<RBS::AST::Declarations::Base>]
59
+ def declarations
60
+ class_declarations + constant_declarations
61
+ end
62
+
63
63
  # @return [RBS::Environment]
64
64
  def environment
65
65
  @environment ||= ::RBS::Environment.from_loader(
@@ -19,13 +19,6 @@ module Rucoa
19
19
 
20
20
  private
21
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
22
  # @return [Enumerable<Pathname>]
30
23
  def each_current_and_ancestor_pathname
31
24
  return to_enum(__method__) unless block_given?
@@ -39,6 +32,13 @@ module Rucoa
39
32
  end
40
33
  self
41
34
  end
35
+
36
+ # @return [Boolean]
37
+ def rubocop_configured_for_current_directory?
38
+ each_current_and_ancestor_pathname.any? do |pathname|
39
+ pathname.join('.rubocop.yml').exist?
40
+ end
41
+ end
42
42
  end
43
43
  end
44
44
  end
data/lib/rucoa/server.rb CHANGED
@@ -17,6 +17,7 @@ module Rucoa
17
17
  'textDocument/didChange' => Handlers::TextDocumentDidChangeHandler,
18
18
  'textDocument/didClose' => Handlers::TextDocumentDidCloseHandler,
19
19
  'textDocument/didOpen' => Handlers::TextDocumentDidOpenHandler,
20
+ 'textDocument/documentHighlight' => Handlers::TextDocumentDocumentHighlightHandler,
20
21
  'textDocument/documentSymbol' => Handlers::TextDocumentDocumentSymbolHandler,
21
22
  'textDocument/formatting' => Handlers::TextDocumentFormattingHandler,
22
23
  'textDocument/hover' => Handlers::TextDocumentHoverHandler,
@@ -43,8 +44,8 @@ module Rucoa
43
44
  # @param io_in [IO]
44
45
  # @param io_out [IO]
45
46
  def initialize(
46
- io_log: ::StringIO.new,
47
47
  io_in: ::StringIO.new,
48
+ io_log: ::StringIO.new,
48
49
  io_out: ::StringIO.new
49
50
  )
50
51
  @logger = ::Logger.new(io_log)
@@ -62,6 +63,19 @@ module Rucoa
62
63
  @definition_store.bulk_add(DefinitionArchiver.load)
63
64
  end
64
65
 
66
+ # @return [void]
67
+ def finish
68
+ exit(0)
69
+ end
70
+
71
+ # @note This method is for testing.
72
+ # @return [Array<Hash>]
73
+ def responses
74
+ io = @writer.io
75
+ io.rewind
76
+ MessageReader.new(io).read.to_a
77
+ end
78
+
65
79
  # @return [void]
66
80
  def start
67
81
  @reader.read do |message|
@@ -75,11 +89,6 @@ module Rucoa
75
89
  end
76
90
  end
77
91
 
78
- # @return [void]
79
- def finish
80
- exit(0)
81
- end
82
-
83
92
  # @yieldparam response [Hash]
84
93
  # @param message [Hash]
85
94
  # @return [void]
@@ -94,15 +103,18 @@ module Rucoa
94
103
  end
95
104
  end
96
105
 
97
- # @note This method is for testing.
98
- # @return [Array<Hash>]
99
- def responses
100
- io = @writer.io
101
- io.rewind
102
- MessageReader.new(io).read.to_a
106
+ private
107
+
108
+ # @yieldparam log [String]
109
+ def debug(&block)
110
+ @logger.debug(&block) if configuration.enables_debug?
103
111
  end
104
112
 
105
- private
113
+ # @param request_method [String]
114
+ # @return [Class, nil]
115
+ def find_client_request_handler(request_method)
116
+ METHOD_TO_HANDLER_MAP[request_method]
117
+ end
106
118
 
107
119
  # @param request [Hash]
108
120
  # @return [void]
@@ -114,11 +126,6 @@ module Rucoa
114
126
  end
115
127
  end
116
128
 
117
- # @yieldparam log [String]
118
- def debug(&block)
119
- @logger.debug(&block) if configuration.enables_debug?
120
- end
121
-
122
129
  # @param request [Hash]
123
130
  # @return [void]
124
131
  def handle_client_request(request)
@@ -134,12 +141,6 @@ module Rucoa
134
141
  @client_response_handlers.delete(response['id'])&.call(response)
135
142
  end
136
143
 
137
- # @param request_method [String]
138
- # @return [Class, nil]
139
- def find_client_request_handler(request_method)
140
- METHOD_TO_HANDLER_MAP[request_method]
141
- end
142
-
143
144
  # @param message [Hash]
144
145
  # @return [void]
145
146
  def write_server_request(
data/lib/rucoa/source.rb CHANGED
@@ -62,6 +62,11 @@ module Rucoa
62
62
  end
63
63
  end
64
64
 
65
+ # @return [Boolean]
66
+ def failed_to_parse?
67
+ parse_result.failed?
68
+ end
69
+
65
70
  # @return [String, nil]
66
71
  # @example returns path for file URI
67
72
  # source = Rucoa::Source.new(
@@ -96,11 +101,6 @@ module Rucoa
96
101
  parse_result.root_node
97
102
  end
98
103
 
99
- # @return [Boolean]
100
- def failed_to_parse?
101
- parse_result.failed?
102
- end
103
-
104
104
  # @return [Boolean]
105
105
  def untitled?
106
106
  uri_object.scheme == 'untitled'
@@ -6,10 +6,10 @@ module Rucoa
6
6
  @data = {}
7
7
  end
8
8
 
9
- # @param source [Rucoa::Source]
10
- # @return [void]
11
- def update(source)
12
- @data[source.uri] = source
9
+ # @yieldparam uri [String]
10
+ # @return [Enumerable<String>]
11
+ def each_uri(&block)
12
+ @data.each_key(&block)
13
13
  end
14
14
 
15
15
  # @param uri [String]
@@ -18,10 +18,10 @@ module Rucoa
18
18
  @data[uri]
19
19
  end
20
20
 
21
- # @yieldparam uri [String]
22
- # @return [Enumerable<String>]
23
- def each_uri(&block)
24
- @data.each_key(&block)
21
+ # @param source [Rucoa::Source]
22
+ # @return [void]
23
+ def update(source)
24
+ @data[source.uri] = source
25
25
  end
26
26
  end
27
27
  end
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.10.0'
4
+ VERSION = '0.12.0'
5
5
  end
@@ -35,10 +35,26 @@ module Rucoa
35
35
  # Foo#bar=
36
36
  # ]
37
37
  # )
38
+ # @example ignores unrecognizable attributes
39
+ # definitions = Rucoa::Source.new(
40
+ # content: <<~RUBY,
41
+ # class Foo
42
+ # attr_reader foo
43
+ # end
44
+ # RUBY
45
+ # uri: '/path/to/foo.rb'
46
+ # ).definitions
47
+ # expect(definitions.map(&:qualified_name)).to eq(
48
+ # %w[
49
+ # Foo
50
+ # ]
51
+ # )
38
52
  def call
39
53
  return [] unless @node.is_a?(Nodes::SendNode) && READER_METHOD_NAMES.include?(@node.name)
40
54
 
41
- @node.arguments.map do |argument|
55
+ @node.arguments.filter_map do |argument|
56
+ next unless argument.respond_to?(:value)
57
+
42
58
  Definitions::MethodDefinition.new(
43
59
  description: description,
44
60
  kind: :instance,
@@ -35,10 +35,26 @@ module Rucoa
35
35
  # Foo#bar=
36
36
  # ]
37
37
  # )
38
+ # @example ignores unrecognizable attributes
39
+ # definitions = Rucoa::Source.new(
40
+ # content: <<~RUBY,
41
+ # class Foo
42
+ # attr_writer foo
43
+ # end
44
+ # RUBY
45
+ # uri: '/path/to/foo.rb'
46
+ # ).definitions
47
+ # expect(definitions.map(&:qualified_name)).to eq(
48
+ # %w[
49
+ # Foo
50
+ # ]
51
+ # )
38
52
  def call
39
53
  return [] unless @node.is_a?(Nodes::SendNode) && WRITER_METHOD_NAMES.include?(@node.name)
40
54
 
41
- @node.arguments.map do |argument|
55
+ @node.arguments.filter_map do |argument|
56
+ next unless argument.respond_to?(:value)
57
+
42
58
  Definitions::MethodDefinition.new(
43
59
  description: description,
44
60
  kind: :instance,
@@ -49,6 +49,7 @@ module Rucoa
49
49
  [
50
50
  Definitions::ClassDefinition.new(
51
51
  description: description,
52
+ extended_module_unqualified_names: extended_module_unqualified_names,
52
53
  included_module_unqualified_names: included_module_unqualified_names,
53
54
  location: location,
54
55
  prepended_module_unqualified_names: prepended_module_unqualified_names,
@@ -22,8 +22,21 @@ module Rucoa
22
22
  # uri: '/path/to/foo.rb'
23
23
  # ).definitions
24
24
  # expect(definitions[0]).to be_a(Rucoa::Definitions::MethodDefinition)
25
+ # @example returns method definition for another style of singleton def node
26
+ # definitions = Rucoa::Source.new(
27
+ # content: <<~RUBY,
28
+ # class Foo
29
+ # class << self
30
+ # def bar
31
+ # end
32
+ # end
33
+ # end
34
+ # RUBY
35
+ # uri: '/path/to/foo.rb'
36
+ # ).definitions
37
+ # expect(definitions[1].qualified_name).to eq('Foo.bar')
25
38
  def call
26
- return [] unless @node.is_a?(Nodes::DefNode) || @node.is_a?(Nodes::DefsNode)
39
+ return [] unless @node.is_a?(Nodes::DefNode)
27
40
 
28
41
  [
29
42
  Definitions::MethodDefinition.new(
@@ -19,6 +19,7 @@ module Rucoa
19
19
  [
20
20
  Definitions::ModuleDefinition.new(
21
21
  description: description,
22
+ extended_module_unqualified_names: extended_module_unqualified_names,
22
23
  included_module_unqualified_names: included_module_unqualified_names,
23
24
  location: location,
24
25
  prepended_module_unqualified_names: prepended_module_unqualified_names,
@@ -29,6 +30,11 @@ module Rucoa
29
30
 
30
31
  private
31
32
 
33
+ # @return [Array<Rucoa::UnqualifiedName>]
34
+ def extended_module_unqualified_names
35
+ unqualified_names_for('extend')
36
+ end
37
+
32
38
  # @return [Array<Rucoa::UnqualifiedName>]
33
39
  def included_module_unqualified_names
34
40
  unqualified_names_for('include')