mirror of https://github.com/dbcli/pgcli
Merge pull request #198 from drocco007/master
Handle a ',' entered before any completions gracefully
This commit is contained in:
commit
4161f66cca
|
@ -189,7 +189,7 @@ def suggest_based_on_last_token(token, text_before_cursor, full_text, identifier
|
||||||
elif token_v.lower() in ('table', 'view', 'function'):
|
elif token_v.lower() in ('table', 'view', 'function'):
|
||||||
# E.g. 'DROP FUNCTION <funcname>', 'ALTER TABLE <tablname>'
|
# E.g. 'DROP FUNCTION <funcname>', 'ALTER TABLE <tablname>'
|
||||||
rel_type = token_v.lower()
|
rel_type = token_v.lower()
|
||||||
schema = (identifier and identifier.get_parent_name()) or []
|
schema = (identifier and identifier.get_parent_name()) or []
|
||||||
if schema:
|
if schema:
|
||||||
return [{'type': rel_type, 'schema': schema}]
|
return [{'type': rel_type, 'schema': schema}]
|
||||||
else:
|
else:
|
||||||
|
@ -220,6 +220,8 @@ def suggest_based_on_last_token(token, text_before_cursor, full_text, identifier
|
||||||
if prev_keyword:
|
if prev_keyword:
|
||||||
return suggest_based_on_last_token(
|
return suggest_based_on_last_token(
|
||||||
prev_keyword, text_before_cursor, full_text, identifier)
|
prev_keyword, text_before_cursor, full_text, identifier)
|
||||||
|
else:
|
||||||
|
return []
|
||||||
else:
|
else:
|
||||||
return [{'type': 'keyword'}]
|
return [{'type': 'keyword'}]
|
||||||
|
|
||||||
|
|
|
@ -278,4 +278,11 @@ def test_specials_not_included_after_initial_token():
|
||||||
def test_drop_schema_qualified_table_suggests_only_tables():
|
def test_drop_schema_qualified_table_suggests_only_tables():
|
||||||
text = 'DROP TABLE schema_name.table_name'
|
text = 'DROP TABLE schema_name.table_name'
|
||||||
suggestions = suggest_type(text, text)
|
suggestions = suggest_type(text, text)
|
||||||
assert suggestions == [{'type': 'table', 'schema': 'schema_name'}]
|
assert suggestions == [{'type': 'table', 'schema': 'schema_name'}]
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('text', [',', ' ,', 'sel ,'])
|
||||||
|
def test_handle_pre_completion_comma_gracefully(text):
|
||||||
|
suggestions = suggest_type(text, text)
|
||||||
|
|
||||||
|
assert iter(suggestions)
|
||||||
|
|
Loading…
Reference in New Issue