Skip to content

feat: suggest columns in SELECT before FROM clause is written#841

Merged
datlechin merged 5 commits intomainfrom
feat/autocomplete-columns-without-from
Apr 23, 2026
Merged

feat: suggest columns in SELECT before FROM clause is written#841
datlechin merged 5 commits intomainfrom
feat/autocomplete-columns-without-from

Conversation

@datlechin
Copy link
Copy Markdown
Collaborator

Summary

  • Column autocomplete now works before a FROM clause is written, suggesting columns from all cached schema tables as fallback (matching DataGrip/SSMS behavior)
  • Eager column cache warming via driver.fetchAllColumns() runs in background after schema loads, so columns are instantly available
  • Schema-qualified table names (e.g. public.users) now correctly resolve in autocomplete regex

Changes

SQLSchemaProvider.swift

  • Eager column loading: after loadSchema() fetches tables, a background Task pre-fetches all columns via fetchAllColumns() and populates the LRU cache (capped at maxCachedTables)
  • New allColumnsFromCachedTables(): zero-network fallback that reads only from cache, deduplicates column names (unique → plain name, ambiguous → table.column), and returns items with sortPriority = 150

SQLCompletionProvider.swift

  • New columnItems(for:) helper: single decision point that dispatches to allColumnsInScope (when table references exist) or allColumnsFromCachedTables (fallback). Replaces 13 call sites.

SQLContextAnalyzer.swift

  • tableRefRegexes updated from [\\w]+ to [\\w.]+ to handle schema-qualified names like public.users
  • New stripSchemaPrefix() strips schema prefix using NSString O(1) operations
  • sqlKeywords promoted to static let tableRefKeywords (avoids per-call allocation)

SQLCompletionAdapter.swift

  • .select added to browseable context list with comma guard — auto-shows completions after SELECT but not after each comma in the column list

Test plan

  • 559 autocomplete tests passing, zero regressions
  • Connect to a database, type SELECT — verify column suggestions appear
  • Type SELECT na — verify columns matching "na" from all tables appear
  • Type SELECT * FROM users WHERE — verify columns from users appear (existing behavior preserved)
  • Type SELECT col1, — verify popup does NOT auto-trigger after comma
  • Type SELECT col1, n — verify columns appear when typing after comma
  • Test with schema-qualified table: SELECT * FROM public.users — verify columns resolve correctly
  • Test with large schema (50+ tables) — verify no performance issues

Closes #840

@datlechin datlechin merged commit 8a5bb85 into main Apr 23, 2026
2 checks passed
@datlechin datlechin deleted the feat/autocomplete-columns-without-from branch April 23, 2026 06:29
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.

No column name suggestions in SELECT before specifying table in FROM

1 participant