@@ -38,21 +38,17 @@ fn try_resolve_intra<T: Resolvable, D: DefDatabase + HirDatabase>(
38
38
let link_target =
39
39
if link_target. is_empty ( ) { link_text. trim_matches ( '`' ) } else { link_target } ;
40
40
41
- // Namespace disambiguation
42
- let namespace = Namespace :: from_intra_spec ( link_target) ;
43
-
44
- // Strip prefixes/suffixes
45
- let link_target = strip_prefixes_suffixes ( link_target) ;
41
+ let doclink = IntraDocLink :: from ( link_target) ;
46
42
47
43
// Parse link as a module path
48
- let path = Path :: parse ( link_target ) . ok ( ) ?;
44
+ let path = Path :: parse ( doclink . path ) . ok ( ) ?;
49
45
let modpath = ModPath :: from_src ( path, & Hygiene :: new_unhygienic ( ) ) . unwrap ( ) ;
50
46
51
47
// Resolve it relative to symbol's location (according to the RFC this should consider small scopes)
52
48
let resolver = definition. resolver ( db) ?;
53
49
54
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
52
// FIXME: .or(resolved.macros)
57
53
None => resolved
58
54
. types
@@ -133,7 +129,7 @@ fn strip_prefixes_suffixes(mut s: &str) -> &str {
133
129
134
130
fn get_doc_url ( db : & dyn HirDatabase , krate : & Crate ) -> Option < Url > {
135
131
krate
136
- . get_doc_url ( db)
132
+ . get_html_root_url ( db)
137
133
. or_else ( ||
138
134
// Fallback to docs.rs
139
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
163
+ struct IntraDocLink < ' s > {
164
+ path : & ' s str ,
165
+ namespace : Option < Namespace > ,
166
+ }
167
+
168
+ impl < ' 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
174
#[ derive( PartialEq , Eq , Hash , Copy , Clone , Debug ) ]
168
175
enum Namespace {
169
176
Types ,
0 commit comments