diff options
Diffstat (limited to 'crates/ide/src/display/navigation_target.rs')
-rw-r--r-- | crates/ide/src/display/navigation_target.rs | 65 |
1 files changed, 19 insertions, 46 deletions
diff --git a/crates/ide/src/display/navigation_target.rs b/crates/ide/src/display/navigation_target.rs index 234f80a3a..522607cb7 100644 --- a/crates/ide/src/display/navigation_target.rs +++ b/crates/ide/src/display/navigation_target.rs | |||
@@ -1,15 +1,13 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! FIXME: write short doc here |
2 | 2 | ||
3 | use either::Either; | 3 | use either::Either; |
4 | use hir::{ | 4 | use hir::{AssocItem, Documentation, FieldSource, HasAttrs, HasSource, InFile, ModuleSource}; |
5 | AssocItem, Documentation, FieldSource, HasAttrs, HasSource, HirFileId, InFile, ModuleSource, | ||
6 | }; | ||
7 | use ide_db::base_db::{FileId, SourceDatabase}; | 5 | use ide_db::base_db::{FileId, SourceDatabase}; |
8 | use ide_db::{defs::Definition, RootDatabase}; | 6 | use ide_db::{defs::Definition, RootDatabase}; |
9 | use syntax::{ | 7 | use syntax::{ |
10 | ast::{self, NameOwner}, | 8 | ast::{self, NameOwner}, |
11 | match_ast, AstNode, SmolStr, | 9 | match_ast, AstNode, SmolStr, |
12 | SyntaxKind::{self, IDENT_PAT, TYPE_PARAM}, | 10 | SyntaxKind::{self, IDENT_PAT, LIFETIME_PARAM, TYPE_PARAM}, |
13 | TextRange, | 11 | TextRange, |
14 | }; | 12 | }; |
15 | 13 | ||
@@ -119,25 +117,6 @@ impl NavigationTarget { | |||
119 | ) | 117 | ) |
120 | } | 118 | } |
121 | 119 | ||
122 | /// Allows `NavigationTarget` to be created from a `DocCommentsOwner` and a `NameOwner` | ||
123 | pub(crate) fn from_doc_commented( | ||
124 | db: &RootDatabase, | ||
125 | named: InFile<&dyn ast::NameOwner>, | ||
126 | node: InFile<&dyn ast::DocCommentsOwner>, | ||
127 | ) -> NavigationTarget { | ||
128 | let name = | ||
129 | named.value.name().map(|it| it.text().clone()).unwrap_or_else(|| SmolStr::new("_")); | ||
130 | let frange = node.map(|it| it.syntax()).original_file_range(db); | ||
131 | |||
132 | NavigationTarget::from_syntax( | ||
133 | frange.file_id, | ||
134 | name, | ||
135 | None, | ||
136 | frange.range, | ||
137 | node.value.syntax().kind(), | ||
138 | ) | ||
139 | } | ||
140 | |||
141 | fn from_syntax( | 120 | fn from_syntax( |
142 | file_id: FileId, | 121 | file_id: FileId, |
143 | name: SmolStr, | 122 | name: SmolStr, |
@@ -168,7 +147,7 @@ impl ToNav for FileSymbol { | |||
168 | focus_range: self.name_range, | 147 | focus_range: self.name_range, |
169 | container_name: self.container_name.clone(), | 148 | container_name: self.container_name.clone(), |
170 | description: description_from_symbol(db, self), | 149 | description: description_from_symbol(db, self), |
171 | docs: docs_from_symbol(db, self), | 150 | docs: None, |
172 | } | 151 | } |
173 | } | 152 | } |
174 | } | 153 | } |
@@ -182,6 +161,7 @@ impl TryToNav for Definition { | |||
182 | Definition::SelfType(it) => Some(it.to_nav(db)), | 161 | Definition::SelfType(it) => Some(it.to_nav(db)), |
183 | Definition::Local(it) => Some(it.to_nav(db)), | 162 | Definition::Local(it) => Some(it.to_nav(db)), |
184 | Definition::TypeParam(it) => Some(it.to_nav(db)), | 163 | Definition::TypeParam(it) => Some(it.to_nav(db)), |
164 | Definition::LifetimeParam(it) => Some(it.to_nav(db)), | ||
185 | } | 165 | } |
186 | } | 166 | } |
187 | } | 167 | } |
@@ -244,7 +224,7 @@ impl ToNav for hir::Module { | |||
244 | } | 224 | } |
245 | } | 225 | } |
246 | 226 | ||
247 | impl ToNav for hir::ImplDef { | 227 | impl ToNav for hir::Impl { |
248 | fn to_nav(&self, db: &RootDatabase) -> NavigationTarget { | 228 | fn to_nav(&self, db: &RootDatabase) -> NavigationTarget { |
249 | let src = self.source(db); | 229 | let src = self.source(db); |
250 | let derive_attr = self.is_builtin_derive(db); | 230 | let derive_attr = self.is_builtin_derive(db); |
@@ -376,28 +356,21 @@ impl ToNav for hir::TypeParam { | |||
376 | } | 356 | } |
377 | } | 357 | } |
378 | 358 | ||
379 | pub(crate) fn docs_from_symbol(db: &RootDatabase, symbol: &FileSymbol) -> Option<Documentation> { | 359 | impl ToNav for hir::LifetimeParam { |
380 | let parse = db.parse(symbol.file_id); | 360 | fn to_nav(&self, db: &RootDatabase) -> NavigationTarget { |
381 | let node = symbol.ptr.to_node(parse.tree().syntax()); | 361 | let src = self.source(db); |
382 | let file_id = HirFileId::from(symbol.file_id); | 362 | let full_range = src.value.syntax().text_range(); |
383 | 363 | NavigationTarget { | |
384 | let it = match_ast! { | 364 | file_id: src.file_id.original_file(db), |
385 | match node { | 365 | name: self.name(db).to_string().into(), |
386 | ast::Fn(it) => hir::Attrs::from_attrs_owner(db, InFile::new(file_id, &it)), | 366 | kind: LIFETIME_PARAM, |
387 | ast::Struct(it) => hir::Attrs::from_attrs_owner(db, InFile::new(file_id, &it)), | 367 | full_range, |
388 | ast::Enum(it) => hir::Attrs::from_attrs_owner(db, InFile::new(file_id, &it)), | 368 | focus_range: Some(full_range), |
389 | ast::Trait(it) => hir::Attrs::from_attrs_owner(db, InFile::new(file_id, &it)), | 369 | container_name: None, |
390 | ast::Module(it) => hir::Attrs::from_attrs_owner(db, InFile::new(file_id, &it)), | 370 | description: None, |
391 | ast::TypeAlias(it) => hir::Attrs::from_attrs_owner(db, InFile::new(file_id, &it)), | 371 | docs: None, |
392 | ast::Const(it) => hir::Attrs::from_attrs_owner(db, InFile::new(file_id, &it)), | ||
393 | ast::Static(it) => hir::Attrs::from_attrs_owner(db, InFile::new(file_id, &it)), | ||
394 | ast::RecordField(it) => hir::Attrs::from_attrs_owner(db, InFile::new(file_id, &it)), | ||
395 | ast::Variant(it) => hir::Attrs::from_attrs_owner(db, InFile::new(file_id, &it)), | ||
396 | ast::MacroCall(it) => hir::Attrs::from_attrs_owner(db, InFile::new(file_id, &it)), | ||
397 | _ => return None, | ||
398 | } | 372 | } |
399 | }; | 373 | } |
400 | it.docs() | ||
401 | } | 374 | } |
402 | 375 | ||
403 | /// Get a description of a symbol. | 376 | /// Get a description of a symbol. |