@@ -255,20 +255,13 @@ class Completer {
255255 this . addCandidatesForExpectedLiterals ( expectedLiteralNodes )
256256 this . addCandidatesForFunctions ( )
257257
258- const { addedSome : addedSomeScopedColumnCandidates } =
259- this . addCandidatesForScopedColumns ( fromNodes , schemaAndSubqueries )
260- if ( ! addedSomeScopedColumnCandidates ) {
261- this . addCandidatesForUnscopedColumns ( fromNodes , schemaAndSubqueries )
262- }
263-
264- this . addCandidatesForAliases ( fromNodes )
265-
258+ // Detect FROM clause context BEFORE adding column suggestions
266259 const fromNodesContainingCursor = fromNodes . filter ( ( tableNode ) =>
267260 isPosInLocation ( tableNode . location , this . pos )
268261 )
269262 const isCursorInsideFromClause = fromNodesContainingCursor . length > 0
270263
271- // Check if cursor is right after FROM keyword (no table typed yet)
264+ // Check if cursor is right after FROM keyword or typing a table name
272265 const afterFromClause = parsedFromClause . after ?. trim ( ) . toUpperCase ( ) || ''
273266 const isCursorAfterFromKeyword =
274267 afterFromClause === 'FROM' ||
@@ -277,7 +270,20 @@ class Completer {
277270 afterFromClause
278271 )
279272
280- if ( isCursorInsideFromClause || isCursorAfterFromKeyword ) {
273+ const isTypingTableName = isCursorInsideFromClause || isCursorAfterFromKeyword
274+
275+ // Only add column suggestions if NOT typing a table name in FROM clause
276+ if ( ! isTypingTableName ) {
277+ const { addedSome : addedSomeScopedColumnCandidates } =
278+ this . addCandidatesForScopedColumns ( fromNodes , schemaAndSubqueries )
279+ if ( ! addedSomeScopedColumnCandidates ) {
280+ this . addCandidatesForUnscopedColumns ( fromNodes , schemaAndSubqueries )
281+ }
282+ }
283+
284+ this . addCandidatesForAliases ( fromNodes )
285+
286+ if ( isTypingTableName ) {
281287 // add table candidates if the cursor is inside a FROM clause, JOIN clause,
282288 // or right after FROM/JOIN keyword waiting for a table name
283289 this . addCandidatesForTables ( schemaAndSubqueries , true )
0 commit comments