ruby-lsp 0.3.2 → 0.3.3
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/VERSION +1 -1
- data/lib/ruby_lsp/document.rb +1 -1
- data/lib/ruby_lsp/handler.rb +4 -4
- data/lib/ruby_lsp/queue.rb +11 -5
- data/lib/ruby_lsp/requests/code_actions.rb +1 -1
- data/lib/ruby_lsp/requests/diagnostics.rb +1 -1
- data/lib/ruby_lsp/requests/document_highlight.rb +1 -1
- data/lib/ruby_lsp/requests/document_link.rb +3 -3
- data/lib/ruby_lsp/requests/document_symbol.rb +20 -20
- data/lib/ruby_lsp/requests/folding_ranges.rb +3 -3
- data/lib/ruby_lsp/requests/formatting.rb +2 -2
- data/lib/ruby_lsp/requests/inlay_hints.rb +56 -0
- data/lib/ruby_lsp/requests/on_type_formatting.rb +6 -6
- data/lib/ruby_lsp/requests/selection_ranges.rb +3 -3
- data/lib/ruby_lsp/requests/semantic_highlighting.rb +18 -30
- data/lib/ruby_lsp/requests/support/rubocop_diagnostic.rb +10 -10
- data/lib/ruby_lsp/requests/support/rubocop_runner.rb +6 -0
- data/lib/ruby_lsp/requests/support/semantic_token_encoder.rb +1 -1
- data/lib/ruby_lsp/requests/support/source_uri.rb +1 -1
- data/lib/ruby_lsp/requests/support/syntax_error_diagnostic.rb +1 -1
- data/lib/ruby_lsp/requests.rb +3 -0
- data/lib/ruby_lsp/server.rb +23 -7
- data/lib/ruby_lsp/store.rb +1 -1
- metadata +3 -3
- data/CHANGELOG.md +0 -75
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 62174da68ba92c0af61878221168a02398c9b3df2867b63c063850b1787c7104
|
4
|
+
data.tar.gz: dc3d2e17e3fe2dcbb6578902eb3b672babc72d0f10511c021db767cfde709b0b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c8295ce6739f9452dd20cab22ebb19fb099040f4782afa4dfd63b423b08ad73eedeb1fccc33113dcd7b27d38745e7112a6d272ea28652e00102a870c18c51b96
|
7
|
+
data.tar.gz: 1e1a2a681dcdf97bbb1f667211111b89ca274c1d89745bcd3cf8511fbc3d41416d0bb5a45f2fcaf85feb8b0469a5441b5500148136f849657d263531ffe5ff8a
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.3
|
data/lib/ruby_lsp/document.rb
CHANGED
@@ -38,7 +38,7 @@ module RubyLsp
|
|
38
38
|
type_parameters(:T)
|
39
39
|
.params(
|
40
40
|
request_name: Symbol,
|
41
|
-
block: T.proc.params(document: Document).returns(T.type_parameter(:T))
|
41
|
+
block: T.proc.params(document: Document).returns(T.type_parameter(:T)),
|
42
42
|
).returns(T.type_parameter(:T))
|
43
43
|
end
|
44
44
|
def cache_fetch(request_name, &block)
|
data/lib/ruby_lsp/handler.rb
CHANGED
@@ -26,7 +26,7 @@ module RubyLsp
|
|
26
26
|
# for displaying window messages on errors
|
27
27
|
sig do
|
28
28
|
params(
|
29
|
-
block: T.proc.bind(Handler).params(error: Exception, request: T::Hash[Symbol, T.untyped]).void
|
29
|
+
block: T.proc.bind(Handler).params(error: Exception, request: T::Hash[Symbol, T.untyped]).void,
|
30
30
|
).void
|
31
31
|
end
|
32
32
|
def on_error(&block)
|
@@ -85,7 +85,7 @@ module RubyLsp
|
|
85
85
|
params(
|
86
86
|
msg: String,
|
87
87
|
parallel: T::Boolean,
|
88
|
-
blk: T.proc.bind(Handler).params(request: T::Hash[Symbol, T.untyped]).returns(T.untyped)
|
88
|
+
blk: T.proc.bind(Handler).params(request: T::Hash[Symbol, T.untyped]).returns(T.untyped),
|
89
89
|
).returns(RequestHandler)
|
90
90
|
end
|
91
91
|
def on(msg, parallel: false, &blk)
|
@@ -103,7 +103,7 @@ module RubyLsp
|
|
103
103
|
def clear_diagnostics(uri)
|
104
104
|
@writer.write(
|
105
105
|
method: "textDocument/publishDiagnostics",
|
106
|
-
params: Interface::PublishDiagnosticsParams.new(uri: uri, diagnostics: [])
|
106
|
+
params: Interface::PublishDiagnosticsParams.new(uri: uri, diagnostics: []),
|
107
107
|
)
|
108
108
|
end
|
109
109
|
|
@@ -111,7 +111,7 @@ module RubyLsp
|
|
111
111
|
def show_message(type, message)
|
112
112
|
@writer.write(
|
113
113
|
method: "window/showMessage",
|
114
|
-
params: Interface::ShowMessageParams.new(type: type, message: message)
|
114
|
+
params: Interface::ShowMessageParams.new(type: type, message: message),
|
115
115
|
)
|
116
116
|
end
|
117
117
|
end
|
data/lib/ruby_lsp/queue.rb
CHANGED
@@ -28,7 +28,7 @@ module RubyLsp
|
|
28
28
|
sig do
|
29
29
|
params(
|
30
30
|
writer: LanguageServer::Protocol::Transport::Stdio::Writer,
|
31
|
-
handlers: T::Hash[String, Handler::RequestHandler]
|
31
|
+
handlers: T::Hash[String, Handler::RequestHandler],
|
32
32
|
).void
|
33
33
|
end
|
34
34
|
def initialize(writer, handlers)
|
@@ -94,7 +94,7 @@ module RubyLsp
|
|
94
94
|
sig do
|
95
95
|
params(
|
96
96
|
result: Result,
|
97
|
-
request: T::Hash[Symbol, T.untyped]
|
97
|
+
request: T::Hash[Symbol, T.untyped],
|
98
98
|
).void
|
99
99
|
end
|
100
100
|
def finalize_request(result, request)
|
@@ -107,7 +107,7 @@ module RubyLsp
|
|
107
107
|
id: request[:id],
|
108
108
|
error: {
|
109
109
|
code: LanguageServer::Protocol::Constant::ErrorCodes::INTERNAL_ERROR,
|
110
|
-
message:
|
110
|
+
message: error.inspect,
|
111
111
|
data: request.to_json,
|
112
112
|
},
|
113
113
|
)
|
@@ -117,7 +117,7 @@ module RubyLsp
|
|
117
117
|
|
118
118
|
request_time = result.request_time
|
119
119
|
if request_time
|
120
|
-
@writer.write(method: "telemetry/event", params: telemetry_params(request, request_time,
|
120
|
+
@writer.write(method: "telemetry/event", params: telemetry_params(request, request_time, error))
|
121
121
|
end
|
122
122
|
end
|
123
123
|
end
|
@@ -152,7 +152,7 @@ module RubyLsp
|
|
152
152
|
params(
|
153
153
|
request: T::Hash[Symbol, T.untyped],
|
154
154
|
request_time: Float,
|
155
|
-
error: T.nilable(Exception)
|
155
|
+
error: T.nilable(Exception),
|
156
156
|
).returns(T::Hash[Symbol, T.any(String, Float)])
|
157
157
|
end
|
158
158
|
def telemetry_params(request, request_time, error)
|
@@ -167,6 +167,12 @@ module RubyLsp
|
|
167
167
|
if error
|
168
168
|
params[:errorClass] = error.class.name
|
169
169
|
params[:errorMessage] = error.message
|
170
|
+
|
171
|
+
log_params = request[:params]&.reject { |k, _| k == :textDocument }
|
172
|
+
params[:params] = log_params.to_json if log_params&.any?
|
173
|
+
|
174
|
+
backtrace = error.backtrace
|
175
|
+
params[:backtrace] = backtrace.map { |bt| bt.sub(/^#{Dir.home}/, "~") }.join("\n") if backtrace
|
170
176
|
end
|
171
177
|
|
172
178
|
params[:uri] = uri.sub(%r{.*://#{Dir.home}}, "~") if uri
|
@@ -25,7 +25,7 @@ module RubyLsp
|
|
25
25
|
[*::Gem::Specification.default_stubs, *::Gem::Specification.stubs].map! do |s|
|
26
26
|
[s.name, s.version.to_s]
|
27
27
|
end.to_h.freeze,
|
28
|
-
T::Hash[String, String]
|
28
|
+
T::Hash[String, String],
|
29
29
|
)
|
30
30
|
|
31
31
|
class << self
|
@@ -82,7 +82,7 @@ module RubyLsp
|
|
82
82
|
@links
|
83
83
|
end
|
84
84
|
|
85
|
-
sig { params(node: SyntaxTree::Comment).void }
|
85
|
+
sig { override.params(node: SyntaxTree::Comment).void }
|
86
86
|
def visit_comment(node)
|
87
87
|
match = node.value.match(%r{source://.*#\d+$})
|
88
88
|
return unless match
|
@@ -95,7 +95,7 @@ module RubyLsp
|
|
95
95
|
@links << LanguageServer::Protocol::Interface::DocumentLink.new(
|
96
96
|
range: range_from_syntax_tree_node(node),
|
97
97
|
target: "file://#{file_path}##{uri.line_number}",
|
98
|
-
tooltip: "Jump to #{file_path}##{uri.line_number}"
|
98
|
+
tooltip: "Jump to #{file_path}##{uri.line_number}",
|
99
99
|
)
|
100
100
|
end
|
101
101
|
|
@@ -79,7 +79,7 @@ module RubyLsp
|
|
79
79
|
@root = T.let(SymbolHierarchyRoot.new, SymbolHierarchyRoot)
|
80
80
|
@stack = T.let(
|
81
81
|
[@root],
|
82
|
-
T::Array[T.any(SymbolHierarchyRoot, LanguageServer::Protocol::Interface::DocumentSymbol)]
|
82
|
+
T::Array[T.any(SymbolHierarchyRoot, LanguageServer::Protocol::Interface::DocumentSymbol)],
|
83
83
|
)
|
84
84
|
end
|
85
85
|
|
@@ -89,13 +89,13 @@ module RubyLsp
|
|
89
89
|
@root.children
|
90
90
|
end
|
91
91
|
|
92
|
-
sig { params(node: SyntaxTree::ClassDeclaration).void }
|
92
|
+
sig { override.params(node: SyntaxTree::ClassDeclaration).void }
|
93
93
|
def visit_class(node)
|
94
94
|
symbol = create_document_symbol(
|
95
95
|
name: fully_qualified_name(node),
|
96
96
|
kind: :class,
|
97
97
|
range_node: node,
|
98
|
-
selection_range_node: node.constant
|
98
|
+
selection_range_node: node.constant,
|
99
99
|
)
|
100
100
|
|
101
101
|
@stack << symbol
|
@@ -103,7 +103,7 @@ module RubyLsp
|
|
103
103
|
@stack.pop
|
104
104
|
end
|
105
105
|
|
106
|
-
sig { params(node: SyntaxTree::Command).void }
|
106
|
+
sig { override.params(node: SyntaxTree::Command).void }
|
107
107
|
def visit_command(node)
|
108
108
|
return unless ATTR_ACCESSORS.include?(node.message.value)
|
109
109
|
|
@@ -114,22 +114,22 @@ module RubyLsp
|
|
114
114
|
name: argument.value.value,
|
115
115
|
kind: :field,
|
116
116
|
range_node: argument,
|
117
|
-
selection_range_node: argument.value
|
117
|
+
selection_range_node: argument.value,
|
118
118
|
)
|
119
119
|
end
|
120
120
|
end
|
121
121
|
|
122
|
-
sig { params(node: SyntaxTree::ConstPathField).void }
|
122
|
+
sig { override.params(node: SyntaxTree::ConstPathField).void }
|
123
123
|
def visit_const_path_field(node)
|
124
124
|
create_document_symbol(
|
125
125
|
name: node.constant.value,
|
126
126
|
kind: :constant,
|
127
127
|
range_node: node,
|
128
|
-
selection_range_node: node.constant
|
128
|
+
selection_range_node: node.constant,
|
129
129
|
)
|
130
130
|
end
|
131
131
|
|
132
|
-
sig { params(node: SyntaxTree::Def).void }
|
132
|
+
sig { override.params(node: SyntaxTree::Def).void }
|
133
133
|
def visit_def(node)
|
134
134
|
name = node.name.value
|
135
135
|
|
@@ -137,7 +137,7 @@ module RubyLsp
|
|
137
137
|
name: name,
|
138
138
|
kind: name == "initialize" ? :constructor : :method,
|
139
139
|
range_node: node,
|
140
|
-
selection_range_node: node.name
|
140
|
+
selection_range_node: node.name,
|
141
141
|
)
|
142
142
|
|
143
143
|
@stack << symbol
|
@@ -145,7 +145,7 @@ module RubyLsp
|
|
145
145
|
@stack.pop
|
146
146
|
end
|
147
147
|
|
148
|
-
sig { params(node: SyntaxTree::DefEndless).void }
|
148
|
+
sig { override.params(node: SyntaxTree::DefEndless).void }
|
149
149
|
def visit_def_endless(node)
|
150
150
|
name = node.name.value
|
151
151
|
|
@@ -153,7 +153,7 @@ module RubyLsp
|
|
153
153
|
name: name,
|
154
154
|
kind: name == "initialize" ? :constructor : :method,
|
155
155
|
range_node: node,
|
156
|
-
selection_range_node: node.name
|
156
|
+
selection_range_node: node.name,
|
157
157
|
)
|
158
158
|
|
159
159
|
@stack << symbol
|
@@ -161,13 +161,13 @@ module RubyLsp
|
|
161
161
|
@stack.pop
|
162
162
|
end
|
163
163
|
|
164
|
-
sig { params(node: SyntaxTree::Defs).void }
|
164
|
+
sig { override.params(node: SyntaxTree::Defs).void }
|
165
165
|
def visit_defs(node)
|
166
166
|
symbol = create_document_symbol(
|
167
167
|
name: "self.#{node.name.value}",
|
168
168
|
kind: :method,
|
169
169
|
range_node: node,
|
170
|
-
selection_range_node: node.name
|
170
|
+
selection_range_node: node.name,
|
171
171
|
)
|
172
172
|
|
173
173
|
@stack << symbol
|
@@ -175,13 +175,13 @@ module RubyLsp
|
|
175
175
|
@stack.pop
|
176
176
|
end
|
177
177
|
|
178
|
-
sig { params(node: SyntaxTree::ModuleDeclaration).void }
|
178
|
+
sig { override.params(node: SyntaxTree::ModuleDeclaration).void }
|
179
179
|
def visit_module(node)
|
180
180
|
symbol = create_document_symbol(
|
181
181
|
name: fully_qualified_name(node),
|
182
182
|
kind: :module,
|
183
183
|
range_node: node,
|
184
|
-
selection_range_node: node.constant
|
184
|
+
selection_range_node: node.constant,
|
185
185
|
)
|
186
186
|
|
187
187
|
@stack << symbol
|
@@ -189,17 +189,17 @@ module RubyLsp
|
|
189
189
|
@stack.pop
|
190
190
|
end
|
191
191
|
|
192
|
-
sig { params(node: SyntaxTree::TopConstField).void }
|
192
|
+
sig { override.params(node: SyntaxTree::TopConstField).void }
|
193
193
|
def visit_top_const_field(node)
|
194
194
|
create_document_symbol(
|
195
195
|
name: node.constant.value,
|
196
196
|
kind: :constant,
|
197
197
|
range_node: node,
|
198
|
-
selection_range_node: node.constant
|
198
|
+
selection_range_node: node.constant,
|
199
199
|
)
|
200
200
|
end
|
201
201
|
|
202
|
-
sig { params(node: SyntaxTree::VarField).void }
|
202
|
+
sig { override.params(node: SyntaxTree::VarField).void }
|
203
203
|
def visit_var_field(node)
|
204
204
|
kind = case node.value
|
205
205
|
when SyntaxTree::Const
|
@@ -214,7 +214,7 @@ module RubyLsp
|
|
214
214
|
name: node.value.value,
|
215
215
|
kind: kind,
|
216
216
|
range_node: node,
|
217
|
-
selection_range_node: node.value
|
217
|
+
selection_range_node: node.value,
|
218
218
|
)
|
219
219
|
end
|
220
220
|
|
@@ -225,7 +225,7 @@ module RubyLsp
|
|
225
225
|
name: String,
|
226
226
|
kind: Symbol,
|
227
227
|
range_node: SyntaxTree::Node,
|
228
|
-
selection_range_node: SyntaxTree::Node
|
228
|
+
selection_range_node: SyntaxTree::Node,
|
229
229
|
).returns(LanguageServer::Protocol::Interface::DocumentSymbol)
|
230
230
|
end
|
231
231
|
def create_document_symbol(name:, kind:, range_node:, selection_range_node:)
|
@@ -73,7 +73,7 @@ module RubyLsp
|
|
73
73
|
|
74
74
|
private
|
75
75
|
|
76
|
-
sig { params(node: T.nilable(SyntaxTree::Node)).void }
|
76
|
+
sig { override.params(node: T.nilable(SyntaxTree::Node)).void }
|
77
77
|
def visit(node)
|
78
78
|
return unless handle_partial_range(node)
|
79
79
|
|
@@ -137,7 +137,7 @@ module RubyLsp
|
|
137
137
|
LanguageServer::Protocol::Interface::FoldingRange.new(
|
138
138
|
start_line: @start_line,
|
139
139
|
end_line: @end_line,
|
140
|
-
kind: @kind
|
140
|
+
kind: @kind,
|
141
141
|
)
|
142
142
|
end
|
143
143
|
|
@@ -248,7 +248,7 @@ module RubyLsp
|
|
248
248
|
@ranges << LanguageServer::Protocol::Interface::FoldingRange.new(
|
249
249
|
start_line: start_line - 1,
|
250
250
|
end_line: end_line - 1,
|
251
|
-
kind: "region"
|
251
|
+
kind: "region",
|
252
252
|
)
|
253
253
|
end
|
254
254
|
end
|
@@ -42,9 +42,9 @@ module RubyLsp
|
|
42
42
|
LanguageServer::Protocol::Interface::TextEdit.new(
|
43
43
|
range: LanguageServer::Protocol::Interface::Range.new(
|
44
44
|
start: LanguageServer::Protocol::Interface::Position.new(line: 0, character: 0),
|
45
|
-
end: LanguageServer::Protocol::Interface::Position.new(line: size, character: size)
|
45
|
+
end: LanguageServer::Protocol::Interface::Position.new(line: size, character: size),
|
46
46
|
),
|
47
|
-
new_text: formatted_text
|
47
|
+
new_text: formatted_text,
|
48
48
|
),
|
49
49
|
]
|
50
50
|
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# typed: strict
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module RubyLsp
|
5
|
+
module Requests
|
6
|
+
# 
|
7
|
+
#
|
8
|
+
# [Inlay hints](https://microsoft.github.io/language-server-protocol/specification#textDocument_inlayHint)
|
9
|
+
# are labels added directly in the code that explicitly show the user something that might
|
10
|
+
# otherwise just be implied.
|
11
|
+
#
|
12
|
+
# # Example
|
13
|
+
#
|
14
|
+
# ```ruby
|
15
|
+
# begin
|
16
|
+
# puts "do something that might raise"
|
17
|
+
# rescue # Label "StandardError" goes here as a bare rescue implies rescuing StandardError
|
18
|
+
# puts "handle some rescue"
|
19
|
+
# end
|
20
|
+
# ```
|
21
|
+
class InlayHints < BaseRequest
|
22
|
+
RESCUE_STRING_LENGTH = T.let("rescue".length, Integer)
|
23
|
+
|
24
|
+
sig { params(document: Document, range: T::Range[Integer]).void }
|
25
|
+
def initialize(document, range)
|
26
|
+
super(document)
|
27
|
+
|
28
|
+
@hints = T.let([], T::Array[LanguageServer::Protocol::Interface::InlayHint])
|
29
|
+
@range = range
|
30
|
+
end
|
31
|
+
|
32
|
+
sig { override.returns(T.all(T::Array[LanguageServer::Protocol::Interface::InlayHint], Object)) }
|
33
|
+
def run
|
34
|
+
visit(@document.tree)
|
35
|
+
@hints
|
36
|
+
end
|
37
|
+
|
38
|
+
sig { override.params(node: SyntaxTree::Rescue).void }
|
39
|
+
def visit_rescue(node)
|
40
|
+
return unless node.exception.nil?
|
41
|
+
|
42
|
+
loc = node.location
|
43
|
+
return unless @range.cover?(loc.start_line - 1) && @range.cover?(loc.end_line - 1)
|
44
|
+
|
45
|
+
@hints << LanguageServer::Protocol::Interface::InlayHint.new(
|
46
|
+
position: { line: loc.start_line - 1, character: loc.start_column + RESCUE_STRING_LENGTH },
|
47
|
+
label: "StandardError",
|
48
|
+
padding_left: true,
|
49
|
+
tooltip: "StandardError is implied in a bare rescue",
|
50
|
+
)
|
51
|
+
|
52
|
+
super
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -101,15 +101,15 @@ module RubyLsp
|
|
101
101
|
def add_edit_with_text(text)
|
102
102
|
position = Interface::Position.new(
|
103
103
|
line: @position[:line],
|
104
|
-
character: @position[:character]
|
104
|
+
character: @position[:character],
|
105
105
|
)
|
106
106
|
|
107
107
|
@edits << Interface::TextEdit.new(
|
108
108
|
range: Interface::Range.new(
|
109
109
|
start: position,
|
110
|
-
end: position
|
110
|
+
end: position,
|
111
111
|
),
|
112
|
-
new_text: text
|
112
|
+
new_text: text,
|
113
113
|
)
|
114
114
|
end
|
115
115
|
|
@@ -117,7 +117,7 @@ module RubyLsp
|
|
117
117
|
def move_cursor_to(line, character)
|
118
118
|
position = Interface::Position.new(
|
119
119
|
line: line,
|
120
|
-
character: character
|
120
|
+
character: character,
|
121
121
|
)
|
122
122
|
|
123
123
|
# The $0 is a special snippet anchor that moves the cursor to that given position. See the snippets
|
@@ -126,9 +126,9 @@ module RubyLsp
|
|
126
126
|
@edits << Interface::TextEdit.new(
|
127
127
|
range: Interface::Range.new(
|
128
128
|
start: position,
|
129
|
-
end: position
|
129
|
+
end: position,
|
130
130
|
),
|
131
|
-
new_text: "$0"
|
131
|
+
new_text: "$0",
|
132
132
|
)
|
133
133
|
end
|
134
134
|
|
@@ -76,7 +76,7 @@ module RubyLsp
|
|
76
76
|
|
77
77
|
private
|
78
78
|
|
79
|
-
sig { params(node: T.nilable(SyntaxTree::Node)).void }
|
79
|
+
sig { override.params(node: T.nilable(SyntaxTree::Node)).void }
|
80
80
|
def visit(node)
|
81
81
|
return if node.nil?
|
82
82
|
|
@@ -93,7 +93,7 @@ module RubyLsp
|
|
93
93
|
sig do
|
94
94
|
params(
|
95
95
|
location: SyntaxTree::Location,
|
96
|
-
parent: T.nilable(Support::SelectionRange)
|
96
|
+
parent: T.nilable(Support::SelectionRange),
|
97
97
|
).returns(Support::SelectionRange)
|
98
98
|
end
|
99
99
|
def create_selection_range(location, parent = nil)
|
@@ -108,7 +108,7 @@ module RubyLsp
|
|
108
108
|
character: location.end_column,
|
109
109
|
),
|
110
110
|
),
|
111
|
-
parent: parent
|
111
|
+
parent: parent,
|
112
112
|
)
|
113
113
|
end
|
114
114
|
end
|
@@ -90,7 +90,7 @@ module RubyLsp
|
|
90
90
|
T.any(
|
91
91
|
LanguageServer::Protocol::Interface::SemanticTokens,
|
92
92
|
T.all(T::Array[SemanticToken], Object),
|
93
|
-
)
|
93
|
+
),
|
94
94
|
)
|
95
95
|
end
|
96
96
|
def run
|
@@ -100,12 +100,7 @@ module RubyLsp
|
|
100
100
|
@encoder.encode(@tokens)
|
101
101
|
end
|
102
102
|
|
103
|
-
sig { params(node: SyntaxTree::
|
104
|
-
def visit_a_ref_field(node)
|
105
|
-
add_token(node.collection.value.location, :variable)
|
106
|
-
end
|
107
|
-
|
108
|
-
sig { params(node: SyntaxTree::Call).void }
|
103
|
+
sig { override.params(node: SyntaxTree::Call).void }
|
109
104
|
def visit_call(node)
|
110
105
|
visit(node.receiver)
|
111
106
|
|
@@ -115,32 +110,32 @@ module RubyLsp
|
|
115
110
|
visit(node.arguments)
|
116
111
|
end
|
117
112
|
|
118
|
-
sig { params(node: SyntaxTree::Command).void }
|
113
|
+
sig { override.params(node: SyntaxTree::Command).void }
|
119
114
|
def visit_command(node)
|
120
115
|
add_token(node.message.location, :method) unless special_method?(node.message.value)
|
121
116
|
visit(node.arguments)
|
122
117
|
end
|
123
118
|
|
124
|
-
sig { params(node: SyntaxTree::CommandCall).void }
|
119
|
+
sig { override.params(node: SyntaxTree::CommandCall).void }
|
125
120
|
def visit_command_call(node)
|
126
121
|
visit(node.receiver)
|
127
122
|
add_token(node.message.location, :method)
|
128
123
|
visit(node.arguments)
|
129
124
|
end
|
130
125
|
|
131
|
-
sig { params(node: SyntaxTree::Const).void }
|
126
|
+
sig { override.params(node: SyntaxTree::Const).void }
|
132
127
|
def visit_const(node)
|
133
128
|
add_token(node.location, :namespace)
|
134
129
|
end
|
135
130
|
|
136
|
-
sig { params(node: SyntaxTree::Def).void }
|
131
|
+
sig { override.params(node: SyntaxTree::Def).void }
|
137
132
|
def visit_def(node)
|
138
133
|
add_token(node.name.location, :method, [:declaration])
|
139
134
|
visit(node.params)
|
140
135
|
visit(node.bodystmt)
|
141
136
|
end
|
142
137
|
|
143
|
-
sig { params(node: SyntaxTree::DefEndless).void }
|
138
|
+
sig { override.params(node: SyntaxTree::DefEndless).void }
|
144
139
|
def visit_def_endless(node)
|
145
140
|
add_token(node.name.location, :method, [:declaration])
|
146
141
|
visit(node.paren)
|
@@ -148,7 +143,7 @@ module RubyLsp
|
|
148
143
|
visit(node.statement)
|
149
144
|
end
|
150
145
|
|
151
|
-
sig { params(node: SyntaxTree::Defs).void }
|
146
|
+
sig { override.params(node: SyntaxTree::Defs).void }
|
152
147
|
def visit_defs(node)
|
153
148
|
visit(node.target)
|
154
149
|
visit(node.operator)
|
@@ -157,13 +152,13 @@ module RubyLsp
|
|
157
152
|
visit(node.bodystmt)
|
158
153
|
end
|
159
154
|
|
160
|
-
sig { params(node: SyntaxTree::FCall).void }
|
155
|
+
sig { override.params(node: SyntaxTree::FCall).void }
|
161
156
|
def visit_fcall(node)
|
162
157
|
add_token(node.value.location, :method) unless special_method?(node.value.value)
|
163
158
|
visit(node.arguments)
|
164
159
|
end
|
165
160
|
|
166
|
-
sig { params(node: SyntaxTree::Kw).void }
|
161
|
+
sig { override.params(node: SyntaxTree::Kw).void }
|
167
162
|
def visit_kw(node)
|
168
163
|
case node.value
|
169
164
|
when "self"
|
@@ -171,14 +166,7 @@ module RubyLsp
|
|
171
166
|
end
|
172
167
|
end
|
173
168
|
|
174
|
-
sig { params(node: SyntaxTree::
|
175
|
-
def visit_m_assign(node)
|
176
|
-
node.target.parts.each do |var_ref|
|
177
|
-
add_token(var_ref.value.location, :variable)
|
178
|
-
end
|
179
|
-
end
|
180
|
-
|
181
|
-
sig { params(node: SyntaxTree::Params).void }
|
169
|
+
sig { override.params(node: SyntaxTree::Params).void }
|
182
170
|
def visit_params(node)
|
183
171
|
node.keywords.each do |keyword,|
|
184
172
|
location = keyword.location
|
@@ -196,7 +184,7 @@ module RubyLsp
|
|
196
184
|
add_token(name.location, :variable) if name
|
197
185
|
end
|
198
186
|
|
199
|
-
sig { params(node: SyntaxTree::VarField).void }
|
187
|
+
sig { override.params(node: SyntaxTree::VarField).void }
|
200
188
|
def visit_var_field(node)
|
201
189
|
case node.value
|
202
190
|
when SyntaxTree::Ident
|
@@ -206,7 +194,7 @@ module RubyLsp
|
|
206
194
|
end
|
207
195
|
end
|
208
196
|
|
209
|
-
sig { params(node: SyntaxTree::VarRef).void }
|
197
|
+
sig { override.params(node: SyntaxTree::VarRef).void }
|
210
198
|
def visit_var_ref(node)
|
211
199
|
case node.value
|
212
200
|
when SyntaxTree::Ident
|
@@ -216,19 +204,19 @@ module RubyLsp
|
|
216
204
|
end
|
217
205
|
end
|
218
206
|
|
219
|
-
sig { params(node: SyntaxTree::VCall).void }
|
207
|
+
sig { override.params(node: SyntaxTree::VCall).void }
|
220
208
|
def visit_vcall(node)
|
221
209
|
add_token(node.value.location, :method) unless special_method?(node.value.value)
|
222
210
|
end
|
223
211
|
|
224
|
-
sig { params(node: SyntaxTree::ClassDeclaration).void }
|
212
|
+
sig { override.params(node: SyntaxTree::ClassDeclaration).void }
|
225
213
|
def visit_class(node)
|
226
214
|
add_token(node.constant.location, :class, [:declaration])
|
227
215
|
add_token(node.superclass.location, :class) if node.superclass
|
228
216
|
visit(node.bodystmt)
|
229
217
|
end
|
230
218
|
|
231
|
-
sig { params(node: SyntaxTree::ModuleDeclaration).void }
|
219
|
+
sig { override.params(node: SyntaxTree::ModuleDeclaration).void }
|
232
220
|
def visit_module(node)
|
233
221
|
add_token(node.constant.location, :class, [:declaration])
|
234
222
|
visit(node.bodystmt)
|
@@ -243,8 +231,8 @@ module RubyLsp
|
|
243
231
|
location: location,
|
244
232
|
length: length,
|
245
233
|
type: T.must(TOKEN_TYPES[type]),
|
246
|
-
modifier: modifiers_indices
|
247
|
-
)
|
234
|
+
modifier: modifiers_indices,
|
235
|
+
),
|
248
236
|
)
|
249
237
|
end
|
250
238
|
|
@@ -25,7 +25,7 @@ module RubyLsp
|
|
25
25
|
@uri = uri
|
26
26
|
@replacements = T.let(
|
27
27
|
offense.correctable? ? offense_replacements : [],
|
28
|
-
T::Array[LanguageServer::Protocol::Interface::TextEdit]
|
28
|
+
T::Array[LanguageServer::Protocol::Interface::TextEdit],
|
29
29
|
)
|
30
30
|
end
|
31
31
|
|
@@ -49,11 +49,11 @@ module RubyLsp
|
|
49
49
|
LanguageServer::Protocol::Interface::TextDocumentEdit.new(
|
50
50
|
text_document: LanguageServer::Protocol::Interface::OptionalVersionedTextDocumentIdentifier.new(
|
51
51
|
uri: @uri,
|
52
|
-
version: nil
|
52
|
+
version: nil,
|
53
53
|
),
|
54
|
-
edits: @replacements
|
54
|
+
edits: @replacements,
|
55
55
|
),
|
56
|
-
]
|
56
|
+
],
|
57
57
|
),
|
58
58
|
is_preferred: true,
|
59
59
|
)
|
@@ -76,13 +76,13 @@ module RubyLsp
|
|
76
76
|
range: LanguageServer::Protocol::Interface::Range.new(
|
77
77
|
start: LanguageServer::Protocol::Interface::Position.new(
|
78
78
|
line: @offense.line - 1,
|
79
|
-
character: @offense.column
|
79
|
+
character: @offense.column,
|
80
80
|
),
|
81
81
|
end: LanguageServer::Protocol::Interface::Position.new(
|
82
82
|
line: @offense.last_line - 1,
|
83
|
-
character: @offense.last_column
|
84
|
-
)
|
85
|
-
)
|
83
|
+
character: @offense.last_column,
|
84
|
+
),
|
85
|
+
),
|
86
86
|
)
|
87
87
|
end
|
88
88
|
|
@@ -95,9 +95,9 @@ module RubyLsp
|
|
95
95
|
range: LanguageServer::Protocol::Interface::Range.new(
|
96
96
|
start: LanguageServer::Protocol::Interface::Position.new(line: range.line - 1, character: range.column),
|
97
97
|
end: LanguageServer::Protocol::Interface::Position.new(line: range.last_line - 1,
|
98
|
-
character: range.last_column)
|
98
|
+
character: range.last_column),
|
99
99
|
),
|
100
|
-
new_text: replacement
|
100
|
+
new_text: replacement,
|
101
101
|
)
|
102
102
|
end
|
103
103
|
end
|
data/lib/ruby_lsp/requests.rb
CHANGED
@@ -14,6 +14,8 @@ module RubyLsp
|
|
14
14
|
# - {RubyLsp::Requests::Diagnostics}
|
15
15
|
# - {RubyLsp::Requests::CodeActions}
|
16
16
|
# - {RubyLsp::Requests::DocumentHighlight}
|
17
|
+
# - {RubyLsp::Requests::InlayHints}
|
18
|
+
|
17
19
|
module Requests
|
18
20
|
autoload :BaseRequest, "ruby_lsp/requests/base_request"
|
19
21
|
autoload :DocumentSymbol, "ruby_lsp/requests/document_symbol"
|
@@ -26,6 +28,7 @@ module RubyLsp
|
|
26
28
|
autoload :Diagnostics, "ruby_lsp/requests/diagnostics"
|
27
29
|
autoload :CodeActions, "ruby_lsp/requests/code_actions"
|
28
30
|
autoload :DocumentHighlight, "ruby_lsp/requests/document_highlight"
|
31
|
+
autoload :InlayHints, "ruby_lsp/requests/inlay_hints"
|
29
32
|
|
30
33
|
# :nodoc:
|
31
34
|
module Support
|
data/lib/ruby_lsp/server.rb
CHANGED
@@ -15,7 +15,7 @@ module RubyLsp
|
|
15
15
|
hierarchical_document_symbol_support: true,
|
16
16
|
symbol_kind: {
|
17
17
|
value_set: Requests::DocumentSymbol::SYMBOL_KIND.values,
|
18
|
-
}
|
18
|
+
},
|
19
19
|
)
|
20
20
|
end
|
21
21
|
|
@@ -32,12 +32,12 @@ module RubyLsp
|
|
32
32
|
document_selector: { scheme: "file", language: "ruby" },
|
33
33
|
legend: Interface::SemanticTokensLegend.new(
|
34
34
|
token_types: Requests::SemanticHighlighting::TOKEN_TYPES.keys,
|
35
|
-
token_modifiers: Requests::SemanticHighlighting::TOKEN_MODIFIERS.keys
|
35
|
+
token_modifiers: Requests::SemanticHighlighting::TOKEN_MODIFIERS.keys,
|
36
36
|
),
|
37
37
|
range: false,
|
38
38
|
full: {
|
39
39
|
delta: true,
|
40
|
-
}
|
40
|
+
},
|
41
41
|
)
|
42
42
|
end
|
43
43
|
|
@@ -51,10 +51,14 @@ module RubyLsp
|
|
51
51
|
on_type_formatting_provider = if enabled_features.include?("onTypeFormatting")
|
52
52
|
Interface::DocumentOnTypeFormattingOptions.new(
|
53
53
|
first_trigger_character: "{",
|
54
|
-
more_trigger_character: ["\n", "|"]
|
54
|
+
more_trigger_character: ["\n", "|"],
|
55
55
|
)
|
56
56
|
end
|
57
57
|
|
58
|
+
inlay_hint_provider = if enabled_features.include?("inlayHint")
|
59
|
+
Interface::InlayHintOptions.new(resolve_provider: false)
|
60
|
+
end
|
61
|
+
|
58
62
|
Interface::InitializeResult.new(
|
59
63
|
capabilities: Interface::ServerCapabilities.new(
|
60
64
|
text_document_sync: Interface::TextDocumentSyncOptions.new(
|
@@ -71,7 +75,8 @@ module RubyLsp
|
|
71
75
|
code_action_provider: enabled_features.include?("codeActions"),
|
72
76
|
document_on_type_formatting_provider: on_type_formatting_provider,
|
73
77
|
diagnostic_provider: diagnostics_provider,
|
74
|
-
|
78
|
+
inlay_hint_provider: inlay_hint_provider,
|
79
|
+
),
|
75
80
|
)
|
76
81
|
end
|
77
82
|
|
@@ -144,9 +149,9 @@ module RubyLsp
|
|
144
149
|
T.cast(
|
145
150
|
Requests::SemanticHighlighting.new(
|
146
151
|
document,
|
147
|
-
encoder: Requests::Support::SemanticTokenEncoder.new
|
152
|
+
encoder: Requests::Support::SemanticTokenEncoder.new,
|
148
153
|
).run,
|
149
|
-
LanguageServer::Protocol::Interface::SemanticTokens
|
154
|
+
LanguageServer::Protocol::Interface::SemanticTokens,
|
150
155
|
)
|
151
156
|
end
|
152
157
|
end
|
@@ -186,6 +191,17 @@ module RubyLsp
|
|
186
191
|
end
|
187
192
|
end
|
188
193
|
|
194
|
+
on("textDocument/inlayHint", parallel: true) do |request|
|
195
|
+
document = store.get(request.dig(:params, :textDocument, :uri))
|
196
|
+
range = request.dig(:params, :range)
|
197
|
+
start_line = range.dig(:start, :line)
|
198
|
+
end_line = range.dig(:end, :line)
|
199
|
+
|
200
|
+
if document.parsed?
|
201
|
+
Requests::InlayHints.new(document, start_line..end_line).run
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
189
205
|
on("$/cancelRequest") do |request|
|
190
206
|
cancel_request(request[:params][:id])
|
191
207
|
Handler::VOID
|
data/lib/ruby_lsp/store.rb
CHANGED
@@ -54,7 +54,7 @@ module RubyLsp
|
|
54
54
|
.params(
|
55
55
|
uri: String,
|
56
56
|
request_name: Symbol,
|
57
|
-
block: T.proc.params(document: Document).returns(T.type_parameter(:T))
|
57
|
+
block: T.proc.params(document: Document).returns(T.type_parameter(:T)),
|
58
58
|
).returns(T.nilable(T.type_parameter(:T)))
|
59
59
|
end
|
60
60
|
def cache_fetch(uri, request_name, &block)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-lsp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shopify
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-10-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: language_server-protocol
|
@@ -60,7 +60,6 @@ executables:
|
|
60
60
|
extensions: []
|
61
61
|
extra_rdoc_files: []
|
62
62
|
files:
|
63
|
-
- CHANGELOG.md
|
64
63
|
- LICENSE.txt
|
65
64
|
- README.md
|
66
65
|
- VERSION
|
@@ -79,6 +78,7 @@ files:
|
|
79
78
|
- lib/ruby_lsp/requests/document_symbol.rb
|
80
79
|
- lib/ruby_lsp/requests/folding_ranges.rb
|
81
80
|
- lib/ruby_lsp/requests/formatting.rb
|
81
|
+
- lib/ruby_lsp/requests/inlay_hints.rb
|
82
82
|
- lib/ruby_lsp/requests/on_type_formatting.rb
|
83
83
|
- lib/ruby_lsp/requests/selection_ranges.rb
|
84
84
|
- lib/ruby_lsp/requests/semantic_highlighting.rb
|
data/CHANGELOG.md
DELETED
@@ -1,75 +0,0 @@
|
|
1
|
-
# Change Log
|
2
|
-
|
3
|
-
All notable changes to the "ruby-lsp" extension will be documented in this file.
|
4
|
-
|
5
|
-
Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.
|
6
|
-
|
7
|
-
## [Unreleased]
|
8
|
-
|
9
|
-
## [0.3.2]
|
10
|
-
|
11
|
-
- Make the diagnostic request parallel (https://github.com/Shopify/ruby-lsp/pull/293)
|
12
|
-
- Improve worker stability (https://github.com/Shopify/ruby-lsp/pull/295)
|
13
|
-
|
14
|
-
## [0.3.1]
|
15
|
-
|
16
|
-
- Resolve TODO for LSP v3.17 (https://github.com/Shopify/ruby-lsp/pull/268)
|
17
|
-
- Add dependency constraint for LSP v3.17 (https://github.com/Shopify/ruby-lsp/pull/269)
|
18
|
-
- Handle class/module declarations as a class token with declaration modifier (https://github.com/Shopify/ruby-lsp/pull/260)
|
19
|
-
- Handle required parameters in semantic highlighting (https://github.com/Shopify/ruby-lsp/pull/271)
|
20
|
-
- Add comment continuation via on type on_type_formatting (https://github.com/Shopify/ruby-lsp/pull/274)
|
21
|
-
- Make RuboCop runner use composition instead of inheritance (https://github.com/Shopify/ruby-lsp/pull/278)
|
22
|
-
- Protect worker against cancellation during popping (https://github.com/Shopify/ruby-lsp/pull/280)
|
23
|
-
- Handle formatting errors in on_error block (https://github.com/Shopify/ruby-lsp/pull/279)
|
24
|
-
- Fix on type formatting pipe completion for regular or expressions (https://github.com/Shopify/ruby-lsp/pull/282)
|
25
|
-
- Do not fail on LoadError (https://github.com/Shopify/ruby-lsp/pull/292)
|
26
|
-
|
27
|
-
## [0.3.0]
|
28
|
-
- Add on type formatting completions (https://github.com/Shopify/ruby-lsp/pull/253)
|
29
|
-
- Upgrade syntax_tree requirement to >= 3.4 (https://github.com/Shopify/ruby-lsp/pull/254)
|
30
|
-
- Show error message when there's a InfiniteCorrectionLoop exception (https://github.com/Shopify/ruby-lsp/pull/252)
|
31
|
-
- Add request cancellation (https://github.com/Shopify/ruby-lsp/pull/243)
|
32
|
-
|
33
|
-
## [0.2.0]
|
34
|
-
|
35
|
-
- Add semantic token for keyword and keyword rest params (https://github.com/Shopify/ruby-lsp/pull/142)
|
36
|
-
- Return error responses on exceptions (https://github.com/Shopify/ruby-lsp/pull/160)
|
37
|
-
- Sanitize home directory for telemetry (https://github.com/Shopify/ruby-lsp/pull/171)
|
38
|
-
- Avoid adding semantic tokens for special methods (https://github.com/Shopify/ruby-lsp/pull/162)
|
39
|
-
- Properly respect excluded files in RuboCop requests (https://github.com/Shopify/ruby-lsp/pull/173)
|
40
|
-
- Clear diagnostics when closing files (https://github.com/Shopify/ruby-lsp/pull/174)
|
41
|
-
- Avoid pushing ranges for single line partial ranges (https://github.com/Shopify/ruby-lsp/pull/185)
|
42
|
-
- Change folding ranges to include closing tokens (https://github.com/Shopify/ruby-lsp/pull/181)
|
43
|
-
- Remove RuboCop dependency and fallback to SyntaxTree formatting (https://github.com/Shopify/ruby-lsp/pull/184)
|
44
|
-
|
45
|
-
## [0.1.0]
|
46
|
-
|
47
|
-
- Implement token modifiers in SemanticTokenEncoder ([#112](https://github.com/Shopify/ruby-lsp/pull/112))
|
48
|
-
- Add semantic token for name in a method definition ([#133](https://github.com/Shopify/ruby-lsp/pull/133))
|
49
|
-
- Add semantic highighting for def endless and singleton method names ([#134](https://github.com/Shopify/ruby-lsp/pull/134))
|
50
|
-
- Add semantic token for keyword self ([#137](https://github.com/Shopify/ruby-lsp/pull/137))
|
51
|
-
- Add semantic token for constants ([#138](https://github.com/Shopify/ruby-lsp/pull/138))
|
52
|
-
- Improve error handling + fix formatting hanging issue ([#149](https://github.com/Shopify/ruby-lsp/pull/149))
|
53
|
-
- Set the minimum syntax_tree version to 2.4 ([#151](https://github.com/Shopify/ruby-lsp/pull/151))
|
54
|
-
|
55
|
-
## [0.0.4]
|
56
|
-
|
57
|
-
- Add basic document highlight (https://github.com/Shopify/ruby-lsp/pull/91)
|
58
|
-
- Add error telemetry (https://github.com/Shopify/ruby-lsp/pull/100)
|
59
|
-
- Always push telemetry events from the server (https://github.com/Shopify/ruby-lsp/pull/109)
|
60
|
-
- Fix multibyte character handling (https://github.com/Shopify/ruby-lsp/pull/122)
|
61
|
-
- Add Sorbet to the Ruby LSP (https://github.com/Shopify/ruby-lsp/pull/119, https://github.com/Shopify/ruby-lsp/pull/123)
|
62
|
-
|
63
|
-
## [0.0.3]
|
64
|
-
|
65
|
-
- Fixed code actions return hanging
|
66
|
-
- Moved to incremental text synchronization
|
67
|
-
- Added syntax error resiliency
|
68
|
-
|
69
|
-
## [0.0.2]
|
70
|
-
|
71
|
-
- Alpha release including
|
72
|
-
- RuboCop formatting, diagnostics and quick fixes
|
73
|
-
- Folding ranges
|
74
|
-
- Initial semantic highlighting
|
75
|
-
- Document symbols
|