3099: Init implementation of structural search replace r=matklad a=mikhail-m1

next steps:
* ignore space and other minor difference
* add support to ra_cli
* call rust parser to check pattern
* documentation

original issue #2267 

Co-authored-by: Mikhail Modin <mikhailm1@gmail.com>
This commit is contained in:
bors[bot] 2020-02-17 10:02:54 +00:00 committed by GitHub
commit 93d28fb50c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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, TestId},
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,