Skip to content

feat(container): index .vue SFCs via their <script> block - #101

Merged
shhdwi merged 1 commit into
trailhq:mainfrom
davidpru:feat/vue-sfc-container
Aug 16, 2026
Merged

shhdwi merged 1 commit into
trailhq:mainfrom
davidpru:feat/vue-sfc-container

Conversation

@davidpru

Copy link
Copy Markdown
Contributor

A .vue file is not a language, it is a wrapper around one, and everything worth indexing lives inside its <script>. Registering tree-sitter-vue as a breadth-tier language would not help: that grammar parses the shell (template/script/style) and hands back the script body as one opaque raw_text node, so the cards would come out empty.

So the container grammar is used only to answer "where does the embedded language start and end", and the block itself goes to the DEPTH-tier extractor. A .vue file gets the same quality of extraction as a .ts file — bindings, imports, resolved calls — rather than the signature-only output the breadth tier gives. On the repo that prompted this, edges went from 863 to 2465, because calls from components into .ts modules now resolve.

The span shift was the part flagged as risky, and it is subtler than it looks: raw_text starts immediately after the > of the opening tag, so its row IS the tag's row and the slice begins with that line's newline. Script line N therefore lands on .vue line row + N, which is exactly "add the start row to a 1-based span". Taking the row from the script_element instead looks equivalent and is right only when the tag carries no attributes — that is, never in practice.

Verified beyond the fixtures: across the 91 .vue files of a real Laravel + Vue app, every one of the 270 extracted symbols has its name on the line its span points to, and the 60 files that yield nothing yield nothing as .ts either.

Also updates the #98 tests, which used .vue as their unsupported-extension example — that example had to move to .svelte now that .vue has a parser, and supportedExtensions() had to learn about the container tier so the new -e warning does not contradict the new feature.

Two small exports from generic.ts (loadWasmLanguage, parseWasm) let the container share the wasm plumbing instead of initialising web-tree-sitter a second time.

Svelte and Astro are the same shape and would be a registry row each, but they are left out until someone has a repo to verify them against: a wrong body node type would produce silently misplaced spans, which is worse than no support.

A .vue file is not a language, it is a wrapper around one, and everything worth
indexing lives inside its <script>. Registering tree-sitter-vue as a breadth-tier
language would not help: that grammar parses the shell (template/script/style)
and hands back the script body as one opaque raw_text node, so the cards would
come out empty.

So the container grammar is used only to answer "where does the embedded language
start and end", and the block itself goes to the DEPTH-tier extractor. A .vue
file gets the same quality of extraction as a .ts file — bindings, imports,
resolved calls — rather than the signature-only output the breadth tier gives.
On the repo that prompted this, edges went from 863 to 2465, because calls from
components into .ts modules now resolve.

The span shift was the part flagged as risky, and it is subtler than it looks:
raw_text starts immediately after the `>` of the opening tag, so its row IS the
tag's row and the slice begins with that line's newline. Script line N therefore
lands on .vue line row + N, which is exactly "add the start row to a 1-based
span". Taking the row from the script_element instead looks equivalent and is
right only when the tag carries no attributes — that is, never in practice.

Verified beyond the fixtures: across the 91 .vue files of a real Laravel + Vue
app, every one of the 270 extracted symbols has its name on the line its span
points to, and the 60 files that yield nothing yield nothing as .ts either.

Also updates the trailhq#98 tests, which used .vue as their unsupported-extension
example — that example had to move to .svelte now that .vue has a parser, and
supportedExtensions() had to learn about the container tier so the new -e warning
does not contradict the new feature.

Two small exports from generic.ts (loadWasmLanguage, parseWasm) let the container
share the wasm plumbing instead of initialising web-tree-sitter a second time.

Svelte and Astro are the same shape and would be a registry row each, but they
are left out until someone has a repo to verify them against: a wrong `body` node
type would produce silently misplaced spans, which is worse than no support.
@shhdwi
shhdwi merged commit b4f2249 into trailhq:main Aug 16, 2026
@shhdwi shhdwi mentioned this pull request Aug 16, 2026
FrancescoMerenda pushed a commit to FrancescoMerenda/Graft that referenced this pull request Sep 7, 2026
feat(container): index .vue SFCs via their <script> block
davidpru added a commit to davidpru/Graft that referenced this pull request Sep 22, 2026
Follow-up to trailhq#101, which left Svelte and Astro out of the container tier
"until someone has a repo to verify them against". Both grammars ship in the
tree-sitter-wasm bundle graft already depends on, so this is two registry
rows plus one generalisation, now verified against four real repos.

Svelte is Vue-shaped (script_element > raw_text) with one wrinkle: raw_text
starts at the first non-blank character of the line after the tag, not right
after its `>`. The span shift reads the offset off the body node's own row,
so the formula holds unchanged; a fixture pins it because taking the row from
the tag would misplace every span silently.

Astro keeps its code in two kinds of node, the `---` frontmatter and
<script>, so ContainerLang.block/body became blocks: EmbeddedBlock[]. Astro
also hoists a <script> from anywhere in the markup, and in its own repo a
quarter of the import-bearing ones sit inside a <Layout>, so the Astro row
sets deep: true and the scan descends. Vue and Svelte stay top-level only,
which is what their compilers do.

Verified beyond the fixtures on sveltejs/kit, huntabyte/shadcn-svelte,
withastro/astro and withastro/docs: every one of the 399 Svelte and 324
Astro symbols extracted has its name on the line its span points to, and
no <script> block is lost to the errors tree-sitter-svelte raises on
Svelte 5 markup.
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.

2 participants