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 @@ -257,8 +257,18 @@ class Completer {
257257 if ( ! addedSome ) {
258258 this . addCandidatesForUnscopedColumns ( fromNodes , schemaAndSubqueries )
259259 }
260+
260261 this . addCandidatesForAliases ( fromNodes )
261- this . addCandidatesForTables ( schemaAndSubqueries , true )
262+
263+ const fromNodesContainingCursor = fromNodes . filter ( ( tableNode ) =>
264+ isPosInLocation ( tableNode . location , this . pos )
265+ )
266+ const isCursorInsideFromClause = fromNodesContainingCursor . length > 0
267+ if ( isCursorInsideFromClause ) {
268+ // only add table candidates if the cursor is inside a FROM clause or JOIN clause, etc.
269+ this . addCandidatesForTables ( schemaAndSubqueries , true )
270+ }
271+
262272 if ( logger . isDebugEnabled ( ) )
263273 logger . debug (
264274 `candidates for error returns: ${ JSON . stringify ( this . candidates ) } `
Original file line number Diff line number Diff line change @@ -189,6 +189,17 @@ describe('on blank space', () => {
189189 expect ( result . candidates ) . toEqual ( expect . arrayContaining ( expected ) )
190190 } )
191191
192+ test ( 'complete after SELECT FROM schema2.table2' , ( ) => {
193+ const result = complete (
194+ 'SELECT FROM schema2.table2' ,
195+ { line : 0 , column : 8 } ,
196+ SIMPLE_NESTED_SCHEMA
197+ )
198+ expect ( result . candidates ) . not . toContainEqual (
199+ expect . objectContaining ( { label : 'TABLE1' } )
200+ )
201+ } )
202+
192203 test ( 'complete function inside WHERE select star' , ( ) => {
193204 const result = complete (
194205 'SELECT * FROM tab1 WHERE arr' ,
You can’t perform that action at this time.
0 commit comments