@@ -3,14 +3,11 @@ use std::{fmt::Write as _, io::Write as _};
3
3
use lsp_server:: ErrorCode ;
4
4
use lsp_types:: {
5
5
CodeAction , CodeActionResponse , CodeLens , Command , CompletionItem , Diagnostic ,
6
- DocumentFormattingParams , DocumentHighlight , DocumentSymbol , FoldingRange , FoldingRangeKind ,
7
- FoldingRangeParams , Hover , HoverContents , Location , MarkupContent , MarkupKind , Position ,
8
- PrepareRenameResponse , Range , RenameParams , SymbolInformation , TextDocumentIdentifier ,
9
- TextEdit , WorkspaceEdit ,
10
- } ;
11
- use ra_ide_api:: {
12
- AssistId , FileId , FilePosition , FileRange , FoldKind , Query , Runnable , RunnableKind ,
6
+ DocumentFormattingParams , DocumentHighlight , DocumentSymbol , FoldingRange , FoldingRangeParams ,
7
+ Hover , HoverContents , Location , MarkupContent , MarkupKind , Position , PrepareRenameResponse ,
8
+ Range , RenameParams , SymbolInformation , TextDocumentIdentifier , TextEdit , WorkspaceEdit ,
13
9
} ;
10
+ use ra_ide_api:: { AssistId , FileId , FilePosition , FileRange , Query , Runnable , RunnableKind } ;
14
11
use ra_prof:: profile;
15
12
use ra_syntax:: { AstNode , SyntaxKind , TextRange , TextUnit } ;
16
13
use rustc_hash:: FxHashMap ;
@@ -383,32 +380,9 @@ pub fn handle_folding_range(
383
380
params : FoldingRangeParams ,
384
381
) -> Result < Option < Vec < FoldingRange > > > {
385
382
let file_id = params. text_document . try_conv_with ( & world) ?;
383
+ let folds = world. analysis ( ) . folding_ranges ( file_id) ?;
386
384
let line_index = world. analysis ( ) . file_line_index ( file_id) ?;
387
-
388
- let res = Some (
389
- world
390
- . analysis ( )
391
- . folding_ranges ( file_id) ?
392
- . into_iter ( )
393
- . map ( |fold| {
394
- let kind = match fold. kind {
395
- FoldKind :: Comment => Some ( FoldingRangeKind :: Comment ) ,
396
- FoldKind :: Imports => Some ( FoldingRangeKind :: Imports ) ,
397
- FoldKind :: Mods => None ,
398
- FoldKind :: Block => None ,
399
- } ;
400
- let range = fold. range . conv_with ( & line_index) ;
401
- FoldingRange {
402
- start_line : range. start . line ,
403
- start_character : Some ( range. start . character ) ,
404
- end_line : range. end . line ,
405
- end_character : Some ( range. start . character ) ,
406
- kind,
407
- }
408
- } )
409
- . collect ( ) ,
410
- ) ;
411
-
385
+ let res = Some ( folds. into_iter ( ) . map_conv_with ( & * line_index) . collect ( ) ) ;
412
386
Ok ( res)
413
387
}
414
388
0 commit comments