diff options
author | Wilfred Hughes <me@wilfred.me.uk> | 2024-11-14 14:29:39 -0500 |
---|---|---|
committer | Wilfred Hughes <me@wilfred.me.uk> | 2024-11-15 00:03:30 -0500 |
commit | 4df51dc57c1e5ea68464d1ff68ce52b8be4e621e (patch) | |
tree | 50ba86fb45655c7fd555e1a638a4ba4230374ee4 | |
parent | 819a672df87b982593bc3d47246ef1e9da35f886 (diff) |
Improve syntax highlighting on tree-sitter lists that are just keywords
Closes #777
-rw-r--r-- | CHANGELOG.md | 4 | ||||
-rw-r--r-- | sample_files/compare.expected | 18 | ||||
-rw-r--r-- | sample_files/swift_1.swift | 4 | ||||
-rw-r--r-- | sample_files/swift_2.swift | 4 | ||||
-rw-r--r-- | src/parse/tree_sitter_parser.rs | 5 |
5 files changed, 26 insertions, 9 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 73542e4060..f7a118d0d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ Improved handling of multiline strings, which could cause a crash if they occurred at the end of the file. This was particularly noticeable with YAML. +### Syntax Highlighting + +Improved syntax highlighting, particularly for keywords. + ## 0.61 (released 24th October 2024) **Recommended git configuration has changed! Please update your diff --git a/sample_files/compare.expected b/sample_files/compare.expected index b13c8b393d..f0477f768e 100644 --- a/sample_files/compare.expected +++ b/sample_files/compare.expected @@ -1,5 +1,5 @@ sample_files/Session_1.kt sample_files/Session_2.kt -7f12794f0cd13609984eca50002cc38c - +a5899a29b0ebb0800923ac368b95fa1e - sample_files/ada_1.adb sample_files/ada_2.adb eb3b0e12e239ae33789136380e81406b - @@ -41,7 +41,7 @@ sample_files/comma_and_comment_1.js sample_files/comma_and_comment_2.js 0a5ccbcd368607e62eaff0c4ae25049f - sample_files/comments_1.rs sample_files/comments_2.rs -4e1515be02b2e14bcd7bcaca3520a542 - +a75827163654d6aed8f837bb586e733c - sample_files/context_1.rs sample_files/context_2.rs e59180fa7029db7939222cb61c95c97c - @@ -65,7 +65,7 @@ sample_files/elisp_contiguous_1.el sample_files/elisp_contiguous_2.el 4a5a33873a4f84ee055d95e1448fba35 - sample_files/elm_1.elm sample_files/elm_2.elm -f16895057138c5e720e656e9c3d9c52b - +ccc1f4bb568cd72781dbcd623b612c43 - sample_files/elvish_1.elv sample_files/elvish_2.elv b1ad27b8907793632e235878f154b1af - @@ -74,7 +74,7 @@ sample_files/erlang_1.erl sample_files/erlang_2.erl dccdb8f65d2f099ab1a8cb66011376a2 - sample_files/f_sharp_1.fs sample_files/f_sharp_2.fs -ff1cccc272e2b4eb160fae1f809cbc0d - +a9251656c7808ec0e3411fbbd189f5aa - sample_files/hack_1.php sample_files/hack_2.php c2bb0aa7d7b07d6ced79f6a5363e878b - @@ -89,7 +89,7 @@ sample_files/hcl_1.hcl sample_files/hcl_2.hcl f3961a9d1e6eb972ca2b8ed3683b4685 - sample_files/hello_world_1.smali sample_files/hello_world_2.smali -296286b067e86cccfad1fa9a0440993b - +fb8be66657ea8773c9eeec231ba5340b - sample_files/helpful_1.el sample_files/helpful_2.el 056471124ae2e582942e214ce9222477 - @@ -170,7 +170,7 @@ sample_files/nested_slider_1.el sample_files/nested_slider_2.el f68f8b8c09afb86965d5e54519f2d881 - sample_files/nested_slider_1.rs sample_files/nested_slider_2.rs -e9045007a25352eb81655458aebb452c - +342df46db959e8c90925ff4400c0fa63 - sample_files/nesting_1.el sample_files/nesting_2.el cf32f6b798a080a2bf14a430337ac4a6 - @@ -245,7 +245,7 @@ sample_files/slider_at_end_1.json sample_files/slider_at_end_2.json cb370f1c0ccc5e155743330629f899f0 - sample_files/slow_1.rs sample_files/slow_2.rs -2e76c128e008d5d255fdd29562208abc - +7a74881e854d68763769991c6445698a - sample_files/small_1.js sample_files/small_2.js 42506285003bb4eacdb2f8d3bd1b07bb - @@ -257,7 +257,7 @@ sample_files/strings_1.el sample_files/strings_2.el 7e136d188ce03cc8fba2b1530a502ffc - sample_files/swift_1.swift sample_files/swift_2.swift -d31e3d17538b5508d10bd9aa8f7f4159 - +73830b14bd8aacac8d4590a3bed61c40 - sample_files/syntax_error_1.js sample_files/syntax_error_2.js 5bbd81f688bdcfbdbdf69d870f0c1357 - @@ -287,7 +287,7 @@ sample_files/typescript_1.ts sample_files/typescript_2.ts fee7ee33d2037ad1941ba6bb5532a1db - sample_files/typing_1.ml sample_files/typing_2.ml -36161bd77a8c86643bc90656ec41c92c - +28bf693af81e1c45ff9ee47ac29895ef - sample_files/utf16_1.py sample_files/utf16_2.py 3bcee785d4cebc38a42eafe49a198b52 - diff --git a/sample_files/swift_1.swift b/sample_files/swift_1.swift index ded0544614..0654ec93b8 100644 --- a/sample_files/swift_1.swift +++ b/sample_files/swift_1.swift @@ -1,3 +1,7 @@ func f(_ x: Int) -> Int { x * 2 } + +public class Foo: Bar { + public func stuff() {} +} diff --git a/sample_files/swift_2.swift b/sample_files/swift_2.swift index 4926ef2d19..f538cf911a 100644 --- a/sample_files/swift_2.swift +++ b/sample_files/swift_2.swift @@ -1,3 +1,7 @@ func f(_ x: Int) -> Int { x * 3 } + +public class Foo: Bar { + private func stuff() {} +} diff --git a/src/parse/tree_sitter_parser.rs b/src/parse/tree_sitter_parser.rs index 4dd9c09082..fa88c30339 100644 --- a/src/parse/tree_sitter_parser.rs +++ b/src/parse/tree_sitter_parser.rs @@ -1651,6 +1651,11 @@ fn syntax_from_cursor<'a>( // Also, if this node is highlighted as a comment, treat it as // an atom unconditionally. atom_from_cursor(arena, src, nl_pos, cursor, highlights, ignore_comments) + } else if highlights.keyword_ids.contains(&node.id()) && node.child_count() == 1 { + // If this list has a single child, and the list itself (not + // the child) is marked as a keyword, treat it as an atom with + // keyword highlighting. + atom_from_cursor(arena, src, nl_pos, cursor, highlights, ignore_comments) } else if node.child_count() > 0 { Some(list_from_cursor( arena, |