@@ -353,6 +353,21 @@ impl State {
353353 Ok ( ( ) )
354354 }
355355
356+ fn location_to_quickfix_entry ( & mut self , loc : & Location ) -> Result < QuickfixEntry > {
357+ let filename = loc. uri . filepath ( ) ?;
358+ let start = loc. range . start ;
359+ let text = self . get_line ( & filename, start. line ) . unwrap_or_default ( ) ;
360+
361+ Ok ( QuickfixEntry {
362+ filename : filename. to_string_lossy ( ) . into_owned ( ) ,
363+ lnum : start. line + 1 ,
364+ col : Some ( start. character + 1 ) ,
365+ text : Some ( text) ,
366+ nr : None ,
367+ typee : None ,
368+ } )
369+ }
370+
356371 fn display_locations ( & mut self , locations : & [ Location ] , _languageId : & str ) -> Result < ( ) > {
357372 match self . get ( |state| Ok ( state. selectionUI . clone ( ) ) ) ? {
358373 SelectionUI :: FZF => {
@@ -381,24 +396,22 @@ impl State {
381396 json ! ( [ source, format!( "s:{}" , NOTIFICATION__FZFSinkLocation ) ] ) ,
382397 ) ?;
383398 }
399+ SelectionUI :: Quickfix => {
400+ let list: Result < Vec < _ > > = locations
401+ . iter ( )
402+ . map ( |loc| self . location_to_quickfix_entry ( loc) )
403+ . collect ( ) ;
404+ let list = list?;
405+ self . setqflist ( & list) ?;
406+ self . echo ( "Quickfix list updated." ) ?;
407+ }
384408 SelectionUI :: LocationList => {
385- let loclist : Result < Vec < _ > > = locations
409+ let list : Result < Vec < _ > > = locations
386410 . iter ( )
387- . map ( |loc| {
388- let filename = loc. uri . filepath ( ) ?;
389- let start = loc. range . start ;
390- let text = self . get_line ( & filename, start. line ) . unwrap_or_default ( ) ;
391- Ok ( json ! ( {
392- "filename" : filename,
393- "lnum" : start. line + 1 ,
394- "col" : start. character + 1 ,
395- "text" : text,
396- } ) )
397- } )
411+ . map ( |loc| self . location_to_quickfix_entry ( loc) )
398412 . collect ( ) ;
399- let loclist = loclist?;
400-
401- self . call :: < _ , u8 > ( None , "setloclist" , json ! ( [ 0 , loclist] ) ) ?;
413+ let list = list?;
414+ self . setloclist ( & list) ?;
402415 self . echo ( "Location list updated." ) ?;
403416 }
404417 }
@@ -906,21 +919,16 @@ impl State {
906919 json ! ( [ source, format!( "s:{}" , NOTIFICATION__FZFSinkLocation ) ] ) ,
907920 ) ?;
908921 }
922+ SelectionUI :: Quickfix => {
923+ let list: Result < Vec < _ > > = symbols. iter ( ) . map ( QuickfixEntry :: from_lsp) . collect ( ) ;
924+ let list = list?;
925+ self . setqflist ( & list) ?;
926+ self . echo ( "Document symbols populated to quickfix list." ) ?;
927+ }
909928 SelectionUI :: LocationList => {
910- let loclist: Vec < _ > = symbols
911- . iter ( )
912- . map ( |sym| {
913- let start = sym. location . range . start ;
914- json ! ( {
915- "filename" : filename,
916- "lnum" : start. line + 1 ,
917- "col" : start. character + 1 ,
918- "text" : sym. name,
919- } )
920- } )
921- . collect ( ) ;
922-
923- self . call :: < _ , u8 > ( None , "setloclist" , json ! ( [ 0 , loclist] ) ) ?;
929+ let list: Result < Vec < _ > > = symbols. iter ( ) . map ( QuickfixEntry :: from_lsp) . collect ( ) ;
930+ let list = list?;
931+ self . setloclist ( & list) ?;
924932 self . echo ( "Document symbols populated to location list." ) ?;
925933 }
926934 }
@@ -1390,22 +1398,16 @@ impl State {
13901398 json ! ( [ source, format!( "s:{}" , NOTIFICATION__FZFSinkLocation ) ] ) ,
13911399 ) ?;
13921400 }
1401+ SelectionUI :: Quickfix => {
1402+ let list: Result < Vec < _ > > = symbols. iter ( ) . map ( QuickfixEntry :: from_lsp) . collect ( ) ;
1403+ let list = list?;
1404+ self . setqflist ( & list) ?;
1405+ self . echo ( "Workspace symbols populated to quickfix list." ) ?;
1406+ }
13931407 SelectionUI :: LocationList => {
1394- let loclist: Result < Vec < _ > > = symbols
1395- . iter ( )
1396- . map ( |sym| {
1397- let start = sym. location . range . start ;
1398- Ok ( json ! ( {
1399- "filename" : sym. location. uri. filepath( ) ?,
1400- "lnum" : start. line + 1 ,
1401- "col" : start. character + 1 ,
1402- "text" : sym. name,
1403- } ) )
1404- } )
1405- . collect ( ) ;
1406- let loclist = loclist?;
1407-
1408- self . call :: < _ , u8 > ( None , "setloclist" , json ! ( [ 0 , loclist] ) ) ?;
1408+ let list: Result < Vec < _ > > = symbols. iter ( ) . map ( QuickfixEntry :: from_lsp) . collect ( ) ;
1409+ let list = list?;
1410+ self . setloclist ( & list) ?;
14091411 self . echo ( "Workspace symbols populated to location list." ) ?;
14101412 }
14111413 }
@@ -1646,14 +1648,10 @@ impl State {
16461648
16471649 match self . get ( |state| Ok ( state. diagnosticsList . clone ( ) ) ) ? {
16481650 DiagnosticsList :: Quickfix => {
1649- if self . call :: < _ , u8 > ( None , "setqflist" , json ! ( [ qflist, "r" ] ) ) ? != 0 {
1650- bail ! ( "Failed to set quickfix list!" ) ;
1651- }
1651+ self . setqflist ( & qflist) ?;
16521652 }
16531653 DiagnosticsList :: Location => {
1654- if self . call :: < _ , u8 > ( None , "setloclist" , json ! ( [ 0 , qflist, "r" ] ) ) ? != 0 {
1655- bail ! ( "Failed to set location list!" ) ;
1656- }
1654+ self . setloclist ( & qflist) ?;
16571655 }
16581656 DiagnosticsList :: Disabled => { }
16591657 }
0 commit comments