Ensure Perl comments are treated as atoms with an atom kind of comment

pull/281/head
Wilfred Hughes 2022-04-29 18:23:31 +07:00
parent 75a3624f7c
commit 3bb5933163
5 changed files with 8 additions and 5 deletions

@ -5,6 +5,8 @@
Improved detection of binary files that have a large number of null Improved detection of binary files that have a large number of null
bytes. bytes.
Improved handling of comments in Perl.
## 0.28 (released 29th April 2022) ## 0.28 (released 29th April 2022)
### Parsing ### Parsing

@ -110,7 +110,7 @@ sample_files/outer_delimiter_before.el sample_files/outer_delimiter_after.el
73130b8572a4f17fa6cf828f74e226ce - 73130b8572a4f17fa6cf828f74e226ce -
sample_files/perl_before.pl sample_files/perl_after.pl sample_files/perl_before.pl sample_files/perl_after.pl
0067b33629bd714177294d913f59f1b4 - 08d7cad58a79d423c0584387d4bb4dd1 -
sample_files/preprocesor_before.h sample_files/preprocesor_after.h sample_files/preprocesor_before.h sample_files/preprocesor_after.h
3e4331cb935cbe735a79ebc43786cd3a - 3e4331cb935cbe735a79ebc43786cd3a -

@ -9,7 +9,7 @@ use constant DEBUG , 0; # comma (,) is also used instead of '=>'
print "Pi equals ", PI, "...\n"; print "Pi equals ", PI, "...\n";
use constant { use constant {
SEC => 0, SEC => 0, # foo
MIN => 1, MIN => 1,
HOUR => 2, HOUR => 2,
MDAY => 3, MDAY => 3,

@ -9,7 +9,7 @@ use constant DEBUG , 0; # comma (,) is also used instead of '=>'
print "Pi equals ", PI, "...\n"; print "Pi equals ", PI, "...\n";
use constant { use constant {
SEC => 0, SEC => 0, # foo bar
MIN => 1, MIN => 1,
HOUR => 2, HOUR => 2,
MDAY => 3, MDAY => 3,

@ -502,7 +502,7 @@ pub fn from_language(language: guess::Language) -> TreeSitterConfig {
TreeSitterConfig { TreeSitterConfig {
name: "Perl", name: "Perl",
language, language,
atom_nodes: vec!["string_single_quoted", "string_double_quoted"] atom_nodes: vec!["string_single_quoted", "string_double_quoted", "comments"]
.into_iter() .into_iter()
.collect(), .collect(),
delimiter_tokens: vec![("(", ")"), ("{", "}"), ("[", "]")], delimiter_tokens: vec![("(", ")"), ("{", "}"), ("[", "]")],
@ -1092,7 +1092,8 @@ fn atom_from_cursor<'a>(
content = content.trim(); 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 AtomKind::Comment
} else if highlights.keyword_ids.contains(&node.id()) { } else if highlights.keyword_ids.contains(&node.id()) {
AtomKind::Keyword AtomKind::Keyword