1
1
mirror of https://github.com/dbcli/pgcli.git synced 2024-10-06 02:07:53 +03:00

Add keyword completion for sub-select.

This commit is contained in:
Amjith Ramanujam 2014-12-30 18:27:21 -08:00
parent 39c6c54f44
commit 16af5d0ec1
2 changed files with 14 additions and 6 deletions

View File

@ -42,6 +42,12 @@ def suggest_based_on_last_token(token, text_before_cursor, full_text):
token_v = token.value
if token_v.lower().endswith('('):
p = sqlparse.parse(text_before_cursor)[0]
if p.token_first().value.lower() == 'select':
# If the lparen is preceeded by a space chances are we're about to
# do a sub-select.
if last_word(text_before_cursor, 'all_punctuations').startswith('('):
return 'keywords', []
return 'columns', extract_tables(full_text)
if token_v.lower() in ('set', 'by', 'distinct'):
return 'columns', extract_tables(full_text)

View File

@ -57,8 +57,7 @@ def test_partially_typed_col_name_suggests_col_names():
assert suggestion == ('columns-and-functions', ['tabl'])
def test_dot_suggests_cols_of_a_table():
suggestion = suggest_type('SELECT tabl. FROM tabl',
'SELECT tabl.')
suggestion = suggest_type('SELECT tabl. FROM tabl', 'SELECT tabl.')
assert suggestion == ('columns', ['tabl'])
def test_dot_suggests_cols_of_an_alias():
@ -71,10 +70,13 @@ def test_dot_col_comma_suggests_cols():
'SELECT t1.a, t2.')
assert suggestion == ('columns', ['tabl2'])
#def test_sub_select_suggests_keyword():
#suggestion = suggest_type('SELECT * FROM (',
#'SELECT * FROM (')
#assert suggestion == ('keywords', [])
def test_sub_select_suggests_keyword():
suggestion = suggest_type('SELECT * FROM (', 'SELECT * FROM (')
assert suggestion == ('keywords', [])
def test_sub_select_partial_text_suggests_keyword():
suggestion = suggest_type('SELECT * FROM (S', 'SELECT * FROM (S')
assert suggestion == ('keywords', [])
def test_sub_select_table_name_completion():
suggestion = suggest_type('SELECT * FROM (SELECT * FROM ',