diff --git a/helix-core/src/comment.rs b/helix-core/src/comment.rs index cfd15ab88..dad40b05d 100644 --- a/helix-core/src/comment.rs +++ b/helix-core/src/comment.rs @@ -92,20 +92,17 @@ pub fn toggle_line_comments(doc: &Rope, range: &Range, token: Option<&str>) -> V let start = start.clamp(0, text.len_lines()); let end = (end + 1).min(text.len_lines()); - // let start_byte = text.line_to_byte(start); - // let end_byte = text.line_to_byte(start); - let mut lines = vec![]; lines.extend(start..end); - let (commented, to_change, min, margin) = find_line_comment(token, text, lines); + let (was_commented, to_change, min, margin) = find_line_comment(token, text, lines); let mut changes: Vec = Vec::with_capacity(to_change.len()); for line in to_change { let pos = text.line_to_char(line) + min; - if !commented { + if !was_commented { // comment line changes.push((pos, pos, Some(comment.clone()))); } else { @@ -145,7 +142,7 @@ pub fn find_block_comments( text: RopeSlice, ranges: &Vec, ) -> (bool, Vec) { - let mut commented = true; + let mut was_commented = true; let mut only_whitespace = true; let mut comment_changes = Vec::with_capacity(ranges.len()); let default_tokens = tokens.first().cloned().unwrap_or_default(); @@ -200,7 +197,7 @@ pub fn find_block_comments( start_token: default_tokens.start.clone(), end_token: default_tokens.end.clone(), }); - commented = false; + was_commented = false; } else { comment_changes.push(CommentChange::Commented { range: *range, @@ -219,14 +216,13 @@ pub fn find_block_comments( } } if only_whitespace { - commented = false; + was_commented = false; } - (commented, comment_changes) + (was_commented, comment_changes) } #[must_use] pub fn create_block_comment_transaction( - _doc: &Rope, ranges: &[Range], was_commented: bool, comment_changes: Vec, @@ -304,7 +300,7 @@ pub fn toggle_block_comments( let text = doc.slice(..); let (was_commented, comment_changes) = find_block_comments(tokens, text, ranges); let (changes, new_ranges) = - create_block_comment_transaction(doc, ranges, was_commented, comment_changes); + create_block_comment_transaction(ranges, was_commented, comment_changes); if was_commented { for (range, changes) in new_ranges.iter().zip(changes.chunks_exact(2)) { diff --git a/helix-core/src/syntax.rs b/helix-core/src/syntax.rs index 333453e1b..8f6184330 100644 --- a/helix-core/src/syntax.rs +++ b/helix-core/src/syntax.rs @@ -1429,6 +1429,7 @@ impl Syntax { }) } + /// Get an injection layer's language configuration pub fn layer_config(&self, layer_id: LayerId) -> Arc { let loader = &self.loader.load(); let language_id = self.layers[layer_id].config.language_id; diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 90a51dc73..27a6a62bf 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -5090,8 +5090,6 @@ pub fn completion(cx: &mut Context) { } // comments -// type CommentTransactionFn = -// Box Transaction>; pub type CommentTransactionFn<'a> = Box< dyn FnMut( @@ -5136,26 +5134,7 @@ fn toggle_comments_impl<'a>( let mut best_fit = None; let mut min_gap = usize::MAX; - // Find the injection with the most tightly encompassing - // range. - // - // TODO: improve performance of this - // - // I'm thinking layer.ranges can be a - // BTreeSet instead of Vec - // - // The "Cmp" implementation can basically be - // range.start_byte.cmp(other.start_byte) - // .then(range.end_byte.cmp(other.end_byte)) - // - // Since we can't implement Cmp for Range (external trate and struct) - // we need to use newtype pattern: struct TSRange(Range) - // But I tried that and I'm not sure it'll work - // - // I *could* just use the same Vec, and when we're inserting into it - // we'll do it in the correct order. Then do Vec::binary_search_by - // - // However, I don't know if that'll be a good idea. + // Find the injection with the most tightly encompassing range. if let Some(syntax) = &syntax { for (layer_id, layer) in &syntax.layers { for ts_range in &layer.ranges { @@ -5239,7 +5218,6 @@ fn toggle_comments(cx: &mut Context) { // block commented by line would also be block commented so check this first if line_commented { return comment::create_block_comment_transaction( - rope, &split_lines, line_commented, line_comment_changes, @@ -5253,7 +5231,6 @@ fn toggle_comments(cx: &mut Context) { // check if selection has block comments if block_commented { return comment::create_block_comment_transaction( - rope, &[*range], block_commented, comment_changes, @@ -5264,7 +5241,6 @@ fn toggle_comments(cx: &mut Context) { // not commented and only have block comment tokens if line_token.is_none() && block_tokens.is_some() { return comment::create_block_comment_transaction( - rope, &split_lines, line_commented, line_comment_changes,