aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_ide/Cargo.toml4
-rw-r--r--crates/ra_ide/src/hover.rs44
2 files changed, 30 insertions, 18 deletions
diff --git a/crates/ra_ide/Cargo.toml b/crates/ra_ide/Cargo.toml
index 4e2ba6d61..6d5c9daf5 100644
--- a/crates/ra_ide/Cargo.toml
+++ b/crates/ra_ide/Cargo.toml
@@ -17,13 +17,11 @@ indexmap = "1.3.2"
17itertools = "0.9.0" 17itertools = "0.9.0"
18log = "0.4.8" 18log = "0.4.8"
19rustc-hash = "1.1.0" 19rustc-hash = "1.1.0"
20rand = { version = "0.7.3", features = ["small_rng"] }
21url = "*" 20url = "*"
22maplit = "*"
23lazy_static = "*"
24pulldown-cmark-to-cmark = "4.0.2" 21pulldown-cmark-to-cmark = "4.0.2"
25pulldown-cmark = "0.7.0" 22pulldown-cmark = "0.7.0"
26oorandom = "11.1.2" 23oorandom = "11.1.2"
24once_cell = "1"
27 25
28stdx = { path = "../stdx" } 26stdx = { path = "../stdx" }
29 27
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}