Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions mssqlcli/key_bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ def mssqlcli_bindings(get_vi_mode_enabled, set_vi_mode_enabled):
enable_search=True,
enable_abort_and_exit_bindings=True)

@key_binding_manager.registry.add_binding(Keys.F2)
def _(event):
"""
Enable/Disable SmartCompletion Mode.
"""
_logger.debug('Detected F2 key.')
buf = event.cli.current_buffer
buf.completer.smart_completion = not buf.completer.smart_completion

@key_binding_manager.registry.add_binding(Keys.F3)
def _(event):
"""
Expand Down
4 changes: 3 additions & 1 deletion mssqlcli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ def __init__(self, force_passwd_prompt=False,

self.query_history = []

# Initialize completer
smart_completion = True if c['main'].get('smart_completion', 'True') == 'True' else False
keyword_casing = c['main']['keyword_casing']
self.settings = {
'casing_file': get_casing_file(c),
Expand All @@ -184,7 +186,7 @@ def __init__(self, force_passwd_prompt=False,
'keyword_casing': keyword_casing,
}

completer = MssqlCompleter(settings=self.settings)
completer = MssqlCompleter(smart_completion=smart_completion, settings=self.settings)

self.completer = completer
self._completer_lock = threading.Lock()
Expand Down
4 changes: 4 additions & 0 deletions mssqlcli/mssqlclirc
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# vi: ft=dosini
[main]

# Enables context sensitive auto-completion. If this is disabled the all
# possible completions will be listed.
smart_completion = True

# Display the completions in several columns. (More completions will be
# visible.)
wider_completion_menu = False
Expand Down
11 changes: 4 additions & 7 deletions mssqlcli/mssqlcompleter.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,15 +426,12 @@ def get_completions(self, document, complete_event, smart_completion=None):
if smart_completion is None:
smart_completion = self.smart_completion

# If smart_completion is off then match any word that starts with
# 'word_before_cursor'.
# If smart_completion is off then return nothing.
# Our notion of smart completion is all or none unlike PGCLI and MyCLI.
matches = []
if not smart_completion:
matches = self.find_matches(word_before_cursor, self.all_completions,
mode='strict')
completions = [m.completion for m in matches]
return sorted(completions, key=operator.attrgetter('text'))
return matches

matches = []
suggestions = suggest_type(document.text, document.text_before_cursor)

for suggestion in suggestions:
Expand Down
5 changes: 5 additions & 0 deletions mssqlcli/mssqltoolbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ def get_toolbar_tokens(cli):
result = []
result.append((token, ' '))

if cli.buffers[DEFAULT_BUFFER].completer.smart_completion:
result.append((token.On, '[F2] Smart Completion: ON '))
else:
result.append((token.Off, '[F2] Smart Completion: OFF '))

if cli.buffers[DEFAULT_BUFFER].always_multiline:
result.append((token.On, '[F3] Multiline: ON '))
else:
Expand Down