rucoa 0.10.0 → 0.12.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.
- checksums.yaml +4 -4
- data/.rubocop.yml +8 -2
- data/Gemfile.lock +3 -3
- data/README.md +4 -1
- data/data/definitions_ruby_3_1 +6594 -6594
- data/lib/rucoa/configuration.rb +22 -12
- data/lib/rucoa/definition_store.rb +270 -158
- data/lib/rucoa/definitions/method_definition.rb +11 -11
- data/lib/rucoa/definitions/module_definition.rb +14 -0
- data/lib/rucoa/handler_concerns/configuration_requestable.rb +7 -7
- data/lib/rucoa/handler_concerns/diagnostics_publishable.rb +11 -11
- data/lib/rucoa/handler_concerns/text_document_position_parameters.rb +29 -0
- data/lib/rucoa/handler_concerns/text_document_uri_parameters.rb +21 -0
- data/lib/rucoa/handler_concerns.rb +2 -0
- data/lib/rucoa/handlers/base.rb +9 -9
- data/lib/rucoa/handlers/initialize_handler.rb +1 -0
- data/lib/rucoa/handlers/initialized_handler.rb +16 -16
- data/lib/rucoa/handlers/text_document_code_action_handler.rb +12 -12
- data/lib/rucoa/handlers/text_document_completion_handler.rb +85 -99
- data/lib/rucoa/handlers/text_document_definition_handler.rb +11 -30
- data/lib/rucoa/handlers/text_document_did_close_handler.rb +2 -8
- data/lib/rucoa/handlers/text_document_did_open_handler.rb +3 -7
- data/lib/rucoa/handlers/text_document_document_highlight_handler.rb +256 -0
- data/lib/rucoa/handlers/text_document_document_symbol_handler.rb +47 -76
- data/lib/rucoa/handlers/text_document_formatting_handler.rb +15 -23
- data/lib/rucoa/handlers/text_document_hover_handler.rb +24 -43
- data/lib/rucoa/handlers/text_document_range_formatting_handler.rb +17 -25
- data/lib/rucoa/handlers/text_document_selection_range_handler.rb +11 -19
- data/lib/rucoa/handlers/text_document_signature_help_handler.rb +17 -36
- data/lib/rucoa/handlers.rb +1 -0
- data/lib/rucoa/node_concerns/body.rb +1 -1
- data/lib/rucoa/node_concerns/qualified_name.rb +5 -5
- data/lib/rucoa/node_concerns/rescue.rb +21 -0
- data/lib/rucoa/node_concerns.rb +1 -0
- data/lib/rucoa/node_inspector.rb +17 -6
- data/lib/rucoa/nodes/base.rb +48 -48
- data/lib/rucoa/nodes/begin_node.rb +2 -0
- data/lib/rucoa/nodes/block_node.rb +24 -0
- data/lib/rucoa/nodes/case_node.rb +24 -0
- data/lib/rucoa/nodes/const_node.rb +26 -26
- data/lib/rucoa/nodes/def_node.rb +14 -13
- data/lib/rucoa/nodes/ensure_node.rb +19 -0
- data/lib/rucoa/nodes/for_node.rb +8 -0
- data/lib/rucoa/nodes/if_node.rb +32 -0
- data/lib/rucoa/nodes/resbody_node.rb +8 -0
- data/lib/rucoa/nodes/rescue_node.rb +17 -0
- data/lib/rucoa/nodes/send_node.rb +40 -0
- data/lib/rucoa/nodes/until_node.rb +8 -0
- data/lib/rucoa/nodes/when_node.rb +8 -0
- data/lib/rucoa/nodes/while_node.rb +8 -0
- data/lib/rucoa/nodes.rb +10 -1
- data/lib/rucoa/parser_builder.rb +16 -2
- data/lib/rucoa/range.rb +9 -3
- data/lib/rucoa/rbs/class_definition_mapper.rb +1 -0
- data/lib/rucoa/rbs/constant_definition_mapper.rb +5 -5
- data/lib/rucoa/rbs/method_definition_mapper.rb +18 -18
- data/lib/rucoa/rbs/module_definition_mapper.rb +17 -12
- data/lib/rucoa/rbs/ruby_definitions_loader.rb +5 -5
- data/lib/rucoa/rubocop/configuration_checker.rb +7 -7
- data/lib/rucoa/server.rb +25 -24
- data/lib/rucoa/source.rb +5 -5
- data/lib/rucoa/source_store.rb +8 -8
- data/lib/rucoa/version.rb +1 -1
- data/lib/rucoa/yard/definition_generators/attribute_reader_definition_generator.rb +17 -1
- data/lib/rucoa/yard/definition_generators/attribute_writer_definition_generator.rb +17 -1
- data/lib/rucoa/yard/definition_generators/class_definition_generator.rb +1 -0
- data/lib/rucoa/yard/definition_generators/method_definition_generator.rb +14 -1
- data/lib/rucoa/yard/definition_generators/module_definition_generator.rb +6 -0
- metadata +16 -3
- data/lib/rucoa/nodes/defs_node.rb +0 -33
@@ -0,0 +1,256 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Rucoa
|
4
|
+
module Handlers
|
5
|
+
class TextDocumentDocumentHighlightHandler < Base
|
6
|
+
include HandlerConcerns::TextDocumentPositionParameters
|
7
|
+
include HandlerConcerns::TextDocumentUriParameters
|
8
|
+
|
9
|
+
DOCUMENT_HIGHLIGHT_KIND_READ = 2
|
10
|
+
DOCUMENT_HIGHLIGHT_KIND_TEXT = 1
|
11
|
+
DOCUMENT_HIGHLIGHT_KIND_WRITE = 3
|
12
|
+
|
13
|
+
# @return [void]
|
14
|
+
def call
|
15
|
+
respond(document_highlights)
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
# @return [Array<Hash>]
|
21
|
+
def document_highlights
|
22
|
+
parser_ranges.map do |parser_range|
|
23
|
+
{
|
24
|
+
'kind' => DOCUMENT_HIGHLIGHT_KIND_TEXT,
|
25
|
+
'range' => Range.from_parser_range(parser_range).to_vscode_range
|
26
|
+
}
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# @return [Array<Parser::Source::Range>]
|
31
|
+
def parser_ranges
|
32
|
+
return [] unless reponsible?
|
33
|
+
|
34
|
+
NodeToRangesMappers::AnyMapper.call(node)
|
35
|
+
end
|
36
|
+
|
37
|
+
# @return [Boolean]
|
38
|
+
def reponsible?
|
39
|
+
configuration.enables_highlight?
|
40
|
+
end
|
41
|
+
|
42
|
+
module NodeToRangesMappers
|
43
|
+
class Base
|
44
|
+
class << self
|
45
|
+
# @param node [Rucoa::Nodes::Base]
|
46
|
+
# @return [Array<Parser::Source::Range>]
|
47
|
+
def call(node)
|
48
|
+
new(node).call
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
# @param node [Rucoa::Nodes::Base]
|
53
|
+
def initialize(node)
|
54
|
+
@node = node
|
55
|
+
end
|
56
|
+
|
57
|
+
# @return [Array<Parser::Source::Range>]
|
58
|
+
def call
|
59
|
+
raise ::NotImplementedError
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
class AnyMapper < Base
|
64
|
+
# @return [Array<Parser::Source::Range>]
|
65
|
+
def call
|
66
|
+
case @node
|
67
|
+
when Nodes::BeginNode, Nodes::BlockNode
|
68
|
+
BeginMapper.call(@node)
|
69
|
+
when Nodes::CaseNode
|
70
|
+
CaseMapper.call(@node)
|
71
|
+
when Nodes::ClassNode, Nodes::ModuleNode
|
72
|
+
ModuleMapper.call(@node)
|
73
|
+
when Nodes::DefNode
|
74
|
+
DefMapper.call(@node)
|
75
|
+
when Nodes::EnsureNode, Nodes::ResbodyNode, Nodes::RescueNode, Nodes::WhenNode
|
76
|
+
AnyMapper.call(@node.parent)
|
77
|
+
when Nodes::ForNode
|
78
|
+
ForMapper.call(@node)
|
79
|
+
when Nodes::IfNode
|
80
|
+
IfMapper.call(@node)
|
81
|
+
when Nodes::SendNode
|
82
|
+
SendMapper.call(@node)
|
83
|
+
when Nodes::UntilNode, Nodes::WhileNode
|
84
|
+
WhileMapper.call(@node)
|
85
|
+
else
|
86
|
+
[]
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
class BeginMapper < Base
|
92
|
+
# @return [Array<Parser::Source::Range>]
|
93
|
+
def call
|
94
|
+
[
|
95
|
+
range_begin,
|
96
|
+
*ranges_resbody,
|
97
|
+
range_else,
|
98
|
+
range_ensure,
|
99
|
+
range_end
|
100
|
+
].compact
|
101
|
+
end
|
102
|
+
|
103
|
+
private
|
104
|
+
|
105
|
+
# @return [Parser::Source::Range]
|
106
|
+
def range_begin
|
107
|
+
@node.location.begin
|
108
|
+
end
|
109
|
+
|
110
|
+
# @return [Parser::Source::Range, nil]
|
111
|
+
def range_else
|
112
|
+
return unless rescue_node
|
113
|
+
|
114
|
+
rescue_node.location.else
|
115
|
+
end
|
116
|
+
|
117
|
+
# @return [Parser::Source::Range]
|
118
|
+
def range_end
|
119
|
+
@node.location.end
|
120
|
+
end
|
121
|
+
|
122
|
+
# @return [Parser::Source::Range]
|
123
|
+
def range_ensure
|
124
|
+
return unless @node.ensure
|
125
|
+
|
126
|
+
@node.ensure.location.keyword
|
127
|
+
end
|
128
|
+
|
129
|
+
# @return [Array<Parser::Source::Range>]
|
130
|
+
def ranges_resbody
|
131
|
+
return [] unless rescue_node
|
132
|
+
|
133
|
+
rescue_node.resbodies.map do |resbody|
|
134
|
+
resbody.location.keyword
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
# @return [Rucoa::Nodes::RescueNode, nil]
|
139
|
+
def rescue_node
|
140
|
+
@rescue_node ||= @node.rescue || @node.ensure&.rescue
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
class DefMapper < BeginMapper
|
145
|
+
private
|
146
|
+
|
147
|
+
# @return [Parser::Source::Range]
|
148
|
+
def range_begin
|
149
|
+
@node.location.keyword
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
class CaseMapper < Base
|
154
|
+
# @return [Array<Parser::Source::Range>]
|
155
|
+
def call
|
156
|
+
[
|
157
|
+
@node.location.keyword,
|
158
|
+
*ranges_when,
|
159
|
+
@node.location.else,
|
160
|
+
@node.location.end
|
161
|
+
].compact
|
162
|
+
end
|
163
|
+
|
164
|
+
private
|
165
|
+
|
166
|
+
# @return [Array<Parser::Source::Range>]
|
167
|
+
def ranges_when
|
168
|
+
@node.whens.map do |when_node|
|
169
|
+
when_node.location.keyword
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
class IfMapper < Base
|
175
|
+
# @return [Array<Parser::Source::Range>]
|
176
|
+
def call
|
177
|
+
return AnyMapper.call(@node.parent) if @node.elsif?
|
178
|
+
|
179
|
+
[
|
180
|
+
@node.location.keyword,
|
181
|
+
*ranges_elsif,
|
182
|
+
@node.location.else,
|
183
|
+
@node.location.end
|
184
|
+
].compact
|
185
|
+
end
|
186
|
+
|
187
|
+
private
|
188
|
+
|
189
|
+
# @return [Array<Parser::Source::Range>]
|
190
|
+
def ranges_elsif
|
191
|
+
return [] unless @node.elsif
|
192
|
+
|
193
|
+
ElsifMapper.call(@node.elsif)
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
class ElsifMapper < IfMapper
|
198
|
+
# @return [Array<Parser::Source::Range>]
|
199
|
+
def call
|
200
|
+
[
|
201
|
+
*ranges_elsif,
|
202
|
+
@node.location.else
|
203
|
+
].compact
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
class ForMapper < Base
|
208
|
+
# @return [Array<Parser::Source::Range>]
|
209
|
+
def call
|
210
|
+
[
|
211
|
+
@node.location.keyword,
|
212
|
+
@node.location.in,
|
213
|
+
@node.location.end
|
214
|
+
].compact
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
class ModuleMapper < Base
|
219
|
+
# @return [Array<Parser::Source::Range>]
|
220
|
+
def call
|
221
|
+
[
|
222
|
+
@node.location.keyword,
|
223
|
+
@node.location.end
|
224
|
+
]
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
class SendMapper < Base
|
229
|
+
# @return [Array<Parser::Source::Range>]
|
230
|
+
def call
|
231
|
+
return [] unless @node.block
|
232
|
+
|
233
|
+
BeginMapper.call(@node.block)
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
class WhenMapper < Base
|
238
|
+
# @return [Array<Parser::Source::Range>]
|
239
|
+
def call
|
240
|
+
CaseMapper.call(@node.parent)
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
class WhileMapper < Base
|
245
|
+
# @return [Array<Parser::Source::Range>]
|
246
|
+
def call
|
247
|
+
[
|
248
|
+
@node.location.keyword,
|
249
|
+
@node.location.end
|
250
|
+
]
|
251
|
+
end
|
252
|
+
end
|
253
|
+
end
|
254
|
+
end
|
255
|
+
end
|
256
|
+
end
|
@@ -5,6 +5,8 @@ require 'set'
|
|
5
5
|
module Rucoa
|
6
6
|
module Handlers
|
7
7
|
class TextDocumentDocumentSymbolHandler < Base
|
8
|
+
include HandlerConcerns::TextDocumentUriParameters
|
9
|
+
|
8
10
|
DOCUMENT_SYMBOL_KIND_FOR_FILE = 1
|
9
11
|
DOCUMENT_SYMBOL_KIND_FOR_MODULE = 2
|
10
12
|
DOCUMENT_SYMBOL_KIND_FOR_NAMESPACE = 3
|
@@ -47,51 +49,6 @@ module Rucoa
|
|
47
49
|
|
48
50
|
private
|
49
51
|
|
50
|
-
# @return [Array<Hash>]
|
51
|
-
def document_symbols
|
52
|
-
visit(source.root_node)
|
53
|
-
document_symbol_stack.first[:children]
|
54
|
-
end
|
55
|
-
|
56
|
-
# @param node [Rucoa::Nodes::Base]
|
57
|
-
# @return [void]
|
58
|
-
def visit(node)
|
59
|
-
document_symbols = create_document_symbols_for(node)
|
60
|
-
document_symbol_stack.last[:children].push(*document_symbols)
|
61
|
-
with_document_symbol_stack(document_symbols.first) do
|
62
|
-
with_singleton_class_stack(node) do
|
63
|
-
node.each_child_node do |child_node|
|
64
|
-
visit(child_node)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
# @param document_symbol [Hash, nil]
|
71
|
-
# @return [void]
|
72
|
-
def with_document_symbol_stack(document_symbol)
|
73
|
-
unless document_symbol
|
74
|
-
yield
|
75
|
-
return
|
76
|
-
end
|
77
|
-
|
78
|
-
document_symbol_stack.push(document_symbol)
|
79
|
-
yield
|
80
|
-
document_symbol_stack.pop
|
81
|
-
end
|
82
|
-
|
83
|
-
# @param node [Rucoa::Nodes::Base]
|
84
|
-
def with_singleton_class_stack(node)
|
85
|
-
unless node.is_a?(Rucoa::Nodes::SclassNode)
|
86
|
-
yield
|
87
|
-
return
|
88
|
-
end
|
89
|
-
|
90
|
-
singleton_class_stack.push(node)
|
91
|
-
yield
|
92
|
-
singleton_class_stack.pop
|
93
|
-
end
|
94
|
-
|
95
52
|
# @param node [Rucoa::Nodes::Base]
|
96
53
|
# @return [Array<Hash>]
|
97
54
|
def create_document_symbols_for(node)
|
@@ -102,8 +59,6 @@ module Rucoa
|
|
102
59
|
create_document_symbols_for_class(node)
|
103
60
|
when Nodes::DefNode
|
104
61
|
create_document_symbols_for_def(node)
|
105
|
-
when Nodes::DefsNode
|
106
|
-
create_document_symbols_for_defs(node)
|
107
62
|
when Nodes::ModuleNode
|
108
63
|
create_document_symbols_for_module(node)
|
109
64
|
when Nodes::SendNode
|
@@ -141,14 +96,14 @@ module Rucoa
|
|
141
96
|
]
|
142
97
|
end
|
143
98
|
|
144
|
-
# @param node [Rucoa::Nodes::
|
99
|
+
# @param node [Rucoa::Nodes::DefNode]
|
145
100
|
# @return [Array<Hash>]
|
146
|
-
def
|
101
|
+
def create_document_symbols_for_def(node)
|
147
102
|
[
|
148
103
|
{
|
149
104
|
children: [],
|
150
|
-
kind:
|
151
|
-
name: node.name,
|
105
|
+
kind: DOCUMENT_SYMBOL_KIND_FOR_METHOD,
|
106
|
+
name: "#{node.method_marker}#{node.name}",
|
152
107
|
range: Range.from_parser_range(node.location.expression).to_vscode_range,
|
153
108
|
selectionRange: Range.from_parser_range(node.location.name).to_vscode_range
|
154
109
|
}
|
@@ -157,26 +112,26 @@ module Rucoa
|
|
157
112
|
|
158
113
|
# @param node [Rucoa::Nodes::DefNode]
|
159
114
|
# @return [Array<Hash>]
|
160
|
-
def
|
115
|
+
def create_document_symbols_for_defs(node)
|
161
116
|
[
|
162
117
|
{
|
163
118
|
children: [],
|
164
119
|
kind: DOCUMENT_SYMBOL_KIND_FOR_METHOD,
|
165
|
-
name:
|
120
|
+
name: ".#{node.name}",
|
166
121
|
range: Range.from_parser_range(node.location.expression).to_vscode_range,
|
167
122
|
selectionRange: Range.from_parser_range(node.location.name).to_vscode_range
|
168
123
|
}
|
169
124
|
]
|
170
125
|
end
|
171
126
|
|
172
|
-
# @param node [Rucoa::Nodes::
|
127
|
+
# @param node [Rucoa::Nodes::ModuleNode]
|
173
128
|
# @return [Array<Hash>]
|
174
|
-
def
|
129
|
+
def create_document_symbols_for_module(node)
|
175
130
|
[
|
176
131
|
{
|
177
132
|
children: [],
|
178
|
-
kind:
|
179
|
-
name:
|
133
|
+
kind: DOCUMENT_SYMBOL_KIND_FOR_MODULE,
|
134
|
+
name: node.name,
|
180
135
|
range: Range.from_parser_range(node.location.expression).to_vscode_range,
|
181
136
|
selectionRange: Range.from_parser_range(node.location.name).to_vscode_range
|
182
137
|
}
|
@@ -205,27 +160,17 @@ module Rucoa
|
|
205
160
|
end
|
206
161
|
end
|
207
162
|
|
208
|
-
# @return [Boolean]
|
209
|
-
def responsible?
|
210
|
-
configuration.enables_document_symbol? &&
|
211
|
-
!source.nil?
|
212
|
-
end
|
213
|
-
|
214
|
-
# @return [Rucoa::Source]
|
215
|
-
def source
|
216
|
-
@source ||= source_store.get(uri)
|
217
|
-
end
|
218
|
-
|
219
|
-
# @return [String]
|
220
|
-
def uri
|
221
|
-
request.dig('params', 'textDocument', 'uri')
|
222
|
-
end
|
223
|
-
|
224
163
|
# @return [Arrah<Hash>]
|
225
164
|
def document_symbol_stack
|
226
165
|
@document_symbol_stack ||= [dummy_document_symbol]
|
227
166
|
end
|
228
167
|
|
168
|
+
# @return [Array<Hash>]
|
169
|
+
def document_symbols
|
170
|
+
visit(source.root_node)
|
171
|
+
document_symbol_stack.first[:children]
|
172
|
+
end
|
173
|
+
|
229
174
|
# @return [Hash]
|
230
175
|
def dummy_document_symbol
|
231
176
|
{
|
@@ -233,9 +178,35 @@ module Rucoa
|
|
233
178
|
}
|
234
179
|
end
|
235
180
|
|
236
|
-
# @return [
|
237
|
-
def
|
238
|
-
|
181
|
+
# @return [Boolean]
|
182
|
+
def responsible?
|
183
|
+
configuration.enables_document_symbol? &&
|
184
|
+
!source.nil?
|
185
|
+
end
|
186
|
+
|
187
|
+
# @param node [Rucoa::Nodes::Base]
|
188
|
+
# @return [void]
|
189
|
+
def visit(node)
|
190
|
+
document_symbols = create_document_symbols_for(node)
|
191
|
+
document_symbol_stack.last[:children].push(*document_symbols)
|
192
|
+
with_document_symbol_stack(document_symbols.first) do
|
193
|
+
node.each_child_node do |child_node|
|
194
|
+
visit(child_node)
|
195
|
+
end
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
# @param document_symbol [Hash, nil]
|
200
|
+
# @return [void]
|
201
|
+
def with_document_symbol_stack(document_symbol)
|
202
|
+
unless document_symbol
|
203
|
+
yield
|
204
|
+
return
|
205
|
+
end
|
206
|
+
|
207
|
+
document_symbol_stack.push(document_symbol)
|
208
|
+
yield
|
209
|
+
document_symbol_stack.pop
|
239
210
|
end
|
240
211
|
end
|
241
212
|
end
|
@@ -3,19 +3,14 @@
|
|
3
3
|
module Rucoa
|
4
4
|
module Handlers
|
5
5
|
class TextDocumentFormattingHandler < Base
|
6
|
+
include HandlerConcerns::TextDocumentUriParameters
|
7
|
+
|
6
8
|
def call
|
7
9
|
respond(edits)
|
8
10
|
end
|
9
11
|
|
10
12
|
private
|
11
13
|
|
12
|
-
# @return [Boolean]
|
13
|
-
def formattable?
|
14
|
-
configuration.enables_formatting? &&
|
15
|
-
source &&
|
16
|
-
Rubocop::ConfigurationChecker.call
|
17
|
-
end
|
18
|
-
|
19
14
|
# @return [Array<Hash>]
|
20
15
|
def edits
|
21
16
|
return [] unless formattable?
|
@@ -23,22 +18,11 @@ module Rucoa
|
|
23
18
|
[text_edit]
|
24
19
|
end
|
25
20
|
|
26
|
-
# @return [
|
27
|
-
def
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
# @return [String]
|
32
|
-
def uri
|
33
|
-
request.dig('params', 'textDocument', 'uri')
|
34
|
-
end
|
35
|
-
|
36
|
-
# @return [Hash]
|
37
|
-
def text_edit
|
38
|
-
{
|
39
|
-
newText: new_text,
|
40
|
-
range: range
|
41
|
-
}
|
21
|
+
# @return [Boolean]
|
22
|
+
def formattable?
|
23
|
+
configuration.enables_formatting? &&
|
24
|
+
source &&
|
25
|
+
Rubocop::ConfigurationChecker.call
|
42
26
|
end
|
43
27
|
|
44
28
|
# @return [String]
|
@@ -59,6 +43,14 @@ module Rucoa
|
|
59
43
|
)
|
60
44
|
).to_vscode_range
|
61
45
|
end
|
46
|
+
|
47
|
+
# @return [Hash]
|
48
|
+
def text_edit
|
49
|
+
{
|
50
|
+
newText: new_text,
|
51
|
+
range: range
|
52
|
+
}
|
53
|
+
end
|
62
54
|
end
|
63
55
|
end
|
64
56
|
end
|
@@ -3,28 +3,15 @@
|
|
3
3
|
module Rucoa
|
4
4
|
module Handlers
|
5
5
|
class TextDocumentHoverHandler < Base
|
6
|
+
include HandlerConcerns::TextDocumentPositionParameters
|
7
|
+
include HandlerConcerns::TextDocumentUriParameters
|
8
|
+
|
6
9
|
def call
|
7
10
|
respond(hover)
|
8
11
|
end
|
9
12
|
|
10
13
|
private
|
11
14
|
|
12
|
-
# @return [Hash, nil]
|
13
|
-
def hover
|
14
|
-
return unless responsible?
|
15
|
-
|
16
|
-
{
|
17
|
-
contents: contents,
|
18
|
-
range: range.to_vscode_range
|
19
|
-
}
|
20
|
-
end
|
21
|
-
|
22
|
-
# @return [Boolean]
|
23
|
-
def responsible?
|
24
|
-
configuration.enables_hover? &&
|
25
|
-
!contents.nil?
|
26
|
-
end
|
27
|
-
|
28
15
|
# @return [String, nil]
|
29
16
|
def contents
|
30
17
|
@contents ||=
|
@@ -42,33 +29,6 @@ module Rucoa
|
|
42
29
|
end
|
43
30
|
end
|
44
31
|
|
45
|
-
# @return [Rucoa::Range]
|
46
|
-
def range
|
47
|
-
Range.from_parser_range(node.location.expression)
|
48
|
-
end
|
49
|
-
|
50
|
-
# @return [Rucoa::Nodes::Base, nil]
|
51
|
-
def node
|
52
|
-
@node ||= source&.node_at(position)
|
53
|
-
end
|
54
|
-
|
55
|
-
# @return [Rucoa::Source, nil]
|
56
|
-
def source
|
57
|
-
@source ||= source_store.get(uri)
|
58
|
-
end
|
59
|
-
|
60
|
-
# @return [String]
|
61
|
-
def uri
|
62
|
-
request.dig('params', 'textDocument', 'uri')
|
63
|
-
end
|
64
|
-
|
65
|
-
# @return [Rucoa::Position]
|
66
|
-
def position
|
67
|
-
Position.from_vscode_position(
|
68
|
-
request.dig('params', 'position')
|
69
|
-
)
|
70
|
-
end
|
71
|
-
|
72
32
|
# @return [Rucoa::Definitions::Base, nil]
|
73
33
|
def definition
|
74
34
|
return unless node
|
@@ -78,6 +38,27 @@ module Rucoa
|
|
78
38
|
node: node
|
79
39
|
).definitions.first
|
80
40
|
end
|
41
|
+
|
42
|
+
# @return [Hash, nil]
|
43
|
+
def hover
|
44
|
+
return unless responsible?
|
45
|
+
|
46
|
+
{
|
47
|
+
contents: contents,
|
48
|
+
range: range.to_vscode_range
|
49
|
+
}
|
50
|
+
end
|
51
|
+
|
52
|
+
# @return [Rucoa::Range]
|
53
|
+
def range
|
54
|
+
Range.from_parser_range(node.location.expression)
|
55
|
+
end
|
56
|
+
|
57
|
+
# @return [Boolean]
|
58
|
+
def responsible?
|
59
|
+
configuration.enables_hover? &&
|
60
|
+
!contents.nil?
|
61
|
+
end
|
81
62
|
end
|
82
63
|
end
|
83
64
|
end
|
@@ -3,12 +3,26 @@
|
|
3
3
|
module Rucoa
|
4
4
|
module Handlers
|
5
5
|
class TextDocumentRangeFormattingHandler < Base
|
6
|
+
include HandlerConcerns::TextDocumentUriParameters
|
7
|
+
|
6
8
|
def call
|
7
9
|
respond(edits)
|
8
10
|
end
|
9
11
|
|
10
12
|
private
|
11
13
|
|
14
|
+
# @return [Array<RuboCop::Cop::Corrector>]
|
15
|
+
def correctable_offenses
|
16
|
+
offenses.select(&:corrector)
|
17
|
+
end
|
18
|
+
|
19
|
+
# @return [Array(Rucoa::Range, String)]
|
20
|
+
def correctable_replacements
|
21
|
+
replacements.select do |replacement_range, _|
|
22
|
+
range.contain?(replacement_range)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
12
26
|
# @return [Array<Hash>]
|
13
27
|
def edits
|
14
28
|
return [] unless formattable?
|
@@ -28,14 +42,9 @@ module Rucoa
|
|
28
42
|
Rubocop::ConfigurationChecker.call
|
29
43
|
end
|
30
44
|
|
31
|
-
# @return [
|
32
|
-
def
|
33
|
-
|
34
|
-
end
|
35
|
-
|
36
|
-
# @return [String]
|
37
|
-
def uri
|
38
|
-
request.dig('params', 'textDocument', 'uri')
|
45
|
+
# @return [Array<RuboCop::Cop::Offense>]
|
46
|
+
def offenses
|
47
|
+
Rubocop::Investigator.call(source: source)
|
39
48
|
end
|
40
49
|
|
41
50
|
# @return [Rucoa::Range]
|
@@ -45,23 +54,6 @@ module Rucoa
|
|
45
54
|
)
|
46
55
|
end
|
47
56
|
|
48
|
-
# @return [Array<RuboCop::Cop::Corrector>]
|
49
|
-
def correctable_offenses
|
50
|
-
offenses.select(&:corrector)
|
51
|
-
end
|
52
|
-
|
53
|
-
# @return [Array(Rucoa::Range, String)]
|
54
|
-
def correctable_replacements
|
55
|
-
replacements.select do |replacement_range, _|
|
56
|
-
range.contain?(replacement_range)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
# @return [Array<RuboCop::Cop::Offense>]
|
61
|
-
def offenses
|
62
|
-
Rubocop::Investigator.call(source: source)
|
63
|
-
end
|
64
|
-
|
65
57
|
# @return [Array(Rucoa::Range, String)]
|
66
58
|
def replacements
|
67
59
|
correctable_offenses.map(&:corrector).flat_map(&:as_replacements).map do |replacement_range, replacement|
|