Skip to content

Commit ab53bb8

Browse files
bors[bot]dustypomerleauzacps
authored
Merge #6320 #6321
6320: Textmate grammar: prevent line comments from breaking block comments (closes #6281) r=matklad a=dustypomerleau Fixes #6281. Previously, line comments were able to break block comments by essentially commenting out the closing `*/`, resulting in a never-ending comment. This PR splits block comments into a separate repository group to fix this problem. Since the comment scopes also include ignored parameters and inferred types, I've added the change proposed by @bnjjj in #6317, in order to close #6311 as well. 6321: Fix opening module documentation opening parent documentation instead r=matklad a=zacps The whole path/URL joining code is kind of ugly which is what led to this, but at the same time I don't really want to rewrite it right now... Fixes #6286 Co-authored-by: Dusty Pomerleau <[email protected]> Co-authored-by: Zac Pullar-Strecker <[email protected]>
3 parents af75a08 + 26b4b1e + 68c67ef commit ab53bb8

File tree

2 files changed

+58
-23
lines changed

2 files changed

+58
-23
lines changed

crates/ide/src/doc_links.rs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ fn get_doc_link(db: &RootDatabase, definition: Definition) -> Option<String> {
132132
let import_map = db.import_map(krate.into());
133133
let base = once(krate.display_name(db)?.to_string())
134134
.chain(import_map.path_of(ns)?.segments.iter().map(|name| name.to_string()))
135-
.join("/");
135+
.join("/")
136+
+ "/";
136137

137138
let filename = get_symbol_filename(db, &target_def);
138139
let fragment = match definition {
@@ -152,9 +153,16 @@ fn get_doc_link(db: &RootDatabase, definition: Definition) -> Option<String> {
152153
_ => None,
153154
};
154155

155-
get_doc_url(db, &krate)
156-
.and_then(|url| url.join(&base).ok())
157-
.and_then(|url| filename.as_deref().and_then(|f| url.join(f).ok()))
156+
get_doc_url(db, &krate)?
157+
.join(&base)
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())
158166
.and_then(
159167
|url| if let Some(fragment) = fragment { url.join(&fragment).ok() } else { Some(url) },
160168
)
@@ -522,6 +530,18 @@ pub struct Foo {
522530
);
523531
}
524532

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+
525545
// FIXME: ImportMap will return re-export paths instead of public module
526546
// paths. The correct path to documentation will never be a re-export.
527547
// This problem stops us from resolving stdlib items included in the prelude

editors/code/rust.tmGrammar.json

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
}
2525
},
2626
"patterns": [
27+
{
28+
"include": "#block-comments"
29+
},
2730
{
2831
"include": "#comments"
2932
},
@@ -184,6 +187,9 @@
184187
}
185188
},
186189
"patterns": [
190+
{
191+
"include": "#block-comments"
192+
},
187193
{
188194
"include": "#comments"
189195
},
@@ -211,6 +217,9 @@
211217
}
212218
},
213219
"patterns": [
220+
{
221+
"include": "#block-comments"
222+
},
214223
{
215224
"include": "#comments"
216225
},
@@ -231,6 +240,9 @@
231240
}
232241
]
233242
},
243+
{
244+
"include": "#block-comments"
245+
},
234246
{
235247
"include": "#comments"
236248
},
@@ -277,31 +289,30 @@
277289
{
278290
"comment": "documentation comments",
279291
"name": "comment.line.documentation.rust",
280-
"match": "^\\s*///.*",
281-
"patterns": [
282-
{
283-
"include": "#comments"
284-
}
285-
]
292+
"match": "^\\s*///.*"
286293
},
287294
{
288295
"comment": "line comments",
289296
"name": "comment.line.double-slash.rust",
290-
"match": "\\s*//.*",
291-
"patterns": [
292-
{
293-
"include": "#comments"
294-
}
295-
]
297+
"match": "\\s*//.*"
296298
},
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": [
297308
{
298309
"comment": "block comments",
299310
"name": "comment.block.rust",
300311
"begin": "/\\*(?!\\*)",
301312
"end": "\\*/",
302313
"patterns": [
303314
{
304-
"include": "#comments"
315+
"include": "#block-comments"
305316
}
306317
]
307318
},
@@ -312,14 +323,9 @@
312323
"end": "\\*/",
313324
"patterns": [
314325
{
315-
"include": "#comments"
326+
"include": "#block-comments"
316327
}
317328
]
318-
},
319-
{
320-
"comment": "inferred types, wildcard patterns, ignored params",
321-
"name": "comment.char.underscore.rust",
322-
"match": "\\b_\\w*\\b"
323329
}
324330
]
325331
},
@@ -450,6 +456,9 @@
450456
}
451457
},
452458
"patterns": [
459+
{
460+
"include": "#block-comments"
461+
},
453462
{
454463
"include": "#comments"
455464
},
@@ -516,6 +525,9 @@
516525
}
517526
},
518527
"patterns": [
528+
{
529+
"include": "#block-comments"
530+
},
519531
{
520532
"include": "#comments"
521533
},
@@ -797,6 +809,9 @@
797809
}
798810
},
799811
"patterns": [
812+
{
813+
"include": "#block-comments"
814+
},
800815
{
801816
"include": "#comments"
802817
},

0 commit comments

Comments
 (0)