Skip to content

Fix multi-line TS/JS imports getting dropped from the dep graph - #3

Closed
nsxdavid wants to merge 1 commit into
mainfrom
fix/ts-multiline-import-extraction
Closed

Fix multi-line TS/JS imports getting dropped from the dep graph#3
nsxdavid wants to merge 1 commit into
mainfrom
fix/ts-multiline-import-extraction

Conversation

@nsxdavid

@nsxdavid nsxdavid commented Jun 6, 2026

Copy link
Copy Markdown
Owner

Fixes #1.

parseTsLine only grabbed the import path off lines that contained import . Multi-line imports put the from "..." on the closing } line, so the dependency never made it into the graph. This adds a small continuation branch that pulls the path off } from "..." lines too. It also catches export ... from re-exports, which are real deps that were getting dropped the same way.

The Go parser already handles multi-line import blocks with its own state. TS never got the equivalent. This is the cheap version of that, no cross-line state needed, since the from "..." clause is the only thing carrying the path.

Red to green: the new test asserts a multi-line import lands in outline.imports. It fails before the change (path missing), passes after. The single-line case sits in the same test as a regression guard.

zig build test is green. The only failures are the three test_mcp --help tests that spawn a child binary and hit error.SpawnFailed under WSL/9p, which is environmental and fails on a clean checkout too.

Files: src/explore.zig (parseTsLine), src/test_parser.zig.

One function plus a test. No generated artifacts. Branch is off current main. Read CONTRIBUTING and followed it.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed an issue where multi-line TypeScript and JavaScript import statements were not being recognized in dependency graphs, improving overall dependency analysis accuracy.

@coderabbitai

coderabbitai Bot commented Jun 6, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@nsxdavid, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 51 minutes and 59 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c38ea624-506c-4e40-ad79-1c167707f1f3

📥 Commits

Reviewing files that changed from the base of the PR and between 7eea083 and 6a56e61.

📒 Files selected for processing (2)
  • src/explore.zig
  • src/test_parser.zig
📝 Walkthrough

Walkthrough

The PR fixes a bug where multi-line TypeScript and JavaScript import statements with the from "..." clause on a separate line were not captured in the dependency graph. The parser now detects continuation lines containing from "..." and extracts the dependency path. A regression test verifies the fix works for multi-line imports and re-exports.

Changes

Multi-line TS/JS Import Path Capture

Layer / File(s) Summary
Parser continuation-line detection and regression test
src/explore.zig, src/test_parser.zig
parseTsLine detects lines containing from "..." / from '...' and extracts the quoted string literal as an import path. A regression test indexes a TypeScript file with multi-line imports and export * from re-exports, verifying the dependency graph includes all expected import paths.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A rabbit hops through import lines,

Where from clauses hide on continuation signs,

Now multi-line imports are caught at last,

The dependency graph's losses are past! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Fix multi-line TS/JS imports getting dropped from the dep graph' directly and clearly describes the main change—handling multi-line imports in the TypeScript parser.
Linked Issues check ✅ Passed The pull request fully addresses issue #1 by adding a continuation branch in parseTsLine to extract 'from' clauses on closing brace lines and includes a regression test.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing multi-line import handling: modifications to parseTsLine logic and a test case specifically validating the fix.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7eea083689

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/explore.zig Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/explore.zig`:
- Around line 3613-3623: The continuation-line branch that currently matches any
line with ` from "…"` / ` from '…'` is too permissive and creates false
dependencies; update the conditional so it only runs when the line is actually
part of import/export syntax (e.g., require that the line also contains an
import/export token such as "import " or "export " before extracting the
string). In the block that uses containsAny(line, &.{ " from \"", " from '" }),
augment the check to also assert containsAny(line, &.{ "import ", "export " })
(or an equivalent check that the line belongs to an import/export statement)
before calling extractStringLiteral and appendImportPath so outline.imports and
the dep_graph are only populated for real import/export continuations.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 565311fa-bcb0-4efe-a858-50516250caa9

📥 Commits

Reviewing files that changed from the base of the PR and between e199484 and 7eea083.

📒 Files selected for processing (2)
  • src/explore.zig
  • src/test_parser.zig

Comment thread src/explore.zig Outdated
parseTsLine only extracted an import's `from "..."` specifier when it
appeared on the same line as `import `. Multi-line ES imports place the
`from "..."` clause on a line beginning with `}`, so those dependency
paths were dropped (only single-line imports were captured).

Add a continuation branch that extracts the specifier from `} from "..."`
lines; this also captures `export ... from` re-export dependencies.

Adds a red-to-green parser test.
@nsxdavid
nsxdavid force-pushed the fix/ts-multiline-import-extraction branch from 7eea083 to 6a56e61 Compare June 6, 2026 23:53
@nsxdavid

nsxdavid commented Jun 7, 2026

Copy link
Copy Markdown
Owner Author

Moved upstream: justrach#542

@nsxdavid nsxdavid closed this Jun 7, 2026
nsxdavid pushed a commit that referenced this pull request Jul 12, 2026
#3 #6)

Three behavior-preserving optimizations on the per-query search/rank path,
identified by the perf audit and adversarially verified:

#1 (mcp.zig, appendSearchSymbolNudge): the bare-identifier nudge did a full
   O(U+S) symbol scan (searchSymbols scans the whole symbol_index AND outlines
   every call) just to test existence. Switched to findAllSymbols — the same
   helper codedb_symbol uses: ensureSymbolIndex + O(1) symbol_index.get, with
   the outline scan only when !symbol_index_complete. Output byte-identical
   (the nudge only checks results.len and prints the query string).

#3 (explore.zig, BM25 posting loop): dropped the doc_tf hashmap. doc_best_line
   already accumulates .count identically per posting, so df = doc_best_line.count()
   and tf = entry.value_ptr.count — one map instead of two, and the redundant
   per-doc .get() re-lookup is gone. Values bit-identical.

#6 (explore.zig, tier-1 sort): the comparator hashed 4 strings + touched 2
   atomics per comparison. Precompute (count, len) per candidate once in O(C)
   (mirroring tier0_order), then sort a struct-key array — identical predicate
   (count desc, len asc) and input order, so ranking is unchanged. Also stops
   the comparator corrupting ContentCache hit/miss stats.

zig build test: full suite green (0 failures).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.

Multi-line TS/JS imports get dropped from the dep graph

1 participant