18
18
CI = any (key in environ for key in ("TRAVIS" , "CI" , "GITHUB_ACTIONS" ))
19
19
20
20
TIMEOUT_TIME = 10000 if CI else 2000
21
- text_config = ClientConfig (
22
- name = "textls" ,
23
- selector = "text.plain" ,
24
- command = [],
25
- tcp_port = None )
21
+ text_config = ClientConfig (name = "textls" , selector = "text.plain" , command = [], tcp_port = None )
26
22
27
23
28
24
class YieldPromise :
29
-
30
- __slots__ = ('__done' , '__result' )
25
+ __slots__ = ("__done" , "__result" )
31
26
32
27
def __init__ (self ) -> None :
33
28
self .__done = False
@@ -49,7 +44,8 @@ def make_stdio_test_config() -> ClientConfig:
49
44
name = "TEST" ,
50
45
command = ["python3" , join ("$packages" , "LSP" , "tests" , "server.py" )],
51
46
selector = "text.plain" ,
52
- enabled = True )
47
+ enabled = True ,
48
+ )
53
49
54
50
55
51
def make_tcp_test_config () -> ClientConfig :
@@ -58,7 +54,8 @@ def make_tcp_test_config() -> ClientConfig:
58
54
command = ["python3" , join ("$packages" , "LSP" , "tests" , "server.py" ), "--tcp-port" , "$port" ],
59
55
selector = "text.plain" ,
60
56
tcp_port = 0 , # select a free one for me
61
- enabled = True )
57
+ enabled = True ,
58
+ )
62
59
63
60
64
61
def add_config (config ):
@@ -81,7 +78,6 @@ def expand(s: str, w: sublime.Window) -> str:
81
78
82
79
83
80
class TextDocumentTestCase (DeferrableTestCase ):
84
-
85
81
@classmethod
86
82
def get_stdio_test_config (cls ) -> ClientConfig :
87
83
return make_stdio_test_config ()
@@ -102,9 +98,7 @@ def setUpClass(cls) -> Generator:
102
98
cls .view = window .open_file (filename )
103
99
yield {"condition" : lambda : not cls .view .is_loading (), "timeout" : TIMEOUT_TIME }
104
100
yield cls .ensure_document_listener_created
105
- yield {
106
- "condition" : lambda : cls .wm .get_session (cls .config .name , filename ) is not None ,
107
- "timeout" : TIMEOUT_TIME }
101
+ yield {"condition" : lambda : cls .wm .get_session (cls .config .name , filename ) is not None , "timeout" : TIMEOUT_TIME }
108
102
cls .session = cls .wm .get_session (cls .config .name , filename )
109
103
yield {"condition" : lambda : cls .session .state == ClientStates .READY , "timeout" : TIMEOUT_TIME }
110
104
cls .initialize_params = yield from cls .await_message ("initialize" )
@@ -122,7 +116,7 @@ def setUp(self) -> Generator:
122
116
self .init_view_settings ()
123
117
yield self .ensure_document_listener_created
124
118
params = yield from self .await_message ("textDocument/didOpen" )
125
- self .assertEqual (params [' textDocument' ][ ' version' ], 0 )
119
+ self .assertEqual (params [" textDocument" ][ " version" ], 0 )
126
120
127
121
@classmethod
128
122
def get_test_name (cls ) -> str :
@@ -211,8 +205,10 @@ def await_promise(cls, promise: YieldPromise | Promise) -> Generator:
211
205
def await_run_code_action (self , code_action : dict [str , Any ]) -> Generator :
212
206
promise = YieldPromise ()
213
207
sublime .set_timeout_async (
214
- lambda : self .session .run_code_action_async (code_action , progress = False , view = self .view )
215
- .then (promise .fulfill ))
208
+ lambda : self .session .run_code_action_async (code_action , progress = False , view = self .view ).then (
209
+ promise .fulfill
210
+ )
211
+ )
216
212
yield from self .await_promise (promise )
217
213
218
214
def set_response (self , method : str , response : Any ) -> None :
@@ -251,15 +247,15 @@ def error_handler(params: Any) -> None:
251
247
yield from self .await_promise (promise )
252
248
253
249
def await_clear_view_and_save (self ) -> Generator :
254
- assert self .view # type: Optional[ sublime.View]
250
+ assert isinstance ( self .view , sublime .View )
255
251
self .view .run_command ("select_all" )
256
252
self .view .run_command ("left_delete" )
257
253
self .view .run_command ("save" )
258
254
yield from self .await_message ("textDocument/didChange" )
259
255
yield from self .await_message ("textDocument/didSave" )
260
256
261
257
def await_view_change (self , expected_change_count : int ) -> Generator :
262
- assert self .view # type: Optional[ sublime.View]
258
+ assert isinstance ( self .view , sublime .View )
263
259
264
260
def condition () -> bool :
265
261
nonlocal self
@@ -271,7 +267,7 @@ def condition() -> bool:
271
267
yield {"condition" : condition , "timeout" : TIMEOUT_TIME }
272
268
273
269
def insert_characters (self , characters : str ) -> int :
274
- assert self .view # type: Optional[ sublime.View]
270
+ assert isinstance ( self .view , sublime .View )
275
271
self .view .run_command ("insert" , {"characters" : characters })
276
272
return self .view .change_count ()
277
273
0 commit comments