diff options
author | Aleksey Kladov <[email protected]> | 2019-06-11 14:40:49 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-06-11 16:28:51 +0100 |
commit | 36865adcb946d5567fb61d3547b78fc71df58b20 (patch) | |
tree | 4cec6a3d18de8242c334fe303717c1f2b1c42be1 /crates/ra_ide_api/src | |
parent | 2a1fe26b6d354dbbd1b3843d288d56e74fa00557 (diff) |
Introduce HasSource trait
Diffstat (limited to 'crates/ra_ide_api/src')
-rw-r--r-- | crates/ra_ide_api/src/display/navigation_target.rs | 46 |
1 files changed, 18 insertions, 28 deletions
diff --git a/crates/ra_ide_api/src/display/navigation_target.rs b/crates/ra_ide_api/src/display/navigation_target.rs index 7c68bb41c..bef5f0980 100644 --- a/crates/ra_ide_api/src/display/navigation_target.rs +++ b/crates/ra_ide_api/src/display/navigation_target.rs | |||
@@ -1,6 +1,6 @@ | |||
1 | use ra_db::{FileId, SourceDatabase}; | 1 | use ra_db::{FileId, SourceDatabase}; |
2 | use ra_syntax::{ | 2 | use ra_syntax::{ |
3 | SyntaxNode, AstNode, SmolStr, TextRange, AstPtr, | 3 | SyntaxNode, AstNode, SmolStr, TextRange, AstPtr, TreeArc, |
4 | SyntaxKind::{self, NAME}, | 4 | SyntaxKind::{self, NAME}, |
5 | ast::{self, DocCommentsOwner}, | 5 | ast::{self, DocCommentsOwner}, |
6 | algo::visit::{visitor, Visitor}, | 6 | algo::visit::{visitor, Visitor}, |
@@ -186,35 +186,25 @@ impl NavigationTarget { | |||
186 | } | 186 | } |
187 | } | 187 | } |
188 | 188 | ||
189 | pub(crate) fn from_def_source<A, D>(db: &RootDatabase, def: D) -> NavigationTarget | ||
190 | where | ||
191 | D: hir::HasSource<Ast = TreeArc<A>>, | ||
192 | A: ast::DocCommentsOwner + ast::NameOwner + ShortLabel, | ||
193 | { | ||
194 | let src = def.source(db); | ||
195 | NavigationTarget::from_named( | ||
196 | src.file_id.original_file(db), | ||
197 | &*src.ast, | ||
198 | src.ast.doc_comment_text(), | ||
199 | src.ast.short_label(), | ||
200 | ) | ||
201 | } | ||
202 | |||
189 | pub(crate) fn from_adt_def(db: &RootDatabase, adt_def: hir::AdtDef) -> NavigationTarget { | 203 | pub(crate) fn from_adt_def(db: &RootDatabase, adt_def: hir::AdtDef) -> NavigationTarget { |
190 | match adt_def { | 204 | match adt_def { |
191 | hir::AdtDef::Struct(s) => { | 205 | hir::AdtDef::Struct(it) => NavigationTarget::from_def_source(db, it), |
192 | let src = s.source(db); | 206 | hir::AdtDef::Union(it) => NavigationTarget::from_def_source(db, it), |
193 | NavigationTarget::from_named( | 207 | hir::AdtDef::Enum(it) => NavigationTarget::from_def_source(db, it), |
194 | src.file_id.original_file(db), | ||
195 | &*src.ast, | ||
196 | src.ast.doc_comment_text(), | ||
197 | src.ast.short_label(), | ||
198 | ) | ||
199 | } | ||
200 | hir::AdtDef::Union(s) => { | ||
201 | let (file_id, node) = s.source(db); | ||
202 | NavigationTarget::from_named( | ||
203 | file_id.original_file(db), | ||
204 | &*node, | ||
205 | node.doc_comment_text(), | ||
206 | node.short_label(), | ||
207 | ) | ||
208 | } | ||
209 | hir::AdtDef::Enum(s) => { | ||
210 | let src = s.source(db); | ||
211 | NavigationTarget::from_named( | ||
212 | src.file_id.original_file(db), | ||
213 | &*src.ast, | ||
214 | src.ast.doc_comment_text(), | ||
215 | src.ast.short_label(), | ||
216 | ) | ||
217 | } | ||
218 | } | 208 | } |
219 | } | 209 | } |
220 | 210 | ||