feat: unqualified column completion inferred from the FROM clause#165
Merged
Conversation
Typing a bare prefix (SELECT e -> email, ORDER BY cre -> created_at) now completes columns of the tables referenced in the current statement's FROM/JOIN clauses, even when the schema defines many tables. Previously this was delegated to @codemirror/lang-sql, which only offers top-level columns with a single defaultTable configured. - Add unqualifiedColumnCompletionSource with dot/table-position guards, per-statement scoping, join unions, CTE columns, and ambiguity safety - Extract shared schema-resolution helpers into completion-utils.ts - Wire into demo (sharing one QueryContextAnalyzer) and document in README
Coverage Report
File Coverage
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
All reported issues were addressed across 8 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
- Skip completion in comma-continued FROM table lists (FROM a, b, <cursor>) while still completing after commas in SELECT/GROUP BY lists - Skip completion inside string literals and comments by reusing maskLiteralsAndComments from query-context - Pass table path segments to findTableColumns/traverseNamespacePath so quoted identifiers containing dots (e.g. "my.table") resolve correctly
…-from-clause # Conflicts: # README.md # src/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Typing a bare identifier prefix now completes columns of the tables referenced in the current statement's
FROM/JOINclauses — even when the schema defines many tables:SELECT e→email,ORDER BY cre→created_at, becauseFROM usersis in the statement.Previously unqualified column completion was delegated entirely to
@codemirror/lang-sql'sschemaCompletionSource, which only offers top-level columns when a singledefaultTableis configured — impossible with 2+ tables/schemas.Changes
unqualifiedColumnCompletionSource({ schema?, parser?, contextAnalyzer? })(src/sql/column-completion-source.ts):FROM/JOIN/INTO/UPDATE/TABLE)QueryContextAnalyzer(AST walk + regex fallback, so it works mid-edit on unparsable SQL)detail: "column of <table>"; duplicate names across joins appear oncesrc/sql/completion-utils.ts:resolveSchema/findTableColumns/toCompletionlifted unchanged from the alias source and shared by both (no behavior change toaliasColumnCompletionSource)src/index.ts, registered in the demo (sharing oneQueryContextAnalyzeracross completion sources), documented in READMETest plan
src/sql/__tests__/column-completion-source.test.ts: the motivating multi-table scenario, ORDER BY, joins + per-table details, dedup, dot/table-position guards, empty prefix, mid-edit SQL, multi-statement scoping, aliased/quoted/nested tables, ambiguity, CTEs, facet fallback, boostspnpm test(412 passed),pnpm run typecheck,pnpm exec oxlint,pnpm run demoall cleanSummary by cubic
Adds FROM-aware autocomplete for bare column prefixes. Typing unqualified text like SELECT e now suggests columns from tables in the current statement, including joins and CTEs, with better multi‑schema support than
@codemirror/lang-sql.New Features
unqualifiedColumnCompletionSource({ schema?, parser?, contextAnalyzer? }).sqlSchemaFacet; preserves schema-provided boosts.Bug Fixes
Written for commit 6510749. Summary will update on new commits.