Skip to content

.vue files are not indexed #97

Closed
Closed

Description

@davidpru

graft 0.10.1

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.

Good Work !!! Fantástico ;-)

Activity

  1. shhdwi commented on Aug 13, 2026

    @shhdwi
    Collaborator

    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 span Lx-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. 🌱

  2. shhdwi commented on Aug 16, 2026

    @shhdwi
    Collaborator

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions