Skip to content

Conversation

@Artmann
Copy link

@Artmann Artmann commented Nov 28, 2025

Summary by CodeRabbit

  • Bug Fixes

    • Autocomplete now prioritizes table-name suggestions (and suppresses column suggestions) when typing a table name after FROM or JOIN, reducing irrelevant column results.
  • Tests

    • Added coverage verifying partial input after FROM returns table-name suggestions and excludes column-name suggestions.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Nov 28, 2025

📝 Walkthrough

Walkthrough

The PR changes SELECT query completion so that when the cursor is typing a table name in a FROM/JOIN context, scoped and unscoped column candidates are not generated; aliases remain suggested. Detection of "after FROM" was broadened to recognize JOIN patterns (INNER/LEFT/RIGHT/FULL, etc.). Control flow reordered: aliases are added first, then column candidates only when not typing a table name. A test verifies that a partial table name after FROM yields table-name suggestions and excludes column-name suggestions.

Sequence Diagram(s)

sequenceDiagram
    actor Editor
    participant CompletionEngine
    participant SchemaStore

    Editor->>CompletionEngine: request completions (query, cursorPos)
    CompletionEngine->>CompletionEngine: analyze token/context (isTypingTableName?)
    alt isTypingTableName == true
        CompletionEngine->>SchemaStore: fetch matching table names
        SchemaStore-->>CompletionEngine: table candidates
        CompletionEngine-->>Editor: return table candidates (+ aliases if applicable)
    else isTypingTableName == false
        CompletionEngine->>SchemaStore: fetch columns (scoped & unscoped) and aliases
        SchemaStore-->>CompletionEngine: column candidates
        CompletionEngine-->>Editor: return aliases + column candidates
    end
Loading

Pre-merge checks

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly describes the main change: preventing column suggestions in FROM clause completions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

@Artmann Artmann force-pushed the chris/dont-include-column-names-in-from-completion branch from 009c14b to ca698f1 Compare November 28, 2025 10:48
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/server/src/complete/complete.ts (1)

258-291: Excellent. I have completed the verification. The review comment is accurate and the issue is confirmed. Let me now output the final rewritten review:


Current JOIN regex misses LEFT OUTER JOIN and RIGHT OUTER JOIN patterns

The isTypingTableName gating correctly prevents column candidates from showing up when the cursor is in the FROM/JOIN area while still surfacing aliases and table names.

However, the JOIN regex on line 269 has a real gap:

/^(INNER |LEFT |RIGHT |FULL |FULL OUTER |CROSS |NATURAL |OUTER )?JOIN( |$)/

This pattern does not match LEFT OUTER JOIN or RIGHT OUTER JOIN. The regex requires the space to be part of the alternative (e.g., LEFT expects JOIN immediately after), but with LEFT OUTER, the next token is OUTER, not JOIN. Only FULL OUTER JOIN is covered because it's explicitly listed as a single alternative.

When users type after LEFT OUTER JOIN or RIGHT OUTER JOIN, isCursorAfterFromKeyword remains false, so column suggestions will still appear instead of table names—defeating the purpose of this change.

A more robust pattern:

-      /^(INNER |LEFT |RIGHT |FULL |FULL OUTER |CROSS |NATURAL |OUTER )?JOIN( |$)/.test(
-        afterFromClause
-      )
+      /^(?:(?:INNER|LEFT|RIGHT|FULL|CROSS|NATURAL|OUTER)(?:\s+OUTER)?\s+)?JOIN(?:\s|$)/.test(
+        afterFromClause
+      )

This covers JOIN, INNER JOIN, LEFT JOIN, LEFT OUTER JOIN, RIGHT OUTER JOIN, FULL OUTER JOIN, etc., after the .trim().toUpperCase() already applied.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 3111377 and ca698f1.

📒 Files selected for processing (2)
  • packages/server/src/complete/complete.ts (2 hunks)
  • packages/server/test/complete/complete_table.test.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
packages/server/test/complete/complete_table.test.ts (1)
packages/server/src/complete/complete.ts (2)
  • complete (79-134)
  • complete (461-474)
packages/server/src/complete/complete.ts (1)
packages/server/src/complete/AstUtils.ts (1)
  • isPosInLocation (35-42)

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between ca698f1 and 452b519.

📒 Files selected for processing (1)
  • packages/server/test/complete/complete_table.test.ts (1 hunks)

@Artmann Artmann merged commit cfe7f22 into release Nov 28, 2025
2 checks passed
@Artmann Artmann deleted the chris/dont-include-column-names-in-from-completion branch November 28, 2025 11:13
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