File tree 2 files changed +54
-1
lines changed
2 files changed +54
-1
lines changed Original file line number Diff line number Diff line change 16
16
17
17
18
18
PUBLISH_DIAGNOSTICS = "textDocument/publishDiagnostics"
19
+ WINDOW_LOG_MESSAGE = "window/logMessage"
20
+ WINDOW_SHOW_MESSAGE = "window/showMessage"
19
21
20
22
21
23
class LspSession (MethodDispatcher ):
@@ -55,7 +57,10 @@ def __enter__(self):
55
57
os .fdopen (self ._sub .stdout .fileno (), "rb" )
56
58
)
57
59
58
- dispatcher = {PUBLISH_DIAGNOSTICS : self ._publish_diagnostics }
60
+ dispatcher = {
61
+ PUBLISH_DIAGNOSTICS : self ._publish_diagnostics ,
62
+ WINDOW_SHOW_MESSAGE : self ._window_show_message ,
63
+ }
59
64
self ._endpoint = Endpoint (dispatcher , self ._writer .write )
60
65
self ._thread_pool .submit (self ._reader .listen , self ._endpoint .consume )
61
66
return self
@@ -228,6 +233,18 @@ def _handler():
228
233
self ._thread_pool .submit (_handler )
229
234
return fut
230
235
236
+ def _window_show_message (self , window_show_message_params ):
237
+ """Internal handler for text document publish diagnostics."""
238
+ fut = Future ()
239
+
240
+ def _handler ():
241
+ callback = self .get_notification_callback (WINDOW_SHOW_MESSAGE )
242
+ callback (window_show_message_params )
243
+ fut .set_result (None )
244
+
245
+ self ._thread_pool .submit (_handler )
246
+ return fut
247
+
231
248
def _send_request (
232
249
self , name , params = None , handle_response = lambda f : f .done ()
233
250
):
Original file line number Diff line number Diff line change
1
+ """Tests for initialization options over language server protocol."""
2
+
3
+ import copy
4
+ from threading import Event
5
+
6
+ from hamcrest import assert_that , is_
7
+
8
+ from tests .lsp_test_client import defaults , session
9
+
10
+
11
+ def test_invalid_initialization_options () -> None :
12
+ """Test what happens when invalid initialization is sent."""
13
+ initialize_params = copy .deepcopy (defaults .VSCODE_DEFAULT_INITIALIZE )
14
+ initialize_params ["initializationOptions" ]["diagnostics" ] = 1
15
+
16
+ with session .LspSession () as ls_session :
17
+ done = Event ()
18
+ actual = []
19
+
20
+ def _handler (params ):
21
+ actual .append (params )
22
+ done .set ()
23
+
24
+ ls_session .set_notification_callback (
25
+ session .WINDOW_SHOW_MESSAGE , _handler
26
+ )
27
+
28
+ ls_session .initialize (initialize_params )
29
+ expected = [
30
+ {
31
+ "type" : 1 ,
32
+ "message" : "Invalid InitializationOptions, using defaults: 1 validation error for InitializationOptions\n diagnostics\n value is not a valid dict (type=type_error.dict)" ,
33
+ }
34
+ ]
35
+
36
+ assert_that (actual , is_ (expected ))
You can’t perform that action at this time.
0 commit comments