From 3bb5933163279657f4039a543e0a8139ca0970ca Mon Sep 17 00:00:00 2001 From: Wilfred Hughes Date: Fri, 29 Apr 2022 18:23:31 -0700 Subject: [PATCH] Ensure Perl comments are treated as atoms with an atom kind of comment --- CHANGELOG.md | 2 ++ sample_files/compare.expected | 2 +- sample_files/perl_after.pl | 2 +- sample_files/perl_before.pl | 2 +- src/tree_sitter_parser.rs | 5 +++-- 5 files changed, 8 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 38b1ccf04..d58ede57a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ Improved detection of binary files that have a large number of null bytes. +Improved handling of comments in Perl. + ## 0.28 (released 29th April 2022) ### Parsing diff --git a/sample_files/compare.expected b/sample_files/compare.expected index d3b3e2ca9..0eb03b9da 100644 --- a/sample_files/compare.expected +++ b/sample_files/compare.expected @@ -110,7 +110,7 @@ sample_files/outer_delimiter_before.el sample_files/outer_delimiter_after.el 73130b8572a4f17fa6cf828f74e226ce - sample_files/perl_before.pl sample_files/perl_after.pl -0067b33629bd714177294d913f59f1b4 - +08d7cad58a79d423c0584387d4bb4dd1 - sample_files/preprocesor_before.h sample_files/preprocesor_after.h 3e4331cb935cbe735a79ebc43786cd3a - diff --git a/sample_files/perl_after.pl b/sample_files/perl_after.pl index 227a5d6cf..e6e31af99 100644 --- a/sample_files/perl_after.pl +++ b/sample_files/perl_after.pl @@ -9,7 +9,7 @@ use constant DEBUG , 0; # comma (,) is also used instead of '=>' print "Pi equals ", PI, "...\n"; use constant { - SEC => 0, + SEC => 0, # foo MIN => 1, HOUR => 2, MDAY => 3, diff --git a/sample_files/perl_before.pl b/sample_files/perl_before.pl index 701f63875..6939e6840 100644 --- a/sample_files/perl_before.pl +++ b/sample_files/perl_before.pl @@ -9,7 +9,7 @@ use constant DEBUG , 0; # comma (,) is also used instead of '=>' print "Pi equals ", PI, "...\n"; use constant { - SEC => 0, + SEC => 0, # foo bar MIN => 1, HOUR => 2, MDAY => 3, diff --git a/src/tree_sitter_parser.rs b/src/tree_sitter_parser.rs index 17d81667d..991370494 100644 --- a/src/tree_sitter_parser.rs +++ b/src/tree_sitter_parser.rs @@ -502,7 +502,7 @@ pub fn from_language(language: guess::Language) -> TreeSitterConfig { TreeSitterConfig { name: "Perl", language, - atom_nodes: vec!["string_single_quoted", "string_double_quoted"] + atom_nodes: vec!["string_single_quoted", "string_double_quoted", "comments"] .into_iter() .collect(), delimiter_tokens: vec![("(", ")"), ("{", "}"), ("[", "]")], @@ -1092,7 +1092,8 @@ fn atom_from_cursor<'a>( content = content.trim(); } - let highlight = if node.is_extra() || node.kind() == "comment" { + // Most languages use "comment", but Perl uses "comments". + let highlight = if node.is_extra() || node.kind() == "comment" || node.kind() == "comments" { AtomKind::Comment } else if highlights.keyword_ids.contains(&node.id()) { AtomKind::Keyword