Skip to content

Incomplete highlights for complex queries (tree-sitter match limit not large enough?). #22042

Open
@JaagupAverin

Description

@JaagupAverin

Description

Currently the match limit for Tree-Sitter is assigned at 64 in zed/crates/language/src/syntax_map.rs:1820:

impl QueryCursorHandle {
    pub fn new() -> Self {
        let mut cursor = QUERY_CURSORS.lock().pop().unwrap_or_default();
        cursor.set_match_limit(64);
        QueryCursorHandle(Some(cursor))
    }
}

This limit appears to cause issues quite easily in Python, for example this code:

class Foo:
    def __init__(self) -> None:
        self.a = 1
        """Docstring A"""
        self.b = 2
        """Docstring B"""
        self.c = 3
        """Docstring C"""
        self.d = 4
        """Docstring D"""
        self.e = 5
        """Docstring E"""

is highlighted as follows:
image
(i.e. after a certain token, the highlighting only semi-works - the attributes and strings are captured as expected, but the string.doc capture stops being applied)
By doubling the match limit to 128, the highlighting works better, but ofc I'm only sweeping the problem under the carpet:
image

I don't know if this limit can be increased easily without performance impact (probably would need to increase it to at least 1024 or so to cover even the most complicated situations?), or in fact the issue lies somewhere else entirely, so I won't be attempting a PR myself but I'm happy if this gets a solution soon :)

Environment

Zed Preview 0.166.1 546b49c

If applicable, add screenshots or screencasts of the incorrect state / behavior

No response

If applicable, attach your Zed.log file to this issue.

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    reproducibleVerified steps to reproduce includedtree-sitterSyntax highlighting and tree-sitter

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions