diff options
author | Amjith Ramanujam <amjith.r@gmail.com> | 2016-09-12 14:57:39 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-09-12 14:57:39 -0700 |
commit | 153a72944c80b44da957390dd37c754bbab5e3d5 (patch) | |
tree | 0c8eb3ad979e77267fdbf221fc28a3590b146433 | |
parent | a0f1826be39bccb651bee58ccf3f5c95a76aeb6b (diff) | |
parent | 514b594909cfef367a33c8c18439bced9c833270 (diff) |
Merge pull request #581 from dbcli/koljonen/leading_parenthesis_crash
Fix crash bug with leading parenthesis
-rw-r--r-- | pgcli/packages/sqlcompletion.py | 2 | ||||
-rw-r--r-- | tests/test_sqlcompletion.py | 8 |
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', ]) |