diff --git a/TODO b/TODO index 828728e6..eabcfd0b 100644 --- a/TODO +++ b/TODO @@ -2,7 +2,6 @@ * [ ] Fix: SELECT id, FROM django_migrations; - Auto-completion for the second column name is broken. Find the last keyword and use it for completion. * [ ] Skip the password prompt by default. It should only be presented if -W option is provided. * [ ] Bottom status bar is cut-off in half pane. Figure out how to fix that. -* [ ] 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. * [ ] Column completion for nested sql. * [ ] Add JOIN to the list of keywords and provide proper autocompletion for it. * [ ] Improve the smart completion for Insert statement. (Needs table specific columns) @@ -27,3 +26,4 @@ * [ ] Set multi-line via config file. * [ ] New Feature List - Write the current version to config file. At launch if the version has changed, display the changelog between the two versions. * [o] Separate the column completions to be table specific. (SELECT, INSERT, UPDATE) +* [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. diff --git a/pgcli/packages/parseutils.py b/pgcli/packages/parseutils.py index a58e0225..f4a5f333 100644 --- a/pgcli/packages/parseutils.py +++ b/pgcli/packages/parseutils.py @@ -3,12 +3,16 @@ import sqlparse from sqlparse.sql import IdentifierList, Identifier from sqlparse.tokens import Keyword, DML -# This matches only alphanumerics and underscores. -_LAST_WORD_RE = re.compile(r'(\w+)$') -# This matches everything except a space. -_LAST_WORD_SPL_RE = re.compile(r'([^\s]+)$') +cleanup_regex = { + # This matches only alphanumerics and underscores. + 'alphanum_underscore': re.compile(r'(\w+)$'), + # This matches everything except spaces, parens and comma. + 'most_punctuations': re.compile(r'([^(),\s]+)$'), + # This matches everything except a space. + 'all_punctuations': re.compile('([^\s]+)$'), + } -def last_word(text, include_special_chars=False): +def last_word(text, include='alphanum_underscore'): """ Find the last word in a sentence. @@ -44,7 +48,7 @@ def last_word(text, include_special_chars=False): if text[-1].isspace(): return '' else: - regex = _LAST_WORD_SPL_RE if include_special_chars else _LAST_WORD_RE + regex = cleanup_regex[include] matches = regex.search(text) if matches: return matches.group(0) diff --git a/pgcli/packages/sqlcompletion.py b/pgcli/packages/sqlcompletion.py index b1fc3a80..c6029ae0 100644 --- a/pgcli/packages/sqlcompletion.py +++ b/pgcli/packages/sqlcompletion.py @@ -12,7 +12,7 @@ def suggest_type(full_text, text_before_cursor): """ word_before_cursor = last_word(text_before_cursor, - include_special_chars=True) + include='all_punctuations') # If we've partially typed a word then word_before_cursor won't be an empty # string. In that case we want to remove the partially typed string before diff --git a/pgcli/pgcompleter.py b/pgcli/pgcompleter.py index 2f0fd6fa..c5c21fac 100644 --- a/pgcli/pgcompleter.py +++ b/pgcli/pgcompleter.py @@ -69,7 +69,7 @@ class PGCompleter(Completer): @staticmethod def find_matches(text, collection): - text = last_word(text) + text = last_word(text, include='most_punctuations') for item in collection: if item.startswith(text) or item.startswith(text.upper()): yield Completion(item, -len(text))