aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_lsp_server/src/conv.rs24
-rw-r--r--crates/ra_lsp_server/src/main_loop/handlers.rs38
2 files changed, 28 insertions, 34 deletions
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::{
6}; 6};
7use ra_ide_api::{ 7use ra_ide_api::{
8 translate_offset_with_edit, CompletionItem, CompletionItemKind, FileId, FilePosition, 8 translate_offset_with_edit, CompletionItem, CompletionItemKind, FileId, FilePosition,
9 FileRange, FileSystemEdit, InsertTextFormat, LineCol, LineIndex, NavigationTarget, RangeInfo, 9 FileRange, FileSystemEdit, Fold, FoldKind, InsertTextFormat, LineCol, LineIndex,
10 Severity, SourceChange, SourceFileEdit, 10 NavigationTarget, RangeInfo, Severity, SourceChange, SourceFileEdit,
11}; 11};
12use ra_syntax::{SyntaxKind, TextRange, TextUnit}; 12use ra_syntax::{SyntaxKind, TextRange, TextUnit};
13use ra_text_edit::{AtomTextEdit, TextEdit}; 13use ra_text_edit::{AtomTextEdit, TextEdit};
@@ -225,6 +225,26 @@ impl ConvWith<(&LineIndex, LineEndings)> for &AtomTextEdit {
225 } 225 }
226} 226}
227 227
228impl ConvWith<&LineIndex> for Fold {
229 type Output = lsp_types::FoldingRange;
230
231 fn conv_with(self, line_index: &LineIndex) -> lsp_types::FoldingRange {
232 let range = self.range.conv_with(&line_index);
233 lsp_types::FoldingRange {
234 start_line: range.start.line,
235 start_character: Some(range.start.character),
236 end_line: range.end.line,
237 end_character: Some(range.end.character),
238 kind: match self.kind {
239 FoldKind::Comment => Some(lsp_types::FoldingRangeKind::Comment),
240 FoldKind::Imports => Some(lsp_types::FoldingRangeKind::Imports),
241 FoldKind::Mods => None,
242 FoldKind::Block => None,
243 },
244 }
245 }
246}
247
228impl<T: ConvWith<CTX>, CTX> ConvWith<CTX> for Option<T> { 248impl<T: ConvWith<CTX>, CTX> ConvWith<CTX> for Option<T> {
229 type Output = Option<T::Output>; 249 type Output = Option<T::Output>;
230 250
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 _};
3use lsp_server::ErrorCode; 3use lsp_server::ErrorCode;
4use lsp_types::{ 4use 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};
11use ra_ide_api::{
12 AssistId, FileId, FilePosition, FileRange, FoldKind, Query, Runnable, RunnableKind,
13}; 9};
10use ra_ide_api::{AssistId, FileId, FilePosition, FileRange, Query, Runnable, RunnableKind};
14use ra_prof::profile; 11use ra_prof::profile;
15use ra_syntax::{AstNode, SyntaxKind, TextRange, TextUnit}; 12use ra_syntax::{AstNode, SyntaxKind, TextRange, TextUnit};
16use rustc_hash::FxHashMap; 13use 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