aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide/src')
-rw-r--r--crates/ra_ide/src/hover.rs44
1 files changed, 29 insertions, 15 deletions
diff --git a/crates/ra_ide/src/hover.rs b/crates/ra_ide/src/hover.rs
index a82fe6714..1531aca2e 100644
--- a/crates/ra_ide/src/hover.rs
+++ b/crates/ra_ide/src/hover.rs
@@ -1,5 +1,8 @@
1use std::collections::{HashMap, HashSet}; 1use std::collections::{HashMap, HashSet};
2use std::iter::once; 2use std::{
3 iter::{once, FromIterator},
4 sync::Mutex,
5};
3 6
4use hir::{ 7use hir::{
5 db::DefDatabase, Adt, AsAssocItem, AsName, AssocItemContainer, AttrDef, Crate, Documentation, 8 db::DefDatabase, Adt, AsAssocItem, AsName, AssocItemContainer, AttrDef, Crate, Documentation,
@@ -7,8 +10,7 @@ use hir::{
7 ModuleSource, Semantics, 10 ModuleSource, Semantics,
8}; 11};
9use itertools::Itertools; 12use itertools::Itertools;
10use lazy_static::lazy_static; 13use once_cell::sync::Lazy;
11use maplit::{hashmap, hashset};
12use pulldown_cmark::{CowStr, Event, Options, Parser, Tag}; 14use pulldown_cmark::{CowStr, Event, Options, Parser, Tag};
13use pulldown_cmark_to_cmark::cmark; 15use pulldown_cmark_to_cmark::cmark;
14use ra_db::SourceDatabase; 16use ra_db::SourceDatabase;
@@ -419,14 +421,26 @@ enum Namespace {
419 Macros, 421 Macros,
420} 422}
421 423
422lazy_static!( 424static NS_MAP: Lazy<
423 /// Map of namespaces to identifying prefixes and suffixes as defined by RFC1946. 425 HashMap<Namespace, (HashSet<&'static &'static str>, HashSet<&'static &'static str>)>,
424 static ref NS_MAP: HashMap<Namespace, (HashSet<&'static str>, HashSet<&'static str>)> = hashmap!{ 426> = Lazy::new(|| {
425 Namespace::Types => (hashset!{"type", "struct", "enum", "mod", "trait", "union", "module"}, hashset!{}), 427 let mut map = HashMap::new();
426 Namespace::Values => (hashset!{"value", "function", "fn", "method", "const", "static", "mod", "module"}, hashset!{"()"}), 428 map.insert(Namespace::Types, (HashSet::new(), HashSet::new()));
427 Namespace::Macros => (hashset!{"macro"}, hashset!{"!"}) 429 map.insert(
428 }; 430 Namespace::Values,
429); 431 (
432 HashSet::from_iter(
433 ["value", "function", "fn", "method", "const", "static", "mod", "module"].iter(),
434 ),
435 HashSet::from_iter(["()"].iter()),
436 ),
437 );
438 map.insert(
439 Namespace::Macros,
440 (HashSet::from_iter(["macro"].iter()), HashSet::from_iter(["!"].iter())),
441 );
442 map
443});
430 444
431impl Namespace { 445impl Namespace {
432 /// Extract the specified namespace from an intra-doc-link if one exists. 446 /// Extract the specified namespace from an intra-doc-link if one exists.
@@ -437,7 +451,7 @@ impl Namespace {
437 prefixes 451 prefixes
438 .iter() 452 .iter()
439 .map(|prefix| { 453 .map(|prefix| {
440 s.starts_with(prefix) 454 s.starts_with(*prefix)
441 && s.chars() 455 && s.chars()
442 .nth(prefix.len() + 1) 456 .nth(prefix.len() + 1)
443 .map(|c| c == '@' || c == ' ') 457 .map(|c| c == '@' || c == ' ')
@@ -447,7 +461,7 @@ impl Namespace {
447 || suffixes 461 || suffixes
448 .iter() 462 .iter()
449 .map(|suffix| { 463 .map(|suffix| {
450 s.starts_with(suffix) 464 s.starts_with(*suffix)
451 && s.chars() 465 && s.chars()
452 .nth(suffix.len() + 1) 466 .nth(suffix.len() + 1)
453 .map(|c| c == '@' || c == ' ') 467 .map(|c| c == '@' || c == ' ')
@@ -464,8 +478,8 @@ impl Namespace {
464fn strip_prefixes_suffixes(mut s: &str) -> &str { 478fn strip_prefixes_suffixes(mut s: &str) -> &str {
465 s = s.trim_matches('`'); 479 s = s.trim_matches('`');
466 NS_MAP.iter().for_each(|(_, (prefixes, suffixes))| { 480 NS_MAP.iter().for_each(|(_, (prefixes, suffixes))| {
467 prefixes.iter().for_each(|prefix| s = s.trim_start_matches(prefix)); 481 prefixes.iter().for_each(|prefix| s = s.trim_start_matches(*prefix));
468 suffixes.iter().for_each(|suffix| s = s.trim_end_matches(suffix)); 482 suffixes.iter().for_each(|suffix| s = s.trim_end_matches(*suffix));
469 }); 483 });
470 s.trim_start_matches("@").trim() 484 s.trim_start_matches("@").trim()
471} 485}