diff options
author | Seivan Heidari <[email protected]> | 2019-10-31 08:43:20 +0000 |
---|---|---|
committer | Seivan Heidari <[email protected]> | 2019-10-31 08:43:20 +0000 |
commit | 8edda0e7b164009d6c03bb3d4be603fb38ad2e2a (patch) | |
tree | 744cf81075d394e2f9c06afb07642a2601800dda /crates/ra_ide_api/src/references | |
parent | 49562d36b97ddde34cf7585a8c2e8f232519b657 (diff) | |
parent | d067afb064a7fa67b172abf561b7d80740cd6f18 (diff) |
Merge branch 'master' into feature/themes
Diffstat (limited to 'crates/ra_ide_api/src/references')
-rw-r--r-- | crates/ra_ide_api/src/references/rename.rs | 24 | ||||
-rw-r--r-- | crates/ra_ide_api/src/references/search_scope.rs | 7 |
2 files changed, 11 insertions, 20 deletions
diff --git a/crates/ra_ide_api/src/references/rename.rs b/crates/ra_ide_api/src/references/rename.rs index ee6e73e1b..a8783d7a0 100644 --- a/crates/ra_ide_api/src/references/rename.rs +++ b/crates/ra_ide_api/src/references/rename.rs | |||
@@ -3,6 +3,7 @@ | |||
3 | use hir::ModuleSource; | 3 | use hir::ModuleSource; |
4 | use ra_db::{SourceDatabase, SourceDatabaseExt}; | 4 | use ra_db::{SourceDatabase, SourceDatabaseExt}; |
5 | use ra_syntax::{algo::find_node_at_offset, ast, AstNode, SyntaxNode}; | 5 | use ra_syntax::{algo::find_node_at_offset, ast, AstNode, SyntaxNode}; |
6 | use ra_text_edit::TextEdit; | ||
6 | use relative_path::{RelativePath, RelativePathBuf}; | 7 | use relative_path::{RelativePath, RelativePathBuf}; |
7 | 8 | ||
8 | use crate::{ | 9 | use crate::{ |
@@ -43,14 +44,7 @@ fn source_edit_from_file_id_range( | |||
43 | range: TextRange, | 44 | range: TextRange, |
44 | new_name: &str, | 45 | new_name: &str, |
45 | ) -> SourceFileEdit { | 46 | ) -> SourceFileEdit { |
46 | SourceFileEdit { | 47 | SourceFileEdit { file_id, edit: TextEdit::replace(range, new_name.into()) } |
47 | file_id, | ||
48 | edit: { | ||
49 | let mut builder = ra_text_edit::TextEditBuilder::default(); | ||
50 | builder.replace(range, new_name.into()); | ||
51 | builder.finish() | ||
52 | }, | ||
53 | } | ||
54 | } | 48 | } |
55 | 49 | ||
56 | fn rename_mod( | 50 | fn rename_mod( |
@@ -94,11 +88,7 @@ fn rename_mod( | |||
94 | 88 | ||
95 | let edit = SourceFileEdit { | 89 | let edit = SourceFileEdit { |
96 | file_id: position.file_id, | 90 | file_id: position.file_id, |
97 | edit: { | 91 | edit: TextEdit::replace(ast_name.syntax().text_range(), new_name.into()), |
98 | let mut builder = ra_text_edit::TextEditBuilder::default(); | ||
99 | builder.replace(ast_name.syntax().text_range(), new_name.into()); | ||
100 | builder.finish() | ||
101 | }, | ||
102 | }; | 92 | }; |
103 | source_file_edits.push(edit); | 93 | source_file_edits.push(edit); |
104 | 94 | ||
@@ -126,12 +116,14 @@ fn rename_reference( | |||
126 | 116 | ||
127 | #[cfg(test)] | 117 | #[cfg(test)] |
128 | mod tests { | 118 | mod tests { |
119 | use insta::assert_debug_snapshot; | ||
120 | use ra_text_edit::TextEditBuilder; | ||
121 | use test_utils::assert_eq_text; | ||
122 | |||
129 | use crate::{ | 123 | use crate::{ |
130 | mock_analysis::analysis_and_position, mock_analysis::single_file_with_position, FileId, | 124 | mock_analysis::analysis_and_position, mock_analysis::single_file_with_position, FileId, |
131 | ReferenceSearchResult, | 125 | ReferenceSearchResult, |
132 | }; | 126 | }; |
133 | use insta::assert_debug_snapshot; | ||
134 | use test_utils::assert_eq_text; | ||
135 | 127 | ||
136 | #[test] | 128 | #[test] |
137 | fn test_find_all_refs_for_local() { | 129 | fn test_find_all_refs_for_local() { |
@@ -452,7 +444,7 @@ mod tests { | |||
452 | fn test_rename(text: &str, new_name: &str, expected: &str) { | 444 | fn test_rename(text: &str, new_name: &str, expected: &str) { |
453 | let (analysis, position) = single_file_with_position(text); | 445 | let (analysis, position) = single_file_with_position(text); |
454 | let source_change = analysis.rename(position, new_name).unwrap(); | 446 | let source_change = analysis.rename(position, new_name).unwrap(); |
455 | let mut text_edit_builder = ra_text_edit::TextEditBuilder::default(); | 447 | let mut text_edit_builder = TextEditBuilder::default(); |
456 | let mut file_id: Option<FileId> = None; | 448 | let mut file_id: Option<FileId> = None; |
457 | if let Some(change) = source_change { | 449 | if let Some(change) = source_change { |
458 | for edit in change.info.source_file_edits { | 450 | for edit in change.info.source_file_edits { |
diff --git a/crates/ra_ide_api/src/references/search_scope.rs b/crates/ra_ide_api/src/references/search_scope.rs index b6eb248b7..f2789e0b2 100644 --- a/crates/ra_ide_api/src/references/search_scope.rs +++ b/crates/ra_ide_api/src/references/search_scope.rs | |||
@@ -111,8 +111,7 @@ impl NameDefinition { | |||
111 | if vis.as_str() != "" { | 111 | if vis.as_str() != "" { |
112 | let source_root_id = db.file_source_root(file_id); | 112 | let source_root_id = db.file_source_root(file_id); |
113 | let source_root = db.source_root(source_root_id); | 113 | let source_root = db.source_root(source_root_id); |
114 | let mut res = | 114 | let mut res = source_root.walk().map(|id| (id, None)).collect::<FxHashMap<_, _>>(); |
115 | source_root.walk().map(|id| (id.into(), None)).collect::<FxHashMap<_, _>>(); | ||
116 | 115 | ||
117 | // FIXME: add "pub(in path)" | 116 | // FIXME: add "pub(in path)" |
118 | 117 | ||
@@ -120,7 +119,7 @@ impl NameDefinition { | |||
120 | return SearchScope::new(res); | 119 | return SearchScope::new(res); |
121 | } | 120 | } |
122 | if vis.as_str() == "pub" { | 121 | if vis.as_str() == "pub" { |
123 | let krate = self.container.krate(db).unwrap(); | 122 | let krate = self.container.krate(); |
124 | let crate_graph = db.crate_graph(); | 123 | let crate_graph = db.crate_graph(); |
125 | for crate_id in crate_graph.iter() { | 124 | for crate_id in crate_graph.iter() { |
126 | let mut crate_deps = crate_graph.dependencies(crate_id); | 125 | let mut crate_deps = crate_graph.dependencies(crate_id); |
@@ -128,7 +127,7 @@ impl NameDefinition { | |||
128 | let root_file = crate_graph.crate_root(crate_id); | 127 | let root_file = crate_graph.crate_root(crate_id); |
129 | let source_root_id = db.file_source_root(root_file); | 128 | let source_root_id = db.file_source_root(root_file); |
130 | let source_root = db.source_root(source_root_id); | 129 | let source_root = db.source_root(source_root_id); |
131 | res.extend(source_root.walk().map(|id| (id.into(), None))); | 130 | res.extend(source_root.walk().map(|id| (id, None))); |
132 | } | 131 | } |
133 | } | 132 | } |
134 | return SearchScope::new(res); | 133 | return SearchScope::new(res); |