@@ -509,14 +509,49 @@ impl Visitor for DocumentSymbolCollector<'_> {
509
509
510
510
#[ cfg( test) ]
511
511
mod document_symbol_tests {
512
- use crate :: test_utils;
512
+ use crate :: { notifications :: on_did_open_text_document , test_utils} ;
513
513
514
514
use super :: * ;
515
515
use async_lsp:: lsp_types:: {
516
- PartialResultParams , Range , SymbolKind , TextDocumentIdentifier , WorkDoneProgressParams ,
516
+ DidOpenTextDocumentParams , PartialResultParams , Range , SymbolKind , TextDocumentIdentifier ,
517
+ TextDocumentItem , WorkDoneProgressParams ,
517
518
} ;
518
519
use tokio:: test;
519
520
521
+ async fn get_document_symbols ( src : & str ) -> Vec < DocumentSymbol > {
522
+ let ( mut state, noir_text_document) = test_utils:: init_lsp_server ( "document_symbol" ) . await ;
523
+
524
+ let _ = on_did_open_text_document (
525
+ & mut state,
526
+ DidOpenTextDocumentParams {
527
+ text_document : TextDocumentItem {
528
+ uri : noir_text_document. clone ( ) ,
529
+ language_id : "noir" . to_string ( ) ,
530
+ version : 0 ,
531
+ text : src. to_string ( ) ,
532
+ } ,
533
+ } ,
534
+ ) ;
535
+
536
+ let response = on_document_symbol_request (
537
+ & mut state,
538
+ DocumentSymbolParams {
539
+ text_document : TextDocumentIdentifier { uri : noir_text_document } ,
540
+ work_done_progress_params : WorkDoneProgressParams { work_done_token : None } ,
541
+ partial_result_params : PartialResultParams { partial_result_token : None } ,
542
+ } ,
543
+ )
544
+ . await
545
+ . expect ( "Could not execute on_document_symbol_request" )
546
+ . unwrap ( ) ;
547
+
548
+ let DocumentSymbolResponse :: Nested ( symbols) = response else {
549
+ panic ! ( "Expected response to be nested" ) ;
550
+ } ;
551
+
552
+ symbols
553
+ }
554
+
520
555
#[ test]
521
556
async fn test_document_symbol ( ) {
522
557
let ( mut state, noir_text_document) = test_utils:: init_lsp_server ( "document_symbol" ) . await ;
@@ -752,4 +787,26 @@ mod document_symbol_tests {
752
787
]
753
788
) ;
754
789
}
790
+
791
+ #[ test]
792
+ async fn test_function_with_just_open_parentheses ( ) {
793
+ let src = "fn main(\n " ;
794
+ let mut symbols = get_document_symbols ( src) . await ;
795
+ assert_eq ! ( symbols. len( ) , 1 ) ;
796
+ let symbol = symbols. remove ( 0 ) ;
797
+ assert_eq ! (
798
+ symbol. range,
799
+ Range {
800
+ start: Position { line: 0 , character: 0 } ,
801
+ end: Position { line: 1 , character: 0 } ,
802
+ }
803
+ ) ;
804
+ assert_eq ! (
805
+ symbol. selection_range,
806
+ Range {
807
+ start: Position { line: 0 , character: 3 } ,
808
+ end: Position { line: 0 , character: 7 } ,
809
+ }
810
+ ) ;
811
+ }
755
812
}
0 commit comments