move fold conversino to conv.rs
This commit is contained in:
parent
184e80007b
commit
36732a42bd
@ -6,8 +6,8 @@ use lsp_types::{
|
|||||||
};
|
};
|
||||||
use ra_ide_api::{
|
use ra_ide_api::{
|
||||||
translate_offset_with_edit, CompletionItem, CompletionItemKind, FileId, FilePosition,
|
translate_offset_with_edit, CompletionItem, CompletionItemKind, FileId, FilePosition,
|
||||||
FileRange, FileSystemEdit, InsertTextFormat, LineCol, LineIndex, NavigationTarget, RangeInfo,
|
FileRange, FileSystemEdit, Fold, FoldKind, InsertTextFormat, LineCol, LineIndex,
|
||||||
Severity, SourceChange, SourceFileEdit,
|
NavigationTarget, RangeInfo, Severity, SourceChange, SourceFileEdit,
|
||||||
};
|
};
|
||||||
use ra_syntax::{SyntaxKind, TextRange, TextUnit};
|
use ra_syntax::{SyntaxKind, TextRange, TextUnit};
|
||||||
use ra_text_edit::{AtomTextEdit, TextEdit};
|
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<T: ConvWith<CTX>, CTX> ConvWith<CTX> for Option<T> {
|
impl<T: ConvWith<CTX>, CTX> ConvWith<CTX> for Option<T> {
|
||||||
type Output = Option<T::Output>;
|
type Output = Option<T::Output>;
|
||||||
|
|
||||||
|
@ -3,14 +3,11 @@ use std::{fmt::Write as _, io::Write as _};
|
|||||||
use lsp_server::ErrorCode;
|
use lsp_server::ErrorCode;
|
||||||
use lsp_types::{
|
use lsp_types::{
|
||||||
CodeAction, CodeActionResponse, CodeLens, Command, CompletionItem, Diagnostic,
|
CodeAction, CodeActionResponse, CodeLens, Command, CompletionItem, Diagnostic,
|
||||||
DocumentFormattingParams, DocumentHighlight, DocumentSymbol, FoldingRange, FoldingRangeKind,
|
DocumentFormattingParams, DocumentHighlight, DocumentSymbol, FoldingRange, FoldingRangeParams,
|
||||||
FoldingRangeParams, Hover, HoverContents, Location, MarkupContent, MarkupKind, Position,
|
Hover, HoverContents, Location, MarkupContent, MarkupKind, Position, PrepareRenameResponse,
|
||||||
PrepareRenameResponse, Range, RenameParams, SymbolInformation, TextDocumentIdentifier,
|
Range, RenameParams, SymbolInformation, TextDocumentIdentifier, TextEdit, WorkspaceEdit,
|
||||||
TextEdit, WorkspaceEdit,
|
|
||||||
};
|
|
||||||
use ra_ide_api::{
|
|
||||||
AssistId, FileId, FilePosition, FileRange, FoldKind, Query, Runnable, RunnableKind,
|
|
||||||
};
|
};
|
||||||
|
use ra_ide_api::{AssistId, FileId, FilePosition, FileRange, Query, Runnable, RunnableKind};
|
||||||
use ra_prof::profile;
|
use ra_prof::profile;
|
||||||
use ra_syntax::{AstNode, SyntaxKind, TextRange, TextUnit};
|
use ra_syntax::{AstNode, SyntaxKind, TextRange, TextUnit};
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::FxHashMap;
|
||||||
@ -383,32 +380,9 @@ pub fn handle_folding_range(
|
|||||||
params: FoldingRangeParams,
|
params: FoldingRangeParams,
|
||||||
) -> Result<Option<Vec<FoldingRange>>> {
|
) -> Result<Option<Vec<FoldingRange>>> {
|
||||||
let file_id = params.text_document.try_conv_with(&world)?;
|
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 line_index = world.analysis().file_line_index(file_id)?;
|
||||||
|
let res = Some(folds.into_iter().map_conv_with(&*line_index).collect());
|
||||||
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(),
|
|
||||||
);
|
|
||||||
|
|
||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user