@@ -2,18 +2,18 @@ use std::path::Path;
2
2
3
3
use lsp_types:: {
4
4
CompletionResponse , DiagnosticSeverity , DocumentSymbolResponse , FoldingRange , FoldingRangeKind ,
5
- GotoDefinitionResponse , HoverContents , InlayHintLabel , MarkedString , PublishDiagnosticsParams ,
5
+ GotoDefinitionResponse , HoverContents , InlayHintLabel , MarkedString ,
6
6
} ;
7
7
const FILE_A : & str = "tests/a.er" ;
8
8
const FILE_B : & str = "tests/b.er" ;
9
9
const FILE_C : & str = "tests/c.er" ;
10
10
const FILE_IMPORTS : & str = "tests/imports.er" ;
11
11
const FILE_INVALID_SYNTAX : & str = "tests/invalid_syntax.er" ;
12
+ const FILE_RETRIGGER : & str = "tests/retrigger.er" ;
12
13
13
14
use els:: { NormalizedUrl , Server } ;
14
15
use erg_proc_macros:: exec_new_thread;
15
16
use molc:: { add_char, delete_line, oneline_range} ;
16
- use serde:: Deserialize ;
17
17
18
18
#[ test]
19
19
fn test_open ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
@@ -68,6 +68,34 @@ fn test_neighbor_completion() -> Result<(), Box<dyn std::error::Error>> {
68
68
}
69
69
}
70
70
71
+ #[ test]
72
+ fn test_completion_retrigger ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
73
+ let mut client = Server :: bind_fake_client ( ) ;
74
+ client. request_initialize ( ) ?;
75
+ client. notify_initialized ( ) ?;
76
+ let uri = NormalizedUrl :: from_file_path ( Path :: new ( FILE_RETRIGGER ) . canonicalize ( ) ?) ?;
77
+ client. notify_open ( FILE_RETRIGGER ) ?;
78
+ let _ = client. wait_diagnostics ( ) ?;
79
+ client. notify_change ( uri. clone ( ) . raw ( ) , add_char ( 2 , 7 , "n" ) ) ?;
80
+ let resp = client. request_completion ( uri. clone ( ) . raw ( ) , 2 , 7 , "n" ) ?;
81
+ if let Some ( CompletionResponse :: Array ( items) ) = resp {
82
+ assert ! ( !items. is_empty( ) ) ;
83
+ assert ! ( items. iter( ) . any( |item| item. label == "print!" ) ) ;
84
+ } else {
85
+ return Err ( format ! ( "not items: {resp:?}" ) . into ( ) ) ;
86
+ }
87
+ client. notify_change ( uri. clone ( ) . raw ( ) , add_char ( 3 , 15 , "t" ) ) ?;
88
+ let resp = client. request_completion ( uri. raw ( ) , 3 , 15 , "t" ) ?;
89
+ if let Some ( CompletionResponse :: Array ( items) ) = resp {
90
+ assert ! ( !items. is_empty( ) ) ;
91
+ assert ! ( items. iter( ) . any( |item| item. label == "bit_count" ) ) ;
92
+ assert ! ( items. iter( ) . any( |item| item. label == "bit_length" ) ) ;
93
+ } else {
94
+ return Err ( format ! ( "not items: {resp:?}" ) . into ( ) ) ;
95
+ }
96
+ Ok ( ( ) )
97
+ }
98
+
71
99
#[ test]
72
100
fn test_rename ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
73
101
let mut client = Server :: bind_fake_client ( ) ;
@@ -251,11 +279,9 @@ fn test_dependents_check() -> Result<(), Box<dyn std::error::Error>> {
251
279
client. wait_messages ( 2 ) ?;
252
280
client. responses . clear ( ) ;
253
281
client. notify_save ( uri_b. clone ( ) . raw ( ) ) ?;
254
- client. wait_messages ( 9 ) ?;
255
- assert ! ( client. responses. iter( ) . any( |resp| resp
256
- . to_string( )
257
- . contains( "tests/b.er passed, found warns: 0" ) ) ) ;
258
- let diags = PublishDiagnosticsParams :: deserialize ( & client. responses . last ( ) . unwrap ( ) [ "params" ] ) ?;
282
+ let diags = client. wait_diagnostics ( ) ?;
283
+ assert ! ( diags. diagnostics. is_empty( ) ) ;
284
+ let diags = client. wait_diagnostics ( ) ?;
259
285
assert_eq ! ( diags. diagnostics. len( ) , 1 ) ;
260
286
assert_eq ! (
261
287
diags. diagnostics[ 0 ] . severity,
@@ -269,24 +295,17 @@ fn test_fix_error() -> Result<(), Box<dyn std::error::Error>> {
269
295
let mut client = Server :: bind_fake_client ( ) ;
270
296
client. request_initialize ( ) ?;
271
297
client. notify_initialized ( ) ?;
272
- client. wait_messages ( 3 ) ?;
273
- client. responses . clear ( ) ;
274
298
client. notify_open ( FILE_INVALID_SYNTAX ) ?;
275
- client. wait_messages ( 6 ) ?;
276
- let msg = client. responses . last ( ) . unwrap ( ) ;
277
- let diags = PublishDiagnosticsParams :: deserialize ( & msg[ "params" ] ) ?;
299
+ let diags = client. wait_diagnostics ( ) ?;
278
300
assert_eq ! ( diags. diagnostics. len( ) , 1 ) ;
279
301
assert_eq ! (
280
302
diags. diagnostics[ 0 ] . severity,
281
303
Some ( DiagnosticSeverity :: ERROR )
282
304
) ;
283
- client. responses . clear ( ) ;
284
305
let uri = NormalizedUrl :: from_file_path ( Path :: new ( FILE_INVALID_SYNTAX ) . canonicalize ( ) ?) ?;
285
306
client. notify_change ( uri. clone ( ) . raw ( ) , add_char ( 0 , 10 , " 1" ) ) ?;
286
307
client. notify_save ( uri. clone ( ) . raw ( ) ) ?;
287
- client. wait_messages ( 4 ) ?;
288
- let msg = client. responses . last ( ) . unwrap ( ) ;
289
- let diags = PublishDiagnosticsParams :: deserialize ( & msg[ "params" ] ) ?;
308
+ let diags = client. wait_diagnostics ( ) ?;
290
309
assert_eq ! ( diags. diagnostics. len( ) , 0 ) ;
291
310
Ok ( ( ) )
292
311
}
0 commit comments