@@ -135,6 +135,7 @@ fn main_loop(
135135 None ,
136136 ) ;
137137 let completions: Comple = Arc :: new ( Mutex :: new ( None ) ) ;
138+ let doc_sym: Arc < Mutex < Vec < ( RequestId , String ) > > > = Arc :: new ( Mutex :: new ( Vec :: new ( ) ) ) ;
138139 let mut last_semantic_file = "" . to_string ( ) ;
139140 let mut last_tokens: SemanticTokens = SemanticTokens :: default ( ) ;
140141
@@ -148,6 +149,7 @@ fn main_loop(
148149 }
149150 }
150151 let completions = completions. clone ( ) ;
152+ let doc_sym = doc_sym. clone ( ) ;
151153 di. on :: < GotoDefinition , _ > ( |id, params| {
152154 let uri = url_to_path ( params. text_document_position_params . text_document . uri ) ;
153155 let pos = Pos :: from_diag_pos ( & params. text_document_position_params . position ) ;
@@ -232,9 +234,10 @@ fn main_loop(
232234 let snapshot = db. clone ( ) ;
233235 let sender = connection. sender . clone ( ) ;
234236 let completions = completions. clone ( ) ;
237+ let doc_sym = doc_sym. clone ( ) ;
235238 pool. execute ( move || {
236239 let _ = compile_dry ( & snapshot, docin) ;
237- do_send_completions_and_diags ( & snapshot, docin, completions, & sender) ;
240+ do_send_completions_and_diags ( & snapshot, docin, completions, doc_sym , & sender) ;
238241 let mut codelens = compile_dry:: accumulated :: < PLCodeLens > ( & snapshot, docin) ;
239242 send_code_lens (
240243 & sender,
@@ -256,6 +259,7 @@ fn main_loop(
256259 & snapshot,
257260 docin,
258261 completions. clone ( ) ,
262+ doc_sym. clone ( ) ,
259263 & connection. sender ,
260264 ) ;
261265 let mut newtokens = compile_dry:: accumulated :: < PLSemanticTokens > ( & snapshot, docin) ;
@@ -291,6 +295,7 @@ fn main_loop(
291295 & snapshot,
292296 docin,
293297 completions. clone ( ) ,
298+ doc_sym. clone ( ) ,
294299 & connection. sender ,
295300 ) ;
296301 let mut newtokens = compile_dry:: accumulated :: < PLSemanticTokens > ( & snapshot, docin) ;
@@ -375,7 +380,13 @@ fn main_loop(
375380 . set_docs ( & mut db)
376381 . to ( Arc :: new ( Mutex :: new ( docs. lock ( ) . unwrap ( ) . clone ( ) ) ) ) ;
377382 let _ = compile_dry ( & db, docin) ;
378- do_send_completions_and_diags ( & db, docin, completions. clone ( ) , & connection. sender ) ;
383+ do_send_completions_and_diags (
384+ & db,
385+ docin,
386+ completions. clone ( ) ,
387+ doc_sym. clone ( ) ,
388+ & connection. sender ,
389+ ) ;
379390 let sigs = compile_dry:: accumulated :: < PLSignatureHelp > ( & db, docin) ;
380391 if !sigs. is_empty ( ) {
381392 let sender = connection. sender . clone ( ) ;
@@ -412,10 +423,11 @@ fn main_loop(
412423 let sender = connection. sender . clone ( ) ;
413424 let snapshot = db. clone ( ) ;
414425 let completions = completions. clone ( ) ;
426+ let doc_sym = doc_sym. clone ( ) ;
415427 pool. execute ( move || {
416428 if docin. file ( & snapshot) != & uri {
417429 let _ = compile_dry ( & snapshot, docin) ;
418- do_send_completions_and_diags ( & snapshot, docin, completions, & sender) ;
430+ do_send_completions_and_diags ( & snapshot, docin, completions, doc_sym , & sender) ;
419431 }
420432 let hints = compile_dry:: accumulated :: < Hints > ( & snapshot, docin) ;
421433 if !hints. is_empty ( ) {
@@ -425,6 +437,10 @@ fn main_loop(
425437 } )
426438 . on :: < DocumentSymbolRequest , _ > ( |id, params| {
427439 let uri = url_to_path ( params. text_document . uri ) ;
440+ // 存储请求ID和URI
441+ let mut guard = doc_sym. lock ( ) . unwrap ( ) ;
442+ guard. push ( ( id. clone ( ) , uri. clone ( ) ) ) ;
443+ drop ( guard) ;
428444 if docin. file ( & db) != & uri {
429445 docin. set_file ( & mut db) . to ( uri. clone ( ) ) ;
430446 docin. set_action ( & mut db) . to ( ActionType :: DocSymbol ) ;
@@ -439,15 +455,12 @@ fn main_loop(
439455 let sender = connection. sender . clone ( ) ;
440456 let snapshot = db. clone ( ) ;
441457 let completions = completions. clone ( ) ;
458+ let doc_sym = doc_sym. clone ( ) ;
442459 pool. execute ( move || {
443460 if docin. file ( & snapshot) != & uri {
444461 let _ = compile_dry ( & snapshot, docin) ;
445462 }
446- do_send_completions_and_diags ( & snapshot, docin, completions, & sender) ;
447- let doc_symbols = compile_dry:: accumulated :: < DocSymbols > ( & snapshot, docin) ;
448- if !doc_symbols. is_empty ( ) {
449- send_doc_symbols ( & sender, id, doc_symbols[ 0 ] . clone ( ) . 0 ) ;
450- }
463+ do_send_completions_and_diags ( & snapshot, docin, completions, doc_sym, & sender) ;
451464 } ) ;
452465 } )
453466 . on_noti :: < DidChangeTextDocument , _ > ( |params| {
@@ -474,9 +487,10 @@ fn main_loop(
474487 let snapshot = db. clone ( ) ;
475488 let sender = connection. sender . clone ( ) ;
476489 let completions = completions. clone ( ) ;
490+ let doc_sym = doc_sym. clone ( ) ;
477491 pool. execute ( move || {
478492 let _ = compile_dry ( & snapshot, docin) ;
479- do_send_completions_and_diags ( & snapshot, docin, completions, & sender) ;
493+ do_send_completions_and_diags ( & snapshot, docin, completions, doc_sym , & sender) ;
480494 } ) ;
481495 } )
482496 . on_noti :: < DidOpenTextDocument , _ > ( |params| {
@@ -517,6 +531,7 @@ fn do_send_completions_and_diags(
517531 snapshot : & crate :: Database ,
518532 docin : MemDocsInput ,
519533 completions : Arc < Mutex < Option < RequestId > > > ,
534+ doc_sym : Arc < Mutex < Vec < ( RequestId , String ) > > > ,
520535 sender : & crossbeam_channel:: Sender < Message > ,
521536) {
522537 let comps = compile_dry:: accumulated :: < Completions > ( snapshot, docin) ;
@@ -530,6 +545,33 @@ fn do_send_completions_and_diags(
530545 }
531546 * guard = None ;
532547 drop ( guard) ;
548+
549+ let current_file = docin. file ( snapshot) ;
550+ let doc_symbols = compile_dry:: accumulated :: < DocSymbols > ( snapshot, docin) ;
551+ // 检查是否有文档符号请求
552+ let mut guard = doc_sym. lock ( ) . unwrap ( ) ;
553+ if !guard. is_empty ( ) {
554+ // 创建一个新的向量来存储未处理的请求
555+ let mut remaining_requests = Vec :: new ( ) ;
556+
557+ for ( id, uri) in guard. drain ( ..) {
558+ // 检查URI是否匹配
559+ if current_file == & uri {
560+ // URI匹配,获取文档符号
561+ if !doc_symbols. is_empty ( ) {
562+ send_doc_symbols ( sender, id. clone ( ) , doc_symbols[ 0 ] . clone ( ) . 0 ) ;
563+ }
564+ } else {
565+ // URI不匹配,保留请求以便后续处理
566+ remaining_requests. push ( ( id, uri) ) ;
567+ }
568+ }
569+
570+ // 将未处理的请求放回向量
571+ * guard = remaining_requests;
572+ }
573+ drop ( guard) ;
574+
533575 let diags = compile_dry:: accumulated :: < Diagnostics > ( snapshot, docin) ;
534576 debug ! ( "diags: {:#?}" , diags) ;
535577 let mut m = FxHashMap :: < String , Vec < Diagnostic > > :: default ( ) ;
0 commit comments