ruby-lsp 0.23.10 → 0.23.13
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 +2 -2
- data/VERSION +1 -1
- data/exe/ruby-lsp-launcher +12 -11
- data/lib/rubocop/cop/ruby_lsp/use_language_server_aliases.rb +1 -1
- data/lib/rubocop/cop/ruby_lsp/use_register_with_handler_method.rb +3 -5
- data/lib/ruby_indexer/lib/ruby_indexer/configuration.rb +81 -115
- data/lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb +117 -166
- data/lib/ruby_indexer/lib/ruby_indexer/enhancement.rb +9 -7
- data/lib/ruby_indexer/lib/ruby_indexer/entry.rb +89 -201
- data/lib/ruby_indexer/lib/ruby_indexer/index.rb +63 -192
- data/lib/ruby_indexer/lib/ruby_indexer/location.rb +4 -27
- data/lib/ruby_indexer/lib/ruby_indexer/prefix_tree.rb +14 -16
- data/lib/ruby_indexer/lib/ruby_indexer/rbs_indexer.rb +22 -45
- data/lib/ruby_indexer/lib/ruby_indexer/reference_finder.rb +42 -60
- data/lib/ruby_indexer/lib/ruby_indexer/uri.rb +9 -16
- data/lib/ruby_indexer/lib/ruby_indexer/visibility_scope.rb +5 -9
- data/lib/ruby_indexer/test/classes_and_modules_test.rb +75 -0
- data/lib/ruby_indexer/test/configuration_test.rb +42 -3
- data/lib/ruby_indexer/test/index_test.rb +21 -0
- data/lib/ruby_indexer/test/method_test.rb +28 -2
- data/lib/ruby_indexer/test/rbs_indexer_test.rb +1 -1
- data/lib/ruby_lsp/addon.rb +44 -71
- data/lib/ruby_lsp/base_server.rb +31 -33
- data/lib/ruby_lsp/client_capabilities.rb +10 -12
- data/lib/ruby_lsp/document.rb +34 -45
- data/lib/ruby_lsp/erb_document.rb +24 -36
- data/lib/ruby_lsp/global_state.rb +51 -56
- data/lib/ruby_lsp/internal.rb +6 -0
- data/lib/ruby_lsp/listeners/code_lens.rb +81 -88
- data/lib/ruby_lsp/listeners/completion.rb +36 -55
- data/lib/ruby_lsp/listeners/definition.rb +37 -51
- data/lib/ruby_lsp/listeners/document_highlight.rb +123 -150
- data/lib/ruby_lsp/listeners/document_link.rb +43 -62
- data/lib/ruby_lsp/listeners/document_symbol.rb +35 -49
- data/lib/ruby_lsp/listeners/folding_ranges.rb +32 -39
- data/lib/ruby_lsp/listeners/hover.rb +81 -100
- data/lib/ruby_lsp/listeners/inlay_hints.rb +4 -11
- data/lib/ruby_lsp/listeners/semantic_highlighting.rb +42 -51
- data/lib/ruby_lsp/listeners/signature_help.rb +6 -25
- data/lib/ruby_lsp/listeners/spec_style.rb +155 -0
- data/lib/ruby_lsp/listeners/test_discovery.rb +89 -0
- data/lib/ruby_lsp/listeners/test_style.rb +236 -0
- data/lib/ruby_lsp/node_context.rb +12 -39
- data/lib/ruby_lsp/rbs_document.rb +8 -6
- data/lib/ruby_lsp/requests/code_action_resolve.rb +10 -10
- data/lib/ruby_lsp/requests/code_actions.rb +14 -26
- data/lib/ruby_lsp/requests/code_lens.rb +6 -17
- data/lib/ruby_lsp/requests/completion.rb +7 -20
- data/lib/ruby_lsp/requests/completion_resolve.rb +5 -5
- data/lib/ruby_lsp/requests/definition.rb +8 -17
- data/lib/ruby_lsp/requests/diagnostics.rb +8 -11
- data/lib/ruby_lsp/requests/discover_tests.rb +75 -0
- data/lib/ruby_lsp/requests/document_highlight.rb +5 -15
- data/lib/ruby_lsp/requests/document_link.rb +6 -17
- data/lib/ruby_lsp/requests/document_symbol.rb +5 -8
- data/lib/ruby_lsp/requests/folding_ranges.rb +7 -15
- data/lib/ruby_lsp/requests/formatting.rb +6 -9
- data/lib/ruby_lsp/requests/go_to_relevant_file.rb +87 -0
- data/lib/ruby_lsp/requests/hover.rb +8 -18
- data/lib/ruby_lsp/requests/inlay_hints.rb +6 -17
- data/lib/ruby_lsp/requests/on_type_formatting.rb +28 -38
- data/lib/ruby_lsp/requests/prepare_rename.rb +4 -9
- data/lib/ruby_lsp/requests/prepare_type_hierarchy.rb +4 -13
- data/lib/ruby_lsp/requests/range_formatting.rb +5 -6
- data/lib/ruby_lsp/requests/references.rb +6 -36
- data/lib/ruby_lsp/requests/rename.rb +11 -37
- data/lib/ruby_lsp/requests/request.rb +7 -19
- data/lib/ruby_lsp/requests/selection_ranges.rb +5 -5
- data/lib/ruby_lsp/requests/semantic_highlighting.rb +12 -31
- data/lib/ruby_lsp/requests/show_syntax_tree.rb +5 -6
- data/lib/ruby_lsp/requests/signature_help.rb +8 -26
- data/lib/ruby_lsp/requests/support/annotation.rb +4 -10
- data/lib/ruby_lsp/requests/support/common.rb +13 -48
- data/lib/ruby_lsp/requests/support/rubocop_diagnostic.rb +27 -35
- data/lib/ruby_lsp/requests/support/rubocop_formatter.rb +9 -12
- data/lib/ruby_lsp/requests/support/rubocop_runner.rb +22 -34
- data/lib/ruby_lsp/requests/support/selection_range.rb +1 -3
- data/lib/ruby_lsp/requests/support/sorbet.rb +29 -38
- data/lib/ruby_lsp/requests/support/source_uri.rb +16 -30
- data/lib/ruby_lsp/requests/support/syntax_tree_formatter.rb +12 -19
- data/lib/ruby_lsp/requests/support/test_item.rb +55 -0
- data/lib/ruby_lsp/requests/type_hierarchy_supertypes.rb +5 -6
- data/lib/ruby_lsp/requests/workspace_symbol.rb +4 -4
- data/lib/ruby_lsp/response_builders/collection_response_builder.rb +5 -5
- data/lib/ruby_lsp/response_builders/document_symbol.rb +10 -16
- data/lib/ruby_lsp/response_builders/hover.rb +10 -13
- data/lib/ruby_lsp/response_builders/response_builder.rb +1 -1
- data/lib/ruby_lsp/response_builders/semantic_highlighting.rb +59 -87
- data/lib/ruby_lsp/response_builders/signature_help.rb +5 -6
- data/lib/ruby_lsp/response_builders/test_collection.rb +34 -0
- data/lib/ruby_lsp/ruby_document.rb +22 -60
- data/lib/ruby_lsp/ruby_lsp_reporter_plugin.rb +109 -0
- data/lib/ruby_lsp/scope.rb +7 -11
- data/lib/ruby_lsp/server.rb +177 -72
- data/lib/ruby_lsp/setup_bundler.rb +61 -59
- data/lib/ruby_lsp/static_docs.rb +4 -7
- data/lib/ruby_lsp/store.rb +21 -40
- data/lib/ruby_lsp/test_helper.rb +3 -12
- data/lib/ruby_lsp/test_reporter.rb +207 -0
- data/lib/ruby_lsp/test_unit_test_runner.rb +98 -0
- data/lib/ruby_lsp/type_inferrer.rb +9 -13
- data/lib/ruby_lsp/utils.rb +37 -81
- metadata +13 -3
@@ -9,12 +9,8 @@ module RubyLsp
|
|
9
9
|
# request](https://microsoft.github.io/language-server-protocol/specification#textDocument_signatureHelp) displays
|
10
10
|
# information about the parameters of a method as you type an invocation.
|
11
11
|
class SignatureHelp < Request
|
12
|
-
extend T::Sig
|
13
|
-
|
14
12
|
class << self
|
15
|
-
|
16
|
-
|
17
|
-
sig { returns(Interface::SignatureHelpOptions) }
|
13
|
+
#: -> Interface::SignatureHelpOptions
|
18
14
|
def provider
|
19
15
|
# Identifier characters are automatically included, such as A-Z, a-z, 0-9, _, * or :
|
20
16
|
Interface::SignatureHelpOptions.new(
|
@@ -23,16 +19,7 @@ module RubyLsp
|
|
23
19
|
end
|
24
20
|
end
|
25
21
|
|
26
|
-
|
27
|
-
params(
|
28
|
-
document: T.any(RubyDocument, ERBDocument),
|
29
|
-
global_state: GlobalState,
|
30
|
-
position: T::Hash[Symbol, T.untyped],
|
31
|
-
context: T.nilable(T::Hash[Symbol, T.untyped]),
|
32
|
-
dispatcher: Prism::Dispatcher,
|
33
|
-
sorbet_level: RubyDocument::SorbetLevel,
|
34
|
-
).void
|
35
|
-
end
|
22
|
+
#: ((RubyDocument | ERBDocument) document, GlobalState global_state, Hash[Symbol, untyped] position, Hash[Symbol, untyped]? context, Prism::Dispatcher dispatcher, RubyDocument::SorbetLevel sorbet_level) -> void
|
36
23
|
def initialize(document, global_state, position, context, dispatcher, sorbet_level) # rubocop:disable Metrics/ParameterLists
|
37
24
|
super()
|
38
25
|
|
@@ -48,13 +35,14 @@ module RubyLsp
|
|
48
35
|
|
49
36
|
target = adjust_for_nested_target(node_context.node, node_context.parent, position)
|
50
37
|
|
51
|
-
@target =
|
38
|
+
@target = target #: Prism::Node?
|
52
39
|
@dispatcher = dispatcher
|
53
|
-
@response_builder =
|
40
|
+
@response_builder = ResponseBuilders::SignatureHelp.new #: ResponseBuilders::SignatureHelp
|
54
41
|
Listeners::SignatureHelp.new(@response_builder, global_state, node_context, dispatcher, sorbet_level)
|
55
42
|
end
|
56
43
|
|
57
|
-
|
44
|
+
# @override
|
45
|
+
#: -> Interface::SignatureHelp?
|
58
46
|
def perform
|
59
47
|
return unless @target
|
60
48
|
|
@@ -70,13 +58,7 @@ module RubyLsp
|
|
70
58
|
# foo(another_method_call)
|
71
59
|
#
|
72
60
|
# In that case, we want to provide signature help for `foo` and not `another_method_call`.
|
73
|
-
|
74
|
-
params(
|
75
|
-
target: T.nilable(Prism::Node),
|
76
|
-
parent: T.nilable(Prism::Node),
|
77
|
-
position: T::Hash[Symbol, T.untyped],
|
78
|
-
).returns(T.nilable(Prism::Node))
|
79
|
-
end
|
61
|
+
#: (Prism::Node? target, Prism::Node? parent, Hash[Symbol, untyped] position) -> Prism::Node?
|
80
62
|
def adjust_for_nested_target(target, parent, position)
|
81
63
|
# If the parent node is not a method call, then make no adjustments
|
82
64
|
return target unless parent.is_a?(Prism::CallNode)
|
@@ -92,7 +74,7 @@ module RubyLsp
|
|
92
74
|
arguments.nil? || !node_covers?(arguments, position) ? parent : target
|
93
75
|
end
|
94
76
|
|
95
|
-
|
77
|
+
#: (Prism::Node node, Hash[Symbol, untyped] position) -> bool
|
96
78
|
def node_covers?(node, position)
|
97
79
|
location = node.location
|
98
80
|
start_line = location.start_line - 1
|
@@ -5,32 +5,26 @@ module RubyLsp
|
|
5
5
|
module Requests
|
6
6
|
module Support
|
7
7
|
class Annotation
|
8
|
-
|
9
|
-
sig do
|
10
|
-
params(
|
11
|
-
arity: T.any(Integer, T::Range[Integer]),
|
12
|
-
receiver: T::Boolean,
|
13
|
-
).void
|
14
|
-
end
|
8
|
+
#: (arity: (Integer | T::Range[Integer]), ?receiver: bool) -> void
|
15
9
|
def initialize(arity:, receiver: false)
|
16
10
|
@arity = arity
|
17
11
|
@receiver = receiver
|
18
12
|
end
|
19
13
|
|
20
|
-
|
14
|
+
#: (Prism::CallNode node) -> bool
|
21
15
|
def match?(node)
|
22
16
|
receiver_matches?(node) && arity_matches?(node)
|
23
17
|
end
|
24
18
|
|
25
19
|
private
|
26
20
|
|
27
|
-
|
21
|
+
#: (Prism::CallNode node) -> bool
|
28
22
|
def receiver_matches?(node)
|
29
23
|
node_receiver = node.receiver
|
30
24
|
(node_receiver && @receiver && node_receiver.location.slice == "T") || (!node_receiver && !@receiver)
|
31
25
|
end
|
32
26
|
|
33
|
-
|
27
|
+
#: (Prism::CallNode node) -> bool
|
34
28
|
def arity_matches?(node)
|
35
29
|
node_arity = node.arguments&.arguments&.size || 0
|
36
30
|
|
@@ -8,12 +8,11 @@ module RubyLsp
|
|
8
8
|
# WARNING: Methods in this class may be used by Ruby LSP add-ons such as
|
9
9
|
# https://github.com/Shopify/ruby-lsp-rails, or add-ons by created by developers outside of Shopify, so be
|
10
10
|
# cautious of changing anything.
|
11
|
-
extend T::Sig
|
12
11
|
extend T::Helpers
|
13
12
|
|
14
13
|
requires_ancestor { Kernel }
|
15
14
|
|
16
|
-
|
15
|
+
#: (Prism::Node node) -> Interface::Range
|
17
16
|
def range_from_node(node)
|
18
17
|
loc = node.location
|
19
18
|
|
@@ -26,7 +25,7 @@ module RubyLsp
|
|
26
25
|
)
|
27
26
|
end
|
28
27
|
|
29
|
-
|
28
|
+
#: ((Prism::Location | RubyIndexer::Location) location) -> Interface::Range
|
30
29
|
def range_from_location(location)
|
31
30
|
Interface::Range.new(
|
32
31
|
start: Interface::Position.new(
|
@@ -37,15 +36,7 @@ module RubyLsp
|
|
37
36
|
)
|
38
37
|
end
|
39
38
|
|
40
|
-
|
41
|
-
params(
|
42
|
-
node: Prism::Node,
|
43
|
-
title: String,
|
44
|
-
command_name: String,
|
45
|
-
arguments: T.nilable(T::Array[T.untyped]),
|
46
|
-
data: T.nilable(T::Hash[T.untyped, T.untyped]),
|
47
|
-
).returns(Interface::CodeLens)
|
48
|
-
end
|
39
|
+
#: (Prism::Node node, title: String, command_name: String, arguments: Array[untyped]?, data: Hash[untyped, untyped]?) -> Interface::CodeLens
|
49
40
|
def create_code_lens(node, title:, command_name:, arguments:, data:)
|
50
41
|
range = range_from_node(node)
|
51
42
|
|
@@ -60,26 +51,20 @@ module RubyLsp
|
|
60
51
|
)
|
61
52
|
end
|
62
53
|
|
63
|
-
|
54
|
+
#: (String file_path) -> bool?
|
64
55
|
def not_in_dependencies?(file_path)
|
65
56
|
BUNDLE_PATH &&
|
66
57
|
!file_path.start_with?(T.must(BUNDLE_PATH)) &&
|
67
58
|
!file_path.start_with?(RbConfig::CONFIG["rubylibdir"])
|
68
59
|
end
|
69
60
|
|
70
|
-
|
61
|
+
#: (Prism::CallNode node) -> bool
|
71
62
|
def self_receiver?(node)
|
72
63
|
receiver = node.receiver
|
73
64
|
receiver.nil? || receiver.is_a?(Prism::SelfNode)
|
74
65
|
end
|
75
66
|
|
76
|
-
|
77
|
-
params(
|
78
|
-
title: String,
|
79
|
-
entries: T.any(T::Array[RubyIndexer::Entry], RubyIndexer::Entry),
|
80
|
-
max_entries: T.nilable(Integer),
|
81
|
-
).returns(T::Hash[Symbol, String])
|
82
|
-
end
|
67
|
+
#: (String title, (Array[RubyIndexer::Entry] | RubyIndexer::Entry) entries, ?Integer? max_entries) -> Hash[Symbol, String]
|
83
68
|
def categorized_markdown_from_index_entries(title, entries, max_entries = nil)
|
84
69
|
markdown_title = "```ruby\n#{title}\n```"
|
85
70
|
definitions = []
|
@@ -112,14 +97,7 @@ module RubyLsp
|
|
112
97
|
}
|
113
98
|
end
|
114
99
|
|
115
|
-
|
116
|
-
params(
|
117
|
-
title: String,
|
118
|
-
entries: T.any(T::Array[RubyIndexer::Entry], RubyIndexer::Entry),
|
119
|
-
max_entries: T.nilable(Integer),
|
120
|
-
extra_links: T.nilable(String),
|
121
|
-
).returns(String)
|
122
|
-
end
|
100
|
+
#: (String title, (Array[RubyIndexer::Entry] | RubyIndexer::Entry) entries, ?Integer? max_entries, ?extra_links: String?) -> String
|
123
101
|
def markdown_from_index_entries(title, entries, max_entries = nil, extra_links: nil)
|
124
102
|
categorized_markdown = categorized_markdown_from_index_entries(title, entries, max_entries)
|
125
103
|
|
@@ -135,20 +113,12 @@ module RubyLsp
|
|
135
113
|
MARKDOWN
|
136
114
|
end
|
137
115
|
|
138
|
-
|
139
|
-
params(
|
140
|
-
node: T.any(
|
141
|
-
Prism::ConstantPathNode,
|
142
|
-
Prism::ConstantReadNode,
|
143
|
-
Prism::ConstantPathTargetNode,
|
144
|
-
),
|
145
|
-
).returns(T.nilable(String))
|
146
|
-
end
|
116
|
+
#: ((Prism::ConstantPathNode | Prism::ConstantReadNode | Prism::ConstantPathTargetNode | Prism::CallNode | Prism::MissingNode) node) -> String?
|
147
117
|
def constant_name(node)
|
148
118
|
RubyIndexer::Index.constant_name(node)
|
149
119
|
end
|
150
120
|
|
151
|
-
|
121
|
+
#: ((Prism::ModuleNode | Prism::ClassNode) node) -> String?
|
152
122
|
def namespace_constant_name(node)
|
153
123
|
path = node.constant_path
|
154
124
|
case path
|
@@ -160,14 +130,9 @@ module RubyLsp
|
|
160
130
|
# Iterates over each part of a constant path, so that we can easily push response items for each section of the
|
161
131
|
# name. For example, for `Foo::Bar::Baz`, this method will invoke the block with `Foo`, then `Bar` and finally
|
162
132
|
# `Baz`.
|
163
|
-
|
164
|
-
params(
|
165
|
-
node: Prism::Node,
|
166
|
-
block: T.proc.params(part: Prism::Node).void,
|
167
|
-
).void
|
168
|
-
end
|
133
|
+
#: (Prism::Node node) { (Prism::Node part) -> void } -> void
|
169
134
|
def each_constant_path_part(node, &block)
|
170
|
-
current =
|
135
|
+
current = node #: Prism::Node?
|
171
136
|
|
172
137
|
while current.is_a?(Prism::ConstantPathNode)
|
173
138
|
block.call(current)
|
@@ -175,7 +140,7 @@ module RubyLsp
|
|
175
140
|
end
|
176
141
|
end
|
177
142
|
|
178
|
-
|
143
|
+
#: (RubyIndexer::Entry entry) -> Integer?
|
179
144
|
def kind_for_entry(entry)
|
180
145
|
case entry
|
181
146
|
when RubyIndexer::Entry::Class
|
@@ -193,7 +158,7 @@ module RubyLsp
|
|
193
158
|
end
|
194
159
|
end
|
195
160
|
|
196
|
-
|
161
|
+
#: (RubyDocument::SorbetLevel sorbet_level) -> bool
|
197
162
|
def sorbet_level_true_or_higher?(sorbet_level)
|
198
163
|
sorbet_level == RubyDocument::SorbetLevel::True || sorbet_level == RubyDocument::SorbetLevel::Strict
|
199
164
|
end
|
@@ -5,40 +5,32 @@ module RubyLsp
|
|
5
5
|
module Requests
|
6
6
|
module Support
|
7
7
|
class RuboCopDiagnostic
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
begin
|
24
|
-
gem("rubocop", ">= 1.64.0")
|
25
|
-
true
|
26
|
-
rescue LoadError
|
27
|
-
false
|
28
|
-
end,
|
29
|
-
T::Boolean,
|
30
|
-
)
|
8
|
+
RUBOCOP_TO_LSP_SEVERITY = {
|
9
|
+
info: Constant::DiagnosticSeverity::HINT,
|
10
|
+
refactor: Constant::DiagnosticSeverity::INFORMATION,
|
11
|
+
convention: Constant::DiagnosticSeverity::INFORMATION,
|
12
|
+
warning: Constant::DiagnosticSeverity::WARNING,
|
13
|
+
error: Constant::DiagnosticSeverity::ERROR,
|
14
|
+
fatal: Constant::DiagnosticSeverity::ERROR,
|
15
|
+
}.freeze #: Hash[Symbol, Integer]
|
16
|
+
|
17
|
+
ENHANCED_DOC_URL = begin
|
18
|
+
gem("rubocop", ">= 1.64.0")
|
19
|
+
true
|
20
|
+
rescue LoadError
|
21
|
+
false
|
22
|
+
end #: bool
|
31
23
|
|
32
24
|
# TODO: avoid passing document once we have alternative ways to get at
|
33
25
|
# encoding and file source
|
34
|
-
|
26
|
+
#: (RubyDocument document, ::RuboCop::Cop::Offense offense, URI::Generic uri) -> void
|
35
27
|
def initialize(document, offense, uri)
|
36
28
|
@document = document
|
37
29
|
@offense = offense
|
38
30
|
@uri = uri
|
39
31
|
end
|
40
32
|
|
41
|
-
|
33
|
+
#: -> Array[Interface::CodeAction]
|
42
34
|
def to_lsp_code_actions
|
43
35
|
code_actions = []
|
44
36
|
|
@@ -48,7 +40,7 @@ module RubyLsp
|
|
48
40
|
code_actions
|
49
41
|
end
|
50
42
|
|
51
|
-
|
43
|
+
#: (::RuboCop::Config config) -> Interface::Diagnostic
|
52
44
|
def to_lsp_diagnostic(config)
|
53
45
|
# highlighted_area contains the begin and end position of the first line
|
54
46
|
# This ensures that multiline offenses don't clutter the editor
|
@@ -78,19 +70,19 @@ module RubyLsp
|
|
78
70
|
|
79
71
|
private
|
80
72
|
|
81
|
-
|
73
|
+
#: -> String
|
82
74
|
def message
|
83
75
|
message = @offense.message
|
84
76
|
message += "\n\nThis offense is not auto-correctable.\n" unless correctable?
|
85
77
|
message
|
86
78
|
end
|
87
79
|
|
88
|
-
|
80
|
+
#: -> Integer?
|
89
81
|
def severity
|
90
82
|
RUBOCOP_TO_LSP_SEVERITY[@offense.severity.name]
|
91
83
|
end
|
92
84
|
|
93
|
-
|
85
|
+
#: (::RuboCop::Config config) -> Interface::CodeDescription?
|
94
86
|
def code_description(config)
|
95
87
|
cop = RuboCopRunner.find_cop_by_name(@offense.cop_name)
|
96
88
|
return unless cop
|
@@ -103,7 +95,7 @@ module RubyLsp
|
|
103
95
|
Interface::CodeDescription.new(href: doc_url) if doc_url
|
104
96
|
end
|
105
97
|
|
106
|
-
|
98
|
+
#: -> Interface::CodeAction
|
107
99
|
def autocorrect_action
|
108
100
|
Interface::CodeAction.new(
|
109
101
|
title: "Autocorrect #{@offense.cop_name}",
|
@@ -123,7 +115,7 @@ module RubyLsp
|
|
123
115
|
)
|
124
116
|
end
|
125
117
|
|
126
|
-
|
118
|
+
#: -> Array[Interface::TextEdit]
|
127
119
|
def offense_replacements
|
128
120
|
@offense.corrector.as_replacements.map do |range, replacement|
|
129
121
|
Interface::TextEdit.new(
|
@@ -136,7 +128,7 @@ module RubyLsp
|
|
136
128
|
end
|
137
129
|
end
|
138
130
|
|
139
|
-
|
131
|
+
#: -> Interface::CodeAction
|
140
132
|
def disable_line_action
|
141
133
|
Interface::CodeAction.new(
|
142
134
|
title: "Disable #{@offense.cop_name} for this line",
|
@@ -155,7 +147,7 @@ module RubyLsp
|
|
155
147
|
)
|
156
148
|
end
|
157
149
|
|
158
|
-
|
150
|
+
#: -> Array[Interface::TextEdit]
|
159
151
|
def line_disable_comment
|
160
152
|
new_text = if @offense.source_line.include?(" # rubocop:disable ")
|
161
153
|
",#{@offense.cop_name}"
|
@@ -178,7 +170,7 @@ module RubyLsp
|
|
178
170
|
[inline_comment]
|
179
171
|
end
|
180
172
|
|
181
|
-
|
173
|
+
#: (String line) -> Integer
|
182
174
|
def length_of_line(line)
|
183
175
|
if @document.encoding == Encoding::UTF_16LE
|
184
176
|
line_length = 0
|
@@ -197,7 +189,7 @@ module RubyLsp
|
|
197
189
|
# When `RuboCop::LSP.enable` is called, contextual autocorrect will not offer itself
|
198
190
|
# as `correctable?` to prevent annoying changes while typing. Instead check if
|
199
191
|
# a corrector is present. If it is, then that means some code transformation can be applied.
|
200
|
-
|
192
|
+
#: -> bool
|
201
193
|
def correctable?
|
202
194
|
!@offense.corrector.nil?
|
203
195
|
end
|
@@ -9,17 +9,17 @@ module RubyLsp
|
|
9
9
|
module Requests
|
10
10
|
module Support
|
11
11
|
class RuboCopFormatter
|
12
|
-
extend T::Sig
|
13
12
|
include Formatter
|
14
13
|
|
15
|
-
|
14
|
+
#: -> void
|
16
15
|
def initialize
|
17
|
-
@diagnostic_runner =
|
16
|
+
@diagnostic_runner = RuboCopRunner.new #: RuboCopRunner
|
18
17
|
# -a is for "--auto-correct" (or "--autocorrect" on newer versions of RuboCop)
|
19
|
-
@format_runner =
|
18
|
+
@format_runner = RuboCopRunner.new("-a") #: RuboCopRunner
|
20
19
|
end
|
21
20
|
|
22
|
-
|
21
|
+
# @override
|
22
|
+
#: (URI::Generic uri, RubyDocument document) -> String?
|
23
23
|
def run_formatting(uri, document)
|
24
24
|
filename = T.must(uri.to_standardized_path || uri.opaque)
|
25
25
|
|
@@ -29,17 +29,14 @@ module RubyLsp
|
|
29
29
|
end
|
30
30
|
|
31
31
|
# RuboCop does not support range formatting
|
32
|
-
|
32
|
+
# @override
|
33
|
+
#: (URI::Generic uri, String source, Integer base_indentation) -> String?
|
33
34
|
def run_range_formatting(uri, source, base_indentation)
|
34
35
|
nil
|
35
36
|
end
|
36
37
|
|
37
|
-
|
38
|
-
|
39
|
-
uri: URI::Generic,
|
40
|
-
document: RubyDocument,
|
41
|
-
).returns(T.nilable(T::Array[Interface::Diagnostic]))
|
42
|
-
end
|
38
|
+
# @override
|
39
|
+
#: (URI::Generic uri, RubyDocument document) -> Array[Interface::Diagnostic]?
|
43
40
|
def run_diagnostic(uri, document)
|
44
41
|
filename = T.must(uri.to_standardized_path || uri.opaque)
|
45
42
|
# Invoke RuboCop with just this file in `paths`
|
@@ -32,15 +32,13 @@ module RubyLsp
|
|
32
32
|
module Requests
|
33
33
|
module Support
|
34
34
|
class InternalRuboCopError < StandardError
|
35
|
-
extend T::Sig
|
36
|
-
|
37
35
|
MESSAGE = <<~EOS
|
38
36
|
An internal error occurred %s.
|
39
37
|
Updating to a newer version of RuboCop may solve this.
|
40
38
|
For more details, run RuboCop on the command line.
|
41
39
|
EOS
|
42
40
|
|
43
|
-
|
41
|
+
#: ((::RuboCop::ErrorWithAnalyzedFileLocation | StandardError) rubocop_error) -> void
|
44
42
|
def initialize(rubocop_error)
|
45
43
|
message = case rubocop_error
|
46
44
|
when ::RuboCop::ErrorWithAnalyzedFileLocation
|
@@ -54,24 +52,19 @@ module RubyLsp
|
|
54
52
|
|
55
53
|
# :nodoc:
|
56
54
|
class RuboCopRunner < ::RuboCop::Runner
|
57
|
-
extend T::Sig
|
58
|
-
|
59
55
|
class ConfigurationError < StandardError; end
|
60
56
|
|
61
|
-
DEFAULT_ARGS =
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
)
|
70
|
-
|
71
|
-
sig { returns(T::Array[::RuboCop::Cop::Offense]) }
|
57
|
+
DEFAULT_ARGS = [
|
58
|
+
"--stderr", # Print any output to stderr so that our stdout does not get polluted
|
59
|
+
"--force-exclusion",
|
60
|
+
"--format",
|
61
|
+
"RuboCop::Formatter::BaseFormatter", # Suppress any output by using the base formatter
|
62
|
+
] #: Array[String]
|
63
|
+
|
64
|
+
#: Array[::RuboCop::Cop::Offense]
|
72
65
|
attr_reader :offenses
|
73
66
|
|
74
|
-
|
67
|
+
#: ::RuboCop::Config
|
75
68
|
attr_reader :config_for_working_directory
|
76
69
|
|
77
70
|
begin
|
@@ -82,24 +75,24 @@ module RubyLsp
|
|
82
75
|
end
|
83
76
|
DEFAULT_ARGS.freeze
|
84
77
|
|
85
|
-
|
78
|
+
#: (*String args) -> void
|
86
79
|
def initialize(*args)
|
87
|
-
@options =
|
88
|
-
@offenses =
|
89
|
-
@errors =
|
90
|
-
@warnings =
|
80
|
+
@options = {} #: Hash[Symbol, untyped]
|
81
|
+
@offenses = [] #: Array[::RuboCop::Cop::Offense]
|
82
|
+
@errors = [] #: Array[String]
|
83
|
+
@warnings = [] #: Array[String]
|
91
84
|
|
92
85
|
args += DEFAULT_ARGS
|
93
86
|
rubocop_options = ::RuboCop::Options.new.parse(args).first
|
94
87
|
|
95
88
|
config_store = ::RuboCop::ConfigStore.new
|
96
89
|
config_store.options_config = rubocop_options[:config] if rubocop_options[:config]
|
97
|
-
@config_for_working_directory =
|
90
|
+
@config_for_working_directory = config_store.for_pwd #: ::RuboCop::Config
|
98
91
|
|
99
92
|
super(rubocop_options, config_store)
|
100
93
|
end
|
101
94
|
|
102
|
-
|
95
|
+
#: (String path, String contents) -> void
|
103
96
|
def run(path, contents)
|
104
97
|
# Clear Runner state between runs since we get a single instance of this class
|
105
98
|
# on every use site.
|
@@ -121,33 +114,28 @@ module RubyLsp
|
|
121
114
|
raise InternalRuboCopError, error
|
122
115
|
end
|
123
116
|
|
124
|
-
|
117
|
+
#: -> String
|
125
118
|
def formatted_source
|
126
119
|
@options[:stdin]
|
127
120
|
end
|
128
121
|
|
129
122
|
class << self
|
130
|
-
|
131
|
-
|
132
|
-
sig { params(cop_name: String).returns(T.nilable(T.class_of(::RuboCop::Cop::Base))) }
|
123
|
+
#: (String cop_name) -> singleton(::RuboCop::Cop::Base)?
|
133
124
|
def find_cop_by_name(cop_name)
|
134
125
|
cop_registry[cop_name]&.first
|
135
126
|
end
|
136
127
|
|
137
128
|
private
|
138
129
|
|
139
|
-
|
130
|
+
#: -> Hash[String, [singleton(::RuboCop::Cop::Base)]]
|
140
131
|
def cop_registry
|
141
|
-
@cop_registry ||=
|
142
|
-
::RuboCop::Cop::Registry.global.to_h,
|
143
|
-
T.nilable(T::Hash[String, [T.class_of(::RuboCop::Cop::Base)]]),
|
144
|
-
)
|
132
|
+
@cop_registry ||= ::RuboCop::Cop::Registry.global.to_h #: Hash[String, [singleton(::RuboCop::Cop::Base)]]?
|
145
133
|
end
|
146
134
|
end
|
147
135
|
|
148
136
|
private
|
149
137
|
|
150
|
-
|
138
|
+
#: (String _file, Array[::RuboCop::Cop::Offense] offenses) -> void
|
151
139
|
def file_finished(_file, offenses)
|
152
140
|
@offenses = offenses
|
153
141
|
end
|
@@ -5,9 +5,7 @@ module RubyLsp
|
|
5
5
|
module Requests
|
6
6
|
module Support
|
7
7
|
class SelectionRange < Interface::SelectionRange
|
8
|
-
|
9
|
-
|
10
|
-
sig { params(position: T::Hash[Symbol, T.untyped]).returns(T::Boolean) }
|
8
|
+
#: (Hash[Symbol, untyped] position) -> bool
|
11
9
|
def cover?(position)
|
12
10
|
start_covered = range.start.line < position[:line] ||
|
13
11
|
(range.start.line == position[:line] && range.start.character <= position[:character])
|
@@ -6,45 +6,36 @@ module RubyLsp
|
|
6
6
|
module Support
|
7
7
|
class Sorbet
|
8
8
|
class << self
|
9
|
-
|
9
|
+
ANNOTATIONS = {
|
10
|
+
abstract!: Annotation.new(arity: 0),
|
11
|
+
absurd: Annotation.new(arity: 1, receiver: true),
|
12
|
+
all: Annotation.new(arity: (2..), receiver: true),
|
13
|
+
any: Annotation.new(arity: (2..), receiver: true),
|
14
|
+
assert_type!: Annotation.new(arity: 2, receiver: true),
|
15
|
+
attached_class: Annotation.new(arity: 0, receiver: true),
|
16
|
+
bind: Annotation.new(arity: 2, receiver: true),
|
17
|
+
cast: Annotation.new(arity: 2, receiver: true),
|
18
|
+
class_of: Annotation.new(arity: 1, receiver: true),
|
19
|
+
enums: Annotation.new(arity: 0),
|
20
|
+
interface!: Annotation.new(arity: 0),
|
21
|
+
let: Annotation.new(arity: 2, receiver: true),
|
22
|
+
mixes_in_class_methods: Annotation.new(arity: 1),
|
23
|
+
must: Annotation.new(arity: 1, receiver: true),
|
24
|
+
must_because: Annotation.new(arity: 1, receiver: true),
|
25
|
+
nilable: Annotation.new(arity: 1, receiver: true),
|
26
|
+
noreturn: Annotation.new(arity: 0, receiver: true),
|
27
|
+
requires_ancestor: Annotation.new(arity: 0),
|
28
|
+
reveal_type: Annotation.new(arity: 1, receiver: true),
|
29
|
+
sealed!: Annotation.new(arity: 0),
|
30
|
+
self_type: Annotation.new(arity: 0, receiver: true),
|
31
|
+
sig: Annotation.new(arity: 0),
|
32
|
+
type_member: Annotation.new(arity: (0..1)),
|
33
|
+
type_template: Annotation.new(arity: 0),
|
34
|
+
unsafe: Annotation.new(arity: 1),
|
35
|
+
untyped: Annotation.new(arity: 0, receiver: true),
|
36
|
+
} #: Hash[Symbol, Annotation]
|
10
37
|
|
11
|
-
|
12
|
-
{
|
13
|
-
abstract!: Annotation.new(arity: 0),
|
14
|
-
absurd: Annotation.new(arity: 1, receiver: true),
|
15
|
-
all: Annotation.new(arity: (2..), receiver: true),
|
16
|
-
any: Annotation.new(arity: (2..), receiver: true),
|
17
|
-
assert_type!: Annotation.new(arity: 2, receiver: true),
|
18
|
-
attached_class: Annotation.new(arity: 0, receiver: true),
|
19
|
-
bind: Annotation.new(arity: 2, receiver: true),
|
20
|
-
cast: Annotation.new(arity: 2, receiver: true),
|
21
|
-
class_of: Annotation.new(arity: 1, receiver: true),
|
22
|
-
enums: Annotation.new(arity: 0),
|
23
|
-
interface!: Annotation.new(arity: 0),
|
24
|
-
let: Annotation.new(arity: 2, receiver: true),
|
25
|
-
mixes_in_class_methods: Annotation.new(arity: 1),
|
26
|
-
must: Annotation.new(arity: 1, receiver: true),
|
27
|
-
must_because: Annotation.new(arity: 1, receiver: true),
|
28
|
-
nilable: Annotation.new(arity: 1, receiver: true),
|
29
|
-
noreturn: Annotation.new(arity: 0, receiver: true),
|
30
|
-
requires_ancestor: Annotation.new(arity: 0),
|
31
|
-
reveal_type: Annotation.new(arity: 1, receiver: true),
|
32
|
-
sealed!: Annotation.new(arity: 0),
|
33
|
-
self_type: Annotation.new(arity: 0, receiver: true),
|
34
|
-
sig: Annotation.new(arity: 0),
|
35
|
-
type_member: Annotation.new(arity: (0..1)),
|
36
|
-
type_template: Annotation.new(arity: 0),
|
37
|
-
unsafe: Annotation.new(arity: 1),
|
38
|
-
untyped: Annotation.new(arity: 0, receiver: true),
|
39
|
-
},
|
40
|
-
T::Hash[Symbol, Annotation],
|
41
|
-
)
|
42
|
-
|
43
|
-
sig do
|
44
|
-
params(
|
45
|
-
node: Prism::CallNode,
|
46
|
-
).returns(T::Boolean)
|
47
|
-
end
|
38
|
+
#: (Prism::CallNode node) -> bool
|
48
39
|
def annotation?(node)
|
49
40
|
!!ANNOTATIONS[node.name]&.match?(node)
|
50
41
|
end
|