diff --git a/src/ls/driver.ts b/src/ls/driver.ts index 91506ff..13facb3 100644 --- a/src/ls/driver.ts +++ b/src/ls/driver.ts @@ -180,9 +180,13 @@ export default class YourDriverClass extends AbstractDriver { switch (itemType) { + case ContextValue.DATABASE: + return this.cachedQuery(this.queries.searchSchemas({ search })); case ContextValue.TABLE: case ContextValue.VIEW: - return this.cachedQuery(this.queries.searchTables({ search, schema: _extraParams.database })); + if (_extraParams.database) { + return this.cachedQuery(this.queries.searchTables({ search, schema: _extraParams.database })); + } case ContextValue.COLUMN: if (_extraParams.tables && _extraParams.tables.length > 0) { return this.cachedQuery(this.queries.searchColumns({ search, tables: _extraParams.tables || [] })); diff --git a/src/ls/keywords.ts b/src/ls/keywords.ts index cdb0ed6..957b6ab 100644 --- a/src/ls/keywords.ts +++ b/src/ls/keywords.ts @@ -1,4 +1,5 @@ import { NSDatabase } from '@sqltools/types'; +import { CompletionItem } from 'vscode-languageserver-types'; // From the EXA_SQL_KEYWORDS table const keywordsArr = [ @@ -816,7 +817,7 @@ const keywordsArr = [ const firstKeywords = ['SELECT', 'CREATE', 'UPDATE', 'DELETE', 'WITH']; const keywordsCompletion: { [w: string]: NSDatabase.IStaticCompletion } = keywordsArr.reduce((agg, word) => { - agg[`"${word}"`] = { + agg[`"${word}"`] = { label: word, detail: word, filterText: word, diff --git a/src/ls/queries.ts b/src/ls/queries.ts index 0aeb7a3..de73c4d 100644 --- a/src/ls/queries.ts +++ b/src/ls/queries.ts @@ -1,4 +1,4 @@ -import { IBaseQueries, ContextValue } from '@sqltools/types'; +import { IBaseQueries, ContextValue, QueryBuilder, NSDatabase } from '@sqltools/types'; import queryFactory from '@sqltools/base-driver/dist/lib/factory'; @@ -84,27 +84,40 @@ order by `; // Search is used for autocomplete. In the context of Tables, Views are also relevant. +const searchSchemas: QueryBuilder<{ search: string }, NSDatabase.ISchema> = queryFactory` +${SNAPSHOT_EXEC} select + "SCHEMA_NAME" as 'label', + '${ContextValue.SCHEMA}' as 'type', + true as 'isView' +from + "EXA_ALL_SCHEMAS" +where + lower("SCHEMA_NAME") like '%${p => p.search.toLowerCase()}%' +` + const searchTables: IBaseQueries['searchTables'] = queryFactory` ${SNAPSHOT_EXEC} select - "VIEW_SCHEMA" || '.' || "VIEW_NAME" as 'label', + "VIEW_NAME" as 'label', "VIEW_SCHEMA" as 'schema', '${ContextValue.VIEW}' as 'type', true as 'isView' from "EXA_ALL_VIEWS" where + "VIEW_SCHEMA" = '${p => p.schema}' and lower("VIEW_NAME") like '%${p => p.search.toLowerCase()}%' union all select - "TABLE_SCHEMA" || '.' || "TABLE_NAME" as 'label', + "TABLE_NAME" as 'label', "TABLE_SCHEMA" as 'schema', '${ContextValue.TABLE}' as 'type', false as 'isView' from "EXA_ALL_TABLES" where + "TABLE_SCHEMA" = '${p => p.schema}' and lower("TABLE_NAME") like '%${p => p.search.toLowerCase()}%' `; @@ -137,6 +150,7 @@ export default { fetchTables, fetchViews, searchTables, + searchSchemas, searchColumns, // Unused but required by the interface describeTable, // Undef