diff options
-rw-r--r-- | crates/ide/src/doc_links.rs | 28 | ||||
-rw-r--r-- | editors/code/rust.tmGrammar.json | 53 |
2 files changed, 58 insertions, 23 deletions
diff --git a/crates/ide/src/doc_links.rs b/crates/ide/src/doc_links.rs index b9d8b8a2b..250f10f9f 100644 --- a/crates/ide/src/doc_links.rs +++ b/crates/ide/src/doc_links.rs | |||
@@ -132,7 +132,8 @@ fn get_doc_link(db: &RootDatabase, definition: Definition) -> Option<String> { | |||
132 | let import_map = db.import_map(krate.into()); | 132 | let import_map = db.import_map(krate.into()); |
133 | let base = once(krate.display_name(db)?.to_string()) | 133 | let base = once(krate.display_name(db)?.to_string()) |
134 | .chain(import_map.path_of(ns)?.segments.iter().map(|name| name.to_string())) | 134 | .chain(import_map.path_of(ns)?.segments.iter().map(|name| name.to_string())) |
135 | .join("/"); | 135 | .join("/") |
136 | + "/"; | ||
136 | 137 | ||
137 | let filename = get_symbol_filename(db, &target_def); | 138 | let filename = get_symbol_filename(db, &target_def); |
138 | let fragment = match definition { | 139 | let fragment = match definition { |
@@ -152,9 +153,16 @@ fn get_doc_link(db: &RootDatabase, definition: Definition) -> Option<String> { | |||
152 | _ => None, | 153 | _ => None, |
153 | }; | 154 | }; |
154 | 155 | ||
155 | get_doc_url(db, &krate) | 156 | get_doc_url(db, &krate)? |
156 | .and_then(|url| url.join(&base).ok()) | 157 | .join(&base) |
157 | .and_then(|url| filename.as_deref().and_then(|f| url.join(f).ok())) | 158 | .ok() |
159 | .and_then(|mut url| { | ||
160 | if !matches!(definition, Definition::ModuleDef(ModuleDef::Module(..))) { | ||
161 | url.path_segments_mut().ok()?.pop(); | ||
162 | }; | ||
163 | Some(url) | ||
164 | }) | ||
165 | .and_then(|url| url.join(filename.as_deref()?).ok()) | ||
158 | .and_then( | 166 | .and_then( |
159 | |url| if let Some(fragment) = fragment { url.join(&fragment).ok() } else { Some(url) }, | 167 | |url| if let Some(fragment) = fragment { url.join(&fragment).ok() } else { Some(url) }, |
160 | ) | 168 | ) |
@@ -522,6 +530,18 @@ pub struct Foo { | |||
522 | ); | 530 | ); |
523 | } | 531 | } |
524 | 532 | ||
533 | #[test] | ||
534 | fn test_module() { | ||
535 | check( | ||
536 | r#" | ||
537 | pub mod foo { | ||
538 | pub mod ba<|>r {} | ||
539 | } | ||
540 | "#, | ||
541 | expect![[r#"https://docs.rs/test/*/test/foo/bar/index.html"#]], | ||
542 | ) | ||
543 | } | ||
544 | |||
525 | // FIXME: ImportMap will return re-export paths instead of public module | 545 | // FIXME: ImportMap will return re-export paths instead of public module |
526 | // paths. The correct path to documentation will never be a re-export. | 546 | // paths. The correct path to documentation will never be a re-export. |
527 | // This problem stops us from resolving stdlib items included in the prelude | 547 | // This problem stops us from resolving stdlib items included in the prelude |
diff --git a/editors/code/rust.tmGrammar.json b/editors/code/rust.tmGrammar.json index 3be565195..f0c5c3cf3 100644 --- a/editors/code/rust.tmGrammar.json +++ b/editors/code/rust.tmGrammar.json | |||
@@ -25,6 +25,9 @@ | |||
25 | }, | 25 | }, |
26 | "patterns": [ | 26 | "patterns": [ |
27 | { | 27 | { |
28 | "include": "#block-comments" | ||
29 | }, | ||
30 | { | ||
28 | "include": "#comments" | 31 | "include": "#comments" |
29 | }, | 32 | }, |
30 | { | 33 | { |
@@ -185,6 +188,9 @@ | |||
185 | }, | 188 | }, |
186 | "patterns": [ | 189 | "patterns": [ |
187 | { | 190 | { |
191 | "include": "#block-comments" | ||
192 | }, | ||
193 | { | ||
188 | "include": "#comments" | 194 | "include": "#comments" |
189 | }, | 195 | }, |
190 | { | 196 | { |
@@ -212,6 +218,9 @@ | |||
212 | }, | 218 | }, |
213 | "patterns": [ | 219 | "patterns": [ |
214 | { | 220 | { |
221 | "include": "#block-comments" | ||
222 | }, | ||
223 | { | ||
215 | "include": "#comments" | 224 | "include": "#comments" |
216 | }, | 225 | }, |
217 | { | 226 | { |
@@ -232,6 +241,9 @@ | |||
232 | ] | 241 | ] |
233 | }, | 242 | }, |
234 | { | 243 | { |
244 | "include": "#block-comments" | ||
245 | }, | ||
246 | { | ||
235 | "include": "#comments" | 247 | "include": "#comments" |
236 | }, | 248 | }, |
237 | { | 249 | { |
@@ -277,31 +289,30 @@ | |||
277 | { | 289 | { |
278 | "comment": "documentation comments", | 290 | "comment": "documentation comments", |
279 | "name": "comment.line.documentation.rust", | 291 | "name": "comment.line.documentation.rust", |
280 | "match": "^\\s*///.*", | 292 | "match": "^\\s*///.*" |
281 | "patterns": [ | ||
282 | { | ||
283 | "include": "#comments" | ||
284 | } | ||
285 | ] | ||
286 | }, | 293 | }, |
287 | { | 294 | { |
288 | "comment": "line comments", | 295 | "comment": "line comments", |
289 | "name": "comment.line.double-slash.rust", | 296 | "name": "comment.line.double-slash.rust", |
290 | "match": "\\s*//.*", | 297 | "match": "\\s*//.*" |
291 | "patterns": [ | ||
292 | { | ||
293 | "include": "#comments" | ||
294 | } | ||
295 | ] | ||
296 | }, | 298 | }, |
297 | { | 299 | { |
300 | "comment": "inferred types, wildcard patterns, ignored params", | ||
301 | "name": "comment.char.underscore.rust", | ||
302 | "match": "\\b_\\w*\\b[^!(]" | ||
303 | } | ||
304 | ] | ||
305 | }, | ||
306 | "block-comments": { | ||
307 | "patterns": [ | ||
308 | { | ||
298 | "comment": "block comments", | 309 | "comment": "block comments", |
299 | "name": "comment.block.rust", | 310 | "name": "comment.block.rust", |
300 | "begin": "/\\*(?!\\*)", | 311 | "begin": "/\\*(?!\\*)", |
301 | "end": "\\*/", | 312 | "end": "\\*/", |
302 | "patterns": [ | 313 | "patterns": [ |
303 | { | 314 | { |
304 | "include": "#comments" | 315 | "include": "#block-comments" |
305 | } | 316 | } |
306 | ] | 317 | ] |
307 | }, | 318 | }, |
@@ -312,14 +323,9 @@ | |||
312 | "end": "\\*/", | 323 | "end": "\\*/", |
313 | "patterns": [ | 324 | "patterns": [ |
314 | { | 325 | { |
315 | "include": "#comments" | 326 | "include": "#block-comments" |
316 | } | 327 | } |
317 | ] | 328 | ] |
318 | }, | ||
319 | { | ||
320 | "comment": "inferred types, wildcard patterns, ignored params", | ||
321 | "name": "comment.char.underscore.rust", | ||
322 | "match": "\\b_\\w*\\b" | ||
323 | } | 329 | } |
324 | ] | 330 | ] |
325 | }, | 331 | }, |
@@ -451,6 +457,9 @@ | |||
451 | }, | 457 | }, |
452 | "patterns": [ | 458 | "patterns": [ |
453 | { | 459 | { |
460 | "include": "#block-comments" | ||
461 | }, | ||
462 | { | ||
454 | "include": "#comments" | 463 | "include": "#comments" |
455 | }, | 464 | }, |
456 | { | 465 | { |
@@ -517,6 +526,9 @@ | |||
517 | }, | 526 | }, |
518 | "patterns": [ | 527 | "patterns": [ |
519 | { | 528 | { |
529 | "include": "#block-comments" | ||
530 | }, | ||
531 | { | ||
520 | "include": "#comments" | 532 | "include": "#comments" |
521 | }, | 533 | }, |
522 | { | 534 | { |
@@ -798,6 +810,9 @@ | |||
798 | }, | 810 | }, |
799 | "patterns": [ | 811 | "patterns": [ |
800 | { | 812 | { |
813 | "include": "#block-comments" | ||
814 | }, | ||
815 | { | ||
801 | "include": "#comments" | 816 | "include": "#comments" |
802 | }, | 817 | }, |
803 | { | 818 | { |