switch to FileRange
This commit is contained in:
parent
02924174bb
commit
fd33c89207
11
crates/ra_analysis/src/extend_selection.rs
Normal file
11
crates/ra_analysis/src/extend_selection.rs
Normal file
@ -0,0 +1,11 @@
|
||||
use ra_db::SyntaxDatabase;
|
||||
|
||||
use crate::{
|
||||
TextRange, FileRange,
|
||||
db::RootDatabase,
|
||||
};
|
||||
|
||||
pub(crate) fn extend_selection(db: &RootDatabase, frange: FileRange) -> TextRange {
|
||||
let file = db.source_file(frange.file_id);
|
||||
ra_editor::extend_selection(&file, frange.range).unwrap_or(frange.range)
|
||||
}
|
@ -14,9 +14,11 @@ macro_rules! ctry {
|
||||
mod imp;
|
||||
mod completion;
|
||||
mod symbol_index;
|
||||
mod syntax_highlighting;
|
||||
pub mod mock_analysis;
|
||||
|
||||
mod extend_selection;
|
||||
mod syntax_highlighting;
|
||||
|
||||
use std::{fmt, sync::Arc};
|
||||
|
||||
use rustc_hash::FxHashMap;
|
||||
@ -277,8 +279,8 @@ pub fn file_syntax(&self, file_id: FileId) -> SourceFileNode {
|
||||
pub fn file_line_index(&self, file_id: FileId) -> Arc<LineIndex> {
|
||||
self.imp.file_line_index(file_id)
|
||||
}
|
||||
pub fn extend_selection(&self, file: &SourceFileNode, range: TextRange) -> TextRange {
|
||||
ra_editor::extend_selection(file, range).unwrap_or(range)
|
||||
pub fn extend_selection(&self, frange: FileRange) -> TextRange {
|
||||
extend_selection::extend_selection(&self.imp.db, frange)
|
||||
}
|
||||
pub fn matching_brace(&self, file: &SourceFileNode, offset: TextUnit) -> Option<TextUnit> {
|
||||
ra_editor::matching_brace(file, offset)
|
||||
|
@ -2,7 +2,7 @@
|
||||
self, Location, Position, Range, SymbolKind, TextDocumentEdit, TextDocumentIdentifier,
|
||||
TextDocumentItem, TextDocumentPositionParams, Url, VersionedTextDocumentIdentifier, InsertTextFormat,
|
||||
};
|
||||
use ra_analysis::{FileId, FileSystemEdit, SourceChange, SourceFileEdit, FilePosition, CompletionItem, CompletionItemKind, InsertText};
|
||||
use ra_analysis::{FileId, FileSystemEdit, SourceChange, SourceFileEdit, FilePosition,FileRange, CompletionItem, CompletionItemKind, InsertText};
|
||||
use ra_editor::{LineCol, LineIndex, translate_offset_with_edit};
|
||||
use ra_text_edit::{AtomTextEdit, TextEdit};
|
||||
use ra_syntax::{SyntaxKind, TextRange, TextUnit};
|
||||
@ -218,6 +218,17 @@ fn try_conv_with(self, world: &ServerWorld) -> Result<FilePosition> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> TryConvWith for (&'a TextDocumentIdentifier, Range) {
|
||||
type Ctx = ServerWorld;
|
||||
type Output = FileRange;
|
||||
fn try_conv_with(self, world: &ServerWorld) -> Result<FileRange> {
|
||||
let file_id = self.0.try_conv_with(world)?;
|
||||
let line_index = world.analysis().file_line_index(file_id);
|
||||
let range = self.1.conv_with(&line_index);
|
||||
Ok(FileRange { file_id, range })
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: TryConvWith> TryConvWith for Vec<T> {
|
||||
type Ctx = <T as TryConvWith>::Ctx;
|
||||
type Output = Vec<<T as TryConvWith>::Output>;
|
||||
|
@ -8,7 +8,7 @@
|
||||
PrepareRenameResponse, RenameParams, SymbolInformation, TextDocumentIdentifier, TextEdit,
|
||||
WorkspaceEdit, ParameterInformation, ParameterLabel, SignatureInformation, Hover, HoverContents,
|
||||
};
|
||||
use ra_analysis::{FileId, FoldKind, Query, RunnableKind, FilePosition, Severity};
|
||||
use ra_analysis::{FileId, FoldKind, Query, RunnableKind, FileRange, FilePosition, Severity};
|
||||
use ra_syntax::{TextUnit, text_utils::intersect};
|
||||
use ra_text_edit::text_utils::contains_offset_nonstrict;
|
||||
use rustc_hash::FxHashMap;
|
||||
@ -33,13 +33,13 @@ pub fn handle_extend_selection(
|
||||
params: req::ExtendSelectionParams,
|
||||
) -> Result<req::ExtendSelectionResult> {
|
||||
let file_id = params.text_document.try_conv_with(&world)?;
|
||||
let file = world.analysis().file_syntax(file_id);
|
||||
let line_index = world.analysis().file_line_index(file_id);
|
||||
let selections = params
|
||||
.selections
|
||||
.into_iter()
|
||||
.map_conv_with(&line_index)
|
||||
.map(|r| world.analysis().extend_selection(&file, r))
|
||||
.map(|range| FileRange { file_id, range })
|
||||
.map(|frange| world.analysis().extend_selection(frange))
|
||||
.map_conv_with(&line_index)
|
||||
.collect();
|
||||
Ok(req::ExtendSelectionResult { selections })
|
||||
@ -71,13 +71,8 @@ pub fn handle_join_lines(
|
||||
world: ServerWorld,
|
||||
params: req::JoinLinesParams,
|
||||
) -> Result<req::SourceChange> {
|
||||
let file_id = params.text_document.try_conv_with(&world)?;
|
||||
let line_index = world.analysis().file_line_index(file_id);
|
||||
let range = params.range.conv_with(&line_index);
|
||||
world
|
||||
.analysis()
|
||||
.join_lines(file_id, range)
|
||||
.try_conv_with(&world)
|
||||
let frange = (¶ms.text_document, params.range).try_conv_with(&world)?;
|
||||
world.analysis().join_lines(frange).try_conv_with(&world)
|
||||
}
|
||||
|
||||
pub fn handle_on_enter(
|
||||
@ -614,7 +609,10 @@ pub fn handle_code_action(
|
||||
let line_index = world.analysis().file_line_index(file_id);
|
||||
let range = params.range.conv_with(&line_index);
|
||||
|
||||
let assists = world.analysis().assists(file_id, range)?.into_iter();
|
||||
let assists = world
|
||||
.analysis()
|
||||
.assists(FileRange { file_id, range })?
|
||||
.into_iter();
|
||||
let fixes = world
|
||||
.analysis()
|
||||
.diagnostics(file_id)?
|
||||
|
Loading…
Reference in New Issue
Block a user