editor: Fix issue where newline on * as prefix adds comment delimiter (#31271)

Release Notes:

- Fixed issue where pressing Enter on a line starting with * incorrectly
added comment delimiter.

---------

Co-authored-by: Piotr Osiewicz <peterosiewicz@gmail.com>
Co-authored-by: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com>
This commit is contained in:
smit 2025-05-23 18:46:55 +05:30 committed by GitHub
parent 0201d1e0b4
commit 03ac3fb91a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 42 additions and 19 deletions

View file

@ -2863,18 +2863,24 @@ async fn test_newline_documentation_comments(cx: &mut TestAppContext) {
settings.defaults.tab_size = NonZeroU32::new(4)
});
let language = Arc::new(Language::new(
LanguageConfig {
documentation: Some(language::DocumentationConfig {
start: "/**".into(),
end: "*/".into(),
prefix: "* ".into(),
tab_size: NonZeroU32::new(1).unwrap(),
}),
..LanguageConfig::default()
},
None,
));
let language = Arc::new(
Language::new(
LanguageConfig {
documentation: Some(language::DocumentationConfig {
start: "/**".into(),
end: "*/".into(),
prefix: "* ".into(),
tab_size: NonZeroU32::new(1).unwrap(),
}),
..LanguageConfig::default()
},
Some(tree_sitter_rust::LANGUAGE.into()),
)
.with_override_query("[(line_comment)(block_comment)] @comment.inclusive")
.unwrap(),
);
{
let mut cx = EditorTestContext::new(cx).await;
cx.update_buffer(|buffer, cx| buffer.set_language(Some(language), cx));
@ -3038,6 +3044,17 @@ async fn test_newline_documentation_comments(cx: &mut TestAppContext) {
*/
ˇtext
"});
// Ensure if not comment block it doesn't
// add comment prefix on newline
cx.set_state(indoc! {"
* textˇ
"});
cx.update_editor(|e, window, cx| e.newline(&Newline, window, cx));
cx.assert_editor_state(indoc! {"
* text
ˇ
"});
}
// Ensure that comment continuations can be disabled.
update_test_language_settings(cx, |settings| {