aboutsummaryrefslogtreecommitdiff
path: root/crates/ide/src/doc_links.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ide/src/doc_links.rs')
-rw-r--r--crates/ide/src/doc_links.rs24
1 files changed, 8 insertions, 16 deletions
diff --git a/crates/ide/src/doc_links.rs b/crates/ide/src/doc_links.rs
index 7ac0118fe..dfab8d313 100644
--- a/crates/ide/src/doc_links.rs
+++ b/crates/ide/src/doc_links.rs
@@ -16,11 +16,10 @@ use hir::{
16}; 16};
17use ide_db::{ 17use ide_db::{
18 defs::{Definition, NameClass, NameRefClass}, 18 defs::{Definition, NameClass, NameRefClass},
19 helpers::pick_best_token,
19 RootDatabase, 20 RootDatabase,
20}; 21};
21use syntax::{ 22use syntax::{ast, match_ast, AstNode, SyntaxKind::*, SyntaxNode, TextRange, T};
22 ast, match_ast, AstNode, SyntaxKind::*, SyntaxNode, SyntaxToken, TextRange, TokenAtOffset, T,
23};
24 23
25use crate::{FilePosition, Semantics}; 24use crate::{FilePosition, Semantics};
26 25
@@ -102,7 +101,12 @@ pub(crate) fn external_docs(
102) -> Option<DocumentationLink> { 101) -> Option<DocumentationLink> {
103 let sema = Semantics::new(db); 102 let sema = Semantics::new(db);
104 let file = sema.parse(position.file_id).syntax().clone(); 103 let file = sema.parse(position.file_id).syntax().clone();
105 let token = pick_best(file.token_at_offset(position.offset))?; 104 let token = pick_best_token(file.token_at_offset(position.offset), |kind| match kind {
105 IDENT | INT_NUMBER => 3,
106 T!['('] | T![')'] => 2,
107 kind if kind.is_trivia() => 0,
108 _ => 1,
109 })?;
106 let token = sema.descend_into_macros(token); 110 let token = sema.descend_into_macros(token);
107 111
108 let node = token.parent()?; 112 let node = token.parent()?;
@@ -522,18 +526,6 @@ fn get_symbol_fragment(db: &dyn HirDatabase, field_or_assoc: &FieldOrAssocItem)
522 }) 526 })
523} 527}
524 528
525fn pick_best(tokens: TokenAtOffset<SyntaxToken>) -> Option<SyntaxToken> {
526 return tokens.max_by_key(priority);
527 fn priority(n: &SyntaxToken) -> usize {
528 match n.kind() {
529 IDENT | INT_NUMBER => 3,
530 T!['('] | T![')'] => 2,
531 kind if kind.is_trivia() => 0,
532 _ => 1,
533 }
534 }
535}
536
537#[cfg(test)] 529#[cfg(test)]
538mod tests { 530mod tests {
539 use expect_test::{expect, Expect}; 531 use expect_test::{expect, Expect};