rucoa 0.11.0 → 0.13.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 (78) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +12 -3
  3. data/Gemfile.lock +3 -3
  4. data/README.md +6 -1
  5. data/images/document-highlight.gif +0 -0
  6. data/lib/rucoa/configuration.rb +22 -12
  7. data/lib/rucoa/definition_store.rb +131 -131
  8. data/lib/rucoa/definitions/method_definition.rb +11 -11
  9. data/lib/rucoa/handler_concerns/configuration_requestable.rb +7 -7
  10. data/lib/rucoa/handler_concerns/diagnostics_publishable.rb +11 -11
  11. data/lib/rucoa/handler_concerns/text_document_position_parameters.rb +29 -0
  12. data/lib/rucoa/handler_concerns/text_document_uri_parameters.rb +21 -0
  13. data/lib/rucoa/handler_concerns.rb +2 -0
  14. data/lib/rucoa/handlers/base.rb +9 -9
  15. data/lib/rucoa/handlers/initialize_handler.rb +1 -0
  16. data/lib/rucoa/handlers/initialized_handler.rb +16 -16
  17. data/lib/rucoa/handlers/text_document_code_action_handler.rb +12 -12
  18. data/lib/rucoa/handlers/text_document_completion_handler.rb +85 -99
  19. data/lib/rucoa/handlers/text_document_definition_handler.rb +11 -30
  20. data/lib/rucoa/handlers/text_document_did_close_handler.rb +2 -8
  21. data/lib/rucoa/handlers/text_document_did_open_handler.rb +3 -7
  22. data/lib/rucoa/handlers/text_document_document_highlight_handler.rb +531 -0
  23. data/lib/rucoa/handlers/text_document_document_symbol_handler.rb +47 -76
  24. data/lib/rucoa/handlers/text_document_formatting_handler.rb +16 -24
  25. data/lib/rucoa/handlers/text_document_hover_handler.rb +24 -43
  26. data/lib/rucoa/handlers/text_document_range_formatting_handler.rb +17 -25
  27. data/lib/rucoa/handlers/text_document_selection_range_handler.rb +11 -19
  28. data/lib/rucoa/handlers/text_document_signature_help_handler.rb +17 -36
  29. data/lib/rucoa/handlers.rb +1 -0
  30. data/lib/rucoa/node_concerns/body.rb +1 -1
  31. data/lib/rucoa/node_concerns/modifier.rb +35 -0
  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/variable.rb +26 -0
  35. data/lib/rucoa/node_concerns.rb +3 -0
  36. data/lib/rucoa/node_inspector.rb +5 -5
  37. data/lib/rucoa/nodes/arg_node.rb +26 -0
  38. data/lib/rucoa/nodes/args_node.rb +14 -0
  39. data/lib/rucoa/nodes/base.rb +111 -47
  40. data/lib/rucoa/nodes/begin_node.rb +2 -0
  41. data/lib/rucoa/nodes/block_node.rb +38 -0
  42. data/lib/rucoa/nodes/case_node.rb +24 -0
  43. data/lib/rucoa/nodes/const_node.rb +26 -26
  44. data/lib/rucoa/nodes/cvar_node.rb +9 -0
  45. data/lib/rucoa/nodes/cvasgn_node.rb +9 -0
  46. data/lib/rucoa/nodes/def_node.rb +28 -13
  47. data/lib/rucoa/nodes/ensure_node.rb +19 -0
  48. data/lib/rucoa/nodes/for_node.rb +8 -0
  49. data/lib/rucoa/nodes/gvar_node.rb +9 -0
  50. data/lib/rucoa/nodes/gvasgn_node.rb +9 -0
  51. data/lib/rucoa/nodes/if_node.rb +34 -0
  52. data/lib/rucoa/nodes/ivar_node.rb +9 -0
  53. data/lib/rucoa/nodes/ivasgn_node.rb +9 -0
  54. data/lib/rucoa/nodes/lvar_node.rb +1 -18
  55. data/lib/rucoa/nodes/lvasgn_node.rb +9 -0
  56. data/lib/rucoa/nodes/resbody_node.rb +8 -0
  57. data/lib/rucoa/nodes/rescue_node.rb +17 -0
  58. data/lib/rucoa/nodes/send_node.rb +40 -0
  59. data/lib/rucoa/nodes/until_node.rb +9 -0
  60. data/lib/rucoa/nodes/when_node.rb +8 -0
  61. data/lib/rucoa/nodes/while_node.rb +9 -0
  62. data/lib/rucoa/nodes.rb +19 -1
  63. data/lib/rucoa/parser_builder.rb +26 -2
  64. data/lib/rucoa/range.rb +9 -3
  65. data/lib/rucoa/rbs/constant_definition_mapper.rb +5 -5
  66. data/lib/rucoa/rbs/method_definition_mapper.rb +18 -18
  67. data/lib/rucoa/rbs/module_definition_mapper.rb +13 -13
  68. data/lib/rucoa/rbs/ruby_definitions_loader.rb +5 -5
  69. data/lib/rucoa/rubocop/configuration_checker.rb +7 -7
  70. data/lib/rucoa/server.rb +24 -23
  71. data/lib/rucoa/source.rb +6 -6
  72. data/lib/rucoa/source_store.rb +8 -8
  73. data/lib/rucoa/version.rb +1 -1
  74. data/lib/rucoa/yard/definition_generators/method_definition_generator.rb +1 -1
  75. data/lib/rucoa/yard/definitions_loader.rb +1 -1
  76. data/rucoa.gemspec +0 -1
  77. metadata +28 -4
  78. data/lib/rucoa/nodes/defs_node.rb +0 -33
@@ -13,18 +13,14 @@ module Rucoa
13
13
 
14
14
  private
15
15
 
16
- # @return [void]
17
- def update_definition_store
18
- sources.each do |source|
19
- definition_store.update_from(source)
20
- end
16
+ # @return [String]
17
+ def glob
18
+ ::File.expand_path('{app,lib}/**/*.rb')
21
19
  end
22
20
 
23
- # @return [void]
24
- def update_source_store
25
- sources.each do |source|
26
- source_store.update(source)
27
- end
21
+ # @return [Array<Pathname>]
22
+ def pathnames
23
+ ::Pathname.glob(glob)
28
24
  end
29
25
 
30
26
  # @return [Array<Rucoa::Source>]
@@ -37,14 +33,18 @@ module Rucoa
37
33
  end
38
34
  end
39
35
 
40
- # @return [Array<Pathname>]
41
- def pathnames
42
- ::Pathname.glob(glob)
36
+ # @return [void]
37
+ def update_definition_store
38
+ sources.each do |source|
39
+ definition_store.update_from(source)
40
+ end
43
41
  end
44
42
 
45
- # @return [String]
46
- def glob
47
- ::File.expand_path('{app,lib}/**/*.rb')
43
+ # @return [void]
44
+ def update_source_store
45
+ sources.each do |source|
46
+ source_store.update(source)
47
+ end
48
48
  end
49
49
  end
50
50
  end
@@ -59,6 +59,16 @@ module Rucoa
59
59
 
60
60
  private
61
61
 
62
+ # @return [String]
63
+ def cop_name
64
+ @diagnostic.dig('data', 'cop_name')
65
+ end
66
+
67
+ # @return [Array]
68
+ def diagnostics
69
+ [@diagnostic]
70
+ end
71
+
62
72
  # @return [Hash]
63
73
  def edit
64
74
  {
@@ -75,13 +85,8 @@ module Rucoa
75
85
  end
76
86
 
77
87
  # @return [String]
78
- def cop_name
79
- @diagnostic.dig('data', 'cop_name')
80
- end
81
-
82
- # @return [Array]
83
- def diagnostics
84
- [@diagnostic]
88
+ def kind
89
+ 'quickfix'
85
90
  end
86
91
 
87
92
  # @return [Boolean]
@@ -89,11 +94,6 @@ module Rucoa
89
94
  true
90
95
  end
91
96
 
92
- # @return [String]
93
- def kind
94
- 'quickfix'
95
- end
96
-
97
97
  # @return [String]
98
98
  def title
99
99
  "Autocorrect #{cop_name}"
@@ -3,6 +3,9 @@
3
3
  module Rucoa
4
4
  module Handlers
5
5
  class TextDocumentCompletionHandler < Base
6
+ include HandlerConcerns::TextDocumentPositionParameters
7
+ include HandlerConcerns::TextDocumentUriParameters
8
+
6
9
  COMPLETION_ITEM_KIND_FOR_TEXT = 1
7
10
  COMPLETION_ITEM_KIND_FOR_METHOD = 2
8
11
  COMPLETION_ITEM_KIND_FOR_FUNCTION = 3
@@ -38,6 +41,42 @@ module Rucoa
38
41
 
39
42
  private
40
43
 
44
+ # @return [Array<String>]
45
+ def callable_method_definitions
46
+ receiver_types.flat_map do |type|
47
+ definition_store.instance_method_definitions_of(type)
48
+ end
49
+ end
50
+
51
+ # @return [Array<String>]
52
+ def callable_method_names
53
+ callable_method_definitions.map(&:method_name).uniq
54
+ end
55
+
56
+ # @return [Array<String>]
57
+ def completable_constant_names
58
+ referrable_constant_names.select do |constant_name|
59
+ constant_name.start_with?(completion_head)
60
+ end.sort
61
+ end
62
+
63
+ # @return [Array<String>]
64
+ def completable_method_names
65
+ callable_method_names.select do |method_name|
66
+ method_name.start_with?(completion_head)
67
+ end.sort
68
+ end
69
+
70
+ # @return [String] e.g. "SE" to `File::SE|`, "ba" to `foo.ba|`
71
+ def completion_head
72
+ @completion_head ||=
73
+ if @repaired
74
+ ''
75
+ else
76
+ node.name
77
+ end
78
+ end
79
+
41
80
  # @return [Array<Hash>, nil]
42
81
  def completion_items
43
82
  return unless responsible?
@@ -56,37 +95,14 @@ module Rucoa
56
95
  end
57
96
  end
58
97
 
59
- # @return [Boolean]
60
- def responsible?
61
- configuration.enables_completion? &&
62
- !source.nil?
63
- end
64
-
65
- # @return [Rucoa::Source, nil]
66
- def source
67
- @source ||= source_store.get(uri)
68
- end
69
-
70
- # @return [Rucoa::Position]
71
- def position
72
- @position ||= Position.from_vscode_position(
73
- request.dig('params', 'position')
74
- )
75
- end
76
-
77
- # @return [String]
78
- def uri
79
- request.dig('params', 'textDocument', 'uri')
80
- end
81
-
82
98
  # @return [Array<Hash>]
83
- def completion_items_for_method
84
- completable_method_names.map do |method_name|
99
+ def completion_items_for_constant
100
+ completable_constant_names.map do |constant_name|
85
101
  {
86
- kind: COMPLETION_ITEM_KIND_FOR_METHOD,
87
- label: method_name,
102
+ kind: COMPLETION_ITEM_KIND_FOR_CONSTANT,
103
+ label: constant_name,
88
104
  textEdit: {
89
- newText: method_name,
105
+ newText: constant_name,
90
106
  range: range.to_vscode_range
91
107
  }
92
108
  }
@@ -94,72 +110,24 @@ module Rucoa
94
110
  end
95
111
 
96
112
  # @return [Array<Hash>]
97
- def completion_items_for_constant
98
- completable_constant_names.map do |constant_name|
113
+ def completion_items_for_method
114
+ completable_method_names.map do |method_name|
99
115
  {
100
- kind: COMPLETION_ITEM_KIND_FOR_CONSTANT,
101
- label: constant_name,
116
+ kind: COMPLETION_ITEM_KIND_FOR_METHOD,
117
+ label: method_name,
102
118
  textEdit: {
103
- newText: constant_name,
119
+ newText: method_name,
104
120
  range: range.to_vscode_range
105
121
  }
106
122
  }
107
123
  end
108
124
  end
109
125
 
110
- # @return [Array<String>]
111
- def completable_constant_names
112
- referrable_constant_names.select do |constant_name|
113
- constant_name.start_with?(completion_head)
114
- end.sort
115
- end
116
-
117
- # @return [String] e.g. "SE" to `File::SE|`, "ba" to `foo.ba|`
118
- def completion_head
119
- @completion_head ||=
120
- if @repaired
121
- ''
122
- else
123
- node.name
124
- end
125
- end
126
-
127
- def referrable_constant_names
128
- definition_store.constant_definitions_under(constant_namespace).map(&:name).uniq
129
- end
130
-
131
126
  # @return [String] e.g. "Foo::Bar" to `Foo::Bar.baz|`.
132
127
  def constant_namespace
133
128
  node.each_child_node(:const).map(&:name).reverse.join('::')
134
129
  end
135
130
 
136
- # @return [Array<String>]
137
- def completable_method_names
138
- callable_method_names.select do |method_name|
139
- method_name.start_with?(completion_head)
140
- end.sort
141
- end
142
-
143
- # @return [Array<String>]
144
- def callable_method_names
145
- callable_method_definitions.map(&:method_name).uniq
146
- end
147
-
148
- # @return [Array<String>]
149
- def callable_method_definitions
150
- receiver_types.flat_map do |type|
151
- definition_store.instance_method_definitions_of(type)
152
- end
153
- end
154
-
155
- # @return [Array<String>]
156
- def receiver_types
157
- NodeInspector.new(
158
- definition_store: definition_store,
159
- node: node
160
- ).method_receiver_types
161
- end
162
-
163
131
  # @return [Rucoa::Node, nil]
164
132
  def node
165
133
  @node ||=
@@ -176,9 +144,33 @@ module Rucoa
176
144
  source.node_at(position)
177
145
  end
178
146
 
179
- # @return [Rucoa::Node, nil]
180
- def repaired_node
181
- repaired_source.node_at(position)
147
+ # @return [Rucoa::Range]
148
+ def range
149
+ @range ||=
150
+ if @repaired
151
+ position.to_range
152
+ else
153
+ Range.from_parser_range(
154
+ case node
155
+ when Nodes::SendNode
156
+ node.location.selector
157
+ else
158
+ node.location.expression
159
+ end
160
+ )
161
+ end
162
+ end
163
+
164
+ # @return [Array<String>]
165
+ def receiver_types
166
+ NodeInspector.new(
167
+ definition_store: definition_store,
168
+ node: node
169
+ ).method_receiver_types
170
+ end
171
+
172
+ def referrable_constant_names
173
+ definition_store.constant_definitions_under(constant_namespace).map(&:name).uniq
182
174
  end
183
175
 
184
176
  # @return [void]
@@ -194,6 +186,11 @@ module Rucoa
194
186
  )
195
187
  end
196
188
 
189
+ # @return [Rucoa::Node, nil]
190
+ def repaired_node
191
+ repaired_source.node_at(position)
192
+ end
193
+
197
194
  # @return [Rucoa::Source]
198
195
  def repaired_source
199
196
  Source.new(
@@ -202,21 +199,10 @@ module Rucoa
202
199
  )
203
200
  end
204
201
 
205
- # @return [Rucoa::Range]
206
- def range
207
- @range ||=
208
- if @repaired
209
- position.to_range
210
- else
211
- Range.from_parser_range(
212
- case node
213
- when Nodes::SendNode
214
- node.location.selector
215
- else
216
- node.location.expression
217
- end
218
- )
219
- end
202
+ # @return [Boolean]
203
+ def responsible?
204
+ configuration.enables_completion? &&
205
+ !source.nil?
220
206
  end
221
207
  end
222
208
  end
@@ -3,12 +3,23 @@
3
3
  module Rucoa
4
4
  module Handlers
5
5
  class TextDocumentDefinitionHandler < Base
6
+ include HandlerConcerns::TextDocumentPositionParameters
7
+ include HandlerConcerns::TextDocumentUriParameters
8
+
6
9
  def call
7
10
  respond(location)
8
11
  end
9
12
 
10
13
  private
11
14
 
15
+ # @return [Rucoa::Definitions::Base, nil]
16
+ def definition
17
+ @definition ||= NodeInspector.new(
18
+ definition_store: definition_store,
19
+ node: node
20
+ ).definitions.first
21
+ end
22
+
12
23
  # @return [Hash, nil]
13
24
  def location
14
25
  return unless reponsible?
@@ -24,36 +35,6 @@ module Rucoa
24
35
  configuration.enables_definition? &&
25
36
  !definition&.location.nil?
26
37
  end
27
-
28
- # @return [Rucoa::Position]
29
- def position
30
- Position.from_vscode_position(
31
- request.dig('params', 'position')
32
- )
33
- end
34
-
35
- # @return [String]
36
- def uri
37
- request.dig('params', 'textDocument', 'uri')
38
- end
39
-
40
- # @return [Rucoa::Source, nil]
41
- def source
42
- source_store.get(uri)
43
- end
44
-
45
- # @return [Rucoa::Nodes::Base]
46
- def node
47
- source&.node_at(position)
48
- end
49
-
50
- # @return [Rucoa::Definitions::Base, nil]
51
- def definition
52
- @definition ||= NodeInspector.new(
53
- definition_store: definition_store,
54
- node: node
55
- ).definitions.first
56
- end
57
38
  end
58
39
  end
59
40
  end
@@ -4,16 +4,10 @@ module Rucoa
4
4
  module Handlers
5
5
  class TextDocumentDidCloseHandler < Base
6
6
  include HandlerConcerns::DiagnosticsPublishable
7
+ include HandlerConcerns::TextDocumentUriParameters
7
8
 
8
9
  def call
9
- clear_diagnostics_on(uri)
10
- end
11
-
12
- private
13
-
14
- # @return [String]
15
- def uri
16
- request.dig('params', 'textDocument', 'uri')
10
+ clear_diagnostics_on(parameter_uri)
17
11
  end
18
12
  end
19
13
  end
@@ -4,11 +4,12 @@ module Rucoa
4
4
  module Handlers
5
5
  class TextDocumentDidOpenHandler < Base
6
6
  include HandlerConcerns::DiagnosticsPublishable
7
+ include HandlerConcerns::TextDocumentUriParameters
7
8
 
8
9
  def call
9
10
  source_store.update(source)
10
11
  definition_store.update_from(source)
11
- publish_diagnostics_on(uri)
12
+ publish_diagnostics_on(parameter_uri)
12
13
  end
13
14
 
14
15
  private
@@ -17,7 +18,7 @@ module Rucoa
17
18
  def source
18
19
  @source ||= Source.new(
19
20
  content: text,
20
- uri: uri
21
+ uri: parameter_uri
21
22
  )
22
23
  end
23
24
 
@@ -25,11 +26,6 @@ module Rucoa
25
26
  def text
26
27
  request.dig('params', 'textDocument', 'text')
27
28
  end
28
-
29
- # @return [String]
30
- def uri
31
- @uri ||= request.dig('params', 'textDocument', 'uri')
32
- end
33
29
  end
34
30
  end
35
31
  end