aboutsummaryrefslogtreecommitdiff
path: root/crates/ide/src/display
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ide/src/display')
-rw-r--r--crates/ide/src/display/navigation_target.rs65
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 73fc73619..48acb8c93 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
3use either::Either; 3use either::Either;
4use hir::{ 4use hir::{AssocItem, Documentation, FieldSource, HasAttrs, HasSource, InFile, ModuleSource};
5 AssocItem, Documentation, FieldSource, HasAttrs, HasSource, HirFileId, InFile, ModuleSource,
6};
7use ide_db::base_db::{FileId, SourceDatabase}; 5use ide_db::base_db::{FileId, SourceDatabase};
8use ide_db::{defs::Definition, RootDatabase}; 6use ide_db::{defs::Definition, RootDatabase};
9use syntax::{ 7use 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}
@@ -190,6 +169,7 @@ impl TryToNav for Definition {
190 Definition::SelfType(it) => Some(it.to_nav(db)), 169 Definition::SelfType(it) => Some(it.to_nav(db)),
191 Definition::Local(it) => Some(it.to_nav(db)), 170 Definition::Local(it) => Some(it.to_nav(db)),
192 Definition::TypeParam(it) => Some(it.to_nav(db)), 171 Definition::TypeParam(it) => Some(it.to_nav(db)),
172 Definition::LifetimeParam(it) => Some(it.to_nav(db)),
193 } 173 }
194 } 174 }
195} 175}
@@ -252,7 +232,7 @@ impl ToNav for hir::Module {
252 } 232 }
253} 233}
254 234
255impl ToNav for hir::ImplDef { 235impl ToNav for hir::Impl {
256 fn to_nav(&self, db: &RootDatabase) -> NavigationTarget { 236 fn to_nav(&self, db: &RootDatabase) -> NavigationTarget {
257 let src = self.source(db); 237 let src = self.source(db);
258 let derive_attr = self.is_builtin_derive(db); 238 let derive_attr = self.is_builtin_derive(db);
@@ -384,28 +364,21 @@ impl ToNav for hir::TypeParam {
384 } 364 }
385} 365}
386 366
387pub(crate) fn docs_from_symbol(db: &RootDatabase, symbol: &FileSymbol) -> Option<Documentation> { 367impl ToNav for hir::LifetimeParam {
388 let parse = db.parse(symbol.file_id); 368 fn to_nav(&self, db: &RootDatabase) -> NavigationTarget {
389 let node = symbol.ptr.to_node(parse.tree().syntax()); 369 let src = self.source(db);
390 let file_id = HirFileId::from(symbol.file_id); 370 let full_range = src.value.syntax().text_range();
391 371 NavigationTarget {
392 let it = match_ast! { 372 file_id: src.file_id.original_file(db),
393 match node { 373 name: self.name(db).to_string().into(),
394 ast::Fn(it) => hir::Attrs::from_attrs_owner(db, InFile::new(file_id, &it)), 374 kind: LIFETIME_PARAM,
395 ast::Struct(it) => hir::Attrs::from_attrs_owner(db, InFile::new(file_id, &it)), 375 full_range,
396 ast::Enum(it) => hir::Attrs::from_attrs_owner(db, InFile::new(file_id, &it)), 376 focus_range: Some(full_range),
397 ast::Trait(it) => hir::Attrs::from_attrs_owner(db, InFile::new(file_id, &it)), 377 container_name: None,
398 ast::Module(it) => hir::Attrs::from_attrs_owner(db, InFile::new(file_id, &it)), 378 description: None,
399 ast::TypeAlias(it) => hir::Attrs::from_attrs_owner(db, InFile::new(file_id, &it)), 379 docs: None,
400 ast::Const(it) => hir::Attrs::from_attrs_owner(db, InFile::new(file_id, &it)),
401 ast::Static(it) => hir::Attrs::from_attrs_owner(db, InFile::new(file_id, &it)),
402 ast::RecordField(it) => hir::Attrs::from_attrs_owner(db, InFile::new(file_id, &it)),
403 ast::Variant(it) => hir::Attrs::from_attrs_owner(db, InFile::new(file_id, &it)),
404 ast::MacroCall(it) => hir::Attrs::from_attrs_owner(db, InFile::new(file_id, &it)),
405 _ => return None,
406 } 380 }
407 }; 381 }
408 it.docs()
409} 382}
410 383
411/// Get a description of a symbol. 384/// Get a description of a symbol.