aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide')
-rw-r--r--crates/ra_ide/Cargo.toml6
-rw-r--r--crates/ra_ide/src/call_hierarchy.rs2
-rw-r--r--crates/ra_ide/src/call_info.rs2
-rw-r--r--crates/ra_ide/src/completion.rs2
-rw-r--r--crates/ra_ide/src/completion/completion_context.rs2
-rw-r--r--crates/ra_ide/src/diagnostics.rs2
-rw-r--r--crates/ra_ide/src/diagnostics/diagnostics_with_fix.rs2
-rw-r--r--crates/ra_ide/src/display/navigation_target.rs2
-rw-r--r--crates/ra_ide/src/expand_macro.rs2
-rw-r--r--crates/ra_ide/src/extend_selection.rs2
-rw-r--r--crates/ra_ide/src/goto_definition.rs2
-rw-r--r--crates/ra_ide/src/goto_implementation.rs2
-rw-r--r--crates/ra_ide/src/goto_type_definition.rs2
-rw-r--r--crates/ra_ide/src/hover.rs4
-rw-r--r--crates/ra_ide/src/inlay_hints.rs2
-rw-r--r--crates/ra_ide/src/lib.rs26
-rw-r--r--crates/ra_ide/src/parent_module.rs2
-rw-r--r--crates/ra_ide/src/references.rs4
-rw-r--r--crates/ra_ide/src/references/rename.rs2
-rw-r--r--crates/ra_ide/src/runnables.rs2
-rw-r--r--crates/ra_ide/src/ssr.rs72
-rw-r--r--crates/ra_ide/src/status.rs4
-rw-r--r--crates/ra_ide/src/syntax_highlighting.rs2
-rw-r--r--crates/ra_ide/src/syntax_tree.rs2
-rw-r--r--crates/ra_ide/src/typing.rs2
-rw-r--r--crates/ra_ide/src/typing/on_enter.rs2
26 files changed, 43 insertions, 113 deletions
diff --git a/crates/ra_ide/Cargo.toml b/crates/ra_ide/Cargo.toml
index 1af51f3ae..8519e9cca 100644
--- a/crates/ra_ide/Cargo.toml
+++ b/crates/ra_ide/Cargo.toml
@@ -24,16 +24,16 @@ stdx = { path = "../stdx" }
24syntax = { path = "../syntax" } 24syntax = { path = "../syntax" }
25text_edit = { path = "../text_edit" } 25text_edit = { path = "../text_edit" }
26base_db = { path = "../base_db" } 26base_db = { path = "../base_db" }
27ra_ide_db = { path = "../ra_ide_db" } 27ide_db = { path = "../ide_db" }
28cfg = { path = "../cfg" } 28cfg = { path = "../cfg" }
29profile = { path = "../profile" } 29profile = { path = "../profile" }
30test_utils = { path = "../test_utils" } 30test_utils = { path = "../test_utils" }
31ra_assists = { path = "../ra_assists" } 31ra_assists = { path = "../ra_assists" }
32ra_ssr = { path = "../ra_ssr" } 32ssr = { path = "../ssr" }
33 33
34# ra_ide should depend only on the top-level `hir` package. if you need 34# ra_ide should depend only on the top-level `hir` package. if you need
35# something from some `hir_xxx` subpackage, reexport the API via `hir`. 35# something from some `hir_xxx` subpackage, reexport the API via `hir`.
36hir = { path = "../ra_hir", package = "ra_hir" } 36hir = { path = "../hir" }
37 37
38[dev-dependencies] 38[dev-dependencies]
39expect = { path = "../expect" } 39expect = { path = "../expect" }
diff --git a/crates/ra_ide/src/call_hierarchy.rs b/crates/ra_ide/src/call_hierarchy.rs
index 3578b8d3c..58e26b94c 100644
--- a/crates/ra_ide/src/call_hierarchy.rs
+++ b/crates/ra_ide/src/call_hierarchy.rs
@@ -3,7 +3,7 @@
3use indexmap::IndexMap; 3use indexmap::IndexMap;
4 4
5use hir::Semantics; 5use hir::Semantics;
6use ra_ide_db::RootDatabase; 6use ide_db::RootDatabase;
7use syntax::{ast, match_ast, AstNode, TextRange}; 7use syntax::{ast, match_ast, AstNode, TextRange};
8 8
9use crate::{ 9use crate::{
diff --git a/crates/ra_ide/src/call_info.rs b/crates/ra_ide/src/call_info.rs
index 703cbc6b4..86abd2d8c 100644
--- a/crates/ra_ide/src/call_info.rs
+++ b/crates/ra_ide/src/call_info.rs
@@ -1,7 +1,7 @@
1//! FIXME: write short doc here 1//! FIXME: write short doc here
2use either::Either; 2use either::Either;
3use hir::{Docs, HirDisplay, Semantics, Type}; 3use hir::{Docs, HirDisplay, Semantics, Type};
4use ra_ide_db::RootDatabase; 4use ide_db::RootDatabase;
5use stdx::format_to; 5use stdx::format_to;
6use syntax::{ 6use syntax::{
7 ast::{self, ArgListOwner}, 7 ast::{self, ArgListOwner},
diff --git a/crates/ra_ide/src/completion.rs b/crates/ra_ide/src/completion.rs
index 68ac05e4c..7fb4d687e 100644
--- a/crates/ra_ide/src/completion.rs
+++ b/crates/ra_ide/src/completion.rs
@@ -19,7 +19,7 @@ mod complete_postfix;
19mod complete_macro_in_item_position; 19mod complete_macro_in_item_position;
20mod complete_trait_impl; 20mod complete_trait_impl;
21 21
22use ra_ide_db::RootDatabase; 22use ide_db::RootDatabase;
23 23
24use crate::{ 24use crate::{
25 completion::{ 25 completion::{
diff --git a/crates/ra_ide/src/completion/completion_context.rs b/crates/ra_ide/src/completion/completion_context.rs
index 0e0a201d0..047ecd9d7 100644
--- a/crates/ra_ide/src/completion/completion_context.rs
+++ b/crates/ra_ide/src/completion/completion_context.rs
@@ -2,7 +2,7 @@
2 2
3use base_db::SourceDatabase; 3use base_db::SourceDatabase;
4use hir::{Semantics, SemanticsScope, Type}; 4use hir::{Semantics, SemanticsScope, Type};
5use ra_ide_db::RootDatabase; 5use ide_db::RootDatabase;
6use syntax::{ 6use syntax::{
7 algo::{find_covering_element, find_node_at_offset}, 7 algo::{find_covering_element, find_node_at_offset},
8 ast, match_ast, AstNode, NodeOrToken, 8 ast, match_ast, AstNode, NodeOrToken,
diff --git a/crates/ra_ide/src/diagnostics.rs b/crates/ra_ide/src/diagnostics.rs
index 4e59e3a48..a3ec98178 100644
--- a/crates/ra_ide/src/diagnostics.rs
+++ b/crates/ra_ide/src/diagnostics.rs
@@ -8,8 +8,8 @@ use std::cell::RefCell;
8 8
9use base_db::SourceDatabase; 9use base_db::SourceDatabase;
10use hir::{diagnostics::DiagnosticSinkBuilder, Semantics}; 10use hir::{diagnostics::DiagnosticSinkBuilder, Semantics};
11use ide_db::RootDatabase;
11use itertools::Itertools; 12use itertools::Itertools;
12use ra_ide_db::RootDatabase;
13use syntax::{ 13use syntax::{
14 ast::{self, AstNode}, 14 ast::{self, AstNode},
15 SyntaxNode, TextRange, T, 15 SyntaxNode, TextRange, T,
diff --git a/crates/ra_ide/src/diagnostics/diagnostics_with_fix.rs b/crates/ra_ide/src/diagnostics/diagnostics_with_fix.rs
index 7e126d7a6..85b46c995 100644
--- a/crates/ra_ide/src/diagnostics/diagnostics_with_fix.rs
+++ b/crates/ra_ide/src/diagnostics/diagnostics_with_fix.rs
@@ -8,7 +8,7 @@ use hir::{
8 diagnostics::{Diagnostic, MissingFields, MissingOkInTailExpr, NoSuchField, UnresolvedModule}, 8 diagnostics::{Diagnostic, MissingFields, MissingOkInTailExpr, NoSuchField, UnresolvedModule},
9 HasSource, HirDisplay, Semantics, VariantDef, 9 HasSource, HirDisplay, Semantics, VariantDef,
10}; 10};
11use ra_ide_db::{ 11use ide_db::{
12 source_change::{FileSystemEdit, SourceFileEdit}, 12 source_change::{FileSystemEdit, SourceFileEdit},
13 RootDatabase, 13 RootDatabase,
14}; 14};
diff --git a/crates/ra_ide/src/display/navigation_target.rs b/crates/ra_ide/src/display/navigation_target.rs
index 09ec3f65e..e77106177 100644
--- a/crates/ra_ide/src/display/navigation_target.rs
+++ b/crates/ra_ide/src/display/navigation_target.rs
@@ -3,7 +3,7 @@
3use base_db::{FileId, SourceDatabase}; 3use base_db::{FileId, SourceDatabase};
4use either::Either; 4use either::Either;
5use hir::{original_range, AssocItem, FieldSource, HasSource, InFile, ModuleSource}; 5use hir::{original_range, AssocItem, FieldSource, HasSource, InFile, ModuleSource};
6use ra_ide_db::{defs::Definition, RootDatabase}; 6use ide_db::{defs::Definition, RootDatabase};
7use syntax::{ 7use syntax::{
8 ast::{self, DocCommentsOwner, NameOwner}, 8 ast::{self, DocCommentsOwner, NameOwner},
9 match_ast, AstNode, SmolStr, 9 match_ast, AstNode, SmolStr,
diff --git a/crates/ra_ide/src/expand_macro.rs b/crates/ra_ide/src/expand_macro.rs
index c25e068d6..31455709d 100644
--- a/crates/ra_ide/src/expand_macro.rs
+++ b/crates/ra_ide/src/expand_macro.rs
@@ -1,5 +1,5 @@
1use hir::Semantics; 1use hir::Semantics;
2use ra_ide_db::RootDatabase; 2use ide_db::RootDatabase;
3use syntax::{ 3use syntax::{
4 algo::{find_node_at_offset, SyntaxRewriter}, 4 algo::{find_node_at_offset, SyntaxRewriter},
5 ast, AstNode, NodeOrToken, SyntaxKind, 5 ast, AstNode, NodeOrToken, SyntaxKind,
diff --git a/crates/ra_ide/src/extend_selection.rs b/crates/ra_ide/src/extend_selection.rs
index f30df2bff..34563a026 100644
--- a/crates/ra_ide/src/extend_selection.rs
+++ b/crates/ra_ide/src/extend_selection.rs
@@ -1,7 +1,7 @@
1use std::iter::successors; 1use std::iter::successors;
2 2
3use hir::Semantics; 3use hir::Semantics;
4use ra_ide_db::RootDatabase; 4use ide_db::RootDatabase;
5use syntax::{ 5use syntax::{
6 algo::{self, find_covering_element, skip_trivia_token}, 6 algo::{self, find_covering_element, skip_trivia_token},
7 ast::{self, AstNode, AstToken}, 7 ast::{self, AstNode, AstToken},
diff --git a/crates/ra_ide/src/goto_definition.rs b/crates/ra_ide/src/goto_definition.rs
index b93d116bf..15e9b7fad 100644
--- a/crates/ra_ide/src/goto_definition.rs
+++ b/crates/ra_ide/src/goto_definition.rs
@@ -1,5 +1,5 @@
1use hir::Semantics; 1use hir::Semantics;
2use ra_ide_db::{ 2use ide_db::{
3 defs::{classify_name, classify_name_ref}, 3 defs::{classify_name, classify_name_ref},
4 symbol_index, RootDatabase, 4 symbol_index, RootDatabase,
5}; 5};
diff --git a/crates/ra_ide/src/goto_implementation.rs b/crates/ra_ide/src/goto_implementation.rs
index 6dc2ccfd0..f503f4ec5 100644
--- a/crates/ra_ide/src/goto_implementation.rs
+++ b/crates/ra_ide/src/goto_implementation.rs
@@ -1,5 +1,5 @@
1use hir::{Crate, ImplDef, Semantics}; 1use hir::{Crate, ImplDef, Semantics};
2use ra_ide_db::RootDatabase; 2use ide_db::RootDatabase;
3use syntax::{algo::find_node_at_offset, ast, AstNode}; 3use syntax::{algo::find_node_at_offset, ast, AstNode};
4 4
5use crate::{display::ToNav, FilePosition, NavigationTarget, RangeInfo}; 5use crate::{display::ToNav, FilePosition, NavigationTarget, RangeInfo};
diff --git a/crates/ra_ide/src/goto_type_definition.rs b/crates/ra_ide/src/goto_type_definition.rs
index 8017ca58c..4a151b150 100644
--- a/crates/ra_ide/src/goto_type_definition.rs
+++ b/crates/ra_ide/src/goto_type_definition.rs
@@ -1,4 +1,4 @@
1use ra_ide_db::RootDatabase; 1use ide_db::RootDatabase;
2use syntax::{ast, match_ast, AstNode, SyntaxKind::*, SyntaxToken, TokenAtOffset, T}; 2use syntax::{ast, match_ast, AstNode, SyntaxKind::*, SyntaxToken, TokenAtOffset, T};
3 3
4use crate::{display::ToNav, FilePosition, NavigationTarget, RangeInfo}; 4use crate::{display::ToNav, FilePosition, NavigationTarget, RangeInfo};
diff --git a/crates/ra_ide/src/hover.rs b/crates/ra_ide/src/hover.rs
index a74087f87..331aa4db0 100644
--- a/crates/ra_ide/src/hover.rs
+++ b/crates/ra_ide/src/hover.rs
@@ -3,11 +3,11 @@ use hir::{
3 Adt, AsAssocItem, AssocItemContainer, Documentation, FieldSource, HasSource, HirDisplay, 3 Adt, AsAssocItem, AssocItemContainer, Documentation, FieldSource, HasSource, HirDisplay,
4 Module, ModuleDef, ModuleSource, Semantics, 4 Module, ModuleDef, ModuleSource, Semantics,
5}; 5};
6use itertools::Itertools; 6use ide_db::{
7use ra_ide_db::{
8 defs::{classify_name, classify_name_ref, Definition}, 7 defs::{classify_name, classify_name_ref, Definition},
9 RootDatabase, 8 RootDatabase,
10}; 9};
10use itertools::Itertools;
11use stdx::format_to; 11use stdx::format_to;
12use syntax::{ast, match_ast, AstNode, SyntaxKind::*, SyntaxToken, TokenAtOffset, T}; 12use syntax::{ast, match_ast, AstNode, SyntaxKind::*, SyntaxToken, TokenAtOffset, T};
13use test_utils::mark; 13use test_utils::mark;
diff --git a/crates/ra_ide/src/inlay_hints.rs b/crates/ra_ide/src/inlay_hints.rs
index 81fe274ad..002adf915 100644
--- a/crates/ra_ide/src/inlay_hints.rs
+++ b/crates/ra_ide/src/inlay_hints.rs
@@ -1,5 +1,5 @@
1use hir::{Adt, Callable, HirDisplay, Semantics, Type}; 1use hir::{Adt, Callable, HirDisplay, Semantics, Type};
2use ra_ide_db::RootDatabase; 2use ide_db::RootDatabase;
3use stdx::to_lower_snake_case; 3use stdx::to_lower_snake_case;
4use syntax::{ 4use syntax::{
5 ast::{self, ArgListOwner, AstNode}, 5 ast::{self, ArgListOwner, AstNode},
diff --git a/crates/ra_ide/src/lib.rs b/crates/ra_ide/src/lib.rs
index 789fbdaf2..bbc9e4b8a 100644
--- a/crates/ra_ide/src/lib.rs
+++ b/crates/ra_ide/src/lib.rs
@@ -3,7 +3,7 @@
3//! Strings, suitable for displaying to the human. 3//! Strings, suitable for displaying to the human.
4//! 4//!
5//! What powers this API are the `RootDatabase` struct, which defines a `salsa` 5//! What powers this API are the `RootDatabase` struct, which defines a `salsa`
6//! database, and the `ra_hir` crate, where majority of the analysis happens. 6//! database, and the `hir` crate, where majority of the analysis happens.
7//! However, IDE specific bits of the analysis (most notably completion) happen 7//! However, IDE specific bits of the analysis (most notably completion) happen
8//! in this crate. 8//! in this crate.
9 9
@@ -39,7 +39,6 @@ mod matching_brace;
39mod parent_module; 39mod parent_module;
40mod references; 40mod references;
41mod runnables; 41mod runnables;
42mod ssr;
43mod status; 42mod status;
44mod syntax_highlighting; 43mod syntax_highlighting;
45mod syntax_tree; 44mod syntax_tree;
@@ -52,7 +51,7 @@ use base_db::{
52 CheckCanceled, Env, FileLoader, FileSet, SourceDatabase, VfsPath, 51 CheckCanceled, Env, FileLoader, FileSet, SourceDatabase, VfsPath,
53}; 52};
54use cfg::CfgOptions; 53use cfg::CfgOptions;
55use ra_ide_db::{ 54use ide_db::{
56 symbol_index::{self, FileSymbol}, 55 symbol_index::{self, FileSymbol},
57 LineIndexDatabase, 56 LineIndexDatabase,
58}; 57};
@@ -86,8 +85,7 @@ pub use base_db::{
86 SourceRootId, 85 SourceRootId,
87}; 86};
88pub use hir::{Documentation, Semantics}; 87pub use hir::{Documentation, Semantics};
89pub use ra_assists::{Assist, AssistConfig, AssistId, AssistKind, ResolvedAssist}; 88pub use ide_db::{
90pub use ra_ide_db::{
91 change::AnalysisChange, 89 change::AnalysisChange,
92 line_index::{LineCol, LineIndex}, 90 line_index::{LineCol, LineIndex},
93 search::SearchScope, 91 search::SearchScope,
@@ -95,7 +93,8 @@ pub use ra_ide_db::{
95 symbol_index::Query, 93 symbol_index::Query,
96 RootDatabase, 94 RootDatabase,
97}; 95};
98pub use ra_ssr::SsrError; 96pub use ra_assists::{Assist, AssistConfig, AssistId, AssistKind, ResolvedAssist};
97pub use ssr::SsrError;
99pub use text_edit::{Indel, TextEdit}; 98pub use text_edit::{Indel, TextEdit};
100 99
101pub type Cancelable<T> = Result<T, Canceled>; 100pub type Cancelable<T> = Result<T, Canceled>;
@@ -515,20 +514,23 @@ impl Analysis {
515 &self, 514 &self,
516 query: &str, 515 query: &str,
517 parse_only: bool, 516 parse_only: bool,
518 position: FilePosition, 517 resolve_context: FilePosition,
519 selections: Vec<FileRange>, 518 selections: Vec<FileRange>,
520 ) -> Cancelable<Result<SourceChange, SsrError>> { 519 ) -> Cancelable<Result<SourceChange, SsrError>> {
521 self.with_db(|db| { 520 self.with_db(|db| {
522 let edits = ssr::parse_search_replace(query, parse_only, db, position, selections)?; 521 let rule: ssr::SsrRule = query.parse()?;
522 let mut match_finder = ssr::MatchFinder::in_context(db, resolve_context, selections);
523 match_finder.add_rule(rule)?;
524 let edits = if parse_only { Vec::new() } else { match_finder.edits() };
523 Ok(SourceChange::from(edits)) 525 Ok(SourceChange::from(edits))
524 }) 526 })
525 } 527 }
526 528
527 /// Performs an operation on that may be Canceled. 529 /// Performs an operation on that may be Canceled.
528 fn with_db<F: FnOnce(&RootDatabase) -> T + std::panic::UnwindSafe, T>( 530 fn with_db<F, T>(&self, f: F) -> Cancelable<T>
529 &self, 531 where
530 f: F, 532 F: FnOnce(&RootDatabase) -> T + std::panic::UnwindSafe,
531 ) -> Cancelable<T> { 533 {
532 self.db.catch_canceled(f) 534 self.db.catch_canceled(f)
533 } 535 }
534} 536}
diff --git a/crates/ra_ide/src/parent_module.rs b/crates/ra_ide/src/parent_module.rs
index 8439e1d5d..59ed2967c 100644
--- a/crates/ra_ide/src/parent_module.rs
+++ b/crates/ra_ide/src/parent_module.rs
@@ -1,6 +1,6 @@
1use base_db::{CrateId, FileId, FilePosition}; 1use base_db::{CrateId, FileId, FilePosition};
2use hir::Semantics; 2use hir::Semantics;
3use ra_ide_db::RootDatabase; 3use ide_db::RootDatabase;
4use syntax::{ 4use syntax::{
5 algo::find_node_at_offset, 5 algo::find_node_at_offset,
6 ast::{self, AstNode}, 6 ast::{self, AstNode},
diff --git a/crates/ra_ide/src/references.rs b/crates/ra_ide/src/references.rs
index e89dca869..0a76ec6b4 100644
--- a/crates/ra_ide/src/references.rs
+++ b/crates/ra_ide/src/references.rs
@@ -12,7 +12,7 @@
12mod rename; 12mod rename;
13 13
14use hir::Semantics; 14use hir::Semantics;
15use ra_ide_db::{ 15use ide_db::{
16 defs::{classify_name, classify_name_ref, Definition}, 16 defs::{classify_name, classify_name_ref, Definition},
17 search::SearchScope, 17 search::SearchScope,
18 RootDatabase, 18 RootDatabase,
@@ -27,7 +27,7 @@ use crate::{display::TryToNav, FilePosition, FileRange, NavigationTarget, RangeI
27 27
28pub(crate) use self::rename::rename; 28pub(crate) use self::rename::rename;
29 29
30pub use ra_ide_db::search::{Reference, ReferenceAccess, ReferenceKind}; 30pub use ide_db::search::{Reference, ReferenceAccess, ReferenceKind};
31 31
32#[derive(Debug, Clone)] 32#[derive(Debug, Clone)]
33pub struct ReferenceSearchResult { 33pub struct ReferenceSearchResult {
diff --git a/crates/ra_ide/src/references/rename.rs b/crates/ra_ide/src/references/rename.rs
index 5697b9d87..d73dc9cd0 100644
--- a/crates/ra_ide/src/references/rename.rs
+++ b/crates/ra_ide/src/references/rename.rs
@@ -2,7 +2,7 @@
2 2
3use base_db::SourceDatabaseExt; 3use base_db::SourceDatabaseExt;
4use hir::{Module, ModuleDef, ModuleSource, Semantics}; 4use hir::{Module, ModuleDef, ModuleSource, Semantics};
5use ra_ide_db::{ 5use ide_db::{
6 defs::{classify_name, classify_name_ref, Definition, NameClass, NameRefClass}, 6 defs::{classify_name, classify_name_ref, Definition, NameClass, NameRefClass},
7 RootDatabase, 7 RootDatabase,
8}; 8};
diff --git a/crates/ra_ide/src/runnables.rs b/crates/ra_ide/src/runnables.rs
index fb40762cf..c3e07c8de 100644
--- a/crates/ra_ide/src/runnables.rs
+++ b/crates/ra_ide/src/runnables.rs
@@ -2,8 +2,8 @@ use std::fmt;
2 2
3use cfg::CfgExpr; 3use cfg::CfgExpr;
4use hir::{AsAssocItem, Attrs, HirFileId, InFile, Semantics}; 4use hir::{AsAssocItem, Attrs, HirFileId, InFile, Semantics};
5use ide_db::RootDatabase;
5use itertools::Itertools; 6use itertools::Itertools;
6use ra_ide_db::RootDatabase;
7use syntax::{ 7use syntax::{
8 ast::{self, AstNode, AttrsOwner, DocCommentsOwner, ModuleItemOwner, NameOwner}, 8 ast::{self, AstNode, AttrsOwner, DocCommentsOwner, ModuleItemOwner, NameOwner},
9 match_ast, SyntaxNode, 9 match_ast, SyntaxNode,
diff --git a/crates/ra_ide/src/ssr.rs b/crates/ra_ide/src/ssr.rs
deleted file mode 100644
index 97b82b70e..000000000
--- a/crates/ra_ide/src/ssr.rs
+++ /dev/null
@@ -1,72 +0,0 @@
1use base_db::{FilePosition, FileRange};
2use ra_ide_db::RootDatabase;
3
4use crate::SourceFileEdit;
5use ra_ssr::{MatchFinder, SsrError, SsrRule};
6
7// Feature: Structural Search and Replace
8//
9// Search and replace with named wildcards that will match any expression, type, path, pattern or item.
10// The syntax for a structural search replace command is `<search_pattern> ==>> <replace_pattern>`.
11// A `$<name>` placeholder in the search pattern will match any AST node and `$<name>` will reference it in the replacement.
12// Within a macro call, a placeholder will match up until whatever token follows the placeholder.
13//
14// All paths in both the search pattern and the replacement template must resolve in the context
15// in which this command is invoked. Paths in the search pattern will then match the code if they
16// resolve to the same item, even if they're written differently. For example if we invoke the
17// command in the module `foo` with a pattern of `Bar`, then code in the parent module that refers
18// to `foo::Bar` will match.
19//
20// Paths in the replacement template will be rendered appropriately for the context in which the
21// replacement occurs. For example if our replacement template is `foo::Bar` and we match some
22// code in the `foo` module, we'll insert just `Bar`.
23//
24// Inherent method calls should generally be written in UFCS form. e.g. `foo::Bar::baz($s, $a)` will
25// match `$s.baz($a)`, provided the method call `baz` resolves to the method `foo::Bar::baz`.
26//
27// The scope of the search / replace will be restricted to the current selection if any, otherwise
28// it will apply to the whole workspace.
29//
30// Placeholders may be given constraints by writing them as `${<name>:<constraint1>:<constraint2>...}`.
31//
32// Supported constraints:
33//
34// |===
35// | Constraint | Restricts placeholder
36//
37// | kind(literal) | Is a literal (e.g. `42` or `"forty two"`)
38// | not(a) | Negates the constraint `a`
39// |===
40//
41// Available via the command `rust-analyzer.ssr`.
42//
43// ```rust
44// // Using structural search replace command [foo($a, $b) ==>> ($a).foo($b)]
45//
46// // BEFORE
47// String::from(foo(y + 5, z))
48//
49// // AFTER
50// String::from((y + 5).foo(z))
51// ```
52//
53// |===
54// | Editor | Action Name
55//
56// | VS Code | **Rust Analyzer: Structural Search Replace**
57// |===
58pub fn parse_search_replace(
59 rule: &str,
60 parse_only: bool,
61 db: &RootDatabase,
62 resolve_context: FilePosition,
63 selections: Vec<FileRange>,
64) -> Result<Vec<SourceFileEdit>, SsrError> {
65 let rule: SsrRule = rule.parse()?;
66 let mut match_finder = MatchFinder::in_context(db, resolve_context, selections);
67 match_finder.add_rule(rule)?;
68 if parse_only {
69 return Ok(Vec::new());
70 }
71 Ok(match_finder.edits())
72}
diff --git a/crates/ra_ide/src/status.rs b/crates/ra_ide/src/status.rs
index 869c74acc..c23708181 100644
--- a/crates/ra_ide/src/status.rs
+++ b/crates/ra_ide/src/status.rs
@@ -5,11 +5,11 @@ use base_db::{
5 FileTextQuery, SourceRootId, 5 FileTextQuery, SourceRootId,
6}; 6};
7use hir::MacroFile; 7use hir::MacroFile;
8use profile::{memory_usage, Bytes}; 8use ide_db::{
9use ra_ide_db::{
10 symbol_index::{LibrarySymbolsQuery, SymbolIndex}, 9 symbol_index::{LibrarySymbolsQuery, SymbolIndex},
11 RootDatabase, 10 RootDatabase,
12}; 11};
12use profile::{memory_usage, Bytes};
13use rustc_hash::FxHashMap; 13use rustc_hash::FxHashMap;
14use syntax::{ast, Parse, SyntaxNode}; 14use syntax::{ast, Parse, SyntaxNode};
15 15
diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs
index 4b41ceb1d..5d7c7e8d0 100644
--- a/crates/ra_ide/src/syntax_highlighting.rs
+++ b/crates/ra_ide/src/syntax_highlighting.rs
@@ -5,7 +5,7 @@ mod injection;
5mod tests; 5mod tests;
6 6
7use hir::{Name, Semantics, VariantDef}; 7use hir::{Name, Semantics, VariantDef};
8use ra_ide_db::{ 8use ide_db::{
9 defs::{classify_name, classify_name_ref, Definition, NameClass, NameRefClass}, 9 defs::{classify_name, classify_name_ref, Definition, NameClass, NameRefClass},
10 RootDatabase, 10 RootDatabase,
11}; 11};
diff --git a/crates/ra_ide/src/syntax_tree.rs b/crates/ra_ide/src/syntax_tree.rs
index 17daf06b6..f80044959 100644
--- a/crates/ra_ide/src/syntax_tree.rs
+++ b/crates/ra_ide/src/syntax_tree.rs
@@ -1,5 +1,5 @@
1use base_db::{FileId, SourceDatabase}; 1use base_db::{FileId, SourceDatabase};
2use ra_ide_db::RootDatabase; 2use ide_db::RootDatabase;
3use syntax::{ 3use syntax::{
4 algo, AstNode, NodeOrToken, SourceFile, 4 algo, AstNode, NodeOrToken, SourceFile,
5 SyntaxKind::{RAW_STRING, STRING}, 5 SyntaxKind::{RAW_STRING, STRING},
diff --git a/crates/ra_ide/src/typing.rs b/crates/ra_ide/src/typing.rs
index 75f2a6b60..899ce5f26 100644
--- a/crates/ra_ide/src/typing.rs
+++ b/crates/ra_ide/src/typing.rs
@@ -16,7 +16,7 @@
16mod on_enter; 16mod on_enter;
17 17
18use base_db::{FilePosition, SourceDatabase}; 18use base_db::{FilePosition, SourceDatabase};
19use ra_ide_db::{source_change::SourceFileEdit, RootDatabase}; 19use ide_db::{source_change::SourceFileEdit, RootDatabase};
20use syntax::{ 20use syntax::{
21 algo::find_node_at_offset, 21 algo::find_node_at_offset,
22 ast::{self, edit::IndentLevel, AstToken}, 22 ast::{self, edit::IndentLevel, AstToken},
diff --git a/crates/ra_ide/src/typing/on_enter.rs b/crates/ra_ide/src/typing/on_enter.rs
index 193930659..f7d46146c 100644
--- a/crates/ra_ide/src/typing/on_enter.rs
+++ b/crates/ra_ide/src/typing/on_enter.rs
@@ -2,7 +2,7 @@
2//! comments, but should handle indent some time in the future as well. 2//! comments, but should handle indent some time in the future as well.
3 3
4use base_db::{FilePosition, SourceDatabase}; 4use base_db::{FilePosition, SourceDatabase};
5use ra_ide_db::RootDatabase; 5use ide_db::RootDatabase;
6use syntax::{ 6use syntax::{
7 ast::{self, AstToken}, 7 ast::{self, AstToken},
8 AstNode, SmolStr, SourceFile, 8 AstNode, SmolStr, SourceFile,