Change default comment token to # for unrecognized files (#12080)

* Change the default comment token

* update test

* keep the original
This commit is contained in:
Kieran Moy 2024-12-05 08:11:39 +08:00 committed by GitHub
parent 565bfbba25
commit e670970dd8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -9,7 +9,7 @@
use helix_stdx::rope::RopeSliceExt; use helix_stdx::rope::RopeSliceExt;
use std::borrow::Cow; use std::borrow::Cow;
pub const DEFAULT_COMMENT_TOKEN: &str = "//"; pub const DEFAULT_COMMENT_TOKEN: &str = "#";
/// Returns the longest matching comment token of the given line (if it exists). /// Returns the longest matching comment token of the given line (if it exists).
pub fn get_comment_token<'a, S: AsRef<str>>( pub fn get_comment_token<'a, S: AsRef<str>>(
@ -373,12 +373,12 @@ fn comment() {
let transaction = toggle_line_comments(&doc, &selection, None); let transaction = toggle_line_comments(&doc, &selection, None);
transaction.apply(&mut doc); transaction.apply(&mut doc);
assert_eq!(doc, " // 1\n\n // 2\n // 3"); assert_eq!(doc, " # 1\n\n # 2\n # 3");
} }
#[test] #[test]
fn uncomment() { fn uncomment() {
let mut doc = Rope::from(" // 1\n\n // 2\n // 3"); let mut doc = Rope::from(" # 1\n\n # 2\n # 3");
let mut selection = Selection::single(0, doc.len_chars() - 1); let mut selection = Selection::single(0, doc.len_chars() - 1);
let transaction = toggle_line_comments(&doc, &selection, None); let transaction = toggle_line_comments(&doc, &selection, None);
@ -391,7 +391,7 @@ fn uncomment() {
#[test] #[test]
fn uncomment_0_margin_comments() { fn uncomment_0_margin_comments() {
let mut doc = Rope::from(" //1\n\n //2\n //3"); let mut doc = Rope::from(" #1\n\n #2\n #3");
let mut selection = Selection::single(0, doc.len_chars() - 1); let mut selection = Selection::single(0, doc.len_chars() - 1);
let transaction = toggle_line_comments(&doc, &selection, None); let transaction = toggle_line_comments(&doc, &selection, None);
@ -404,7 +404,7 @@ fn uncomment_0_margin_comments() {
#[test] #[test]
fn uncomment_0_margin_comments_with_no_space() { fn uncomment_0_margin_comments_with_no_space() {
let mut doc = Rope::from("//"); let mut doc = Rope::from("#");
let mut selection = Selection::single(0, doc.len_chars() - 1); let mut selection = Selection::single(0, doc.len_chars() - 1);
let transaction = toggle_line_comments(&doc, &selection, None); let transaction = toggle_line_comments(&doc, &selection, None);