-
Notifications
You must be signed in to change notification settings - Fork 2
fix: Fix autocomplete table name issues. #25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -149,4 +149,113 @@ describe('TableName completion', () => { | |
| const TABLE_KIND = 21 | ||
| expect(result.candidates.every((c) => c.kind === TABLE_KIND)).toBe(true) | ||
| }) | ||
|
|
||
| test('complete table name with database-qualified tables', () => { | ||
| const schema = { | ||
| tables: [ | ||
| { | ||
| catalog: null, | ||
| database: 'squeal', | ||
| tableName: 'actor', | ||
| columns: [{ columnName: 'actor_id', description: '' }], | ||
| }, | ||
| { | ||
| catalog: null, | ||
| database: 'squeal', | ||
| tableName: 'actor_info', | ||
| columns: [{ columnName: 'actor_id', description: '' }], | ||
| }, | ||
| { | ||
| catalog: null, | ||
| database: 'squeal', | ||
| tableName: 'film', | ||
| columns: [{ columnName: 'film_id', description: '' }], | ||
| }, | ||
| ], | ||
| functions: [], | ||
| } | ||
|
|
||
| // Test: typing 'a' after FROM should match 'actor' and 'actor_info' | ||
| const result = complete('SELECT * FROM a', { line: 0, column: 15 }, schema) | ||
|
|
||
| const labels = result.candidates.map((c) => c.label) | ||
| expect(labels).toContain('actor') | ||
| expect(labels).toContain('actor_info') | ||
| expect(labels).not.toContain('film') | ||
| }) | ||
|
|
||
| test('complete table name when SQL parses successfully', () => { | ||
| // This tests the case when the parser treats partial table name as valid | ||
| // See https://github.com/deepnote/sql-language-server/issues/24 | ||
| const schema = { | ||
| tables: [ | ||
| { catalog: null, database: null, tableName: 'actor', columns: [] }, | ||
| { catalog: null, database: null, tableName: 'actor_info', columns: [] }, | ||
| { catalog: null, database: null, tableName: 'film', columns: [] }, | ||
| ], | ||
| functions: [], | ||
| } | ||
|
|
||
| const result = complete( | ||
| 'SELECT * FROM act', | ||
| { line: 0, column: 17 }, | ||
| schema | ||
| ) | ||
|
|
||
| const labels = result.candidates.map((c) => c.label) | ||
| expect(labels).toContain('actor') | ||
| expect(labels).toContain('actor_info') | ||
| expect(labels).not.toContain('film') | ||
| }) | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| test('complete table name with partial input after typing more characters', () => { | ||
| const schema = { | ||
| tables: [ | ||
| { | ||
| catalog: null, | ||
| database: 'squeal', | ||
| tableName: 'actor', | ||
| columns: [], | ||
| }, | ||
| { | ||
| catalog: null, | ||
| database: 'squeal', | ||
| tableName: 'actor_info', | ||
| columns: [], | ||
| }, | ||
| { | ||
| catalog: null, | ||
| database: 'squeal', | ||
| tableName: 'film', | ||
| columns: [], | ||
| }, | ||
| { | ||
| catalog: null, | ||
| database: 'squeal', | ||
| tableName: 'film_actor', | ||
| columns: [], | ||
| }, | ||
| { | ||
| catalog: null, | ||
| database: 'squeal', | ||
| tableName: 'customer', | ||
| columns: [], | ||
| }, | ||
| ], | ||
| functions: [], | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit - i'd create a helper function for creating schema, something along the lines of: it being so sparse makes it a bit hard to understand at a glance
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a good point |
||
|
|
||
| // Test: typing 'fil' should match 'film' and 'film_actor' | ||
| const result = complete( | ||
| 'SELECT * FROM fil', | ||
| { line: 0, column: 17 }, | ||
| schema | ||
| ) | ||
|
|
||
| const labels = result.candidates.map((c) => c.label) | ||
| expect(labels).toContain('film') | ||
| expect(labels).toContain('film_actor') | ||
| expect(labels).not.toContain('actor') | ||
| expect(labels).not.toContain('customer') | ||
| }) | ||
|
Artmann marked this conversation as resolved.
|
||
| }) | ||
Uh oh!
There was an error while loading. Please reload this page.