ruby-lsp 0.23.16 → 0.23.17
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_indexer/lib/ruby_indexer/declaration_listener.rb +16 -19
- data/lib/ruby_indexer/lib/ruby_indexer/enhancement.rb +0 -3
- data/lib/ruby_indexer/lib/ruby_indexer/entry.rb +9 -19
- data/lib/ruby_indexer/lib/ruby_indexer/index.rb +32 -68
- data/lib/ruby_indexer/lib/ruby_indexer/rbs_indexer.rb +1 -10
- data/lib/ruby_indexer/lib/ruby_indexer/visibility_scope.rb +4 -4
- data/lib/ruby_indexer/test/index_test.rb +7 -0
- data/lib/ruby_indexer/test/method_test.rb +7 -7
- data/lib/ruby_indexer/test/rbs_indexer_test.rb +4 -3
- data/lib/ruby_indexer/test/test_case.rb +7 -1
- data/lib/ruby_lsp/document.rb +1 -9
- data/lib/ruby_lsp/erb_document.rb +2 -2
- data/lib/ruby_lsp/listeners/completion.rb +8 -8
- data/lib/ruby_lsp/listeners/definition.rb +7 -7
- data/lib/ruby_lsp/listeners/document_link.rb +7 -10
- data/lib/ruby_lsp/listeners/hover.rb +10 -9
- data/lib/ruby_lsp/listeners/signature_help.rb +2 -2
- data/lib/ruby_lsp/listeners/spec_style.rb +11 -11
- data/lib/ruby_lsp/listeners/test_style.rb +10 -5
- data/lib/ruby_lsp/rbs_document.rb +2 -2
- data/lib/ruby_lsp/requests/code_action_resolve.rb +44 -39
- data/lib/ruby_lsp/requests/code_lens.rb +15 -3
- data/lib/ruby_lsp/requests/completion.rb +2 -2
- data/lib/ruby_lsp/requests/definition.rb +3 -4
- data/lib/ruby_lsp/requests/document_highlight.rb +1 -1
- data/lib/ruby_lsp/requests/document_link.rb +1 -1
- data/lib/ruby_lsp/requests/folding_ranges.rb +1 -1
- data/lib/ruby_lsp/requests/go_to_relevant_file.rb +0 -2
- data/lib/ruby_lsp/requests/hover.rb +1 -1
- data/lib/ruby_lsp/requests/inlay_hints.rb +1 -1
- data/lib/ruby_lsp/requests/references.rb +1 -16
- data/lib/ruby_lsp/requests/rename.rb +1 -4
- data/lib/ruby_lsp/requests/request.rb +2 -1
- data/lib/ruby_lsp/requests/semantic_highlighting.rb +1 -1
- data/lib/ruby_lsp/requests/signature_help.rb +1 -1
- data/lib/ruby_lsp/requests/support/annotation.rb +1 -1
- data/lib/ruby_lsp/requests/support/common.rb +0 -5
- data/lib/ruby_lsp/requests/support/test_item.rb +6 -0
- data/lib/ruby_lsp/response_builders/document_symbol.rb +1 -1
- data/lib/ruby_lsp/response_builders/test_collection.rb +37 -0
- data/lib/ruby_lsp/ruby_document.rb +2 -32
- data/lib/ruby_lsp/server.rb +36 -21
- data/lib/ruby_lsp/store.rb +6 -6
- data/lib/ruby_lsp/test_reporters/lsp_reporter.rb +31 -4
- data/lib/ruby_lsp/utils.rb +43 -0
- metadata +1 -1
@@ -25,7 +25,7 @@ module RubyLsp
|
|
25
25
|
code_units_cache: document.code_units_cache,
|
26
26
|
)
|
27
27
|
|
28
|
-
@response_builder = ResponseBuilders::CollectionResponseBuilder
|
28
|
+
@response_builder = ResponseBuilders::CollectionResponseBuilder
|
29
29
|
.new #: ResponseBuilders::CollectionResponseBuilder[Interface::DocumentHighlight]
|
30
30
|
Listeners::DocumentHighlight.new(
|
31
31
|
@response_builder,
|
@@ -19,7 +19,7 @@ module RubyLsp
|
|
19
19
|
#: (URI::Generic uri, Array[Prism::Comment] comments, Prism::Dispatcher dispatcher) -> void
|
20
20
|
def initialize(uri, comments, dispatcher)
|
21
21
|
super()
|
22
|
-
@response_builder = ResponseBuilders::CollectionResponseBuilder
|
22
|
+
@response_builder = ResponseBuilders::CollectionResponseBuilder
|
23
23
|
.new #: ResponseBuilders::CollectionResponseBuilder[Interface::DocumentLink]
|
24
24
|
Listeners::DocumentLink.new(@response_builder, uri, comments, dispatcher)
|
25
25
|
end
|
@@ -18,7 +18,7 @@ module RubyLsp
|
|
18
18
|
#: (Array[Prism::Comment] comments, Prism::Dispatcher dispatcher) -> void
|
19
19
|
def initialize(comments, dispatcher)
|
20
20
|
super()
|
21
|
-
@response_builder = ResponseBuilders::CollectionResponseBuilder
|
21
|
+
@response_builder = ResponseBuilders::CollectionResponseBuilder
|
22
22
|
.new #: ResponseBuilders::CollectionResponseBuilder[Interface::FoldingRange]
|
23
23
|
@listener = Listeners::FoldingRanges.new(@response_builder, comments, dispatcher) #: Listeners::FoldingRanges
|
24
24
|
end
|
@@ -8,8 +8,6 @@ module RubyLsp
|
|
8
8
|
# that navigates to the relevant file for the current document.
|
9
9
|
# Currently, it supports source code file <> test file navigation.
|
10
10
|
class GoToRelevantFile < Request
|
11
|
-
extend T::Sig
|
12
|
-
|
13
11
|
TEST_KEYWORDS = ["test", "spec", "integration_test"]
|
14
12
|
|
15
13
|
TEST_PREFIX_PATTERN = /^(#{TEST_KEYWORDS.join("_|")}_)/
|
@@ -19,7 +19,7 @@ module RubyLsp
|
|
19
19
|
|
20
20
|
ResponseType = type_member { { fixed: T.nilable(Interface::Hover) } }
|
21
21
|
|
22
|
-
#: ((RubyDocument | ERBDocument) document, GlobalState global_state, Hash[Symbol, untyped] position, Prism::Dispatcher dispatcher,
|
22
|
+
#: ((RubyDocument | ERBDocument) document, GlobalState global_state, Hash[Symbol, untyped] position, Prism::Dispatcher dispatcher, SorbetLevel sorbet_level) -> void
|
23
23
|
def initialize(document, global_state, position, dispatcher, sorbet_level)
|
24
24
|
super()
|
25
25
|
|
@@ -20,7 +20,7 @@ module RubyLsp
|
|
20
20
|
def initialize(document, hints_configuration, dispatcher)
|
21
21
|
super()
|
22
22
|
|
23
|
-
@response_builder = ResponseBuilders::CollectionResponseBuilder
|
23
|
+
@response_builder = ResponseBuilders::CollectionResponseBuilder
|
24
24
|
.new #: ResponseBuilders::CollectionResponseBuilder[Interface::InlayHint]
|
25
25
|
Listeners::InlayHints.new(@response_builder, hints_configuration, dispatcher)
|
26
26
|
end
|
@@ -55,22 +55,7 @@ module RubyLsp
|
|
55
55
|
)
|
56
56
|
end
|
57
57
|
|
58
|
-
target =
|
59
|
-
target,
|
60
|
-
T.any(
|
61
|
-
Prism::ConstantReadNode,
|
62
|
-
Prism::ConstantPathNode,
|
63
|
-
Prism::ConstantPathTargetNode,
|
64
|
-
Prism::InstanceVariableAndWriteNode,
|
65
|
-
Prism::InstanceVariableOperatorWriteNode,
|
66
|
-
Prism::InstanceVariableOrWriteNode,
|
67
|
-
Prism::InstanceVariableReadNode,
|
68
|
-
Prism::InstanceVariableTargetNode,
|
69
|
-
Prism::InstanceVariableWriteNode,
|
70
|
-
Prism::CallNode,
|
71
|
-
Prism::DefNode,
|
72
|
-
),
|
73
|
-
)
|
58
|
+
target = target #: as Prism::ConstantReadNode | Prism::ConstantPathNode | Prism::ConstantPathTargetNode | Prism::InstanceVariableAndWriteNode | Prism::InstanceVariableOperatorWriteNode | Prism::InstanceVariableOrWriteNode | Prism::InstanceVariableReadNode | Prism::InstanceVariableTargetNode | Prism::InstanceVariableWriteNode | Prism::CallNode | Prism::DefNode, # rubocop:disable Layout/LineLength
|
74
59
|
|
75
60
|
reference_target = create_reference_target(target, node_context)
|
76
61
|
return @locations unless reference_target
|
@@ -51,10 +51,7 @@ module RubyLsp
|
|
51
51
|
)
|
52
52
|
end
|
53
53
|
|
54
|
-
target =
|
55
|
-
target,
|
56
|
-
T.any(Prism::ConstantReadNode, Prism::ConstantPathNode, Prism::ConstantPathTargetNode),
|
57
|
-
)
|
54
|
+
target = target #: as Prism::ConstantReadNode | Prism::ConstantPathNode | Prism::ConstantPathTargetNode
|
58
55
|
|
59
56
|
name = RubyIndexer::Index.constant_name(target)
|
60
57
|
return unless name
|
@@ -60,7 +60,8 @@ module RubyLsp
|
|
60
60
|
return target unless parent.is_a?(Prism::ConstantPathNode)
|
61
61
|
|
62
62
|
target = parent #: Prism::Node
|
63
|
-
parent =
|
63
|
+
parent = target #: as Prism::ConstantPathNode
|
64
|
+
.parent #: Prism::Node?
|
64
65
|
|
65
66
|
while parent && cover?(parent.location, position)
|
66
67
|
target = parent
|
@@ -74,7 +74,7 @@ module RubyLsp
|
|
74
74
|
@result_id = 0 #: Integer
|
75
75
|
@mutex = Mutex.new #: Mutex
|
76
76
|
|
77
|
-
#: (GlobalState global_state, Prism::Dispatcher dispatcher, (RubyDocument | ERBDocument) document, String? previous_result_id, ?range:
|
77
|
+
#: (GlobalState global_state, Prism::Dispatcher dispatcher, (RubyDocument | ERBDocument) document, String? previous_result_id, ?range: Range[Integer]?) -> void
|
78
78
|
def initialize(global_state, dispatcher, document, previous_result_id, range: nil)
|
79
79
|
super()
|
80
80
|
|
@@ -19,7 +19,7 @@ module RubyLsp
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
#: ((RubyDocument | ERBDocument) document, GlobalState global_state, Hash[Symbol, untyped] position, Hash[Symbol, untyped]? context, Prism::Dispatcher dispatcher,
|
22
|
+
#: ((RubyDocument | ERBDocument) document, GlobalState global_state, Hash[Symbol, untyped] position, Hash[Symbol, untyped]? context, Prism::Dispatcher dispatcher, SorbetLevel sorbet_level) -> void
|
23
23
|
def initialize(document, global_state, position, context, dispatcher, sorbet_level) # rubocop:disable Metrics/ParameterLists
|
24
24
|
super()
|
25
25
|
|
@@ -5,7 +5,7 @@ module RubyLsp
|
|
5
5
|
module Requests
|
6
6
|
module Support
|
7
7
|
class Annotation
|
8
|
-
#: (arity: (Integer |
|
8
|
+
#: (arity: (Integer | Range[Integer]), ?receiver: bool) -> void
|
9
9
|
def initialize(arity:, receiver: false)
|
10
10
|
@arity = arity
|
11
11
|
@receiver = receiver
|
@@ -159,11 +159,6 @@ module RubyLsp
|
|
159
159
|
Constant::SymbolKind::FIELD
|
160
160
|
end
|
161
161
|
end
|
162
|
-
|
163
|
-
#: (RubyDocument::SorbetLevel sorbet_level) -> bool
|
164
|
-
def sorbet_level_true_or_higher?(sorbet_level)
|
165
|
-
sorbet_level == RubyDocument::SorbetLevel::True || sorbet_level == RubyDocument::SorbetLevel::Strict
|
166
|
-
end
|
167
162
|
end
|
168
163
|
end
|
169
164
|
end
|
@@ -13,6 +13,12 @@ module RubyLsp
|
|
13
13
|
#: String
|
14
14
|
attr_reader :id, :label
|
15
15
|
|
16
|
+
#: URI::Generic
|
17
|
+
attr_reader :uri
|
18
|
+
|
19
|
+
#: Interface::Range
|
20
|
+
attr_reader :range
|
21
|
+
|
16
22
|
#: (String id, String label, URI::Generic uri, Interface::Range range, Symbol framework) -> void
|
17
23
|
def initialize(id, label, uri, range, framework:)
|
18
24
|
@id = id
|
@@ -8,10 +8,14 @@ module RubyLsp
|
|
8
8
|
|
9
9
|
ResponseType = type_member { { fixed: Requests::Support::TestItem } }
|
10
10
|
|
11
|
+
#: Array[Interface::CodeLens]
|
12
|
+
attr_reader :code_lens
|
13
|
+
|
11
14
|
#: -> void
|
12
15
|
def initialize
|
13
16
|
super
|
14
17
|
@items = {} #: Hash[String, ResponseType]
|
18
|
+
@code_lens = [] #: Array[Interface::CodeLens]
|
15
19
|
end
|
16
20
|
|
17
21
|
#: (ResponseType item) -> void
|
@@ -19,6 +23,39 @@ module RubyLsp
|
|
19
23
|
@items[item.id] = item
|
20
24
|
end
|
21
25
|
|
26
|
+
#: (ResponseType item) -> void
|
27
|
+
def add_code_lens(item)
|
28
|
+
range = item.range
|
29
|
+
arguments = [item.uri.to_standardized_path, item.id]
|
30
|
+
|
31
|
+
@code_lens << Interface::CodeLens.new(
|
32
|
+
range: range,
|
33
|
+
command: Interface::Command.new(
|
34
|
+
title: "▶ Run",
|
35
|
+
command: "rubyLsp.runTest",
|
36
|
+
arguments: arguments,
|
37
|
+
),
|
38
|
+
)
|
39
|
+
|
40
|
+
@code_lens << Interface::CodeLens.new(
|
41
|
+
range: range,
|
42
|
+
command: Interface::Command.new(
|
43
|
+
title: "▶ Run In Terminal",
|
44
|
+
command: "rubyLsp.runTestInTerminal",
|
45
|
+
arguments: arguments,
|
46
|
+
),
|
47
|
+
)
|
48
|
+
|
49
|
+
@code_lens << Interface::CodeLens.new(
|
50
|
+
range: range,
|
51
|
+
command: Interface::Command.new(
|
52
|
+
title: "⚙ Debug",
|
53
|
+
command: "rubyLsp.debugTest",
|
54
|
+
arguments: arguments,
|
55
|
+
),
|
56
|
+
)
|
57
|
+
end
|
58
|
+
|
22
59
|
#: (String id) -> ResponseType?
|
23
60
|
def [](id)
|
24
61
|
@items[id]
|
@@ -23,16 +23,6 @@ module RubyLsp
|
|
23
23
|
:private_class_method,
|
24
24
|
].freeze
|
25
25
|
|
26
|
-
class SorbetLevel < T::Enum
|
27
|
-
enums do
|
28
|
-
None = new("none")
|
29
|
-
Ignore = new("ignore")
|
30
|
-
False = new("false")
|
31
|
-
True = new("true")
|
32
|
-
Strict = new("strict")
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
26
|
class << self
|
37
27
|
#: (Prism::Node node, Integer char_position, code_units_cache: (^(Integer arg0) -> Integer | Prism::CodeUnitsCache), ?node_types: Array[singleton(Prism::Node)]) -> NodeContext
|
38
28
|
def locate(node, char_position, code_units_cache:, node_types: [])
|
@@ -154,29 +144,9 @@ module RubyLsp
|
|
154
144
|
end
|
155
145
|
|
156
146
|
# @override
|
157
|
-
#: ->
|
147
|
+
#: -> Symbol
|
158
148
|
def language_id
|
159
|
-
|
160
|
-
end
|
161
|
-
|
162
|
-
#: -> SorbetLevel
|
163
|
-
def sorbet_level
|
164
|
-
sigil = parse_result.magic_comments.find do |comment|
|
165
|
-
comment.key == "typed"
|
166
|
-
end&.value
|
167
|
-
|
168
|
-
case sigil
|
169
|
-
when "ignore"
|
170
|
-
SorbetLevel::Ignore
|
171
|
-
when "false"
|
172
|
-
SorbetLevel::False
|
173
|
-
when "true"
|
174
|
-
SorbetLevel::True
|
175
|
-
when "strict", "strong"
|
176
|
-
SorbetLevel::Strict
|
177
|
-
else
|
178
|
-
SorbetLevel::None
|
179
|
-
end
|
149
|
+
:ruby
|
180
150
|
end
|
181
151
|
|
182
152
|
#: (Hash[Symbol, untyped] range, ?node_types: Array[singleton(Prism::Node)]) -> Prism::Node?
|
data/lib/ruby_lsp/server.rb
CHANGED
@@ -242,7 +242,9 @@ module RubyLsp
|
|
242
242
|
|
243
243
|
bundle_env_path = File.join(".ruby-lsp", "bundle_env")
|
244
244
|
bundle_env = if File.exist?(bundle_env_path)
|
245
|
-
env = File.readlines(bundle_env_path).to_h
|
245
|
+
env = File.readlines(bundle_env_path).to_h do |line|
|
246
|
+
line.chomp.split("=", 2) #: as [String, String]
|
247
|
+
end
|
246
248
|
FileUtils.rm(bundle_env_path)
|
247
249
|
env
|
248
250
|
end
|
@@ -385,11 +387,11 @@ module RubyLsp
|
|
385
387
|
text_document = message.dig(:params, :textDocument)
|
386
388
|
language_id = case text_document[:languageId]
|
387
389
|
when "erb", "eruby"
|
388
|
-
|
390
|
+
:erb
|
389
391
|
when "rbs"
|
390
|
-
|
392
|
+
:rbs
|
391
393
|
else
|
392
|
-
|
394
|
+
:ruby
|
393
395
|
end
|
394
396
|
|
395
397
|
document = @store.set(
|
@@ -489,13 +491,16 @@ module RubyLsp
|
|
489
491
|
folding_range = Requests::FoldingRanges.new(parse_result.comments, dispatcher)
|
490
492
|
document_symbol = Requests::DocumentSymbol.new(uri, dispatcher)
|
491
493
|
document_link = Requests::DocumentLink.new(uri, parse_result.comments, dispatcher)
|
492
|
-
code_lens = Requests::CodeLens.new(@global_state, uri, dispatcher)
|
493
494
|
inlay_hint = Requests::InlayHints.new(
|
494
495
|
document,
|
495
496
|
@store.features_configuration.dig(:inlayHint), #: as !nil
|
496
497
|
dispatcher,
|
497
498
|
)
|
498
499
|
|
500
|
+
# The code lens listener requires the index to be populated, so the DeclarationListener must be inserted first in
|
501
|
+
# the dispatcher's state
|
502
|
+
code_lens = nil #: Requests::CodeLens?
|
503
|
+
|
499
504
|
if document.is_a?(RubyDocument) && document.should_index?
|
500
505
|
# Re-index the file as it is modified. This mode of indexing updates entries only. Require path trees are only
|
501
506
|
# updated on save
|
@@ -505,10 +510,12 @@ module RubyLsp
|
|
505
510
|
@global_state.index.handle_change(uri) do |index|
|
506
511
|
index.delete(uri, skip_require_paths_tree: true)
|
507
512
|
RubyIndexer::DeclarationListener.new(index, dispatcher, parse_result, uri, collect_comments: true)
|
513
|
+
code_lens = Requests::CodeLens.new(@global_state, uri, dispatcher)
|
508
514
|
dispatcher.dispatch(parse_result.value)
|
509
515
|
end
|
510
516
|
end
|
511
517
|
else
|
518
|
+
code_lens = Requests::CodeLens.new(@global_state, uri, dispatcher)
|
512
519
|
dispatcher.dispatch(parse_result.value)
|
513
520
|
end
|
514
521
|
|
@@ -517,7 +524,11 @@ module RubyLsp
|
|
517
524
|
document.cache_set("textDocument/foldingRange", folding_range.perform)
|
518
525
|
document.cache_set("textDocument/documentSymbol", document_symbol.perform)
|
519
526
|
document.cache_set("textDocument/documentLink", document_link.perform)
|
520
|
-
document.cache_set(
|
527
|
+
document.cache_set(
|
528
|
+
"textDocument/codeLens",
|
529
|
+
code_lens #: as !nil
|
530
|
+
.perform,
|
531
|
+
)
|
521
532
|
document.cache_set("textDocument/inlayHint", inlay_hint.perform)
|
522
533
|
|
523
534
|
send_message(Result.new(id: message[:id], response: document.cache_get(message[:method])))
|
@@ -672,6 +683,10 @@ module RubyLsp
|
|
672
683
|
"Formatting error: #{error.message}",
|
673
684
|
type: Constant::MessageType::ERROR,
|
674
685
|
))
|
686
|
+
send_message(Notification.window_log_message(
|
687
|
+
"Formatting failed with\r\n: #{error.full_message}",
|
688
|
+
type: Constant::MessageType::ERROR,
|
689
|
+
))
|
675
690
|
send_empty_response(message[:id])
|
676
691
|
end
|
677
692
|
|
@@ -795,12 +810,16 @@ module RubyLsp
|
|
795
810
|
)
|
796
811
|
end
|
797
812
|
|
798
|
-
#: (Document[untyped] document) ->
|
813
|
+
#: (Document[untyped] document) -> SorbetLevel
|
799
814
|
def sorbet_level(document)
|
800
|
-
return
|
801
|
-
return
|
815
|
+
return SorbetLevel.ignore unless document.is_a?(RubyDocument)
|
816
|
+
return SorbetLevel.ignore unless @global_state.has_type_checker
|
817
|
+
|
818
|
+
sigil = document.parse_result.magic_comments.find do |comment|
|
819
|
+
comment.key == "typed"
|
820
|
+
end&.value
|
802
821
|
|
803
|
-
|
822
|
+
SorbetLevel.new(sigil)
|
804
823
|
end
|
805
824
|
|
806
825
|
#: (Hash[Symbol, untyped] message) -> void
|
@@ -871,17 +890,9 @@ module RubyLsp
|
|
871
890
|
end
|
872
891
|
|
873
892
|
result = Requests::CodeActionResolve.new(document, @global_state, params).perform
|
874
|
-
|
875
|
-
|
876
|
-
|
877
|
-
fail_request_and_notify(message[:id], "Invalid selection for extract variable refactor")
|
878
|
-
when Requests::CodeActionResolve::Error::InvalidTargetRange
|
879
|
-
fail_request_and_notify(message[:id], "Couldn't find an appropriate location to place extracted refactor")
|
880
|
-
when Requests::CodeActionResolve::Error::UnknownCodeAction
|
881
|
-
fail_request_and_notify(message[:id], "Unknown code action")
|
882
|
-
else
|
883
|
-
send_message(Result.new(id: message[:id], response: result))
|
884
|
-
end
|
893
|
+
send_message(Result.new(id: message[:id], response: result))
|
894
|
+
rescue Requests::CodeActionResolve::CodeActionError => e
|
895
|
+
fail_request_and_notify(message[:id], e.message)
|
885
896
|
end
|
886
897
|
|
887
898
|
#: (Hash[Symbol, untyped] message) -> void
|
@@ -921,6 +932,10 @@ module RubyLsp
|
|
921
932
|
"Error running diagnostics: #{error.message}",
|
922
933
|
type: Constant::MessageType::ERROR,
|
923
934
|
))
|
935
|
+
send_message(Notification.window_log_message(
|
936
|
+
"Diagnostics failed with\r\n: #{error.full_message}",
|
937
|
+
type: Constant::MessageType::ERROR,
|
938
|
+
))
|
924
939
|
send_empty_response(message[:id])
|
925
940
|
end
|
926
941
|
|
data/lib/ruby_lsp/store.rb
CHANGED
@@ -38,11 +38,11 @@ module RubyLsp
|
|
38
38
|
ext = File.extname(path)
|
39
39
|
language_id = case ext
|
40
40
|
when ".erb", ".rhtml"
|
41
|
-
|
41
|
+
:erb
|
42
42
|
when ".rbs"
|
43
|
-
|
43
|
+
:rbs
|
44
44
|
else
|
45
|
-
|
45
|
+
:ruby
|
46
46
|
end
|
47
47
|
|
48
48
|
set(uri: uri, source: File.binread(path), version: 0, language_id: language_id)
|
@@ -51,12 +51,12 @@ module RubyLsp
|
|
51
51
|
raise NonExistingDocumentError, uri.to_s
|
52
52
|
end
|
53
53
|
|
54
|
-
#: (uri: URI::Generic, source: String, version: Integer, language_id:
|
54
|
+
#: (uri: URI::Generic, source: String, version: Integer, language_id: Symbol) -> Document[untyped]
|
55
55
|
def set(uri:, source:, version:, language_id:)
|
56
56
|
@state[uri.to_s] = case language_id
|
57
|
-
when
|
57
|
+
when :erb
|
58
58
|
ERBDocument.new(source: source, version: version, uri: uri, global_state: @global_state)
|
59
|
-
when
|
59
|
+
when :rbs
|
60
60
|
RBSDocument.new(source: source, version: version, uri: uri, global_state: @global_state)
|
61
61
|
else
|
62
62
|
RubyDocument.new(source: source, version: version, uri: uri, global_state: @global_state)
|
@@ -4,21 +4,40 @@
|
|
4
4
|
require "json"
|
5
5
|
require "socket"
|
6
6
|
require "singleton"
|
7
|
+
require "tmpdir"
|
7
8
|
|
8
9
|
module RubyLsp
|
9
10
|
class LspReporter
|
10
11
|
include Singleton
|
11
12
|
|
13
|
+
#: bool
|
14
|
+
attr_reader :invoked_shutdown
|
15
|
+
|
12
16
|
#: -> void
|
13
17
|
def initialize
|
18
|
+
dir_path = File.join(Dir.tmpdir, "ruby-lsp")
|
19
|
+
FileUtils.mkdir_p(dir_path)
|
20
|
+
|
21
|
+
port_path = File.join(dir_path, "test_reporter_port")
|
14
22
|
port = ENV["RUBY_LSP_REPORTER_PORT"]
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
23
|
+
|
24
|
+
@io = begin
|
25
|
+
# The environment variable is only used for tests. The extension always writes to the temporary file
|
26
|
+
if port
|
27
|
+
TCPSocket.new("localhost", port)
|
28
|
+
elsif File.exist?(port_path)
|
29
|
+
TCPSocket.new("localhost", File.read(port_path))
|
30
|
+
else
|
31
|
+
# For tests that don't spawn the TCP server
|
32
|
+
require "stringio"
|
33
|
+
StringIO.new
|
34
|
+
end
|
35
|
+
rescue
|
19
36
|
require "stringio"
|
20
37
|
StringIO.new
|
21
38
|
end #: IO | StringIO
|
39
|
+
|
40
|
+
@invoked_shutdown = false #: bool
|
22
41
|
end
|
23
42
|
|
24
43
|
#: -> void
|
@@ -34,6 +53,8 @@ module RubyLsp
|
|
34
53
|
# reporter, use `shutdown` instead
|
35
54
|
#: -> void
|
36
55
|
def internal_shutdown
|
56
|
+
@invoked_shutdown = true
|
57
|
+
|
37
58
|
send_message("finish")
|
38
59
|
@io.close
|
39
60
|
end
|
@@ -161,4 +182,10 @@ if ENV["RUBY_LSP_TEST_RUNNER"] == "coverage"
|
|
161
182
|
File.write(File.join(".ruby-lsp", "coverage_result.json"), coverage_results.to_json)
|
162
183
|
RubyLsp::LspReporter.instance.internal_shutdown
|
163
184
|
end
|
185
|
+
elsif ENV["RUBY_LSP_TEST_RUNNER"] && ENV["RUBY_LSP_ENV"] != "test"
|
186
|
+
at_exit do
|
187
|
+
# If the test process crashed immediately without finishing the tests, we still need to tell the extension that the
|
188
|
+
# execution ended so that it can clean up
|
189
|
+
RubyLsp::LspReporter.instance.internal_shutdown unless RubyLsp::LspReporter.instance.invoked_shutdown
|
190
|
+
end
|
164
191
|
end
|
data/lib/ruby_lsp/utils.rb
CHANGED
@@ -259,4 +259,47 @@ module RubyLsp
|
|
259
259
|
@configuration[:enableAll] || @configuration[feature]
|
260
260
|
end
|
261
261
|
end
|
262
|
+
|
263
|
+
class SorbetLevel
|
264
|
+
class << self
|
265
|
+
#: -> SorbetLevel
|
266
|
+
def ignore
|
267
|
+
new("ignore")
|
268
|
+
end
|
269
|
+
end
|
270
|
+
|
271
|
+
#: (String?) -> void
|
272
|
+
def initialize(sigil)
|
273
|
+
@level = case sigil
|
274
|
+
when "ignore"
|
275
|
+
:ignore
|
276
|
+
when "false"
|
277
|
+
:false
|
278
|
+
when "true"
|
279
|
+
:true
|
280
|
+
when "strict", "strong"
|
281
|
+
:strict
|
282
|
+
else
|
283
|
+
:none
|
284
|
+
end #: Symbol
|
285
|
+
end
|
286
|
+
|
287
|
+
#: -> bool
|
288
|
+
def ignore? = @level == :ignore
|
289
|
+
|
290
|
+
#: -> bool
|
291
|
+
def false? = @level == :false
|
292
|
+
|
293
|
+
#: -> bool
|
294
|
+
def true? = @level == :true
|
295
|
+
|
296
|
+
#: -> bool
|
297
|
+
def strict? = @level == :strict
|
298
|
+
|
299
|
+
#: -> bool
|
300
|
+
def none? = @level == :none
|
301
|
+
|
302
|
+
#: -> bool
|
303
|
+
def true_or_higher? = @level == :true || @level == :strict
|
304
|
+
end
|
262
305
|
end
|