From 184e80007b1d549ebabb6c7a86103648470a8c9f Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 19 Sep 2019 18:18:58 +0300 Subject: fix typo --- crates/ra_lsp_server/src/main_loop/handlers.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates') diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index 948d543ea..f18a6871e 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs @@ -402,7 +402,7 @@ pub fn handle_folding_range( start_line: range.start.line, start_character: Some(range.start.character), end_line: range.end.line, - end_character: Some(range.start.character), + end_character: Some(range.end.character), kind, } }) -- cgit v1.2.3 From 36732a42bd24b6138b2c7bbc91495adfe558ec0f Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 19 Sep 2019 18:23:12 +0300 Subject: move fold conversino to conv.rs --- crates/ra_lsp_server/src/conv.rs | 24 ++++++++++++++-- crates/ra_lsp_server/src/main_loop/handlers.rs | 38 ++++---------------------- 2 files changed, 28 insertions(+), 34 deletions(-) (limited to 'crates') diff --git a/crates/ra_lsp_server/src/conv.rs b/crates/ra_lsp_server/src/conv.rs index 5fa52ec1b..d78f77925 100644 --- a/crates/ra_lsp_server/src/conv.rs +++ b/crates/ra_lsp_server/src/conv.rs @@ -6,8 +6,8 @@ use lsp_types::{ }; use ra_ide_api::{ translate_offset_with_edit, CompletionItem, CompletionItemKind, FileId, FilePosition, - FileRange, FileSystemEdit, InsertTextFormat, LineCol, LineIndex, NavigationTarget, RangeInfo, - Severity, SourceChange, SourceFileEdit, + FileRange, FileSystemEdit, Fold, FoldKind, InsertTextFormat, LineCol, LineIndex, + NavigationTarget, RangeInfo, Severity, SourceChange, SourceFileEdit, }; use ra_syntax::{SyntaxKind, TextRange, TextUnit}; use ra_text_edit::{AtomTextEdit, TextEdit}; @@ -225,6 +225,26 @@ impl ConvWith<(&LineIndex, LineEndings)> for &AtomTextEdit { } } +impl ConvWith<&LineIndex> for Fold { + type Output = lsp_types::FoldingRange; + + fn conv_with(self, line_index: &LineIndex) -> lsp_types::FoldingRange { + let range = self.range.conv_with(&line_index); + lsp_types::FoldingRange { + start_line: range.start.line, + start_character: Some(range.start.character), + end_line: range.end.line, + end_character: Some(range.end.character), + kind: match self.kind { + FoldKind::Comment => Some(lsp_types::FoldingRangeKind::Comment), + FoldKind::Imports => Some(lsp_types::FoldingRangeKind::Imports), + FoldKind::Mods => None, + FoldKind::Block => None, + }, + } + } +} + impl, CTX> ConvWith for Option { type Output = Option; 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 _}; use lsp_server::ErrorCode; use lsp_types::{ CodeAction, CodeActionResponse, CodeLens, Command, CompletionItem, Diagnostic, - DocumentFormattingParams, DocumentHighlight, DocumentSymbol, FoldingRange, FoldingRangeKind, - FoldingRangeParams, Hover, HoverContents, Location, MarkupContent, MarkupKind, Position, - PrepareRenameResponse, Range, RenameParams, SymbolInformation, TextDocumentIdentifier, - TextEdit, WorkspaceEdit, -}; -use ra_ide_api::{ - AssistId, FileId, FilePosition, FileRange, FoldKind, Query, Runnable, RunnableKind, + DocumentFormattingParams, DocumentHighlight, DocumentSymbol, FoldingRange, FoldingRangeParams, + Hover, HoverContents, Location, MarkupContent, MarkupKind, Position, PrepareRenameResponse, + Range, RenameParams, SymbolInformation, TextDocumentIdentifier, TextEdit, WorkspaceEdit, }; +use ra_ide_api::{AssistId, FileId, FilePosition, FileRange, Query, Runnable, RunnableKind}; use ra_prof::profile; use ra_syntax::{AstNode, SyntaxKind, TextRange, TextUnit}; use rustc_hash::FxHashMap; @@ -383,32 +380,9 @@ pub fn handle_folding_range( params: FoldingRangeParams, ) -> Result>> { let file_id = params.text_document.try_conv_with(&world)?; + let folds = world.analysis().folding_ranges(file_id)?; let line_index = world.analysis().file_line_index(file_id)?; - - let res = Some( - world - .analysis() - .folding_ranges(file_id)? - .into_iter() - .map(|fold| { - let kind = match fold.kind { - FoldKind::Comment => Some(FoldingRangeKind::Comment), - FoldKind::Imports => Some(FoldingRangeKind::Imports), - FoldKind::Mods => None, - FoldKind::Block => None, - }; - let range = fold.range.conv_with(&line_index); - FoldingRange { - start_line: range.start.line, - start_character: Some(range.start.character), - end_line: range.end.line, - end_character: Some(range.end.character), - kind, - } - }) - .collect(), - ); - + let res = Some(folds.into_iter().map_conv_with(&*line_index).collect()); Ok(res) } -- cgit v1.2.3