mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 13:03:31 +00:00
Lift SourceChange to the ra_ide_db
This commit is contained in:
parent
beb35c3ecb
commit
3850b1c086
6 changed files with 25 additions and 25 deletions
|
@ -16,7 +16,6 @@ macro_rules! eprintln {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod mock_analysis;
|
pub mod mock_analysis;
|
||||||
mod source_change;
|
|
||||||
|
|
||||||
mod prime_caches;
|
mod prime_caches;
|
||||||
mod status;
|
mod status;
|
||||||
|
@ -78,7 +77,6 @@ pub use crate::{
|
||||||
inlay_hints::{InlayHint, InlayHintsConfig, InlayKind},
|
inlay_hints::{InlayHint, InlayHintsConfig, InlayKind},
|
||||||
references::{Declaration, Reference, ReferenceAccess, ReferenceKind, ReferenceSearchResult},
|
references::{Declaration, Reference, ReferenceAccess, ReferenceKind, ReferenceSearchResult},
|
||||||
runnables::{Runnable, RunnableKind, TestId},
|
runnables::{Runnable, RunnableKind, TestId},
|
||||||
source_change::{FileSystemEdit, SourceChange, SourceFileEdit},
|
|
||||||
ssr::SsrError,
|
ssr::SsrError,
|
||||||
syntax_highlighting::{
|
syntax_highlighting::{
|
||||||
Highlight, HighlightModifier, HighlightModifiers, HighlightTag, HighlightedRange,
|
Highlight, HighlightModifier, HighlightModifiers, HighlightTag, HighlightedRange,
|
||||||
|
@ -94,6 +92,7 @@ pub use ra_ide_db::{
|
||||||
line_index::{LineCol, LineIndex},
|
line_index::{LineCol, LineIndex},
|
||||||
line_index_utils::translate_offset_with_edit,
|
line_index_utils::translate_offset_with_edit,
|
||||||
search::SearchScope,
|
search::SearchScope,
|
||||||
|
source_change::{FileSystemEdit, SourceChange, SourceFileEdit},
|
||||||
symbol_index::Query,
|
symbol_index::Query,
|
||||||
RootDatabase,
|
RootDatabase,
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
//! structural search replace
|
//! structural search replace
|
||||||
|
|
||||||
use crate::source_change::SourceFileEdit;
|
use std::{collections::HashMap, iter::once, str::FromStr};
|
||||||
|
|
||||||
use ra_db::{SourceDatabase, SourceDatabaseExt};
|
use ra_db::{SourceDatabase, SourceDatabaseExt};
|
||||||
use ra_ide_db::symbol_index::SymbolsDatabase;
|
use ra_ide_db::{symbol_index::SymbolsDatabase, RootDatabase};
|
||||||
use ra_ide_db::RootDatabase;
|
|
||||||
use ra_syntax::ast::make::try_expr_from_text;
|
|
||||||
use ra_syntax::ast::{
|
use ra_syntax::ast::{
|
||||||
ArgList, AstToken, CallExpr, Comment, Expr, MethodCallExpr, RecordField, RecordLit,
|
make::try_expr_from_text, ArgList, AstToken, CallExpr, Comment, Expr, MethodCallExpr,
|
||||||
|
RecordField, RecordLit,
|
||||||
};
|
};
|
||||||
use ra_syntax::{AstNode, SyntaxElement, SyntaxKind, SyntaxNode};
|
use ra_syntax::{AstNode, SyntaxElement, SyntaxKind, SyntaxNode};
|
||||||
use ra_text_edit::{TextEdit, TextEditBuilder};
|
use ra_text_edit::{TextEdit, TextEditBuilder};
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::FxHashMap;
|
||||||
use std::collections::HashMap;
|
|
||||||
use std::{iter::once, str::FromStr};
|
use crate::SourceFileEdit;
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
pub struct SsrError(String);
|
pub struct SsrError(String);
|
||||||
|
|
|
@ -17,15 +17,16 @@ mod on_enter;
|
||||||
|
|
||||||
use ra_db::{FilePosition, SourceDatabase};
|
use ra_db::{FilePosition, SourceDatabase};
|
||||||
use ra_fmt::leading_indent;
|
use ra_fmt::leading_indent;
|
||||||
use ra_ide_db::RootDatabase;
|
use ra_ide_db::{source_change::SingleFileChange, RootDatabase};
|
||||||
use ra_syntax::{
|
use ra_syntax::{
|
||||||
algo::find_node_at_offset,
|
algo::find_node_at_offset,
|
||||||
ast::{self, AstToken},
|
ast::{self, AstToken},
|
||||||
AstNode, SourceFile, TextRange, TextSize,
|
AstNode, SourceFile, TextRange, TextSize,
|
||||||
};
|
};
|
||||||
|
|
||||||
use ra_text_edit::TextEdit;
|
use ra_text_edit::TextEdit;
|
||||||
|
|
||||||
use crate::{source_change::SingleFileChange, SourceChange};
|
use crate::SourceChange;
|
||||||
|
|
||||||
pub(crate) use on_enter::on_enter;
|
pub(crate) use on_enter::on_enter;
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ pub mod change;
|
||||||
pub mod defs;
|
pub mod defs;
|
||||||
pub mod search;
|
pub mod search;
|
||||||
pub mod imports_locator;
|
pub mod imports_locator;
|
||||||
|
pub mod source_change;
|
||||||
mod wasm_shims;
|
mod wasm_shims;
|
||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
|
@ -3,13 +3,12 @@
|
||||||
//!
|
//!
|
||||||
//! It can be viewed as a dual for `AnalysisChange`.
|
//! It can be viewed as a dual for `AnalysisChange`.
|
||||||
|
|
||||||
use ra_db::RelativePathBuf;
|
use ra_db::{FileId, FilePosition, RelativePathBuf, SourceRootId};
|
||||||
use ra_text_edit::TextEdit;
|
use ra_text_edit::{TextEdit, TextSize};
|
||||||
|
|
||||||
use crate::{FileId, FilePosition, SourceRootId, TextSize};
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct SourceChange {
|
pub struct SourceChange {
|
||||||
|
/// For display in the undo log in the editor
|
||||||
pub label: String,
|
pub label: String,
|
||||||
pub source_file_edits: Vec<SourceFileEdit>,
|
pub source_file_edits: Vec<SourceFileEdit>,
|
||||||
pub file_system_edits: Vec<FileSystemEdit>,
|
pub file_system_edits: Vec<FileSystemEdit>,
|
||||||
|
@ -19,7 +18,7 @@ pub struct SourceChange {
|
||||||
impl SourceChange {
|
impl SourceChange {
|
||||||
/// Creates a new SourceChange with the given label
|
/// Creates a new SourceChange with the given label
|
||||||
/// from the edits.
|
/// from the edits.
|
||||||
pub(crate) fn from_edits<L: Into<String>>(
|
pub fn from_edits<L: Into<String>>(
|
||||||
label: L,
|
label: L,
|
||||||
source_file_edits: Vec<SourceFileEdit>,
|
source_file_edits: Vec<SourceFileEdit>,
|
||||||
file_system_edits: Vec<FileSystemEdit>,
|
file_system_edits: Vec<FileSystemEdit>,
|
||||||
|
@ -34,7 +33,7 @@ impl SourceChange {
|
||||||
|
|
||||||
/// Creates a new SourceChange with the given label,
|
/// Creates a new SourceChange with the given label,
|
||||||
/// containing only the given `SourceFileEdits`.
|
/// containing only the given `SourceFileEdits`.
|
||||||
pub(crate) fn source_file_edits<L: Into<String>>(label: L, edits: Vec<SourceFileEdit>) -> Self {
|
pub fn source_file_edits<L: Into<String>>(label: L, edits: Vec<SourceFileEdit>) -> Self {
|
||||||
let label = label.into();
|
let label = label.into();
|
||||||
assert!(label.starts_with(char::is_uppercase));
|
assert!(label.starts_with(char::is_uppercase));
|
||||||
SourceChange {
|
SourceChange {
|
||||||
|
@ -58,13 +57,13 @@ impl SourceChange {
|
||||||
|
|
||||||
/// Creates a new SourceChange with the given label,
|
/// Creates a new SourceChange with the given label,
|
||||||
/// containing only a single `SourceFileEdit`.
|
/// containing only a single `SourceFileEdit`.
|
||||||
pub(crate) fn source_file_edit<L: Into<String>>(label: L, edit: SourceFileEdit) -> Self {
|
pub fn source_file_edit<L: Into<String>>(label: L, edit: SourceFileEdit) -> Self {
|
||||||
SourceChange::source_file_edits(label, vec![edit])
|
SourceChange::source_file_edits(label, vec![edit])
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new SourceChange with the given label
|
/// Creates a new SourceChange with the given label
|
||||||
/// from the given `FileId` and `TextEdit`
|
/// from the given `FileId` and `TextEdit`
|
||||||
pub(crate) fn source_file_edit_from<L: Into<String>>(
|
pub fn source_file_edit_from<L: Into<String>>(
|
||||||
label: L,
|
label: L,
|
||||||
file_id: FileId,
|
file_id: FileId,
|
||||||
edit: TextEdit,
|
edit: TextEdit,
|
||||||
|
@ -74,18 +73,18 @@ impl SourceChange {
|
||||||
|
|
||||||
/// Creates a new SourceChange with the given label
|
/// Creates a new SourceChange with the given label
|
||||||
/// from the given `FileId` and `TextEdit`
|
/// from the given `FileId` and `TextEdit`
|
||||||
pub(crate) fn file_system_edit<L: Into<String>>(label: L, edit: FileSystemEdit) -> Self {
|
pub fn file_system_edit<L: Into<String>>(label: L, edit: FileSystemEdit) -> Self {
|
||||||
SourceChange::file_system_edits(label, vec![edit])
|
SourceChange::file_system_edits(label, vec![edit])
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the cursor position to the given `FilePosition`
|
/// Sets the cursor position to the given `FilePosition`
|
||||||
pub(crate) fn with_cursor(mut self, cursor_position: FilePosition) -> Self {
|
pub fn with_cursor(mut self, cursor_position: FilePosition) -> Self {
|
||||||
self.cursor_position = Some(cursor_position);
|
self.cursor_position = Some(cursor_position);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the cursor position to the given `FilePosition`
|
/// Sets the cursor position to the given `FilePosition`
|
||||||
pub(crate) fn with_cursor_opt(mut self, cursor_position: Option<FilePosition>) -> Self {
|
pub fn with_cursor_opt(mut self, cursor_position: Option<FilePosition>) -> Self {
|
||||||
self.cursor_position = cursor_position;
|
self.cursor_position = cursor_position;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -103,14 +102,14 @@ pub enum FileSystemEdit {
|
||||||
MoveFile { src: FileId, dst_source_root: SourceRootId, dst_path: RelativePathBuf },
|
MoveFile { src: FileId, dst_source_root: SourceRootId, dst_path: RelativePathBuf },
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) struct SingleFileChange {
|
pub struct SingleFileChange {
|
||||||
pub label: String,
|
pub label: String,
|
||||||
pub edit: TextEdit,
|
pub edit: TextEdit,
|
||||||
pub cursor_position: Option<TextSize>,
|
pub cursor_position: Option<TextSize>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SingleFileChange {
|
impl SingleFileChange {
|
||||||
pub(crate) fn into_source_change(self, file_id: FileId) -> SourceChange {
|
pub fn into_source_change(self, file_id: FileId) -> SourceChange {
|
||||||
SourceChange {
|
SourceChange {
|
||||||
label: self.label,
|
label: self.label,
|
||||||
source_file_edits: vec![SourceFileEdit { file_id, edit: self.edit }],
|
source_file_edits: vec![SourceFileEdit { file_id, edit: self.edit }],
|
|
@ -4,7 +4,7 @@
|
||||||
//! so `TextEdit` is the ultimate representation of the work done by
|
//! so `TextEdit` is the ultimate representation of the work done by
|
||||||
//! rust-analyzer.
|
//! rust-analyzer.
|
||||||
|
|
||||||
use text_size::{TextRange, TextSize};
|
pub use text_size::{TextRange, TextSize};
|
||||||
|
|
||||||
/// `InsertDelete` -- a single "atomic" change to text
|
/// `InsertDelete` -- a single "atomic" change to text
|
||||||
///
|
///
|
||||||
|
|
Loading…
Reference in a new issue