diff options
Diffstat (limited to 'crates/ra_lsp_server/src/main_loop')
-rw-r--r-- | crates/ra_lsp_server/src/main_loop/handlers.rs | 38 |
1 files changed, 6 insertions, 32 deletions
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index f18a6871e..ae57e57e9 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs | |||
@@ -3,14 +3,11 @@ use std::{fmt::Write as _, io::Write as _}; | |||
3 | use lsp_server::ErrorCode; | 3 | use lsp_server::ErrorCode; |
4 | use lsp_types::{ | 4 | use lsp_types::{ |
5 | CodeAction, CodeActionResponse, CodeLens, Command, CompletionItem, Diagnostic, | 5 | CodeAction, CodeActionResponse, CodeLens, Command, CompletionItem, Diagnostic, |
6 | DocumentFormattingParams, DocumentHighlight, DocumentSymbol, FoldingRange, FoldingRangeKind, | 6 | DocumentFormattingParams, DocumentHighlight, DocumentSymbol, FoldingRange, FoldingRangeParams, |
7 | FoldingRangeParams, Hover, HoverContents, Location, MarkupContent, MarkupKind, Position, | 7 | Hover, HoverContents, Location, MarkupContent, MarkupKind, Position, PrepareRenameResponse, |
8 | PrepareRenameResponse, Range, RenameParams, SymbolInformation, TextDocumentIdentifier, | 8 | Range, RenameParams, SymbolInformation, TextDocumentIdentifier, TextEdit, WorkspaceEdit, |
9 | TextEdit, WorkspaceEdit, | ||
10 | }; | ||
11 | use ra_ide_api::{ | ||
12 | AssistId, FileId, FilePosition, FileRange, FoldKind, Query, Runnable, RunnableKind, | ||
13 | }; | 9 | }; |
10 | use ra_ide_api::{AssistId, FileId, FilePosition, FileRange, Query, Runnable, RunnableKind}; | ||
14 | use ra_prof::profile; | 11 | use ra_prof::profile; |
15 | use ra_syntax::{AstNode, SyntaxKind, TextRange, TextUnit}; | 12 | use ra_syntax::{AstNode, SyntaxKind, TextRange, TextUnit}; |
16 | use rustc_hash::FxHashMap; | 13 | use rustc_hash::FxHashMap; |
@@ -383,32 +380,9 @@ pub fn handle_folding_range( | |||
383 | params: FoldingRangeParams, | 380 | params: FoldingRangeParams, |
384 | ) -> Result<Option<Vec<FoldingRange>>> { | 381 | ) -> Result<Option<Vec<FoldingRange>>> { |
385 | let file_id = params.text_document.try_conv_with(&world)?; | 382 | let file_id = params.text_document.try_conv_with(&world)?; |
383 | let folds = world.analysis().folding_ranges(file_id)?; | ||
386 | let line_index = world.analysis().file_line_index(file_id)?; | 384 | let line_index = world.analysis().file_line_index(file_id)?; |
387 | 385 | let res = Some(folds.into_iter().map_conv_with(&*line_index).collect()); | |
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.end.character), | ||
406 | kind, | ||
407 | } | ||
408 | }) | ||
409 | .collect(), | ||
410 | ); | ||
411 | |||
412 | Ok(res) | 386 | Ok(res) |
413 | } | 387 | } |
414 | 388 | ||