Skip to content

Load each language's tree-sitter query from a .scm file#65

Open
janrito wants to merge 1 commit into
languages-skillfrom
feat/query-scm-offload
Open

Load each language's tree-sitter query from a .scm file#65
janrito wants to merge 1 commit into
languages-skillfrom
feat/query-scm-offload

Conversation

@janrito

@janrito janrito commented Jul 8, 2026

Copy link
Copy Markdown
Owner

Every language plugin carried its tree-sitter query as a triple-quoted Python
string; this moves each query into a standalone .scm file loaded at runtime.

The house rule is to never embed another language as a string literal, and
queries were the last violation of it — a _QUERY = """…""" per plugin, the
SQL and HTML ones generated from a Python verb table and an f-string.
An inline query is invisible to tree-sitter tooling and can't itself be
indexed.

A load_query(__package__, name) helper reads each query from a .scm beside
its plugin. Assembly stays in Python where a query is built from parts, since
the query language has no #include: js/ts concatenate shared fragments with
+, and SQL's DDL verbs collapse into [...] alternations in one static
sql.scm, retiring the generated table. (Templating was rejected — it would
leave the .scm files non-static and unparseable.) uv ships them as package
data with no config change.

Each plugin's module and its .scm now sit together in a languages/<lang>/
directory — co-location, not the separate in-progress split into installable
rbtr-lang-* packages.

No behaviour change: each .scm holds the same query text as the inline
string it replaces, and SQL's rewrite into alternations matches the same
statements.

Each plugin now lives in languages/<lang>/ (plugin.py plus its .scm
file(s)), loaded at import via a small load_query helper instead of
inline Python string literals. SQL's DDL becomes a static sql.scm,
js/ts compose shared .scm fragments, and html's semantic-tag query
resolves to a static file. Extraction output is unchanged: no snapshot
diff, no language_plugin_version bumps. Docs (rbtr-languages skill,
README, ARCHITECTURE) gain a "Where queries live" note.
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.

1 participant