Skip to content

Commit

Permalink
fix(tree-sitter): remove slow html highlight patterns (#4195)
Browse files Browse the repository at this point in the history
* fix(tree-sitter): remove slow html highlight patterns

Fixes #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!

* run tests in ci

* Update changelog

---------

Co-authored-by: Darren Burns <[email protected]>
  • Loading branch information
TomJGooding and darrenburns authored Feb 22, 2024
1 parent de3ac12 commit 65c4cce
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 40 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Fixed `TextArea.code_editor` missing recently added attributes https://github.com/Textualize/textual/pull/4172
- Fixed `Sparkline` not working with data in a `deque` https://github.com/Textualize/textual/issues/3899
- Tooltips are now cleared when the related widget is no longer under them https://github.com/Textualize/textual/issues/3045
- Simplified tree-sitter highlight queries for HTML, which also seems to fix segfault issue https://github.com/Textualize/textual/pull/4195

## [0.52.1] - 2024-02-20

Expand Down
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
2 changes: 1 addition & 1 deletion src/textual/widgets/_text_area.py
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ def _watch_show_line_numbers(self) -> None:
self.scroll_cursor_visible()

def _watch_indent_width(self) -> None:
"""Changing width of tabs will change document display width."""
"""Changing width of tabs will change the document display width."""
self._rewrap_and_refresh_virtual_size()
self.scroll_cursor_visible()

Expand Down

0 comments on commit 65c4cce

Please sign in to comment.