Skip to content

refactor: share SQL analysis and enforce type safety - #238

Merged
Light2Dark merged 14 commits into
mainfrom
refactor/repo-type-safety
Nov 17, 2026
Merged

Light2Dark merged 14 commits into
mainfrom
refactor/repo-type-safety

Conversation

@Light2Dark

@Light2Dark Light2Dark commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

🤖 gpt-6.1-sol from Codex responding on behalf of Shahmir.

  • SQL features previously parsed independently, reused results after dialect changes, and could mix error offsets across concurrent calls. Share pending parses and analysis scoped to document and parser configuration, keep transformations local to each parse, and discard stale gutter work.
  • Reference operations now refuse shadowed or multiply declared bindings, including aliases on subqueries and table functions. Consolidate SQL scanning and schema resolution so features apply the same rules.
  • Enforce strict types across source, tests, demo, and configuration; prohibit any, casts, non-null assertions, and TypeScript suppressions. Validate external ASTs into stricter internal representations while preserving extensible public parser/result and namespace interfaces.

Existing sanitizer subclass hooks, per-feature parser defaults, and peer dependency requirements remain compatible. A parser configured through linterConfig still applies to syntax linting, semantic linting, and navigation, while hover and gutter retain independent defaults. Sharing a custom parser across all features is opt-in through the new top-level analysis options.

createSqlAnalysis shares dependencies across extension and completion bundles. needsRefresh refreshes linting and gutter state when parser configuration changes without an edit. The unused hover dialect option is deprecated for compatibility.

The demo normalizes all six dialect choices, updates parser state and SQL language together, and re-registers schema-aware completion sources when switching languages.

MySQL CTE column completion after switching the demo dialect

Review follow-up preserves array and subscript statement boundaries, restores column-completion fallback when namespace names collide, and distinguishes CAST types from binding declarations. Gutter selection and focus updates reuse analysis; comment stripping avoids repeatedly processing accumulated output.

The built-in parser now reuses parse, structure, and query-context analysis across cursor-only states with the same document and options. Dialect and parser-option changes still invalidate results. Custom parsers and subclasses remain state-scoped unless they provide getCacheKey(state). Document caches use weak ownership and bound configuration variants. Comment stripping walks quoted/comment spans without constructing the full token list.

The scanner preserves the original first-closing-bracket and non-nested block-comment behavior. Pending gutter markers map through edits until fresh analysis arrives, so asynchronous parsers do not clear the gutter on each keystroke.

User-visible dialect correction: BigQueryDialect now inherits PostgreSQL keyword and type definitions from PostgreSQL.spec, fixing its base dialect configuration.

@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 95.66% 1701 / 1778
🔵 Statements 95.36% 1789 / 1876
🔵 Functions 97.55% 279 / 286
🔵 Branches 89.91% 1399 / 1556
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
src/index.ts 0% 0% 0% 0%
src/vite-env.d.ts 0% 0% 0% 0%
src/dialects/bigquery.ts 100% 100% 100% 100%
src/sql/alias-completion-source.ts 100% 82.6% 100% 100%
src/sql/analysis.ts 100% 82.35% 100% 100%
src/sql/ast.ts 100% 100% 100% 100%
src/sql/column-completion-source.ts 96.36% 83.78% 100% 96.29% 71, 118
src/sql/completion-extension.ts 100% 100% 100% 100%
src/sql/completion-utils.ts 100% 100% 100% 100%
src/sql/cte-completion-source.ts 94.54% 88.23% 100% 94.23% 73, 102, 131
src/sql/diagnostics.ts 100% 100% 100% 100%
src/sql/extension.ts 100% 100% 100% 100%
src/sql/hover.ts 99.57% 97.24% 100% 99.55% 475
src/sql/namespace-utils.ts 96.89% 85.71% 100% 96.85% 107-113, 193
src/sql/parser.ts 97.69% 90% 100% 97.6% 67, 168-169
src/sql/query-context.ts 98.94% 94.59% 100% 98.91% 87, 186
src/sql/references.ts 97.07% 89.77% 100% 98.57% 178, 193, 262, 330, 338, 391, 423
src/sql/scanner.ts 97.4% 97.18% 100% 97.14% 51-52
src/sql/schema-utils.ts 100% 100% 100% 100%
src/sql/semantic-diagnostics.ts 96.83% 92% 100% 97.24% 139, 188, 204, 263, 356, 496, 532
src/sql/state-cache.ts 95.65% 90% 100% 100% 30
src/sql/structure-analyzer.ts 100% 97.5% 100% 100%
src/sql/structure-extension.ts 93.4% 92.75% 100% 97.53% 155, 157, 164, 199-200
src/sql/types.ts 0% 0% 0% 0%
Generated in workflow #1007 for commit ebbd698 by the Vitest Coverage Report Action

@Light2Dark Light2Dark left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

🤖 Automated comment by Shahmir's Code Review agent running gpt-6.1-sol on Codex

✅ Approve — Three independent specialist subagent reviews found five P2 issues, addressed in 80af6a5. A fourth independent review of the fixes found no remaining actionable issues. This is an automated review conclusion, posted as a comment because the PR author cannot approve their own PR.

Additional review evidence
  • Nested arrays and arrays containing ] or semicolons in strings now preserve statement boundaries. Statement splitting retains the original array/subscript interpretation of brackets.
  • Cursor and focus changes reuse pending/completed gutter analysis; document and configuration changes still refresh it. The original review benchmark found 300 extra parses per cursor movement, which the new parse-count checks prevent.
  • Comment stripping on a 960 KB comment-heavy input improved from approximately 1,941 ms to 35 ms locally.
  • Under-qualified completion again finds a nested table when a same-named namespace has no columns, while ambiguous table matches remain unresolved.
  • CAST type names no longer count as binding declarations; nested declaration collisions still cause conservative refusal.

The security review found no additional introduced XSS or tooltip trust-boundary defect. Existing parser limitations for dialect-specific casts remain.

@Light2Dark

Copy link
Copy Markdown
Member Author

🤖 Automated comment by Shahmir's Code Review agent running gpt-6.1-sol on Codex

Performance follow-up is pushed in bd3b0c3 and 2bd8c69. Reference highlighting now reuses pending/completed analysis across cursor-only states, including the full editor path with linting and gutter effects. Built-in parser option changes still invalidate all analysis caches. Custom parsers and subclasses retain exact-state caching unless they explicitly provide a configuration key.

Benchmark and review evidence

Local Node v26.13.0 microbenchmarks: 20 alternating measured runs after five warmups. These measure individual operations rather than end-to-end editor latency.

Operation main Before these fixes Current PR
Reference lookup after a cursor change, 300 statements 0.050 ms 18.794 ms 0.058 ms
New parses per lookup 0 300 0
Strip and consume 960 KB of synthetic comment-heavy input 3.169 ms 30.360 ms 4.292 ms

Comment stripping retains roughly 1.1 ms of overhead versus main on this stress input; it also preserves token separators that the original stripper removed.

An independent cache review found no actionable issues. The scanner review caught an unbounded speculative regex scan in the rewrite; that was fixed by restricting each scan to its own gap. A 128,000-literal case now runs in about 10 ms locally. The reviewer independently matched 335,923 short inputs against the previous scanner, and an additional 20,000 generated inputs matched tokenization in three modes and comment-stripping output.

All 696 tests pass, including 14 Chromium tests. Strict typecheck, lint, package build, and demo build pass. The new browser test verifies that keyboard cursor movement updates reference highlights without reparsing the document.

@Light2Dark Light2Dark left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

🤖 Automated comment by Shahmir's Code Review agent running gpt-6.1-sol on Codex

✅ Approve — All confirmed findings from three independent reviews (two Astra specialists and Claude Fable 5.2) are addressed. Posted as a comment because the PR author cannot approve their own PR.

Findings, resolutions, and verification limits
  • ignoreBrackets skipped placeholders inside arrays/subscripts. Fixed in e9d2cb7, with PostgreSQL, DuckDB, and BigQuery coverage plus original-source error-offset checks.
  • Doubled closing brackets caused masking to swallow later literals/comments, making rename unsafe. Fixed in 76169d7 by preserving the original first-closing-bracket behavior. Tests cover CTE references, fallback table extraction, completion suppression inside literals, and actual Chromium F2 rename/undo that preserves string/comment contents.
  • Nested block-comment handling could swallow all subsequent SQL for inputs accepted by MySQL, BigQuery, and SQLite. Fixed in 76169d7 by preserving the original non-nested scanner semantics, with syntax-error and statement-count coverage for all three dialects.
  • Asynchronous parsing cleared gutter markers after every edit. Fixed in fe63832 by mapping existing statement ranges through edits while analysis is pending; tests cover insertion, deletion, eventual replacement, and stale-result suppression.

Fable also verified that a consumer shaped like marimo's integration typechecks against built declarations. The real downstream marimo application was not built. Browser verification is Chromium only. No review or test run establishes universal regression-freedom.

Custom parsers and NodeSqlParser subclasses remain state-scoped unless they implement getCacheKey(state), so cursor moves can reparse in those integrations. The concise README now points custom-parser users to that opt-in. The previously disclosed small comment-stress overhead remains. Legacy integrations must adopt shared analysis to receive its cross-feature savings.

Latest local verification on the final code: 712 tests pass, including 14 Chromium tests; strict typecheck, non-mutating lint, package build, and demo build pass. CI is rerunning for 98aac68.

@Light2Dark
Light2Dark marked this pull request as ready for review November 17, 2026 01:05
Copilot AI lite review requested due to automatic review settings November 17, 2026 01:05

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@Light2Dark
Light2Dark merged commit ebbd698 into main Nov 17, 2026
6 checks passed
@Light2Dark
Light2Dark deleted the refactor/repo-type-safety branch November 17, 2026 01:05
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