aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide')
-rw-r--r--crates/ra_ide/src/references.rs32
1 files changed, 23 insertions, 9 deletions
diff --git a/crates/ra_ide/src/references.rs b/crates/ra_ide/src/references.rs
index 3ea0ac230..746cc86ba 100644
--- a/crates/ra_ide/src/references.rs
+++ b/crates/ra_ide/src/references.rs
@@ -94,12 +94,16 @@ pub(crate) fn find_all_refs(
94 let sema = Semantics::new(db); 94 let sema = Semantics::new(db);
95 let syntax = sema.parse(position.file_id).syntax().clone(); 95 let syntax = sema.parse(position.file_id).syntax().clone();
96 96
97 let (opt_name, search_kind) = 97 let (opt_name, search_kind) = if let Some(name) =
98 if let Some(name) = get_struct_def_name_for_struct_literal_search(&syntax, position) { 98 get_struct_def_name_for_struct_literal_search(&sema, &syntax, position)
99 (Some(name), ReferenceKind::StructLiteral) 99 {
100 } else { 100 (Some(name), ReferenceKind::StructLiteral)
101 (find_node_at_offset::<ast::Name>(&syntax, position.offset), ReferenceKind::Other) 101 } else {
102 }; 102 (
103 sema.find_node_at_offset_with_descend::<ast::Name>(&syntax, position.offset),
104 ReferenceKind::Other,
105 )
106 };
103 107
104 let RangeInfo { range, info: def } = find_name(&sema, &syntax, position, opt_name)?; 108 let RangeInfo { range, info: def } = find_name(&sema, &syntax, position, opt_name)?;
105 109
@@ -131,7 +135,8 @@ fn find_name(
131 let range = name.syntax().text_range(); 135 let range = name.syntax().text_range();
132 return Some(RangeInfo::new(range, def)); 136 return Some(RangeInfo::new(range, def));
133 } 137 }
134 let name_ref = find_node_at_offset::<ast::NameRef>(&syntax, position.offset)?; 138 let name_ref =
139 sema.find_node_at_offset_with_descend::<ast::NameRef>(&syntax, position.offset)?;
135 let def = classify_name_ref(sema, &name_ref)?.definition(); 140 let def = classify_name_ref(sema, &name_ref)?.definition();
136 let range = name_ref.syntax().text_range(); 141 let range = name_ref.syntax().text_range();
137 Some(RangeInfo::new(range, def)) 142 Some(RangeInfo::new(range, def))
@@ -157,6 +162,7 @@ fn decl_access(def: &Definition, syntax: &SyntaxNode, range: TextRange) -> Optio
157} 162}
158 163
159fn get_struct_def_name_for_struct_literal_search( 164fn get_struct_def_name_for_struct_literal_search(
165 sema: &Semantics<RootDatabase>,
160 syntax: &SyntaxNode, 166 syntax: &SyntaxNode,
161 position: FilePosition, 167 position: FilePosition,
162) -> Option<ast::Name> { 168) -> Option<ast::Name> {
@@ -164,10 +170,18 @@ fn get_struct_def_name_for_struct_literal_search(
164 if right.kind() != SyntaxKind::L_CURLY && right.kind() != SyntaxKind::L_PAREN { 170 if right.kind() != SyntaxKind::L_CURLY && right.kind() != SyntaxKind::L_PAREN {
165 return None; 171 return None;
166 } 172 }
167 if let Some(name) = find_node_at_offset::<ast::Name>(&syntax, left.text_range().start()) { 173 if let Some(name) =
174 sema.find_node_at_offset_with_descend::<ast::Name>(&syntax, left.text_range().start())
175 {
168 return name.syntax().ancestors().find_map(ast::StructDef::cast).and_then(|l| l.name()); 176 return name.syntax().ancestors().find_map(ast::StructDef::cast).and_then(|l| l.name());
169 } 177 }
170 if find_node_at_offset::<ast::TypeParamList>(&syntax, left.text_range().start()).is_some() { 178 if sema
179 .find_node_at_offset_with_descend::<ast::TypeParamList>(
180 &syntax,
181 left.text_range().start(),
182 )
183 .is_some()
184 {
171 return left.ancestors().find_map(ast::StructDef::cast).and_then(|l| l.name()); 185 return left.ancestors().find_map(ast::StructDef::cast).and_then(|l| l.name());
172 } 186 }
173 } 187 }