forked from Shopify/ruby-lsp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexecutor_test.rb
144 lines (118 loc) · 4.13 KB
/
executor_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# typed: true
# frozen_string_literal: true
require "test_helper"
class ExecutorTest < Minitest::Test
def setup
@store = RubyLsp::Store.new
@message_queue = Thread::Queue.new
@executor = RubyLsp::Executor.new(@store, @message_queue)
end
def teardown
@message_queue.close
end
def test_initialize_enabled_features_with_array
response = @executor.execute({
method: "initialize",
params: {
initializationOptions: { enabledFeatures: ["semanticHighlighting"] },
capabilities: { general: { positionEncodings: ["utf-8"] } },
},
}).response
hash = JSON.parse(response.to_json)
capabilities = hash["capabilities"]
# TextSynchronization + encodings + semanticHighlighting
assert_equal(3, capabilities.length)
assert_includes(capabilities, "semanticTokensProvider")
end
def test_initialize_enabled_features_with_hash
response = @executor.execute({
method: "initialize",
params: {
initializationOptions: { enabledFeatures: { "semanticHighlighting" => false } },
capabilities: { general: { positionEncodings: ["utf-8"] } },
},
}).response
hash = JSON.parse(response.to_json)
capabilities = hash["capabilities"]
# Only semantic highlighting is turned off because all others default to true when configuring with a hash
refute_includes(capabilities, "semanticTokensProvider")
end
def test_initialize_enabled_features_with_no_configuration
response = @executor.execute({
method: "initialize",
params: {
initializationOptions: {},
capabilities: { general: { positionEncodings: ["utf-8"] } },
},
}).response
hash = JSON.parse(response.to_json)
capabilities = hash["capabilities"]
# All features are enabled by default
assert_includes(capabilities, "semanticTokensProvider")
end
def test_initialize_defaults_to_utf_8_if_present
response = @executor.execute({
method: "initialize",
params: {
initializationOptions: {},
capabilities: { general: { positionEncodings: ["utf-8", "utf-16"] } },
},
}).response
hash = JSON.parse(response.to_json)
# All features are enabled by default
assert_includes("utf-8", hash.dig("capabilities", "positionEncoding"))
end
def test_initialize_uses_utf_16_if_utf_8_is_not_present
response = @executor.execute({
method: "initialize",
params: {
initializationOptions: {},
capabilities: { general: { positionEncodings: ["utf-16"] } },
},
}).response
hash = JSON.parse(response.to_json)
# All features are enabled by default
assert_includes("utf-16", hash.dig("capabilities", "positionEncoding"))
end
def test_initialize_uses_utf_16_if_no_encodings_are_specified
response = @executor.execute({
method: "initialize",
params: {
initializationOptions: {},
capabilities: { general: { positionEncodings: [] } },
},
}).response
hash = JSON.parse(response.to_json)
# All features are enabled by default
assert_includes("utf-16", hash.dig("capabilities", "positionEncoding"))
end
def test_rubocop_errors_push_window_notification
@executor.expects(:formatting).raises(StandardError, "boom").once
@executor.execute({
method: "textDocument/formatting",
params: {
textDocument: { uri: "file:///foo.rb" },
},
})
notification = T.must(@message_queue.pop)
assert_equal("window/showMessage", notification.message)
assert_equal(
"Formatting error: boom",
T.cast(notification.params, RubyLsp::Interface::ShowMessageParams).message,
)
end
def test_did_close_clears_diagnostics
@store.set(uri: "file:///foo.rb", source: "", version: 1)
@executor.execute({
method: "textDocument/didClose",
params: {
textDocument: { uri: "file:///foo.rb" },
},
})
notification = T.must(@message_queue.pop)
assert_equal("textDocument/publishDiagnostics", notification.message)
assert_empty(T.cast(notification.params, RubyLsp::Interface::PublishDiagnosticsParams).diagnostics)
ensure
@store.delete("file:///foo.rb")
end
end