diff options
author | Lukas Wirth <[email protected]> | 2021-03-30 17:27:16 +0100 |
---|---|---|
committer | Lukas Wirth <[email protected]> | 2021-03-30 17:27:16 +0100 |
commit | bb56b7a75cfae8297535d55fbddbee9875cbc756 (patch) | |
tree | d367c18dddc65d4442679680ea728f5b06280ea5 /crates/ide/src/goto_definition.rs | |
parent | 9a327311e4a9b9102528751e052c63266c00c6bd (diff) |
Use new new docs string source mapping in goto_def and hover
Diffstat (limited to 'crates/ide/src/goto_definition.rs')
-rw-r--r-- | crates/ide/src/goto_definition.rs | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/crates/ide/src/goto_definition.rs b/crates/ide/src/goto_definition.rs index 1951c599f..780bdd40d 100644 --- a/crates/ide/src/goto_definition.rs +++ b/crates/ide/src/goto_definition.rs | |||
@@ -1,5 +1,5 @@ | |||
1 | use either::Either; | 1 | use either::Either; |
2 | use hir::Semantics; | 2 | use hir::{InFile, Semantics}; |
3 | use ide_db::{ | 3 | use ide_db::{ |
4 | defs::{NameClass, NameRefClass}, | 4 | defs::{NameClass, NameRefClass}, |
5 | RootDatabase, | 5 | RootDatabase, |
@@ -8,7 +8,7 @@ use syntax::{ast, match_ast, AstNode, AstToken, SyntaxKind::*, SyntaxToken, Toke | |||
8 | 8 | ||
9 | use crate::{ | 9 | use crate::{ |
10 | display::TryToNav, | 10 | display::TryToNav, |
11 | doc_links::{doc_owner_to_def, extract_positioned_link_from_comment, resolve_doc_path_for_def}, | 11 | doc_links::{doc_attributes, extract_definitions_from_markdown, resolve_doc_path_for_def}, |
12 | FilePosition, NavigationTarget, RangeInfo, | 12 | FilePosition, NavigationTarget, RangeInfo, |
13 | }; | 13 | }; |
14 | 14 | ||
@@ -30,11 +30,16 @@ pub(crate) fn goto_definition( | |||
30 | let original_token = pick_best(file.token_at_offset(position.offset))?; | 30 | let original_token = pick_best(file.token_at_offset(position.offset))?; |
31 | let token = sema.descend_into_macros(original_token.clone()); | 31 | let token = sema.descend_into_macros(original_token.clone()); |
32 | let parent = token.parent()?; | 32 | let parent = token.parent()?; |
33 | if let Some(comment) = ast::Comment::cast(token) { | 33 | if let Some(_) = ast::Comment::cast(token) { |
34 | let docs = doc_owner_to_def(&sema, &parent)?.docs(db)?; | 34 | let (attributes, def) = doc_attributes(&sema, &parent)?; |
35 | 35 | ||
36 | let (_, link, ns) = extract_positioned_link_from_comment(position.offset, &comment, docs)?; | 36 | let (docs, doc_mapping) = attributes.docs_with_rangemap(db)?; |
37 | let def = doc_owner_to_def(&sema, &parent)?; | 37 | let (_, link, ns) = |
38 | extract_definitions_from_markdown(docs.as_str()).into_iter().find(|(range, ..)| { | ||
39 | doc_mapping.map(range.clone()).map_or(false, |InFile { file_id, value: range }| { | ||
40 | file_id == position.file_id.into() && range.contains(position.offset) | ||
41 | }) | ||
42 | })?; | ||
38 | let nav = resolve_doc_path_for_def(db, def, &link, ns)?.try_to_nav(db)?; | 43 | let nav = resolve_doc_path_for_def(db, def, &link, ns)?.try_to_nav(db)?; |
39 | return Some(RangeInfo::new(original_token.text_range(), vec![nav])); | 44 | return Some(RangeInfo::new(original_token.text_range(), vec![nav])); |
40 | } | 45 | } |