File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -256,8 +256,18 @@ class Completer {
256256 if ( ! addedSome ) {
257257 this . addCandidatesForUnscopedColumns ( fromNodes , schemaAndSubqueries )
258258 }
259+
259260 this . addCandidatesForAliases ( fromNodes )
260- this . addCandidatesForTables ( schemaAndSubqueries , true )
261+
262+ const fromNodesContainingCursor = fromNodes . filter ( ( tableNode ) =>
263+ isPosInLocation ( tableNode . location , this . pos )
264+ )
265+ const isCursorInsideFromClause = fromNodesContainingCursor . length > 0
266+ if ( isCursorInsideFromClause ) {
267+ // only add table candidates if the cursor is inside a FROM clause or JOIN clause, etc.
268+ this . addCandidatesForTables ( schemaAndSubqueries , true )
269+ }
270+
261271 if ( logger . isDebugEnabled ( ) )
262272 logger . debug (
263273 `candidates for error returns: ${ JSON . stringify ( this . candidates ) } `
Original file line number Diff line number Diff line change @@ -181,6 +181,17 @@ describe('on blank space', () => {
181181 expect ( result . candidates ) . toEqual ( expect . arrayContaining ( expected ) )
182182 } )
183183
184+ test ( 'complete after SELECT FROM schema2.table2' , ( ) => {
185+ const result = complete (
186+ 'SELECT FROM schema2.table2' ,
187+ { line : 0 , column : 8 } ,
188+ SIMPLE_NESTED_SCHEMA
189+ )
190+ expect ( result . candidates ) . not . toContainEqual (
191+ expect . objectContaining ( { label : 'TABLE1' } )
192+ )
193+ } )
194+
184195 test ( 'complete function inside WHERE select star' , ( ) => {
185196 const result = complete (
186197 'SELECT * FROM tab1 WHERE arr' ,
You can’t perform that action at this time.
0 commit comments