1
0
Fork 0

ON keyword now suggests tables and aliases on the right side of equal sign also.

This commit is contained in:
Iryna Cherniavska 2015-01-19 17:03:44 -08:00
parent b78b81ea15
commit 13f3af72c3
3 changed files with 35 additions and 1 deletions

View File

@ -81,7 +81,7 @@ def suggest_based_on_last_token(token, text_before_cursor, full_text):
return 'tables', []
elif token_v.lower() in ('c', 'use'): # \c
return 'databases', []
elif token_v.endswith(','):
elif token_v.endswith(',') or token_v == '=':
prev_keyword = find_prev_keyword(text_before_cursor)
if prev_keyword:
return suggest_based_on_last_token(prev_keyword, text_before_cursor, full_text)

View File

@ -197,6 +197,16 @@ def test_suggested_aliases_after_on(completer, complete_event):
Completion(text='u', start_position=0),
Completion(text='o', start_position=0)])
def test_suggested_aliases_after_on_right_side(completer, complete_event):
text = 'SELECT u.name, o.id FROM users u JOIN orders o ON o.user_id = '
position = len('SELECT u.name, o.id FROM users u JOIN orders o ON o.user_id = ')
result = set(completer.get_completions(
Document(text=text, cursor_position=position),
complete_event))
assert set(result) == set([
Completion(text='u', start_position=0),
Completion(text='o', start_position=0)])
def test_suggested_tables_after_on(completer, complete_event):
text = 'SELECT users.name, orders.id FROM users JOIN orders ON '
position = len('SELECT users.name, orders.id FROM users JOIN orders ON ')
@ -207,6 +217,16 @@ def test_suggested_tables_after_on(completer, complete_event):
Completion(text='users', start_position=0),
Completion(text='orders', start_position=0)])
def test_suggested_tables_after_on_right_side(completer, complete_event):
text = 'SELECT users.name, orders.id FROM users JOIN orders ON orders.user_id = '
position = len('SELECT users.name, orders.id FROM users JOIN orders ON orders.user_id = ')
result = set(completer.get_completions(
Document(text=text, cursor_position=position),
complete_event))
assert set(result) == set([
Completion(text='users', start_position=0),
Completion(text='orders', start_position=0)])
def test_table_names_after_from(completer, complete_event):
text = 'SELECT * FROM '
position = len('SELECT * FROM ')

View File

@ -127,3 +127,17 @@ def test_on_suggests_tables():
'select abc.x, bcd.y from abc join bcd on ')
assert category == 'tables-or-aliases'
assert set(scope) == set(['abc', 'bcd'])
def test_on_suggests_aliases_right_side():
category, scope = suggest_type(
'select a.x, b.y from abc a join bcd b on a.id = ',
'select a.x, b.y from abc a join bcd b on a.id = ')
assert category == 'tables-or-aliases'
assert set(scope) == set(['a', 'b'])
def test_on_suggests_tables_right_side():
category, scope = suggest_type(
'select abc.x, bcd.y from abc join bcd on ',
'select abc.x, bcd.y from abc join bcd on ')
assert category == 'tables-or-aliases'
assert set(scope) == set(['abc', 'bcd'])