Skip to content

Commit

Permalink
fix(tree-sitter): remove slow html highlight patterns
Browse files Browse the repository at this point in the history
Fixes Textualize#4152 by removing all
`((element (start_tag (tag_name) @_tag)` patterns from the `html.scm`
highlights query file.

These patterns will cause a segfault on relatively large documents
and even just one seems a massively expensive operation from some
quick testing.

All tests pass after removing these and I couldn't see they were
actually used anywhere in syntax highlighting, but please correct me
if I'm wrong!
  • Loading branch information
TomJGooding committed Feb 20, 2024
1 parent 823d32a commit ea5fb2c
Showing 1 changed file with 0 additions and 39 deletions.
39 changes: 0 additions & 39 deletions src/textual/tree-sitter/highlights/html.scm
Original file line number Diff line number Diff line change
Expand Up @@ -6,45 +6,6 @@
(quoted_attribute_value) @string)
(text) @text @spell

((element (start_tag (tag_name) @_tag) (text) @text.title)
(#eq? @_tag "title"))

((element (start_tag (tag_name) @_tag) (text) @text.title.1)
(#eq? @_tag "h1"))

((element (start_tag (tag_name) @_tag) (text) @text.title.2)
(#eq? @_tag "h2"))

((element (start_tag (tag_name) @_tag) (text) @text.title.3)
(#eq? @_tag "h3"))

((element (start_tag (tag_name) @_tag) (text) @text.title.4)
(#eq? @_tag "h4"))

((element (start_tag (tag_name) @_tag) (text) @text.title.5)
(#eq? @_tag "h5"))

((element (start_tag (tag_name) @_tag) (text) @text.title.6)
(#eq? @_tag "h6"))

((element (start_tag (tag_name) @_tag) (text) @text.strong)
(#any-of? @_tag "strong" "b"))

((element (start_tag (tag_name) @_tag) (text) @text.emphasis)
(#any-of? @_tag "em" "i"))

((element (start_tag (tag_name) @_tag) (text) @text.strike)
(#any-of? @_tag "s" "del"))

((element (start_tag (tag_name) @_tag) (text) @text.underline)
(#eq? @_tag "u"))

((element (start_tag (tag_name) @_tag) (text) @text.literal)
(#any-of? @_tag "code" "kbd"))

((element (start_tag (tag_name) @_tag) (text) @text.uri)
(#eq? @_tag "a"))

((attribute
(attribute_name) @_attr
(quoted_attribute_value (attribute_value) @text.uri))
Expand Down

0 comments on commit ea5fb2c

Please sign in to comment.