1
0
Fork 0

Add schema suggestion for functions (#1206)

* Add schema suggestion for functions

- Update sqlcompletion.py
- Update metadata files

* Move autocomletion for function under condition

- Make sure suggestion are only added under drop, alter etc.
This commit is contained in:
Jan Brun Rasmussen 2020-09-08 19:02:25 +02:00 committed by GitHub
parent d9adca7d5e
commit 352ed41980
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 2 deletions

View File

@ -112,6 +112,7 @@ Contributors:
* Anthony DeBarros (anthonydb)
* Seungyong Kwak (GUIEEN)
* Tom Caruso (tomplex)
* Jan Brun Rasmussen (janbrunrasmussen)
Creator:
--------

View File

@ -10,6 +10,7 @@ Features:
* Support setting color for null, string, number, keyword value
* Support Prompt Toolkit 2
* Update functions, datatypes literals for auto-suggestion field
* Add suggestion for schema in function auto-complete
Bug fixes:
----------

View File

@ -92,7 +92,7 @@ class SqlStatement(object):
return self.parsed.token_first().value.lower() == "insert"
def get_tables(self, scope="full"):
""" Gets the tables available in the statement.
"""Gets the tables available in the statement.
param `scope:` possible values: 'full', 'insert', 'before'
If 'insert', only the first table is returned.
If 'before', only tables before the cursor are returned.
@ -431,11 +431,23 @@ def suggest_based_on_last_token(token, stmt):
elif token_v == "function":
schema = stmt.get_identifier_schema()
# stmt.get_previous_token will fail for e.g. `SELECT 1 FROM functions WHERE function:`
try:
prev = stmt.get_previous_token(token).value.lower()
if prev in ("drop", "alter", "create", "create or replace"):
return (Function(schema=schema, usage="signature"),)
# Suggest functions from either the currently-selected schema or the
# public schema if no schema has been specified
suggest = []
if not schema:
# Suggest schemas
suggest.insert(0, Schema())
suggest.append(Function(schema=schema, usage="signature"))
return tuple(suggest)
except ValueError:
pass
return tuple()