diff options
author | Lukas Wirth <[email protected]> | 2021-03-15 08:32:06 +0000 |
---|---|---|
committer | Lukas Wirth <[email protected]> | 2021-03-15 08:32:06 +0000 |
commit | 9763d9e8c4ca01a4df0d70877020ec7351403b75 (patch) | |
tree | b007710dcc6152b5c0fedd1c0bedf8c96811652d /crates/ide | |
parent | c0459c53572f90fa9134192e432562af3daba5fa (diff) |
Enable searching for builtin types
Diffstat (limited to 'crates/ide')
-rw-r--r-- | crates/ide/src/references.rs | 26 | ||||
-rw-r--r-- | crates/ide/src/references/rename.rs | 3 |
2 files changed, 21 insertions, 8 deletions
diff --git a/crates/ide/src/references.rs b/crates/ide/src/references.rs index fef70533d..ec7c7686d 100644 --- a/crates/ide/src/references.rs +++ b/crates/ide/src/references.rs | |||
@@ -29,7 +29,7 @@ use crate::{display::TryToNav, FilePosition, NavigationTarget}; | |||
29 | 29 | ||
30 | #[derive(Debug, Clone)] | 30 | #[derive(Debug, Clone)] |
31 | pub struct ReferenceSearchResult { | 31 | pub struct ReferenceSearchResult { |
32 | pub declaration: Declaration, | 32 | pub declaration: Option<Declaration>, |
33 | pub references: FxHashMap<FileId, Vec<(TextRange, Option<ReferenceAccess>)>>, | 33 | pub references: FxHashMap<FileId, Vec<(TextRange, Option<ReferenceAccess>)>>, |
34 | } | 34 | } |
35 | 35 | ||
@@ -91,10 +91,10 @@ pub(crate) fn find_all_refs( | |||
91 | _ => {} | 91 | _ => {} |
92 | } | 92 | } |
93 | } | 93 | } |
94 | let nav = def.try_to_nav(sema.db)?; | 94 | let declaration = def.try_to_nav(sema.db).map(|nav| { |
95 | let decl_range = nav.focus_or_full_range(); | 95 | let decl_range = nav.focus_or_full_range(); |
96 | 96 | Declaration { nav, access: decl_access(&def, &syntax, decl_range) } | |
97 | let declaration = Declaration { nav, access: decl_access(&def, &syntax, decl_range) }; | 97 | }); |
98 | let references = usages | 98 | let references = usages |
99 | .into_iter() | 99 | .into_iter() |
100 | .map(|(file_id, refs)| { | 100 | .map(|(file_id, refs)| { |
@@ -1004,8 +1004,7 @@ impl Foo { | |||
1004 | let refs = analysis.find_all_refs(pos, search_scope).unwrap().unwrap(); | 1004 | let refs = analysis.find_all_refs(pos, search_scope).unwrap().unwrap(); |
1005 | 1005 | ||
1006 | let mut actual = String::new(); | 1006 | let mut actual = String::new(); |
1007 | { | 1007 | if let Some(decl) = refs.declaration { |
1008 | let decl = refs.declaration; | ||
1009 | format_to!(actual, "{}", decl.nav.debug_render()); | 1008 | format_to!(actual, "{}", decl.nav.debug_render()); |
1010 | if let Some(access) = decl.access { | 1009 | if let Some(access) = decl.access { |
1011 | format_to!(actual, " {:?}", access) | 1010 | format_to!(actual, " {:?}", access) |
@@ -1258,4 +1257,17 @@ fn main() { | |||
1258 | "#]], | 1257 | "#]], |
1259 | ); | 1258 | ); |
1260 | } | 1259 | } |
1260 | |||
1261 | #[test] | ||
1262 | fn test_primitives() { | ||
1263 | check( | ||
1264 | r#" | ||
1265 | fn foo(_: bool) -> bo$0ol { true } | ||
1266 | "#, | ||
1267 | expect![[r#" | ||
1268 | FileId(0) 10..14 | ||
1269 | FileId(0) 19..23 | ||
1270 | "#]], | ||
1271 | ); | ||
1272 | } | ||
1261 | } | 1273 | } |
diff --git a/crates/ide/src/references/rename.rs b/crates/ide/src/references/rename.rs index 1e378279d..5340b638a 100644 --- a/crates/ide/src/references/rename.rs +++ b/crates/ide/src/references/rename.rs | |||
@@ -510,7 +510,8 @@ fn source_edit_from_def( | |||
510 | def: Definition, | 510 | def: Definition, |
511 | new_name: &str, | 511 | new_name: &str, |
512 | ) -> RenameResult<(FileId, TextEdit)> { | 512 | ) -> RenameResult<(FileId, TextEdit)> { |
513 | let nav = def.try_to_nav(sema.db).unwrap(); | 513 | let nav = |
514 | def.try_to_nav(sema.db).ok_or_else(|| format_err!("No references found at position"))?; | ||
514 | 515 | ||
515 | let mut replacement_text = String::new(); | 516 | let mut replacement_text = String::new(); |
516 | let mut repl_range = nav.focus_or_full_range(); | 517 | let mut repl_range = nav.focus_or_full_range(); |