summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Brun Rasmussen <janbrunrasmussen@gmail.com>2020-09-08 19:02:25 +0200
committerGitHub <noreply@github.com>2020-09-08 10:02:25 -0700
commit352ed4198034a5a7016ee6b105bf95fb415a5110 (patch)
treed73434fd127c148e547bf6a273adc4b6f698d53a
parentd9adca7d5e53cf4f447cc804b3137fd9934150bd (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--AUTHORS1
-rw-r--r--changelog.rst1
-rw-r--r--pgcli/packages/sqlcompletion.py16
3 files changed, 16 insertions, 2 deletions
diff --git a/AUTHORS b/AUTHORS
index 4be4126a..21263c89 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -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()