mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 13:25:09 +00:00
6320: Textmate grammar: prevent line comments from breaking block comments (closes #6281) r=matklad a=dustypomerleau Fixes https://github.com/rust-analyzer/rust-analyzer/issues/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 https://github.com/rust-analyzer/rust-analyzer/pull/6317, in order to close https://github.com/rust-analyzer/rust-analyzer/issues/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 https://github.com/rust-analyzer/rust-analyzer/issues/6286 Co-authored-by: Dusty Pomerleau <dustypomerleau@users.noreply.github.com> Co-authored-by: Zac Pullar-Strecker <zacmps@gmail.com>
This commit is contained in:
commit
ab53bb8718
2 changed files with 58 additions and 23 deletions
|
@ -132,7 +132,8 @@ fn get_doc_link(db: &RootDatabase, definition: Definition) -> Option<String> {
|
||||||
let import_map = db.import_map(krate.into());
|
let import_map = db.import_map(krate.into());
|
||||||
let base = once(krate.display_name(db)?.to_string())
|
let base = once(krate.display_name(db)?.to_string())
|
||||||
.chain(import_map.path_of(ns)?.segments.iter().map(|name| name.to_string()))
|
.chain(import_map.path_of(ns)?.segments.iter().map(|name| name.to_string()))
|
||||||
.join("/");
|
.join("/")
|
||||||
|
+ "/";
|
||||||
|
|
||||||
let filename = get_symbol_filename(db, &target_def);
|
let filename = get_symbol_filename(db, &target_def);
|
||||||
let fragment = match definition {
|
let fragment = match definition {
|
||||||
|
@ -152,9 +153,16 @@ fn get_doc_link(db: &RootDatabase, definition: Definition) -> Option<String> {
|
||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
|
|
||||||
get_doc_url(db, &krate)
|
get_doc_url(db, &krate)?
|
||||||
.and_then(|url| url.join(&base).ok())
|
.join(&base)
|
||||||
.and_then(|url| filename.as_deref().and_then(|f| url.join(f).ok()))
|
.ok()
|
||||||
|
.and_then(|mut url| {
|
||||||
|
if !matches!(definition, Definition::ModuleDef(ModuleDef::Module(..))) {
|
||||||
|
url.path_segments_mut().ok()?.pop();
|
||||||
|
};
|
||||||
|
Some(url)
|
||||||
|
})
|
||||||
|
.and_then(|url| url.join(filename.as_deref()?).ok())
|
||||||
.and_then(
|
.and_then(
|
||||||
|url| if let Some(fragment) = fragment { url.join(&fragment).ok() } else { Some(url) },
|
|url| if let Some(fragment) = fragment { url.join(&fragment).ok() } else { Some(url) },
|
||||||
)
|
)
|
||||||
|
@ -522,6 +530,18 @@ pub struct Foo {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_module() {
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
pub mod foo {
|
||||||
|
pub mod ba<|>r {}
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
expect![[r#"https://docs.rs/test/*/test/foo/bar/index.html"#]],
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
// FIXME: ImportMap will return re-export paths instead of public module
|
// FIXME: ImportMap will return re-export paths instead of public module
|
||||||
// paths. The correct path to documentation will never be a re-export.
|
// paths. The correct path to documentation will never be a re-export.
|
||||||
// This problem stops us from resolving stdlib items included in the prelude
|
// This problem stops us from resolving stdlib items included in the prelude
|
||||||
|
|
|
@ -24,6 +24,9 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"patterns": [
|
"patterns": [
|
||||||
|
{
|
||||||
|
"include": "#block-comments"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"include": "#comments"
|
"include": "#comments"
|
||||||
},
|
},
|
||||||
|
@ -184,6 +187,9 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"patterns": [
|
"patterns": [
|
||||||
|
{
|
||||||
|
"include": "#block-comments"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"include": "#comments"
|
"include": "#comments"
|
||||||
},
|
},
|
||||||
|
@ -211,6 +217,9 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"patterns": [
|
"patterns": [
|
||||||
|
{
|
||||||
|
"include": "#block-comments"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"include": "#comments"
|
"include": "#comments"
|
||||||
},
|
},
|
||||||
|
@ -231,6 +240,9 @@
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"include": "#block-comments"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"include": "#comments"
|
"include": "#comments"
|
||||||
},
|
},
|
||||||
|
@ -277,23 +289,22 @@
|
||||||
{
|
{
|
||||||
"comment": "documentation comments",
|
"comment": "documentation comments",
|
||||||
"name": "comment.line.documentation.rust",
|
"name": "comment.line.documentation.rust",
|
||||||
"match": "^\\s*///.*",
|
"match": "^\\s*///.*"
|
||||||
"patterns": [
|
|
||||||
{
|
|
||||||
"include": "#comments"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"comment": "line comments",
|
"comment": "line comments",
|
||||||
"name": "comment.line.double-slash.rust",
|
"name": "comment.line.double-slash.rust",
|
||||||
"match": "\\s*//.*",
|
"match": "\\s*//.*"
|
||||||
"patterns": [
|
},
|
||||||
{
|
{
|
||||||
"include": "#comments"
|
"comment": "inferred types, wildcard patterns, ignored params",
|
||||||
|
"name": "comment.char.underscore.rust",
|
||||||
|
"match": "\\b_\\w*\\b[^!(]"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
"block-comments": {
|
||||||
|
"patterns": [
|
||||||
{
|
{
|
||||||
"comment": "block comments",
|
"comment": "block comments",
|
||||||
"name": "comment.block.rust",
|
"name": "comment.block.rust",
|
||||||
|
@ -301,7 +312,7 @@
|
||||||
"end": "\\*/",
|
"end": "\\*/",
|
||||||
"patterns": [
|
"patterns": [
|
||||||
{
|
{
|
||||||
"include": "#comments"
|
"include": "#block-comments"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -312,14 +323,9 @@
|
||||||
"end": "\\*/",
|
"end": "\\*/",
|
||||||
"patterns": [
|
"patterns": [
|
||||||
{
|
{
|
||||||
"include": "#comments"
|
"include": "#block-comments"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
|
||||||
{
|
|
||||||
"comment": "inferred types, wildcard patterns, ignored params",
|
|
||||||
"name": "comment.char.underscore.rust",
|
|
||||||
"match": "\\b_\\w*\\b"
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -450,6 +456,9 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"patterns": [
|
"patterns": [
|
||||||
|
{
|
||||||
|
"include": "#block-comments"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"include": "#comments"
|
"include": "#comments"
|
||||||
},
|
},
|
||||||
|
@ -516,6 +525,9 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"patterns": [
|
"patterns": [
|
||||||
|
{
|
||||||
|
"include": "#block-comments"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"include": "#comments"
|
"include": "#comments"
|
||||||
},
|
},
|
||||||
|
@ -797,6 +809,9 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"patterns": [
|
"patterns": [
|
||||||
|
{
|
||||||
|
"include": "#block-comments"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"include": "#comments"
|
"include": "#comments"
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue