diff options
Diffstat (limited to 'helix-core/src')
-rw-r--r-- | helix-core/src/comment.rs | 10 | ||||
-rw-r--r-- | helix-core/src/indent.rs | 1 | ||||
-rw-r--r-- | helix-core/src/syntax.rs | 1 |
3 files changed, 7 insertions, 5 deletions
diff --git a/helix-core/src/comment.rs b/helix-core/src/comment.rs index 07f685d8..5d564055 100644 --- a/helix-core/src/comment.rs +++ b/helix-core/src/comment.rs @@ -38,18 +38,18 @@ fn find_line_comment( } #[must_use] -pub fn toggle_line_comments(doc: &Rope, selection: &Selection) -> Transaction { +pub fn toggle_line_comments(doc: &Rope, selection: &Selection, token: Option<&str>) -> Transaction { let text = doc.slice(..); let mut changes: Vec<Change> = Vec::new(); - let token = "//"; + let token = token.unwrap_or("//"); let comment = Tendril::from(format!("{} ", token)); for selection in selection { let start = text.char_to_line(selection.from()); let end = text.char_to_line(selection.to()); let lines = start..end + 1; - let (commented, skipped, min) = find_line_comment(token, text, lines.clone()); + let (commented, skipped, min) = find_line_comment(&token, text, lines.clone()); changes.reserve((end - start).saturating_sub(skipped.len())); @@ -95,14 +95,14 @@ mod test { assert_eq!(res, (false, vec![1], 2)); // comment - let transaction = toggle_line_comments(&state.doc, &state.selection); + let transaction = toggle_line_comments(&state.doc, &state.selection, None); transaction.apply(&mut state.doc); state.selection = state.selection.clone().map(transaction.changes()); assert_eq!(state.doc, " // 1\n\n // 2\n // 3"); // uncomment - let transaction = toggle_line_comments(&state.doc, &state.selection); + let transaction = toggle_line_comments(&state.doc, &state.selection, None); transaction.apply(&mut state.doc); state.selection = state.selection.clone().map(transaction.changes()); assert_eq!(state.doc, " 1\n\n 2\n 3"); diff --git a/helix-core/src/indent.rs b/helix-core/src/indent.rs index 292ade4b..0ca05fb3 100644 --- a/helix-core/src/indent.rs +++ b/helix-core/src/indent.rs @@ -265,6 +265,7 @@ where config: None, // roots: vec![], + comment_token: None, auto_format: false, language_server: None, indent: Some(IndentationConfiguration { diff --git a/helix-core/src/syntax.rs b/helix-core/src/syntax.rs index 621cd046..9acf3d87 100644 --- a/helix-core/src/syntax.rs +++ b/helix-core/src/syntax.rs @@ -35,6 +35,7 @@ pub struct LanguageConfiguration { pub scope: String, // source.rust pub file_types: Vec<String>, // filename ends_with? <Gemfile, rb, etc> pub roots: Vec<String>, // these indicate project roots <.git, Cargo.toml> + pub comment_token: Option<String>, pub config: Option<String>, #[serde(default)] |