Skip to content

Tree-sitter queries: highlights, locals, tags#52

Merged
djankov merged 1 commit into
mainfrom
issue-21-tree-sitter-queries
Jun 8, 2026
Merged

Tree-sitter queries: highlights, locals, tags#52
djankov merged 1 commit into
mainfrom
issue-21-tree-sitter-queries

Conversation

@djankov

@djankov djankov commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Author the three shared tree-sitter query files in tree-sitter-gmat/queries/, against the frozen grammar node taxonomy (D3):
    • highlights.scm — structural keywords, Create types, command heads (@function), dotted member fields (@property), resource/variable names, numbers/strings/comments, command labels, operators, and punctuation. Patterns are ordered specific-first so a host resolving overlaps by first match gives the specific captures precedence over the catch-all.
    • locals.scm — a single file-global scope (GMAT resources are global and may be forward-referenced); definitions for Create names, GmatFunction names + parameters, and For variables; an (identifier) @local.reference catch-all. Powers go-to-definition / find-references.
    • tags.scm@definition.class for resources, @definition.function for GmatFunction headers, and @reference.call for mission commands and output-binding function calls (bare, dotted, and parenthesised shapes). Powers the document-symbol outline and code navigation.
  • Register locals in tree-sitter.json and package.json alongside the existing highlights (tags is auto-discovered by convention); all three .scm files pack with the npm grammar (verified via npm pack --dry-run).
  • Add tests/test_queries.py validating the definition of done.

Note on tag kinds: resources are tagged @definition.class as the closest standard kind for a named, typed object — a downstream LSP can remap to whatever SymbolKind it prefers.

Test plan

  • All three queries load against the vendored, compiled grammar (parametrized load test).
  • Highlight captures land on the expected nodes for each category.
  • locals.scm resolves a resource's definition to its Create and each use back to it (go-to-definition + find-references on a fixture).
  • tags.scm exposes resource, function, command, and call symbols.
  • ruff check, ruff format --check, and mypy (strict, tests included) clean.
  • Full non-corpus suite green locally (366 passed); npm tarball includes queries/*.scm.

Closes #21

Author the three shared query files against the frozen grammar node set
(D3) and register them with the grammar package:

- highlights.scm: keywords, Create types, command heads, member fields,
  resource/variable names, literals, labels, operators, punctuation.
- locals.scm: a single file scope; Create / function / parameter /
  For-loop definitions and identifier references, for go-to-definition
  and find-references.
- tags.scm: resource and GmatFunction definitions plus command and
  output-binding-call references, for the symbol outline and navigation.
- tree-sitter.json / package.json: list locals alongside highlights
  (tags is auto-discovered); all three pack with the npm grammar.

Add tests/test_queries.py: every query loads against the vendored
compiled grammar, highlight captures land on the expected nodes, resource
definition/reference resolution works on a fixture, and tags expose the
resource and command symbols.
@djankov djankov marked this pull request as ready for review June 8, 2026 20:43
@djankov djankov merged commit 1833ee6 into main Jun 8, 2026
25 checks passed
@djankov djankov deleted the issue-21-tree-sitter-queries branch June 8, 2026 20:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tree-sitter queries: highlights, locals, tags

1 participant