summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAmjith Ramanujam <amjith.r@gmail.com>2016-09-12 14:57:39 -0700
committerGitHub <noreply@github.com>2016-09-12 14:57:39 -0700
commit153a72944c80b44da957390dd37c754bbab5e3d5 (patch)
tree0c8eb3ad979e77267fdbf221fc28a3590b146433
parenta0f1826be39bccb651bee58ccf3f5c95a76aeb6b (diff)
parent514b594909cfef367a33c8c18439bced9c833270 (diff)
Merge pull request #581 from dbcli/koljonen/leading_parenthesis_crash
Fix crash bug with leading parenthesis
-rw-r--r--pgcli/packages/sqlcompletion.py2
-rw-r--r--tests/test_sqlcompletion.py8
2 files changed, 9 insertions, 1 deletions
diff --git a/pgcli/packages/sqlcompletion.py b/pgcli/packages/sqlcompletion.py
index 5fe37067..94edb3a8 100644
--- a/pgcli/packages/sqlcompletion.py
+++ b/pgcli/packages/sqlcompletion.py
@@ -335,7 +335,7 @@ def suggest_based_on_last_token(token, stmt):
if last_word(stmt.text_before_cursor,
'all_punctuations').startswith('('):
return (Keyword(),)
- prev_prev_tok = p.token_prev(p.token_index(prev_tok))[1]
+ prev_prev_tok = prev_tok and p.token_prev(p.token_index(prev_tok))[1]
if prev_prev_tok and prev_prev_tok.normalized == 'INTO':
return (Column(table_refs=stmt.get_tables('insert')),)
# We're probably in a function argument list
diff --git a/tests/test_sqlcompletion.py b/tests/test_sqlcompletion.py
index d9fffef5..68c9e3de 100644
--- a/tests/test_sqlcompletion.py
+++ b/tests/test_sqlcompletion.py
@@ -716,6 +716,14 @@ def test_select_suggests_fields_from_function():
@pytest.mark.parametrize('sql', [
+ '(',
+])
+def test_leading_parenthesis(sql):
+ # No assertion for now; just make sure it doesn't crash
+ suggest_type(sql, sql)
+
+
+@pytest.mark.parametrize('sql', [
'select * from "',
'select * from "foo',
])