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 {
256
256
if ( ! addedSome ) {
257
257
this . addCandidatesForUnscopedColumns ( fromNodes , schemaAndSubqueries )
258
258
}
259
+
259
260
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
+
261
271
if ( logger . isDebugEnabled ( ) )
262
272
logger . debug (
263
273
`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', () => {
181
181
expect ( result . candidates ) . toEqual ( expect . arrayContaining ( expected ) )
182
182
} )
183
183
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
+
184
195
test ( 'complete function inside WHERE select star' , ( ) => {
185
196
const result = complete (
186
197
'SELECT * FROM tab1 WHERE arr' ,
You can’t perform that action at this time.
0 commit comments