mirror of https://github.com/dbcli/pgcli
Strip only a limited set of punctuations before matching.
This commit is contained in:
parent
1f60224ee6
commit
114f3a4a09
2
TODO
2
TODO
|
@ -2,7 +2,6 @@
|
|||
* [ ] Fix: SELECT id, <tab> 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.
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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))
|
||||
|
|
Loading…
Reference in New Issue