You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I found this while migrating a logistics app from Retool to a custom stack. My repo is Laravel + Vue 3: 165 .php, 91 .vue, 27 .ts/.js. After 0.10.1 added PHP it indexes 228 files, which is much better than 0.9.1 (27, frontend only). But the 91 .vue files are not indexed, and that is where all my UI components are.
I looked at why. tree-sitter-vue is already in your tree-sitter-wasms dependency, but it only parses the SFC shell (template/script/style) and the script body stays opaque text, so just registering the grammar would give almost empty cards.
What I think would work better: handle .vue as a container, cut out the <script> block, pass it to the TypeScript extractor you already have, and shift the line numbers by where the block starts. Getting the offset wrong would be worse than not indexing at all.
Is that the approach you would want? I can try a PR if so.
Thank you — and yes, that's exactly the approach I'd want. A .vue SFC is a container; the value is in the <script>, and graft already has a strong TypeScript extractor. A PR would be very welcome. 🙌
A few pointers so the offset (the part you rightly flagged as the risk) is safe:
Get the offset from the grammar, not a regex.tree-sitter-vue (already in tree-sitter-wasms) parses the SFC and gives you the script_element node with its exact startPosition (row/column) and startIndex (byte). Use that as the offset — it removes the guesswork, and it's robust to <script setup lang="ts">, attributes, leading comments, and CRLF. Slice the script by the element's byte range, don't hand-parse the tags.
Where it hooks. In src/graph/build.ts, the extract loop dispatches depth (extractFile) vs breadth (extractGeneric). Add a .vue container branch before that: locate the <script> block, then call the existing extractFile(rel, scriptSource, \"typescript\") (or \"tsx\" — TS is a superset, so it's the safe grammar for both JS and TS blocks).
The shift.extractFile returns nodes with 1-based spanLx-Ly relative to the script string. Add the script block's start row to both ends: L(x+row)-L(y+row). Keep body_text/body_hash/crux derived from the script string itself (that's the real code) — only the span pointer needs to map back to the .vue file's true lines.
The one test that matters (your instinct is right — a wrong offset is worse than nothing): a fixture .vue with a known symbol on a known line, asserting the node's span maps to the real.vue line, not the script-relative one. Maybe also one with leading template/style above the script (so the offset is non-zero) and one <script setup>.
Two edge cases worth a line each: an SFC with two blocks (<script> + <script setup>) — process each with its own offset; and an empty/absent <script> — skip cleanly (the file still gets a file node, like today).
Separately: the silent-e behaviour you hit while investigating is fixed in #100 (an unsupported -e extension now warns and lists the supported set) — orthogonal to this, but it should stop the next person losing time the way you did.
Happy to review as you go. Obrigado for the sharp diagnosis. 🌱
Shipped: PR #101 (@davidpru) indexes .vue SFCs by routing the <script> block through the TypeScript extractor with span offsets. Merged to main. Thanks for the sharp diagnosis and the clean PR.
Activity
shhdwi commentedon Aug 13, 2026
Thank you — and yes, that's exactly the approach I'd want. A
.vueSFC is a container; the value is in the<script>, and graft already has a strong TypeScript extractor. A PR would be very welcome. 🙌A few pointers so the offset (the part you rightly flagged as the risk) is safe:
Get the offset from the grammar, not a regex.
tree-sitter-vue(already intree-sitter-wasms) parses the SFC and gives you thescript_elementnode with its exactstartPosition(row/column) andstartIndex(byte). Use that as the offset — it removes the guesswork, and it's robust to<script setup lang="ts">, attributes, leading comments, and CRLF. Slice the script by the element's byte range, don't hand-parse the tags.Where it hooks. In
src/graph/build.ts, the extract loop dispatches depth (extractFile) vs breadth (extractGeneric). Add a.vuecontainer branch before that: locate the<script>block, then call the existingextractFile(rel, scriptSource, \"typescript\")(or\"tsx\"— TS is a superset, so it's the safe grammar for both JS and TS blocks).The shift.
extractFilereturns nodes with 1-basedspanLx-Lyrelative to the script string. Add the script block's start row to both ends:L(x+row)-L(y+row). Keepbody_text/body_hash/cruxderived from the script string itself (that's the real code) — only thespanpointer needs to map back to the.vuefile's true lines.The one test that matters (your instinct is right — a wrong offset is worse than nothing): a fixture
.vuewith a known symbol on a known line, asserting the node'sspanmaps to the real.vueline, not the script-relative one. Maybe also one with leading template/style above the script (so the offset is non-zero) and one<script setup>.Two edge cases worth a line each: an SFC with two blocks (
<script>+<script setup>) — process each with its own offset; and an empty/absent<script>— skip cleanly (the file still gets a file node, like today).Separately: the silent
-ebehaviour you hit while investigating is fixed in #100 (an unsupported-eextension now warns and lists the supported set) — orthogonal to this, but it should stop the next person losing time the way you did.Happy to review as you go. Obrigado for the sharp diagnosis. 🌱
fix(cli): warn when -e names an extension no parser claims (trailhq#98)
feat(container): index .vue SFCs via their <script> block (#97)
feat: add Clojure support, on a broader WASM grammar bundle
shhdwi commentedon Aug 16, 2026
Shipped: PR #101 (@davidpru) indexes .vue SFCs by routing the <script> block through the TypeScript extractor with span offsets. Merged to main. Thanks for the sharp diagnosis and the clean PR.
fix(cli): warn when -e names an extension no parser claims (trailhq#98)
feat(container): index .vue SFCs via their <script> block (trailhq#97)
feat: add Clojure support, on a broader WASM grammar bundle