aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock85
-rw-r--r--crates/ra_ide/Cargo.toml4
-rw-r--r--crates/ra_ide/src/hover.rs44
3 files changed, 31 insertions, 102 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 572fb868e..9bd5fac2d 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -409,17 +409,6 @@ dependencies = [
409] 409]
410 410
411[[package]] 411[[package]]
412name = "getrandom"
413version = "0.1.14"
414source = "registry+https://github.com/rust-lang/crates.io-index"
415checksum = "7abc8dd8451921606d809ba32e95b6111925cd2906060d2dcc29c070220503eb"
416dependencies = [
417 "cfg-if",
418 "libc",
419 "wasi",
420]
421
422[[package]]
423name = "gimli" 412name = "gimli"
424version = "0.22.0" 413version = "0.22.0"
425source = "registry+https://github.com/rust-lang/crates.io-index" 414source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -640,12 +629,6 @@ dependencies = [
640] 629]
641 630
642[[package]] 631[[package]]
643name = "maplit"
644version = "1.0.2"
645source = "registry+https://github.com/rust-lang/crates.io-index"
646checksum = "3e2e65a1a2e43cfcb47a895c4c8b10d1f4a61097f9f254f183aee60cad9c651d"
647
648[[package]]
649name = "matchers" 632name = "matchers"
650version = "0.0.1" 633version = "0.0.1"
651source = "registry+https://github.com/rust-lang/crates.io-index" 634source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -908,12 +891,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
908checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6" 891checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6"
909 892
910[[package]] 893[[package]]
911name = "ppv-lite86"
912version = "0.2.8"
913source = "registry+https://github.com/rust-lang/crates.io-index"
914checksum = "237a5ed80e274dbc66f86bd59c1e25edc039660be53194b5fe0a482e0f2612ea"
915
916[[package]]
917name = "proc-macro2" 894name = "proc-macro2"
918version = "1.0.19" 895version = "1.0.19"
919source = "registry+https://github.com/rust-lang/crates.io-index" 896source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1105,9 +1082,8 @@ dependencies = [
1105 "expect", 1082 "expect",
1106 "indexmap", 1083 "indexmap",
1107 "itertools", 1084 "itertools",
1108 "lazy_static",
1109 "log", 1085 "log",
1110 "maplit", 1086 "once_cell",
1111 "oorandom", 1087 "oorandom",
1112 "pulldown-cmark", 1088 "pulldown-cmark",
1113 "pulldown-cmark-to-cmark", 1089 "pulldown-cmark-to-cmark",
@@ -1124,11 +1100,9 @@ dependencies = [
1124 "ra_syntax", 1100 "ra_syntax",
1125 "ra_text_edit", 1101 "ra_text_edit",
1126 "ra_tt", 1102 "ra_tt",
1127 "rand",
1128 "rustc-hash", 1103 "rustc-hash",
1129 "stdx", 1104 "stdx",
1130 "test_utils", 1105 "test_utils",
1131 "url",
1132] 1106]
1133 1107
1134[[package]] 1108[[package]]
@@ -1289,57 +1263,6 @@ dependencies = [
1289] 1263]
1290 1264
1291[[package]] 1265[[package]]
1292name = "rand"
1293version = "0.7.3"
1294source = "registry+https://github.com/rust-lang/crates.io-index"
1295checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03"
1296dependencies = [
1297 "getrandom",
1298 "libc",
1299 "rand_chacha",
1300 "rand_core",
1301 "rand_hc",
1302 "rand_pcg",
1303]
1304
1305[[package]]
1306name = "rand_chacha"
1307version = "0.2.2"
1308source = "registry+https://github.com/rust-lang/crates.io-index"
1309checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402"
1310dependencies = [
1311 "ppv-lite86",
1312 "rand_core",
1313]
1314
1315[[package]]
1316name = "rand_core"
1317version = "0.5.1"
1318source = "registry+https://github.com/rust-lang/crates.io-index"
1319checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19"
1320dependencies = [
1321 "getrandom",
1322]
1323
1324[[package]]
1325name = "rand_hc"
1326version = "0.2.0"
1327source = "registry+https://github.com/rust-lang/crates.io-index"
1328checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c"
1329dependencies = [
1330 "rand_core",
1331]
1332
1333[[package]]
1334name = "rand_pcg"
1335version = "0.2.1"
1336source = "registry+https://github.com/rust-lang/crates.io-index"
1337checksum = "16abd0c1b639e9eb4d7c50c0b8100b0d0f849be2349829c740fe8e6eb4816429"
1338dependencies = [
1339 "rand_core",
1340]
1341
1342[[package]]
1343name = "rayon" 1266name = "rayon"
1344version = "1.3.1" 1267version = "1.3.1"
1345source = "registry+https://github.com/rust-lang/crates.io-index" 1268source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1924,12 +1847,6 @@ dependencies = [
1924] 1847]
1925 1848
1926[[package]] 1849[[package]]
1927name = "wasi"
1928version = "0.9.0+wasi-snapshot-preview1"
1929source = "registry+https://github.com/rust-lang/crates.io-index"
1930checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519"
1931
1932[[package]]
1933name = "winapi" 1850name = "winapi"
1934version = "0.2.8" 1851version = "0.2.8"
1935source = "registry+https://github.com/rust-lang/crates.io-index" 1852source = "registry+https://github.com/rust-lang/crates.io-index"
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}