@@ -2,18 +2,18 @@ use std::path::Path;
22
33use lsp_types:: {
44 CompletionResponse , DiagnosticSeverity , DocumentSymbolResponse , FoldingRange , FoldingRangeKind ,
5- GotoDefinitionResponse , HoverContents , InlayHintLabel , MarkedString , PublishDiagnosticsParams ,
5+ GotoDefinitionResponse , HoverContents , InlayHintLabel , MarkedString ,
66} ;
77const FILE_A : & str = "tests/a.er" ;
88const FILE_B : & str = "tests/b.er" ;
99const FILE_C : & str = "tests/c.er" ;
1010const FILE_IMPORTS : & str = "tests/imports.er" ;
1111const FILE_INVALID_SYNTAX : & str = "tests/invalid_syntax.er" ;
12+ const FILE_RETRIGGER : & str = "tests/retrigger.er" ;
1213
1314use els:: { NormalizedUrl , Server } ;
1415use erg_proc_macros:: exec_new_thread;
1516use molc:: { add_char, delete_line, oneline_range} ;
16- use serde:: Deserialize ;
1717
1818#[ test]
1919fn test_open ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
@@ -68,6 +68,34 @@ fn test_neighbor_completion() -> Result<(), Box<dyn std::error::Error>> {
6868 }
6969}
7070
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+
7199#[ test]
72100fn test_rename ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
73101 let mut client = Server :: bind_fake_client ( ) ;
@@ -251,11 +279,9 @@ fn test_dependents_check() -> Result<(), Box<dyn std::error::Error>> {
251279 client. wait_messages ( 2 ) ?;
252280 client. responses . clear ( ) ;
253281 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 ( ) ?;
259285 assert_eq ! ( diags. diagnostics. len( ) , 1 ) ;
260286 assert_eq ! (
261287 diags. diagnostics[ 0 ] . severity,
@@ -269,24 +295,17 @@ fn test_fix_error() -> Result<(), Box<dyn std::error::Error>> {
269295 let mut client = Server :: bind_fake_client ( ) ;
270296 client. request_initialize ( ) ?;
271297 client. notify_initialized ( ) ?;
272- client. wait_messages ( 3 ) ?;
273- client. responses . clear ( ) ;
274298 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 ( ) ?;
278300 assert_eq ! ( diags. diagnostics. len( ) , 1 ) ;
279301 assert_eq ! (
280302 diags. diagnostics[ 0 ] . severity,
281303 Some ( DiagnosticSeverity :: ERROR )
282304 ) ;
283- client. responses . clear ( ) ;
284305 let uri = NormalizedUrl :: from_file_path ( Path :: new ( FILE_INVALID_SYNTAX ) . canonicalize ( ) ?) ?;
285306 client. notify_change ( uri. clone ( ) . raw ( ) , add_char ( 0 , 10 , " 1" ) ) ?;
286307 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 ( ) ?;
290309 assert_eq ! ( diags. diagnostics. len( ) , 0 ) ;
291310 Ok ( ( ) )
292311}
0 commit comments