Skip to content

Commit

Permalink
Better Completer responsiveness in interactive after command table lo…
Browse files Browse the repository at this point in the history
…aded (Azure#5794)

* improved completer responsiveness upon command table load

* history and version bump

* mock create_interface()

* delay create_interface and remove refresh_cli flag

* close file descriptor
  • Loading branch information
williexu authored Mar 13, 2018
1 parent 4993251 commit 83fb2ae
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 75 deletions.
98 changes: 65 additions & 33 deletions azure-cli.pyproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@
<OutputPath>.</OutputPath>
<ProjectTypeGuids>{888888a0-9f3d-457c-b088-3a5042f75d52}</ProjectTypeGuids>
<LaunchProvider>Standard Python launcher</LaunchProvider>
<InterpreterId>{0739f18f-8f0c-4ff7-b592-f6a44eacf0ba}</InterpreterId>
<InterpreterVersion>3.5</InterpreterVersion>
<InterpreterId>{78c1ee79-34bd-41e9-beb0-9ecf0336c9a2}</InterpreterId>
<InterpreterVersion>2.7</InterpreterVersion>
<EnableNativeCodeDebugging>False</EnableNativeCodeDebugging>
<CommandLineArguments>
</CommandLineArguments>
<CommandLineArguments>interactive</CommandLineArguments>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Debug'" />
<PropertyGroup Condition="'$(Configuration)' == 'Release'" />
Expand Down Expand Up @@ -351,30 +350,29 @@
<Compile Include="command_modules\azure-cli-find\azure\cli\command_modules\find\_params.py" />
<Compile Include="command_modules\azure-cli-find\azure\cli\command_modules\find\__init__.py" />
<Compile Include="command_modules\azure-cli-find\setup.py" />
<Compile Include="command_modules\azure-cli-interactive\azclishell\app.py" />
<Compile Include="command_modules\azure-cli-interactive\azclishell\argfinder.py" />
<Compile Include="command_modules\azure-cli-interactive\azclishell\az_completer.py" />
<Compile Include="command_modules\azure-cli-interactive\azclishell\az_lexer.py" />
<Compile Include="command_modules\azure-cli-interactive\azclishell\color_styles.py" />
<Compile Include="command_modules\azure-cli-interactive\azclishell\command_tree.py" />
<Compile Include="command_modules\azure-cli-interactive\azclishell\configuration.py" />
<Compile Include="command_modules\azure-cli-interactive\azclishell\frequency_heuristic.py" />
<Compile Include="command_modules\azure-cli-interactive\azclishell\gather_commands.py" />
<Compile Include="command_modules\azure-cli-interactive\azclishell\key_bindings.py" />
<Compile Include="command_modules\azure-cli-interactive\azclishell\layout.py" />
<Compile Include="command_modules\azure-cli-interactive\azclishell\progress.py" />
<Compile Include="command_modules\azure-cli-interactive\azclishell\telemetry.py" />
<Compile Include="command_modules\azure-cli-interactive\azclishell\threads.py" />
<Compile Include="command_modules\azure-cli-interactive\azclishell\util.py" />
<Compile Include="command_modules\azure-cli-interactive\azclishell\_dump_commands.py" />
<Compile Include="command_modules\azure-cli-interactive\azclishell\__init__.py" />
<Compile Include="command_modules\azure-cli-interactive\azure\cli\command_modules\interactive\azclishell\app.py" />
<Compile Include="command_modules\azure-cli-interactive\azure\cli\command_modules\interactive\azclishell\argfinder.py" />
<Compile Include="command_modules\azure-cli-interactive\azure\cli\command_modules\interactive\azclishell\az_completer.py" />
<Compile Include="command_modules\azure-cli-interactive\azure\cli\command_modules\interactive\azclishell\az_lexer.py" />
<Compile Include="command_modules\azure-cli-interactive\azure\cli\command_modules\interactive\azclishell\color_styles.py" />
<Compile Include="command_modules\azure-cli-interactive\azure\cli\command_modules\interactive\azclishell\command_tree.py" />
<Compile Include="command_modules\azure-cli-interactive\azure\cli\command_modules\interactive\azclishell\configuration.py" />
<Compile Include="command_modules\azure-cli-interactive\azure\cli\command_modules\interactive\azclishell\frequency_heuristic.py" />
<Compile Include="command_modules\azure-cli-interactive\azure\cli\command_modules\interactive\azclishell\gather_commands.py" />
<Compile Include="command_modules\azure-cli-interactive\azure\cli\command_modules\interactive\azclishell\key_bindings.py" />
<Compile Include="command_modules\azure-cli-interactive\azure\cli\command_modules\interactive\azclishell\layout.py" />
<Compile Include="command_modules\azure-cli-interactive\azure\cli\command_modules\interactive\azclishell\progress.py" />
<Compile Include="command_modules\azure-cli-interactive\azure\cli\command_modules\interactive\azclishell\telemetry.py" />
<Compile Include="command_modules\azure-cli-interactive\azure\cli\command_modules\interactive\azclishell\threads.py" />
<Compile Include="command_modules\azure-cli-interactive\azure\cli\command_modules\interactive\azclishell\util.py" />
<Compile Include="command_modules\azure-cli-interactive\azure\cli\command_modules\interactive\azclishell\_dump_commands.py" />
<Compile Include="command_modules\azure-cli-interactive\azure\cli\command_modules\interactive\azclishell\__init__.py" />
<Compile Include="command_modules\azure-cli-interactive\azure\cli\command_modules\interactive\tests\latest\test_completion.py" />
<Compile Include="command_modules\azure-cli-interactive\azure\cli\command_modules\interactive\tests\latest\test_feedback.py" />
<Compile Include="command_modules\azure-cli-interactive\azure\cli\command_modules\interactive\tests\latest\test_gather.py" />
<Compile Include="command_modules\azure-cli-interactive\azure\cli\command_modules\interactive\tests\latest\test_query_injection.py" />
<Compile Include="command_modules\azure-cli-interactive\azure\cli\command_modules\interactive\tests\latest\test_quote_parse.py" />
<Compile Include="command_modules\azure-cli-interactive\azure\cli\command_modules\interactive\tests\latest\test_shell_progress.py" />
<Compile Include="command_modules\azure-cli-interactive\azure\cli\command_modules\interactive\tests\latest\test_telemetry.py" />
<Compile Include="command_modules\azure-cli-interactive\azure\cli\command_modules\interactive\tests\latest\test_tree.py" />
<Compile Include="command_modules\azure-cli-interactive\azure\cli\command_modules\interactive\__init__.py" />
<Compile Include="command_modules\azure-cli-interactive\setup.py" />
Expand Down Expand Up @@ -856,11 +854,12 @@
<Folder Include="command_modules\azure-cli-find\azure\cli\command_modules\find\tests\" />
<Folder Include="command_modules\azure-cli-find\azure\cli\command_modules\find\tests\latest\" />
<Folder Include="command_modules\azure-cli-interactive\" />
<Folder Include="command_modules\azure-cli-interactive\azclishell\" />
<Folder Include="command_modules\azure-cli-interactive\azure\" />
<Folder Include="command_modules\azure-cli-interactive\azure\cli\" />
<Folder Include="command_modules\azure-cli-interactive\azure\cli\command_modules\" />
<Folder Include="command_modules\azure-cli-interactive\azure\cli\command_modules\interactive\" />
<Folder Include="command_modules\azure-cli-interactive\azure\cli\command_modules\interactive\azclishell\" />
<Folder Include="command_modules\azure-cli-interactive\azure\cli\command_modules\interactive\azclishell\__pycache__\" />
<Folder Include="command_modules\azure-cli-interactive\azure\cli\command_modules\interactive\tests\" />
<Folder Include="command_modules\azure-cli-interactive\azure\cli\command_modules\interactive\tests\latest\" />
<Folder Include="command_modules\azure-cli-interactive\docs\" />
Expand Down Expand Up @@ -1088,6 +1087,41 @@
<Content Include="command_modules\azure-cli-find\MANIFEST.in" />
<Content Include="command_modules\azure-cli-find\README.rst" />
<Content Include="command_modules\azure-cli-find\setup.cfg" />
<Content Include="command_modules\azure-cli-interactive\azure\cli\command_modules\interactive\azclishell\app.pyc" />
<Content Include="command_modules\azure-cli-interactive\azure\cli\command_modules\interactive\azclishell\argfinder.pyc" />
<Content Include="command_modules\azure-cli-interactive\azure\cli\command_modules\interactive\azclishell\az_completer.pyc" />
<Content Include="command_modules\azure-cli-interactive\azure\cli\command_modules\interactive\azclishell\az_lexer.pyc" />
<Content Include="command_modules\azure-cli-interactive\azure\cli\command_modules\interactive\azclishell\color_styles.pyc" />
<Content Include="command_modules\azure-cli-interactive\azure\cli\command_modules\interactive\azclishell\command_tree.pyc" />
<Content Include="command_modules\azure-cli-interactive\azure\cli\command_modules\interactive\azclishell\configuration.pyc" />
<Content Include="command_modules\azure-cli-interactive\azure\cli\command_modules\interactive\azclishell\frequency_heuristic.pyc" />
<Content Include="command_modules\azure-cli-interactive\azure\cli\command_modules\interactive\azclishell\gather_commands.pyc" />
<Content Include="command_modules\azure-cli-interactive\azure\cli\command_modules\interactive\azclishell\key_bindings.pyc" />
<Content Include="command_modules\azure-cli-interactive\azure\cli\command_modules\interactive\azclishell\layout.pyc" />
<Content Include="command_modules\azure-cli-interactive\azure\cli\command_modules\interactive\azclishell\progress.pyc" />
<Content Include="command_modules\azure-cli-interactive\azure\cli\command_modules\interactive\azclishell\telemetry.pyc" />
<Content Include="command_modules\azure-cli-interactive\azure\cli\command_modules\interactive\azclishell\threads.pyc" />
<Content Include="command_modules\azure-cli-interactive\azure\cli\command_modules\interactive\azclishell\util.pyc" />
<Content Include="command_modules\azure-cli-interactive\azure\cli\command_modules\interactive\azclishell\_dump_commands.pyc" />
<Content Include="command_modules\azure-cli-interactive\azure\cli\command_modules\interactive\azclishell\__init__.pyc" />
<Content Include="command_modules\azure-cli-interactive\azure\cli\command_modules\interactive\azclishell\__pycache__\app.cpython-36.pyc" />
<Content Include="command_modules\azure-cli-interactive\azure\cli\command_modules\interactive\azclishell\__pycache__\argfinder.cpython-36.pyc" />
<Content Include="command_modules\azure-cli-interactive\azure\cli\command_modules\interactive\azclishell\__pycache__\az_completer.cpython-36.pyc" />
<Content Include="command_modules\azure-cli-interactive\azure\cli\command_modules\interactive\azclishell\__pycache__\az_lexer.cpython-36.pyc" />
<Content Include="command_modules\azure-cli-interactive\azure\cli\command_modules\interactive\azclishell\__pycache__\color_styles.cpython-36.pyc" />
<Content Include="command_modules\azure-cli-interactive\azure\cli\command_modules\interactive\azclishell\__pycache__\command_tree.cpython-36.pyc" />
<Content Include="command_modules\azure-cli-interactive\azure\cli\command_modules\interactive\azclishell\__pycache__\configuration.cpython-36.pyc" />
<Content Include="command_modules\azure-cli-interactive\azure\cli\command_modules\interactive\azclishell\__pycache__\frequency_heuristic.cpython-36.pyc" />
<Content Include="command_modules\azure-cli-interactive\azure\cli\command_modules\interactive\azclishell\__pycache__\gather_commands.cpython-36.pyc" />
<Content Include="command_modules\azure-cli-interactive\azure\cli\command_modules\interactive\azclishell\__pycache__\key_bindings.cpython-36.pyc" />
<Content Include="command_modules\azure-cli-interactive\azure\cli\command_modules\interactive\azclishell\__pycache__\layout.cpython-36.pyc" />
<Content Include="command_modules\azure-cli-interactive\azure\cli\command_modules\interactive\azclishell\__pycache__\progress.cpython-36.pyc" />
<Content Include="command_modules\azure-cli-interactive\azure\cli\command_modules\interactive\azclishell\__pycache__\telemetry.cpython-36.pyc" />
<Content Include="command_modules\azure-cli-interactive\azure\cli\command_modules\interactive\azclishell\__pycache__\threads.cpython-36.pyc" />
<Content Include="command_modules\azure-cli-interactive\azure\cli\command_modules\interactive\azclishell\__pycache__\util.cpython-36.pyc" />
<Content Include="command_modules\azure-cli-interactive\azure\cli\command_modules\interactive\azclishell\__pycache__\_dump_commands.cpython-36.pyc" />
<Content Include="command_modules\azure-cli-interactive\azure\cli\command_modules\interactive\azclishell\__pycache__\__init__.cpython-36.pyc" />
<Content Include="command_modules\azure-cli-interactive\azure\cli\command_modules\interactive\azclishell\__pycache__\__main__.cpython-36.pyc" />
<Content Include="command_modules\azure-cli-interactive\docs\faster-shell-cast.gif" />
<Content Include="command_modules\azure-cli-interactive\docs\shell.gif" />
<Content Include="command_modules\azure-cli-interactive\docs\shell_tutorial.gif" />
Expand Down Expand Up @@ -1165,18 +1199,16 @@
<Content Include="command_modules\azure-cli-vm\HISTORY.rst" />
</ItemGroup>
<ItemGroup>
<InterpreterReference Include="{6121b83b-bf4d-4953-9b9d-9360b34efe09}\3.5" />
</ItemGroup>
<ItemGroup>
<Interpreter Include="..\env\">
<Id>{0739f18f-8f0c-4ff7-b592-f6a44eacf0ba}</Id>
<BaseInterpreter>{6121b83b-bf4d-4953-9b9d-9360b34efe09}</BaseInterpreter>
<Version>3.5</Version>
<Description>env (Python 3.6)</Description>
<Interpreter Include="..\env36b\">
<Id>{78c1ee79-34bd-41e9-beb0-9ecf0336c9a2}</Id>
<BaseInterpreter>{d09116de-bd02-4de4-8a41-0d9752df0ac8}</BaseInterpreter>
<Version>2.7</Version>
<Description>env36b (env36)</Description>
<InterpreterPath>Scripts\python.exe</InterpreterPath>
<WindowsInterpreterPath>Scripts\pythonw.exe</WindowsInterpreterPath>
<WindowsInterpreterPath>Scripts\python.exe</WindowsInterpreterPath>
<LibraryPath>Lib\</LibraryPath>
<PathEnvironmentVariable>PYTHONPATH</PathEnvironmentVariable>
<PathEnvironmentVariable>
</PathEnvironmentVariable>
<Architecture>Amd64</Architecture>
</Interpreter>
</ItemGroup>
Expand Down
4 changes: 4 additions & 0 deletions src/command_modules/azure-cli-interactive/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
Release History
===============

0.3.18
++++++
* Completions kick in as soon as command table loading is done.

0.3.17
++++++
* Persist history across different sessions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,6 @@ def space_toolbar(settings_items, empty_space):
return settings, empty_space


def restart_completer(shell_ctx):
shell_ctx.completer = AzCompleter(shell_ctx, GatherCommands(shell_ctx.config))
shell_ctx.refresh_cli = True


# pylint: disable=too-many-instance-attributes
class AzInteractiveShell(object):

Expand All @@ -98,21 +93,18 @@ def __init__(self, cli_ctx, style=None, completer=None,
self.lexer = lexer or get_az_lexer(self.config) if self.styles else None
try:
self.completer = completer or AzCompleter(self, GatherCommands(self.config))
from .az_completer import initialize_command_table_attributes
initialize_command_table_attributes(self.completer)
self.completer.initialize_command_table_attributes()
except IOError: # if there is no cache
self.completer = None
self.completer = AzCompleter(self, None)
self.history = history or FileHistory(os.path.join(self.config.config_dir, self.config.get_history()))
os.environ[ENV_ADDITIONAL_USER_AGENT] = 'AZURECLISHELL/' + __version__

# OH WHAT FUN TO FIGURE OUT WHAT THESE ARE!
self._cli = None
self.refresh_cli = False
self.layout = None
self.description_docs = u''
self.param_docs = u''
self.example_docs = u''
self._env = os.environ
self.last = None
self.last_exit = 0
self.user_feedback = user_feedback
Expand Down Expand Up @@ -155,9 +147,8 @@ def __call__(self):
@property
def cli(self):
""" Makes the interface or refreshes it """
if self._cli is None or self.refresh_cli:
if self._cli is None:
self._cli = self.create_interface()
self.refresh_cli = False
return self._cli

def handle_cd(self, cmd):
Expand Down Expand Up @@ -201,6 +192,12 @@ def on_input_timeout(self, cli):
self._update_toolbar()
cli.request_redraw()

def restart_completer(self):
if not self.completer:
self.completer.start(self, GatherCommands(self.config))
self.completer.initialize_command_table_attributes()
self._cli = self.create_interface()

def _space_examples(self, list_examples, rows, section_value):
""" makes the example text """
examples_with_index = []
Expand Down Expand Up @@ -686,7 +683,7 @@ def run(self):
self.cli_ctx.get_progress_controller().init_progress(ShellProgressView())
self.cli_ctx.get_progress_controller = self.progress_patch

self.command_table_thread = LoadCommandTableThread(restart_completer, self)
self.command_table_thread = LoadCommandTableThread(self.restart_completer, self)
self.command_table_thread.start()

from .configuration import SHELL_HELP
Expand Down
Loading

0 comments on commit 83fb2ae

Please sign in to comment.