Init implementation of structural search replace

This commit is contained in:
Mikhail Modin 2020-02-10 22:45:38 +00:00
parent 6fb36dfdcb
commit f8f454ab5c
10 changed files with 399 additions and 1 deletions

View file

@ -37,6 +37,7 @@ mod display;
mod inlay_hints;
mod expand;
mod expand_macro;
mod ssr;
#[cfg(test)]
mod marks;
@ -73,6 +74,7 @@ pub use crate::{
},
runnables::{Runnable, RunnableKind},
source_change::{FileSystemEdit, SourceChange, SourceFileEdit},
ssr::SsrError,
syntax_highlighting::HighlightedRange,
};
@ -464,6 +466,16 @@ impl Analysis {
self.with_db(|db| references::rename(db, position, new_name))
}
pub fn structural_search_replace(
&self,
query: &str,
) -> Cancelable<Result<SourceChange, SsrError>> {
self.with_db(|db| {
let edits = ssr::parse_search_replace(query, db)?;
Ok(SourceChange::source_file_edits("ssr", edits))
})
}
/// Performs an operation on that may be Canceled.
fn with_db<F: FnOnce(&RootDatabase) -> T + std::panic::UnwindSafe, T>(
&self,