summaryrefslogtreecommitdiff
path: root/helix-core/src
diff options
context:
space:
mode:
authorCor Peters2021-07-18 16:33:38 +0000
committerGitHub2021-07-18 16:33:38 +0000
commitcd65a48635d49ccc2aed55a315c3a33875e13f88 (patch)
tree0197d8f8fc68d29517e3ac564e4f9b2a2bf881b0 /helix-core/src
parent0aa43902cab5dbcddb72ddf5d3b825ef874dc620 (diff)
Made toggle_comments language dependent (#463)
* Made toggle_comments language dependent * Fixed Test Cases * Added clippy suggestion * Small Fixes * Clippy Suggestion Co-authored-by: Cor <prive@corpeters.nl>
Diffstat (limited to 'helix-core/src')
-rw-r--r--helix-core/src/comment.rs10
-rw-r--r--helix-core/src/indent.rs1
-rw-r--r--helix-core/src/syntax.rs1
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)]