Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rush] Shell tab completion #2060

Merged
merged 109 commits into from
Aug 18, 2020
Merged

Conversation

sachinjoseph
Copy link
Member

@sachinjoseph sachinjoseph commented Jul 28, 2020

Tab completion for the Rush CLI

Inspired by Tab completion for the .NET Core CLI.

Because changes were made to @microsoft/rush package, the globally installed version of Rush will need to be updated.

Note: In the below scripts, replace rush tab-complete with node "absolute/path/to/rushstack/rush-lib/lib/start.js" tab-complete to use the locally built Rush.

PowerShell

To add tab completion to PowerShell for the Rush CLI, create or edit the profile stored in the variable $PROFILE. For more information, see How to create your profile and Profiles and execution policy.

Add the following code to your profile:

# PowerShell parameter completion shim for the Rush CLI
Register-ArgumentCompleter -Native -CommandName rush -ScriptBlock {
     param($commandName, $wordToComplete, $cursorPosition)
         rush tab-complete --position $cursorPosition --word "$wordToComplete" | ForEach-Object {
            [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
         }
 }

Bash

To add tab completion to your bash shell for the Rush CLI, add the following code to your .bashrc file:

# bash parameter completion for the Rush CLI

_rush_bash_complete()
{
  local word=${COMP_WORDS[COMP_CWORD]}

  local completions
  completions="$(rush tab-complete --position "${COMP_POINT}" --word "${COMP_LINE}" 2>/dev/null)"
  if [ $? -ne 0 ]; then
    completions=""
  fi

  COMPREPLY=( $(compgen -W "$completions" -- "$word") )
}

complete -f -F _rush_bash_complete rush

Lazy-import optimization

import-lazy + a few other optimizations here and there helped bring it down from ~2.2 seconds to ~0.7 seconds!

@sachinjoseph sachinjoseph changed the title [rush] Shell tab complete [rush] Shell tab completion Jul 28, 2020
@octogonz
Copy link
Collaborator

@ sachinjoseph Could you add a PR description explaining how to use this feature?

@sachinjoseph
Copy link
Member Author

@ sachinjoseph Could you add a PR description explaining how to use this feature?

Sure.

@octogonz
Copy link
Collaborator

octogonz commented Aug 18, 2020

@sachinjoseph This PR looks good to me except for two minor issues:

I'm very eager to get this merged so we can go optimize Heft next!

@sachinjoseph sachinjoseph requested a review from octogonz August 18, 2020 22:19
@sachinjoseph
Copy link
Member Author

@sachinjoseph This PR looks good to me except for two minor issues:

* The `getOwnPackageJsonVersion()` API should be removed; if optimizations are really needed they should be moved to `loadOwnPackageJsonVersion()`: [#2060 (comment)](https://github.com/microsoft/rushstack/pull/2060#discussion_r472385419)

* Seems like we can eliminate the `JsonSchema` caching everywhere:  https://github.com/microsoft/rushstack/pull/2060/files#r472405412

I'm very eager to get this merged so we can go optimize Heft next!

Done. Reverted both of these as they aren't providing any real perf gains.

…h/rush-shell-tab-complete

# Conflicts:
#	common/config/rush/pnpm-lock.yaml
#	common/config/rush/repo-state.json
@octogonz octogonz merged commit a43b607 into master Aug 18, 2020
@octogonz octogonz deleted the sachinjoseph/rush-shell-tab-complete branch August 18, 2020 23:32
@iclanton iclanton mentioned this pull request Nov 9, 2020
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants