@@ -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,21 @@ class Completer {
277270 afterFromClause
278271 )
279272
280- if ( isCursorInsideFromClause || isCursorAfterFromKeyword ) {
273+ const isTypingTableName =
274+ isCursorInsideFromClause || isCursorAfterFromKeyword
275+
276+ if ( ! isTypingTableName ) {
277+ const { addedSome : addedSomeScopedColumnCandidates } =
278+ this . addCandidatesForScopedColumns ( fromNodes , schemaAndSubqueries )
279+
280+ if ( ! addedSomeScopedColumnCandidates ) {
281+ this . addCandidatesForUnscopedColumns ( fromNodes , schemaAndSubqueries )
282+ }
283+ }
284+
285+ this . addCandidatesForAliases ( fromNodes )
286+
287+ if ( isTypingTableName ) {
281288 // add table candidates if the cursor is inside a FROM clause, JOIN clause,
282289 // or right after FROM/JOIN keyword waiting for a table name
283290 this . addCandidatesForTables ( schemaAndSubqueries , true )
0 commit comments