ruby-lsp 0.3.7 → 0.3.8
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/README.md +21 -2
- data/VERSION +1 -1
- data/lib/ruby_lsp/document.rb +12 -40
- data/lib/ruby_lsp/handler.rb +2 -2
- data/lib/ruby_lsp/requests/base_request.rb +35 -20
- data/lib/ruby_lsp/requests/code_actions.rb +1 -1
- data/lib/ruby_lsp/requests/diagnostics.rb +1 -8
- data/lib/ruby_lsp/requests/document_highlight.rb +13 -9
- data/lib/ruby_lsp/requests/document_link.rb +30 -25
- data/lib/ruby_lsp/requests/document_symbol.rb +43 -83
- data/lib/ruby_lsp/requests/folding_ranges.rb +58 -38
- data/lib/ruby_lsp/requests/formatting.rb +2 -0
- data/lib/ruby_lsp/requests/hover.rb +15 -6
- data/lib/ruby_lsp/requests/on_type_formatting.rb +16 -19
- data/lib/ruby_lsp/requests/selection_ranges.rb +40 -38
- data/lib/ruby_lsp/requests/semantic_highlighting.rb +62 -78
- data/lib/ruby_lsp/requests/support/highlight_target.rb +8 -9
- data/lib/ruby_lsp/requests/support/rails_document_client.rb +13 -6
- data/lib/ruby_lsp/requests/support/rubocop_diagnostic.rb +15 -10
- data/lib/ruby_lsp/requests/support/rubocop_diagnostics_runner.rb +1 -1
- data/lib/ruby_lsp/requests/support/rubocop_formatting_runner.rb +1 -1
- data/lib/ruby_lsp/requests/support/rubocop_runner.rb +9 -6
- data/lib/ruby_lsp/requests/support/source_uri.rb +10 -7
- metadata +6 -6
@@ -18,34 +18,38 @@ module RubyLsp
|
|
18
18
|
class FoldingRanges < BaseRequest
|
19
19
|
extend T::Sig
|
20
20
|
|
21
|
-
SIMPLE_FOLDABLES = T.let(
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
21
|
+
SIMPLE_FOLDABLES = T.let(
|
22
|
+
[
|
23
|
+
SyntaxTree::ArrayLiteral,
|
24
|
+
SyntaxTree::BlockNode,
|
25
|
+
SyntaxTree::Case,
|
26
|
+
SyntaxTree::ClassDeclaration,
|
27
|
+
SyntaxTree::Command,
|
28
|
+
SyntaxTree::For,
|
29
|
+
SyntaxTree::HashLiteral,
|
30
|
+
SyntaxTree::Heredoc,
|
31
|
+
SyntaxTree::IfNode,
|
32
|
+
SyntaxTree::ModuleDeclaration,
|
33
|
+
SyntaxTree::SClass,
|
34
|
+
SyntaxTree::UnlessNode,
|
35
|
+
SyntaxTree::UntilNode,
|
36
|
+
SyntaxTree::WhileNode,
|
37
|
+
SyntaxTree::Else,
|
38
|
+
SyntaxTree::Ensure,
|
39
|
+
SyntaxTree::Begin,
|
40
|
+
].freeze,
|
41
|
+
T::Array[T.class_of(SyntaxTree::Node)],
|
42
|
+
)
|
43
|
+
|
44
|
+
NODES_WITH_STATEMENTS = T.let(
|
45
|
+
[
|
46
|
+
SyntaxTree::Elsif,
|
47
|
+
SyntaxTree::In,
|
48
|
+
SyntaxTree::Rescue,
|
49
|
+
SyntaxTree::When,
|
50
|
+
].freeze,
|
51
|
+
T::Array[T.class_of(SyntaxTree::Node)],
|
52
|
+
)
|
49
53
|
|
50
54
|
StatementNode = T.type_alias do
|
51
55
|
T.any(
|
@@ -86,10 +90,17 @@ module RubyLsp
|
|
86
90
|
add_lines_range(location.start_line, location.end_line - 1)
|
87
91
|
when *NODES_WITH_STATEMENTS
|
88
92
|
add_statements_range(T.must(node), T.cast(node, StatementNode).statements)
|
89
|
-
when SyntaxTree::
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
+
when SyntaxTree::CallNode, SyntaxTree::CommandCall
|
94
|
+
# If there is a receiver, it may be a chained invocation,
|
95
|
+
# so we need to process it in special way.
|
96
|
+
if node.receiver.nil?
|
97
|
+
location = node.location
|
98
|
+
add_lines_range(location.start_line, location.end_line - 1)
|
99
|
+
else
|
100
|
+
add_call_range(node)
|
101
|
+
return
|
102
|
+
end
|
103
|
+
when SyntaxTree::DefNode
|
93
104
|
add_def_range(node)
|
94
105
|
when SyntaxTree::StringConcat
|
95
106
|
add_string_concat(node)
|
@@ -192,19 +203,19 @@ module RubyLsp
|
|
192
203
|
@partial_range = nil
|
193
204
|
end
|
194
205
|
|
195
|
-
sig { params(node: T.any(SyntaxTree::
|
206
|
+
sig { params(node: T.any(SyntaxTree::CallNode, SyntaxTree::CommandCall)).void }
|
196
207
|
def add_call_range(node)
|
197
208
|
receiver = T.let(node.receiver, SyntaxTree::Node)
|
198
209
|
loop do
|
199
210
|
case receiver
|
200
|
-
when SyntaxTree::
|
211
|
+
when SyntaxTree::CallNode
|
201
212
|
visit(receiver.arguments)
|
202
213
|
receiver = receiver.receiver
|
203
214
|
when SyntaxTree::MethodAddBlock
|
204
215
|
visit(receiver.block)
|
205
216
|
receiver = receiver.call
|
206
217
|
|
207
|
-
if receiver.is_a?(SyntaxTree::
|
218
|
+
if receiver.is_a?(SyntaxTree::CallNode) || receiver.is_a?(SyntaxTree::CommandCall)
|
208
219
|
receiver = receiver.receiver
|
209
220
|
end
|
210
221
|
else
|
@@ -212,13 +223,17 @@ module RubyLsp
|
|
212
223
|
end
|
213
224
|
end
|
214
225
|
|
215
|
-
add_lines_range(receiver.location.start_line, node.location.end_line - 1)
|
226
|
+
add_lines_range(receiver.location.start_line, node.location.end_line - 1) if receiver
|
216
227
|
|
217
228
|
visit(node.arguments)
|
218
229
|
end
|
219
230
|
|
220
|
-
sig { params(node:
|
231
|
+
sig { params(node: SyntaxTree::DefNode).void }
|
221
232
|
def add_def_range(node)
|
233
|
+
# For an endless method with no arguments, `node.params` returns `nil` for Ruby 3.0, but a `Syntax::Params`
|
234
|
+
# for Ruby 3.1
|
235
|
+
return unless node.params
|
236
|
+
|
222
237
|
params_location = node.params.location
|
223
238
|
|
224
239
|
if params_location.start_line < params_location.end_line
|
@@ -228,7 +243,12 @@ module RubyLsp
|
|
228
243
|
add_lines_range(location.start_line, location.end_line - 1)
|
229
244
|
end
|
230
245
|
|
231
|
-
|
246
|
+
bodystmt = node.bodystmt
|
247
|
+
if bodystmt.is_a?(SyntaxTree::BodyStmt)
|
248
|
+
visit(bodystmt.statements)
|
249
|
+
else
|
250
|
+
visit(bodystmt)
|
251
|
+
end
|
232
252
|
end
|
233
253
|
|
234
254
|
sig { params(node: SyntaxTree::Node, statements: SyntaxTree::Statements).void }
|
@@ -11,6 +11,8 @@ module RubyLsp
|
|
11
11
|
# request uses RuboCop to fix auto-correctable offenses in the document. This requires enabling format on save and
|
12
12
|
# registering the ruby-lsp as the Ruby formatter.
|
13
13
|
#
|
14
|
+
# If RuboCop is not available, the request will fall back to SyntaxTree.
|
15
|
+
#
|
14
16
|
# # Example
|
15
17
|
#
|
16
18
|
# ```ruby
|
@@ -20,6 +20,15 @@ module RubyLsp
|
|
20
20
|
class Hover < BaseRequest
|
21
21
|
extend T::Sig
|
22
22
|
|
23
|
+
ALLOWED_TARGETS = T.let(
|
24
|
+
[
|
25
|
+
SyntaxTree::Command,
|
26
|
+
SyntaxTree::CallNode,
|
27
|
+
SyntaxTree::ConstPathRef,
|
28
|
+
],
|
29
|
+
T::Array[T.class_of(SyntaxTree::Node)],
|
30
|
+
)
|
31
|
+
|
23
32
|
sig { params(document: Document, position: Document::PositionShape).void }
|
24
33
|
def initialize(document, position)
|
25
34
|
super(document)
|
@@ -31,17 +40,17 @@ module RubyLsp
|
|
31
40
|
def run
|
32
41
|
return unless @document.parsed?
|
33
42
|
|
34
|
-
target,
|
35
|
-
|
36
|
-
)
|
43
|
+
target, parent = locate(T.must(@document.tree), @position)
|
44
|
+
target = parent if !ALLOWED_TARGETS.include?(target.class) && ALLOWED_TARGETS.include?(parent.class)
|
37
45
|
|
38
46
|
case target
|
39
47
|
when SyntaxTree::Command
|
40
48
|
message = target.message
|
41
49
|
generate_rails_document_link_hover(message.value, message)
|
42
|
-
when SyntaxTree::
|
43
|
-
|
44
|
-
|
50
|
+
when SyntaxTree::CallNode
|
51
|
+
return if target.message == :call
|
52
|
+
|
53
|
+
generate_rails_document_link_hover(target.message.value, target.message)
|
45
54
|
when SyntaxTree::ConstPathRef
|
46
55
|
constant_name = full_constant_name(target)
|
47
56
|
generate_rails_document_link_hover(constant_name, target)
|
@@ -18,10 +18,13 @@ module RubyLsp
|
|
18
18
|
class OnTypeFormatting < BaseRequest
|
19
19
|
extend T::Sig
|
20
20
|
|
21
|
-
END_REGEXES = T.let(
|
22
|
-
|
23
|
-
|
24
|
-
|
21
|
+
END_REGEXES = T.let(
|
22
|
+
[
|
23
|
+
/(if|unless|for|while|class|module|until|def|case).*/,
|
24
|
+
/.*\sdo/,
|
25
|
+
],
|
26
|
+
T::Array[Regexp],
|
27
|
+
)
|
25
28
|
|
26
29
|
sig { params(document: Document, position: Document::PositionShape, trigger_character: String).void }
|
27
30
|
def initialize(document, position, trigger_character)
|
@@ -41,17 +44,17 @@ module RubyLsp
|
|
41
44
|
|
42
45
|
sig { override.returns(T.nilable(T.all(T::Array[Interface::TextEdit], Object))) }
|
43
46
|
def run
|
44
|
-
handle_comment_line
|
45
|
-
|
46
|
-
return @edits unless @document.syntax_errors?
|
47
|
-
|
48
47
|
case @trigger_character
|
49
48
|
when "{"
|
50
|
-
handle_curly_brace
|
49
|
+
handle_curly_brace if @document.syntax_error?
|
51
50
|
when "|"
|
52
|
-
handle_pipe
|
51
|
+
handle_pipe if @document.syntax_error?
|
53
52
|
when "\n"
|
54
|
-
|
53
|
+
if (comment_match = @previous_line.match(/^#(\s*)/))
|
54
|
+
handle_comment_line(T.must(comment_match[1]))
|
55
|
+
elsif @document.syntax_error?
|
56
|
+
handle_statement_end
|
57
|
+
end
|
55
58
|
end
|
56
59
|
|
57
60
|
@edits
|
@@ -85,14 +88,8 @@ module RubyLsp
|
|
85
88
|
move_cursor_to(@position[:line], @indentation + 2)
|
86
89
|
end
|
87
90
|
|
88
|
-
sig { void }
|
89
|
-
def handle_comment_line
|
90
|
-
return unless @trigger_character == "\n"
|
91
|
-
|
92
|
-
is_comment_match = @previous_line.match(/^#(\s*)/)
|
93
|
-
return unless is_comment_match
|
94
|
-
|
95
|
-
spaces = T.must(is_comment_match[1])
|
91
|
+
sig { params(spaces: String).void }
|
92
|
+
def handle_comment_line(spaces)
|
96
93
|
add_edit_with_text("##{spaces}")
|
97
94
|
move_cursor_to(@position[:line], @indentation + spaces.size + 1)
|
98
95
|
end
|
@@ -11,6 +11,8 @@ module RubyLsp
|
|
11
11
|
#
|
12
12
|
# Trigger this request with: Ctrl + Shift + -> or Ctrl + Shift + <-
|
13
13
|
#
|
14
|
+
# Note that if using VSCode Neovim, you will need to be in Insert mode for this to work correctly.
|
15
|
+
#
|
14
16
|
# # Example
|
15
17
|
#
|
16
18
|
# ```ruby
|
@@ -21,44 +23,44 @@ module RubyLsp
|
|
21
23
|
class SelectionRanges < BaseRequest
|
22
24
|
extend T::Sig
|
23
25
|
|
24
|
-
NODES_THAT_CAN_BE_PARENTS = T.let(
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
SyntaxTree::
|
61
|
-
|
26
|
+
NODES_THAT_CAN_BE_PARENTS = T.let(
|
27
|
+
[
|
28
|
+
SyntaxTree::Assign,
|
29
|
+
SyntaxTree::ArrayLiteral,
|
30
|
+
SyntaxTree::Begin,
|
31
|
+
SyntaxTree::BlockNode,
|
32
|
+
SyntaxTree::CallNode,
|
33
|
+
SyntaxTree::Case,
|
34
|
+
SyntaxTree::ClassDeclaration,
|
35
|
+
SyntaxTree::Command,
|
36
|
+
SyntaxTree::DefNode,
|
37
|
+
SyntaxTree::Elsif,
|
38
|
+
SyntaxTree::Else,
|
39
|
+
SyntaxTree::EmbDoc,
|
40
|
+
SyntaxTree::Ensure,
|
41
|
+
SyntaxTree::For,
|
42
|
+
SyntaxTree::HashLiteral,
|
43
|
+
SyntaxTree::Heredoc,
|
44
|
+
SyntaxTree::HeredocBeg,
|
45
|
+
SyntaxTree::HshPtn,
|
46
|
+
SyntaxTree::IfNode,
|
47
|
+
SyntaxTree::In,
|
48
|
+
SyntaxTree::Lambda,
|
49
|
+
SyntaxTree::MethodAddBlock,
|
50
|
+
SyntaxTree::ModuleDeclaration,
|
51
|
+
SyntaxTree::Params,
|
52
|
+
SyntaxTree::Rescue,
|
53
|
+
SyntaxTree::RescueEx,
|
54
|
+
SyntaxTree::StringConcat,
|
55
|
+
SyntaxTree::StringLiteral,
|
56
|
+
SyntaxTree::UnlessNode,
|
57
|
+
SyntaxTree::UntilNode,
|
58
|
+
SyntaxTree::VCall,
|
59
|
+
SyntaxTree::When,
|
60
|
+
SyntaxTree::WhileNode,
|
61
|
+
].freeze,
|
62
|
+
T::Array[T.class_of(SyntaxTree::Node)],
|
63
|
+
)
|
62
64
|
|
63
65
|
sig { params(document: Document).void }
|
64
66
|
def initialize(document)
|
@@ -22,52 +22,61 @@ module RubyLsp
|
|
22
22
|
extend T::Sig
|
23
23
|
include SyntaxTree::WithEnvironment
|
24
24
|
|
25
|
-
TOKEN_TYPES = T.let(
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
25
|
+
TOKEN_TYPES = T.let(
|
26
|
+
{
|
27
|
+
namespace: 0,
|
28
|
+
type: 1,
|
29
|
+
class: 2,
|
30
|
+
enum: 3,
|
31
|
+
interface: 4,
|
32
|
+
struct: 5,
|
33
|
+
typeParameter: 6,
|
34
|
+
parameter: 7,
|
35
|
+
variable: 8,
|
36
|
+
property: 9,
|
37
|
+
enumMember: 10,
|
38
|
+
event: 11,
|
39
|
+
function: 12,
|
40
|
+
method: 13,
|
41
|
+
macro: 14,
|
42
|
+
keyword: 15,
|
43
|
+
modifier: 16,
|
44
|
+
comment: 17,
|
45
|
+
string: 18,
|
46
|
+
number: 19,
|
47
|
+
regexp: 20,
|
48
|
+
operator: 21,
|
49
|
+
decorator: 22,
|
50
|
+
}.freeze,
|
51
|
+
T::Hash[Symbol, Integer],
|
52
|
+
)
|
53
|
+
|
54
|
+
TOKEN_MODIFIERS = T.let(
|
55
|
+
{
|
56
|
+
declaration: 0,
|
57
|
+
definition: 1,
|
58
|
+
readonly: 2,
|
59
|
+
static: 3,
|
60
|
+
deprecated: 4,
|
61
|
+
abstract: 5,
|
62
|
+
async: 6,
|
63
|
+
modification: 7,
|
64
|
+
documentation: 8,
|
65
|
+
default_library: 9,
|
66
|
+
}.freeze,
|
67
|
+
T::Hash[Symbol, Integer],
|
68
|
+
)
|
69
|
+
|
70
|
+
SPECIAL_RUBY_METHODS = T.let(
|
71
|
+
[
|
72
|
+
Module.instance_methods(false),
|
73
|
+
Kernel.instance_methods(false),
|
74
|
+
Kernel.methods(false),
|
75
|
+
Bundler::Dsl.instance_methods(false),
|
76
|
+
Module.private_instance_methods(false),
|
77
|
+
].flatten.map(&:to_s),
|
78
|
+
T::Array[String],
|
79
|
+
)
|
71
80
|
|
72
81
|
class SemanticToken < T::Struct
|
73
82
|
const :location, SyntaxTree::Location
|
@@ -110,14 +119,16 @@ module RubyLsp
|
|
110
119
|
@encoder.encode(@tokens)
|
111
120
|
end
|
112
121
|
|
113
|
-
sig { override.params(node: SyntaxTree::
|
122
|
+
sig { override.params(node: SyntaxTree::CallNode).void }
|
114
123
|
def visit_call(node)
|
115
124
|
return super unless visible?(node, @range)
|
116
125
|
|
117
126
|
visit(node.receiver)
|
118
127
|
|
119
128
|
message = node.message
|
120
|
-
|
129
|
+
unless message == :call || special_method?(message.value)
|
130
|
+
add_token(message.location, :method)
|
131
|
+
end
|
121
132
|
|
122
133
|
visit(node.arguments)
|
123
134
|
end
|
@@ -146,42 +157,15 @@ module RubyLsp
|
|
146
157
|
add_token(node.location, :namespace)
|
147
158
|
end
|
148
159
|
|
149
|
-
sig { override.params(node: SyntaxTree::
|
160
|
+
sig { override.params(node: SyntaxTree::DefNode).void }
|
150
161
|
def visit_def(node)
|
151
162
|
return super unless visible?(node, @range)
|
152
163
|
|
153
164
|
add_token(node.name.location, :method, [:declaration])
|
154
165
|
visit(node.params)
|
155
166
|
visit(node.bodystmt)
|
156
|
-
|
157
|
-
|
158
|
-
sig { override.params(node: SyntaxTree::DefEndless).void }
|
159
|
-
def visit_def_endless(node)
|
160
|
-
return super unless visible?(node, @range)
|
161
|
-
|
162
|
-
add_token(node.name.location, :method, [:declaration])
|
163
|
-
visit(node.paren)
|
164
|
-
visit(node.operator)
|
165
|
-
visit(node.statement)
|
166
|
-
end
|
167
|
-
|
168
|
-
sig { override.params(node: SyntaxTree::Defs).void }
|
169
|
-
def visit_defs(node)
|
170
|
-
return super unless visible?(node, @range)
|
171
|
-
|
172
|
-
visit(node.target)
|
173
|
-
visit(node.operator)
|
174
|
-
add_token(node.name.location, :method, [:declaration])
|
175
|
-
visit(node.params)
|
176
|
-
visit(node.bodystmt)
|
177
|
-
end
|
178
|
-
|
179
|
-
sig { override.params(node: SyntaxTree::FCall).void }
|
180
|
-
def visit_fcall(node)
|
181
|
-
return super unless visible?(node, @range)
|
182
|
-
|
183
|
-
add_token(node.value.location, :method) unless special_method?(node.value.value)
|
184
|
-
visit(node.arguments)
|
167
|
+
visit(node.target) if node.target
|
168
|
+
visit(node.operator) if node.operator
|
185
169
|
end
|
186
170
|
|
187
171
|
sig { override.params(node: SyntaxTree::Kw).void }
|
@@ -34,12 +34,12 @@ module RubyLsp
|
|
34
34
|
def matched_highlight(other)
|
35
35
|
case @node
|
36
36
|
# Method definitions and invocations
|
37
|
-
when SyntaxTree::VCall, SyntaxTree::
|
38
|
-
SyntaxTree::CommandCall, SyntaxTree::
|
37
|
+
when SyntaxTree::VCall, SyntaxTree::CallNode, SyntaxTree::Command,
|
38
|
+
SyntaxTree::CommandCall, SyntaxTree::DefNode
|
39
39
|
case other
|
40
|
-
when SyntaxTree::VCall, SyntaxTree::
|
40
|
+
when SyntaxTree::VCall, SyntaxTree::CallNode, SyntaxTree::Command, SyntaxTree::CommandCall
|
41
41
|
HighlightMatch.new(type: READ, node: other)
|
42
|
-
when SyntaxTree::
|
42
|
+
when SyntaxTree::DefNode
|
43
43
|
HighlightMatch.new(type: WRITE, node: other.name)
|
44
44
|
end
|
45
45
|
# Variables, parameters and constants
|
@@ -67,15 +67,14 @@ module RubyLsp
|
|
67
67
|
case node
|
68
68
|
when SyntaxTree::ConstPathRef, SyntaxTree::ConstPathField, SyntaxTree::TopConstField
|
69
69
|
node.constant.value
|
70
|
-
when SyntaxTree::GVar, SyntaxTree::IVar, SyntaxTree::Const, SyntaxTree::CVar, SyntaxTree::Ident
|
71
|
-
SyntaxTree::ArgsForward
|
70
|
+
when SyntaxTree::GVar, SyntaxTree::IVar, SyntaxTree::Const, SyntaxTree::CVar, SyntaxTree::Ident
|
72
71
|
node.value
|
73
|
-
when SyntaxTree::Field, SyntaxTree::
|
72
|
+
when SyntaxTree::Field, SyntaxTree::DefNode, SyntaxTree::RestParam,
|
74
73
|
SyntaxTree::KwRestParam, SyntaxTree::BlockArg
|
75
74
|
node.name&.value
|
76
|
-
when SyntaxTree::VarField, SyntaxTree::VarRef, SyntaxTree::VCall
|
75
|
+
when SyntaxTree::VarField, SyntaxTree::VarRef, SyntaxTree::VCall
|
77
76
|
node.value&.value
|
78
|
-
when SyntaxTree::
|
77
|
+
when SyntaxTree::CallNode, SyntaxTree::Command, SyntaxTree::CommandCall
|
79
78
|
message = node.message
|
80
79
|
message != :call ? message.value : nil
|
81
80
|
when SyntaxTree::ClassDeclaration, SyntaxTree::ModuleDeclaration
|
@@ -10,8 +10,14 @@ module RubyLsp
|
|
10
10
|
RAILS_DOC_HOST = "https://api.rubyonrails.org"
|
11
11
|
SUPPORTED_RAILS_DOC_NAMESPACES = T.let(
|
12
12
|
Regexp.union(
|
13
|
-
/ActionDispatch/,
|
14
|
-
/
|
13
|
+
/ActionDispatch/,
|
14
|
+
/ActionController/,
|
15
|
+
/AbstractController/,
|
16
|
+
/ActiveRecord/,
|
17
|
+
/ActiveModel/,
|
18
|
+
/ActiveStorage/,
|
19
|
+
/ActionText/,
|
20
|
+
/ActiveJob/,
|
15
21
|
).freeze,
|
16
22
|
Regexp,
|
17
23
|
)
|
@@ -19,7 +25,8 @@ module RubyLsp
|
|
19
25
|
RAILTIES_VERSION = T.let(
|
20
26
|
[*::Gem::Specification.default_stubs, *::Gem::Specification.stubs].find do |s|
|
21
27
|
s.name == "railties"
|
22
|
-
end&.version&.to_s,
|
28
|
+
end&.version&.to_s,
|
29
|
+
T.nilable(String),
|
23
30
|
)
|
24
31
|
|
25
32
|
class << self
|
@@ -59,7 +66,7 @@ module RubyLsp
|
|
59
66
|
private def build_search_index
|
60
67
|
return unless RAILTIES_VERSION
|
61
68
|
|
62
|
-
|
69
|
+
warn("Fetching Rails Documents...")
|
63
70
|
# If the version's doc is not found, e.g. Rails main, it'll be redirected
|
64
71
|
# In this case, we just fetch the latest doc
|
65
72
|
response = if Gem::Version.new(RAILTIES_VERSION).prerelease?
|
@@ -71,11 +78,11 @@ module RubyLsp
|
|
71
78
|
if response.code == "200"
|
72
79
|
process_search_index(response.body)
|
73
80
|
else
|
74
|
-
|
81
|
+
warn("Response failed: #{response.inspect}")
|
75
82
|
nil
|
76
83
|
end
|
77
84
|
rescue StandardError => e
|
78
|
-
|
85
|
+
warn("Exception occurred when fetching Rails document index: #{e.inspect}")
|
79
86
|
end
|
80
87
|
|
81
88
|
sig { params(js: String).returns(T::Hash[String, T::Array[T::Hash[Symbol, String]]]) }
|
@@ -7,14 +7,17 @@ module RubyLsp
|
|
7
7
|
class RuboCopDiagnostic
|
8
8
|
extend T::Sig
|
9
9
|
|
10
|
-
RUBOCOP_TO_LSP_SEVERITY = T.let(
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
10
|
+
RUBOCOP_TO_LSP_SEVERITY = T.let(
|
11
|
+
{
|
12
|
+
convention: LanguageServer::Protocol::Constant::DiagnosticSeverity::INFORMATION,
|
13
|
+
info: LanguageServer::Protocol::Constant::DiagnosticSeverity::INFORMATION,
|
14
|
+
refactor: LanguageServer::Protocol::Constant::DiagnosticSeverity::INFORMATION,
|
15
|
+
warning: LanguageServer::Protocol::Constant::DiagnosticSeverity::WARNING,
|
16
|
+
error: LanguageServer::Protocol::Constant::DiagnosticSeverity::ERROR,
|
17
|
+
fatal: LanguageServer::Protocol::Constant::DiagnosticSeverity::ERROR,
|
18
|
+
}.freeze,
|
19
|
+
T::Hash[Symbol, Integer],
|
20
|
+
)
|
18
21
|
|
19
22
|
sig { returns(T::Array[LanguageServer::Protocol::Interface::TextEdit]) }
|
20
23
|
attr_reader :replacements
|
@@ -94,8 +97,10 @@ module RubyLsp
|
|
94
97
|
LanguageServer::Protocol::Interface::TextEdit.new(
|
95
98
|
range: LanguageServer::Protocol::Interface::Range.new(
|
96
99
|
start: LanguageServer::Protocol::Interface::Position.new(line: range.line - 1, character: range.column),
|
97
|
-
end: LanguageServer::Protocol::Interface::Position.new(
|
98
|
-
|
100
|
+
end: LanguageServer::Protocol::Interface::Position.new(
|
101
|
+
line: range.last_line - 1,
|
102
|
+
character: range.last_column,
|
103
|
+
),
|
99
104
|
),
|
100
105
|
new_text: replacement,
|
101
106
|
)
|