mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-15 01:17:27 +00:00
Merge #1874
1874: move fold conversino to conv.rs r=matklad a=matklad Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
commit
4eb0bb4810
2 changed files with 28 additions and 34 deletions
|
@ -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<T: ConvWith<CTX>, CTX> ConvWith<CTX> for Option<T> {
|
||||
type Output = Option<T::Output>;
|
||||
|
||||
|
|
|
@ -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<Option<Vec<FoldingRange>>> {
|
||||
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.start.character),
|
||||
kind,
|
||||
}
|
||||
})
|
||||
.collect(),
|
||||
);
|
||||
|
||||
let res = Some(folds.into_iter().map_conv_with(&*line_index).collect());
|
||||
Ok(res)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue