diff --git a/TODO b/TODO index 8fcc5d1b..dfc55ea5 100644 --- a/TODO +++ b/TODO @@ -1,8 +1,4 @@ # vi: ft=vimwiki -* [ ] Skip the password prompt by default. It should only be presented if -W option is provided. -* [ ] Detect a '.' and parse the word before it and get it's real name. -* [ ] Multiple cols for dot is failing. -* [ ] Table detection for INSERT INTO is not stopping after it encounters the lparen. * [ ] Bottom status bar is cut-off in half pane. Figure out how to fix that. * [ ] Column completion for nested sql. * [ ] Add JOIN to the list of keywords and provide proper autocompletion for it. @@ -28,3 +24,7 @@ * [X] Fix: Autocompletion won't go away after semi-colons. This an artifact of stripping special chars in the partially typed words. Need to selectively remove parens. * [X] Fix: SELECT id, FROM django_migrations; - Auto-completion for the second column name is broken. Find the last keyword and use it for completion. * [X] Show only table sensitive columns in autocompletion. +* [X] Skip the password prompt by default. It should only be presented if -W option is provided. +* [X] Detect a '.' and parse the word before it and get it's real name. +* [X] Multiple cols for dot is failing. +* [X] Table detection for INSERT INTO is not stopping after it encounters the lparen. diff --git a/pgcli/packages/sqlcompletion.py b/pgcli/packages/sqlcompletion.py index cb5c51c0..41c8c6d5 100644 --- a/pgcli/packages/sqlcompletion.py +++ b/pgcli/packages/sqlcompletion.py @@ -59,8 +59,9 @@ def suggest_based_on_last_token(token, text_before_cursor, full_text): prev_keyword = find_prev_keyword(text_before_cursor) return suggest_based_on_last_token(prev_keyword, text_before_cursor, full_text) elif token_v.endswith('.'): + current_alias = last_word(token_v[:-1]) tables = extract_tables(full_text, include_alias=True) - return 'columns', [tables.get(token.token_first().value)] + return 'columns', [tables.get(current_alias)] else: return 'keywords', [] diff --git a/tests/test_sqlcompletion.py b/tests/test_sqlcompletion.py index b816e3d4..eb3e7ddd 100644 --- a/tests/test_sqlcompletion.py +++ b/tests/test_sqlcompletion.py @@ -66,3 +66,8 @@ def test_dot_suggests_cols_of_an_alias(): suggestion = suggest_type('SELECT t1. FROM tabl1 t1, tabl2 t2', 'SELECT t1.') assert suggestion == ('columns', ['tabl1']) + +def test_dot_col_comma_suggests_cols(): + suggestion = suggest_type('SELECT t1.a, t2. FROM tabl1 t1, tabl2 t2', + 'SELECT t1.a, t2.') + assert suggestion == ('columns', ['tabl2'])