diff options
Diffstat (limited to 'crates/ra_ide_api/src/display')
-rw-r--r-- | crates/ra_ide_api/src/display/navigation_target.rs | 40 |
1 files changed, 21 insertions, 19 deletions
diff --git a/crates/ra_ide_api/src/display/navigation_target.rs b/crates/ra_ide_api/src/display/navigation_target.rs index 291b5ee40..b30ef8e05 100644 --- a/crates/ra_ide_api/src/display/navigation_target.rs +++ b/crates/ra_ide_api/src/display/navigation_target.rs | |||
@@ -6,7 +6,7 @@ use ra_syntax::{ | |||
6 | ast::{self, DocCommentsOwner, NameOwner}, | 6 | ast::{self, DocCommentsOwner, NameOwner}, |
7 | match_ast, AstNode, SmolStr, | 7 | match_ast, AstNode, SmolStr, |
8 | SyntaxKind::{self, BIND_PAT}, | 8 | SyntaxKind::{self, BIND_PAT}, |
9 | SyntaxNode, TextRange, | 9 | TextRange, |
10 | }; | 10 | }; |
11 | 11 | ||
12 | use crate::{db::RootDatabase, expand::original_range, FileSymbol}; | 12 | use crate::{db::RootDatabase, expand::original_range, FileSymbol}; |
@@ -86,7 +86,7 @@ impl NavigationTarget { | |||
86 | name, | 86 | name, |
87 | None, | 87 | None, |
88 | frange.range, | 88 | frange.range, |
89 | src.ast.syntax(), | 89 | src.ast.syntax().kind(), |
90 | src.ast.doc_comment_text(), | 90 | src.ast.doc_comment_text(), |
91 | src.ast.short_label(), | 91 | src.ast.short_label(), |
92 | ); | 92 | ); |
@@ -141,23 +141,22 @@ impl NavigationTarget { | |||
141 | /// Allows `NavigationTarget` to be created from a `NameOwner` | 141 | /// Allows `NavigationTarget` to be created from a `NameOwner` |
142 | pub(crate) fn from_named( | 142 | pub(crate) fn from_named( |
143 | db: &RootDatabase, | 143 | db: &RootDatabase, |
144 | file_id: hir::HirFileId, | 144 | node: Source<&dyn ast::NameOwner>, |
145 | node: &impl ast::NameOwner, | ||
146 | docs: Option<String>, | 145 | docs: Option<String>, |
147 | description: Option<String>, | 146 | description: Option<String>, |
148 | ) -> NavigationTarget { | 147 | ) -> NavigationTarget { |
149 | //FIXME: use `_` instead of empty string | 148 | //FIXME: use `_` instead of empty string |
150 | let name = node.name().map(|it| it.text().clone()).unwrap_or_default(); | 149 | let name = node.ast.name().map(|it| it.text().clone()).unwrap_or_default(); |
151 | let focus_range = | 150 | let focus_range = |
152 | node.name().map(|it| original_range(db, Source::new(file_id, it.syntax())).range); | 151 | node.ast.name().map(|it| original_range(db, node.with_ast(it.syntax())).range); |
153 | let frange = original_range(db, Source::new(file_id, node.syntax())); | 152 | let frange = original_range(db, node.map(|it| it.syntax())); |
154 | 153 | ||
155 | NavigationTarget::from_syntax( | 154 | NavigationTarget::from_syntax( |
156 | frange.file_id, | 155 | frange.file_id, |
157 | name, | 156 | name, |
158 | focus_range, | 157 | focus_range, |
159 | frange.range, | 158 | frange.range, |
160 | node.syntax(), | 159 | node.ast.syntax().kind(), |
161 | docs, | 160 | docs, |
162 | description, | 161 | description, |
163 | ) | 162 | ) |
@@ -168,14 +167,14 @@ impl NavigationTarget { | |||
168 | name: SmolStr, | 167 | name: SmolStr, |
169 | focus_range: Option<TextRange>, | 168 | focus_range: Option<TextRange>, |
170 | full_range: TextRange, | 169 | full_range: TextRange, |
171 | node: &SyntaxNode, | 170 | kind: SyntaxKind, |
172 | docs: Option<String>, | 171 | docs: Option<String>, |
173 | description: Option<String>, | 172 | description: Option<String>, |
174 | ) -> NavigationTarget { | 173 | ) -> NavigationTarget { |
175 | NavigationTarget { | 174 | NavigationTarget { |
176 | file_id, | 175 | file_id, |
177 | name, | 176 | name, |
178 | kind: node.kind(), | 177 | kind, |
179 | full_range, | 178 | full_range, |
180 | focus_range, | 179 | focus_range, |
181 | container_name: None, | 180 | container_name: None, |
@@ -220,8 +219,7 @@ where | |||
220 | let src = self.source(db); | 219 | let src = self.source(db); |
221 | NavigationTarget::from_named( | 220 | NavigationTarget::from_named( |
222 | db, | 221 | db, |
223 | src.file_id, | 222 | src.as_ref().map(|it| it as &dyn ast::NameOwner), |
224 | &src.ast, | ||
225 | src.ast.doc_comment_text(), | 223 | src.ast.doc_comment_text(), |
226 | src.ast.short_label(), | 224 | src.ast.short_label(), |
227 | ) | 225 | ) |
@@ -241,7 +239,7 @@ impl ToNav for hir::Module { | |||
241 | name, | 239 | name, |
242 | None, | 240 | None, |
243 | frange.range, | 241 | frange.range, |
244 | node.syntax(), | 242 | node.syntax().kind(), |
245 | None, | 243 | None, |
246 | None, | 244 | None, |
247 | ) | 245 | ) |
@@ -254,7 +252,7 @@ impl ToNav for hir::Module { | |||
254 | name, | 252 | name, |
255 | None, | 253 | None, |
256 | frange.range, | 254 | frange.range, |
257 | node.syntax(), | 255 | node.syntax().kind(), |
258 | node.doc_comment_text(), | 256 | node.doc_comment_text(), |
259 | node.short_label(), | 257 | node.short_label(), |
260 | ) | 258 | ) |
@@ -273,7 +271,7 @@ impl ToNav for hir::ImplBlock { | |||
273 | "impl".into(), | 271 | "impl".into(), |
274 | None, | 272 | None, |
275 | frange.range, | 273 | frange.range, |
276 | src.ast.syntax(), | 274 | src.ast.syntax().kind(), |
277 | None, | 275 | None, |
278 | None, | 276 | None, |
279 | ) | 277 | ) |
@@ -287,8 +285,7 @@ impl ToNav for hir::StructField { | |||
287 | match &src.ast { | 285 | match &src.ast { |
288 | FieldSource::Named(it) => NavigationTarget::from_named( | 286 | FieldSource::Named(it) => NavigationTarget::from_named( |
289 | db, | 287 | db, |
290 | src.file_id, | 288 | src.with_ast(it), |
291 | it, | ||
292 | it.doc_comment_text(), | 289 | it.doc_comment_text(), |
293 | it.short_label(), | 290 | it.short_label(), |
294 | ), | 291 | ), |
@@ -299,7 +296,7 @@ impl ToNav for hir::StructField { | |||
299 | "".into(), | 296 | "".into(), |
300 | None, | 297 | None, |
301 | frange.range, | 298 | frange.range, |
302 | it.syntax(), | 299 | it.syntax().kind(), |
303 | None, | 300 | None, |
304 | None, | 301 | None, |
305 | ) | 302 | ) |
@@ -312,7 +309,12 @@ impl ToNav for hir::MacroDef { | |||
312 | fn to_nav(&self, db: &RootDatabase) -> NavigationTarget { | 309 | fn to_nav(&self, db: &RootDatabase) -> NavigationTarget { |
313 | let src = self.source(db); | 310 | let src = self.source(db); |
314 | log::debug!("nav target {:#?}", src.ast.syntax()); | 311 | log::debug!("nav target {:#?}", src.ast.syntax()); |
315 | NavigationTarget::from_named(db, src.file_id, &src.ast, src.ast.doc_comment_text(), None) | 312 | NavigationTarget::from_named( |
313 | db, | ||
314 | src.as_ref().map(|it| it as &dyn ast::NameOwner), | ||
315 | src.ast.doc_comment_text(), | ||
316 | None, | ||
317 | ) | ||
316 | } | 318 | } |
317 | } | 319 | } |
318 | 320 | ||