aboutsummaryrefslogtreecommitdiff
path: root/crates/hir/src/code_model.rs
diff options
context:
space:
mode:
authorZac Pullar-Strecker <[email protected]>2020-08-25 05:40:43 +0100
committerZac Pullar-Strecker <[email protected]>2020-08-25 05:40:43 +0100
commit452afaebe188251cd4403e56999bf8b58de4fba9 (patch)
tree88ba82f044248adb6ccc4da8931e26bbe9b345dd /crates/hir/src/code_model.rs
parent5452368fad8ee8d03d980de47604fa108111ea57 (diff)
Changes from review
Diffstat (limited to 'crates/hir/src/code_model.rs')
-rw-r--r--crates/hir/src/code_model.rs18
1 files changed, 8 insertions, 10 deletions
diff --git a/crates/hir/src/code_model.rs b/crates/hir/src/code_model.rs
index bd80102fa..94dd7f6f5 100644
--- a/crates/hir/src/code_model.rs
+++ b/crates/hir/src/code_model.rs
@@ -126,13 +126,16 @@ impl Crate {
126 } 126 }
127 127
128 /// Try to get the root URL of the documentation of a crate. 128 /// Try to get the root URL of the documentation of a crate.
129 pub fn get_doc_url(self: &Crate, db: &dyn HirDatabase) -> Option<String> { 129 pub fn get_html_root_url(self: &Crate, db: &dyn HirDatabase) -> Option<String> {
130 // Look for #![doc(html_root_url = "...")] 130 // Look for #![doc(html_root_url = "...")]
131 let attrs = db.attrs(AttrDef::from(self.root_module(db)).into()); 131 let attrs = db.attrs(AttrDef::from(self.root_module(db)).into());
132 let doc_attr_q = attrs.by_key("doc"); 132 let doc_attr_q = attrs.by_key("doc");
133 133
134 let doc_url = if doc_attr_q.exists() { 134 if !doc_attr_q.exists() {
135 doc_attr_q.tt_values().map(|tt| { 135 return None;
136 }
137
138 let doc_url = doc_attr_q.tt_values().map(|tt| {
136 let name = tt.token_trees.iter() 139 let name = tt.token_trees.iter()
137 .skip_while(|tt| !matches!(tt, TokenTree::Leaf(Leaf::Ident(Ident{text: ref ident, ..})) if ident == "html_root_url")) 140 .skip_while(|tt| !matches!(tt, TokenTree::Leaf(Leaf::Ident(Ident{text: ref ident, ..})) if ident == "html_root_url"))
138 .skip(2) 141 .skip(2)
@@ -142,14 +145,9 @@ impl Crate {
142 Some(TokenTree::Leaf(Leaf::Literal(Literal{ref text, ..}))) => Some(text), 145 Some(TokenTree::Leaf(Leaf::Literal(Literal{ref text, ..}))) => Some(text),
143 _ => None 146 _ => None
144 } 147 }
145 }).flat_map(|t| t).next().map(|s| s.to_string()) 148 }).flat_map(|t| t).next();
146 } else {
147 None
148 };
149 149
150 doc_url 150 doc_url.map(|s| s.trim_matches('"').trim_end_matches("/").to_owned() + "/")
151 .map(|s| s.trim_matches('"').trim_end_matches("/").to_owned() + "/")
152 .map(|s| s.to_string())
153 } 151 }
154} 152}
155 153