diff options
author | Jan Brun Rasmussen <janbrunrasmussen@gmail.com> | 2020-09-08 19:02:25 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-08 10:02:25 -0700 |
commit | 352ed4198034a5a7016ee6b105bf95fb415a5110 (patch) | |
tree | d73434fd127c148e547bf6a273adc4b6f698d53a | |
parent | d9adca7d5e53cf4f447cc804b3137fd9934150bd (diff) |
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.
-rw-r--r-- | AUTHORS | 1 | ||||
-rw-r--r-- | changelog.rst | 1 | ||||
-rw-r--r-- | pgcli/packages/sqlcompletion.py | 16 |
3 files changed, 16 insertions, 2 deletions
@@ -112,6 +112,7 @@ Contributors: * Anthony DeBarros (anthonydb) * Seungyong Kwak (GUIEEN) * Tom Caruso (tomplex) + * Jan Brun Rasmussen (janbrunrasmussen) Creator: -------- diff --git a/changelog.rst b/changelog.rst index 2c5e7ca7..b303970f 100644 --- a/changelog.rst +++ b/changelog.rst @@ -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: ---------- diff --git a/pgcli/packages/sqlcompletion.py b/pgcli/packages/sqlcompletion.py index 93736e34..6ef88595 100644 --- a/pgcli/packages/sqlcompletion.py +++ b/pgcli/packages/sqlcompletion.py @@ -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() |