aboutsummaryrefslogtreecommitdiff
path: root/crates/hir/src/doc_links.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir/src/doc_links.rs')
-rw-r--r--crates/hir/src/doc_links.rs23
1 files changed, 15 insertions, 8 deletions
diff --git a/crates/hir/src/doc_links.rs b/crates/hir/src/doc_links.rs
index 45b26519e..dd2379bfc 100644
--- a/crates/hir/src/doc_links.rs
+++ b/crates/hir/src/doc_links.rs
@@ -38,21 +38,17 @@ fn try_resolve_intra<T: Resolvable, D: DefDatabase + HirDatabase>(
38 let link_target = 38 let link_target =
39 if link_target.is_empty() { link_text.trim_matches('`') } else { link_target }; 39 if link_target.is_empty() { link_text.trim_matches('`') } else { link_target };
40 40
41 // Namespace disambiguation 41 let doclink = IntraDocLink::from(link_target);
42 let namespace = Namespace::from_intra_spec(link_target);
43
44 // Strip prefixes/suffixes
45 let link_target = strip_prefixes_suffixes(link_target);
46 42
47 // Parse link as a module path 43 // Parse link as a module path
48 let path = Path::parse(link_target).ok()?; 44 let path = Path::parse(doclink.path).ok()?;
49 let modpath = ModPath::from_src(path, &Hygiene::new_unhygienic()).unwrap(); 45 let modpath = ModPath::from_src(path, &Hygiene::new_unhygienic()).unwrap();
50 46
51 // Resolve it relative to symbol's location (according to the RFC this should consider small scopes) 47 // Resolve it relative to symbol's location (according to the RFC this should consider small scopes)
52 let resolver = definition.resolver(db)?; 48 let resolver = definition.resolver(db)?;
53 49
54 let resolved = resolver.resolve_module_path_in_items(db, &modpath); 50 let resolved = resolver.resolve_module_path_in_items(db, &modpath);
55 let (defid, namespace) = match namespace { 51 let (defid, namespace) = match doclink.namespace {
56 // FIXME: .or(resolved.macros) 52 // FIXME: .or(resolved.macros)
57 None => resolved 53 None => resolved
58 .types 54 .types
@@ -133,7 +129,7 @@ fn strip_prefixes_suffixes(mut s: &str) -> &str {
133 129
134fn get_doc_url(db: &dyn HirDatabase, krate: &Crate) -> Option<Url> { 130fn get_doc_url(db: &dyn HirDatabase, krate: &Crate) -> Option<Url> {
135 krate 131 krate
136 .get_doc_url(db) 132 .get_html_root_url(db)
137 .or_else(|| 133 .or_else(||
138 // Fallback to docs.rs 134 // Fallback to docs.rs
139 // FIXME: Specify an exact version here. This may be difficult, as multiple versions of the same crate could exist. 135 // FIXME: Specify an exact version here. This may be difficult, as multiple versions of the same crate could exist.
@@ -164,6 +160,17 @@ fn get_symbol_filename(db: &dyn HirDatabase, definition: &ModuleDef) -> Option<S
164 }) 160 })
165} 161}
166 162
163struct IntraDocLink<'s> {
164 path: &'s str,
165 namespace: Option<Namespace>,
166}
167
168impl<'s> From<&'s str> for IntraDocLink<'s> {
169 fn from(s: &'s str) -> Self {
170 Self { path: strip_prefixes_suffixes(s), namespace: Namespace::from_intra_spec(s) }
171 }
172}
173
167#[derive(PartialEq, Eq, Hash, Copy, Clone, Debug)] 174#[derive(PartialEq, Eq, Hash, Copy, Clone, Debug)]
168enum Namespace { 175enum Namespace {
169 Types, 176 Types,