Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change default comment token to # for unrecognized files #12080

Merged
merged 4 commits into from
Dec 5, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions helix-core/src/comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
use helix_stdx::rope::RopeSliceExt;
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).
pub fn get_comment_token<'a, S: AsRef<str>>(
Expand Down Expand Up @@ -345,17 +345,17 @@ mod test {

let text = doc.slice(..);

let res = find_line_comment("//", text, 0..3);
let res = find_line_comment("#", text, 0..3);
kfatyuip marked this conversation as resolved.
Show resolved Hide resolved
// (commented = false, to_change = [line 0, line 2], min = col 2, margin = 0)
assert_eq!(res, (false, vec![0, 2], 2, 0));
}

#[test]
fn is_commented() {
// three lines where the second line is empty.
let doc = Rope::from("// hello\n\n// there");
let doc = Rope::from("# hello\n\n# there");

let res = find_line_comment("//", doc.slice(..), 0..3);
let res = find_line_comment("#", doc.slice(..), 0..3);

// (commented = true, to_change = [line 0, line 2], min = col 0, margin = 1)
assert_eq!(res, (true, vec![0, 2], 0, 1));
Expand All @@ -376,12 +376,12 @@ mod test {
let transaction = toggle_line_comments(&doc, &selection, None);
transaction.apply(&mut doc);

assert_eq!(doc, " // 1\n\n // 2\n // 3");
assert_eq!(doc, " # 1\n\n # 2\n # 3");
}

#[test]
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 transaction = toggle_line_comments(&doc, &selection, None);
Expand All @@ -394,7 +394,7 @@ mod test {

#[test]
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 transaction = toggle_line_comments(&doc, &selection, None);
Expand All @@ -407,7 +407,7 @@ mod test {

#[test]
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 transaction = toggle_line_comments(&doc, &selection, None);
Expand Down