Skip to content

'Parser fails at 0:0 for TypeScript files with adjacent value + type imports from same module path #1

Description

@srbsa

CodeGraph version: 0.14.0
VS Code version: 1.117.0
OS: macOS (Apple Silicon)

Description

12 TypeScript files in my monorepo fail to parse with Syntax error at 0:0 during indexing. No BOM is present (confirmed via hexdump). The files parse and compile correctly with tsc.

Log output

text

ERROR codegraph_server::backend: Parse failed for "...graph-quality.ts":
  Syntax error in ...graph-quality.ts:0:0: Syntax error in source code

[Error - 18:45:39] Parse error in file:///...graph-quality.ts:
  Syntax error in .../graph-quality.ts:0:0: Syntax error in source code
Minimal reproduction — first 3 lines of a failing file

ts

import { queueInterrupt } from '@platform/db'
import type { DbClient, NodeRow } from '@platform/db'

Pattern across all 12 failing files
All failures share the same structure: a regular value import immediately followed by import type { ... } importing from the same module path (workspace package alias like @platform/db).

Files affected (representative sample)

  • packages/agents/src/shared/graph-quality.ts
  • packages/agents/src/query/loop.ts
  • packages/db/src/queries/nodes/get-by-name.ts
  • packages/db/src/queries/chunks/search-by-embedding.ts
  • packages/worker/src/tasks/process-resolution.ts
  • (8 others with the same import pattern)

Hypothesis

The bundled tree-sitter-typescript grammar version may not handle adjacent import + import type declarations from the same specifier path. The error at 0:0 suggests the parser is rejecting the file before any content is processed, which is unusual for a mid-file syntax issue.

Workaround

None currently — excluding the files is the only option. Splitting import type into a separate file or merging into import { value, type Type } syntax works around it but is not acceptable at scale.

Expected behavior

Files that compile cleanly with tsc should parse without errors

Activity

  1. anvanster commented on May 22, 2026

    @anvanster
    Member

    Thanks for the report and the precise reproducer. Two findings from investigating:

    1. The minimal pattern alone doesn't reproduce on 0.16.x.

    I built a fixture matching your minimal example:

    import { queueInterrupt } from '@platform/db'
    import type { DbClient, NodeRow } from '@platform/db'
    
    export function poll(c: DbClient): NodeRow | undefined { ... }

    Parsed against tree-sitter-typescript 0.23.2 (currently bundled in 0.16.x) and got root.has_error() == false — a clean parse tree, both imports correctly recognized. The grammar handles adjacent value + type imports from the same module path on the current version.

    You were on 0.14.0. Between 0.14.0 and 0.16.x we upgraded tree-sitter from 0.22 → 0.25 and tree-sitter-typescript along with it. It's plausible your specific pattern was a grammar bug fixed upstream. Could you try 0.16.2 (publishing today) and report whether the 12 files still fail?

    2. Separately, found a real bug in how we handle parse errors.

    When investigating I noticed extractor.rs rejected the entire file with a hardcoded (0, 0) position whenever root.has_error() was true. tree-sitter is error-tolerant by design — ERROR/MISSING nodes are inserted at points of confusion but the rest of the parse tree stays intact, so we were throwing away ~99% of the symbols in every file that had even one unknown construct (newer syntax like using, satisfies, complex generics, etc.).

    Fix in https://github.com/codegraph-ai/CodeGraph/commit/<pending — will land in 0.16.3>:

    • Don't reject on has_error(); let the visitor walk what tree-sitter recovered
    • Log a warning to stderr with the actual error row/column + a 40-char snippet of the source near the error
    • The visitor's catch-all branch already skips ERROR subtrees safely

    After this fix, even if your specific files DO still trigger an error node on 0.16.x, you'd get the symbols from the rest of the file instead of zero. The warning message tells you exactly where the parser tripped, which lets us file the upstream grammar issue with the exact construct.

    Will ship 0.16.3 once we cross-compile and re-package the binary across all 4 platforms. In the meantime, please try 0.16.2 with your real files and:

    1. If they parse cleanly — your original issue was a 0.14.0 grammar bug already fixed upstream.
    2. If they still fail with "Syntax error at 0:0" — the new warning in 0.16.3 will show us the actual position. Share the stderr line and we can chase the upstream tree-sitter-typescript grammar bug or apply a vendored workaround.
  2. anvanster commented on May 22, 2026

    @anvanster
    Member

    0.16.3 is live on the VS Code Marketplace and npm.

    Two layers of fix in this release:

    1. tree-sitter-typescript 0.23.2 (already in 0.16.x) handles the value + type imports pattern you reported correctly on the minimal repro. If the 12 failing files were a 0.14.0-era grammar bug, they should now parse cleanly.

    2. Extractor error tolerance (commit e2f2329) — even if your real files contain some other construct that DOES trigger a tree-sitter error node, the parser no longer rejects the whole file. Instead it:

      • Walks the rest of the tree and extracts whatever parsed cleanly
      • Logs a WARN to stderr with the actual error row/column + a 40-char source snippet near the failure point

    So if anything still fails on your repo after upgrading to 0.16.3, the "CodeGraph" output channel will show a precise warning instead of the old hardcoded Syntax error at 0:0. That makes the next bug report (if needed) actionable — please share the warning line and we can chase the upstream grammar issue or apply a workaround.

    Closing as fixed. Reopen if 0.16.3 still drops symbols from your TypeScript files.

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