-
-
Notifications
You must be signed in to change notification settings - Fork 764
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
Completion on xrepo install packages #3214
Conversation
@@ -79,7 +79,8 @@ function menu_options() | |||
" - xrepo install -p iphoneos -a arm64 \"zlib >=1.2.0\"", | |||
" - xrepo install -p android [--ndk=/xxx] -m debug \"pcre2 10.x\"", | |||
" - xrepo install -p mingw [--mingw=/xxx] -k shared zlib", | |||
" - xrepo install conan::zlib/1.2.11 vcpkg::zlib"} | |||
" - xrepo install conan::zlib/1.2.11 vcpkg::zlib", | |||
values = function (complete, opt) return import("private.xrepo.quick_search.completion")(complete, opt) end} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it will break xrepo install -h
error: attempt to index a boolean value (local 'complete')
you need handle help menu and disable complete.
if complete then
-- do complete
end
@@ -79,7 +79,8 @@ function menu_options() | |||
" - xrepo install -p iphoneos -a arm64 \"zlib >=1.2.0\"", | |||
" - xrepo install -p android [--ndk=/xxx] -m debug \"pcre2 10.x\"", | |||
" - xrepo install -p mingw [--mingw=/xxx] -k shared zlib", | |||
" - xrepo install conan::zlib/1.2.11 vcpkg::zlib"} | |||
" - xrepo install conan::zlib/1.2.11 vcpkg::zlib", | |||
values = function (complete, opt) return import("private.xrepo.quick_search.completion")(complete, opt) end} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it will break xrepo install -h
error: attempt to index a boolean value (local 'complete')
you need handle help menu and disable complete.
if complete then
-- do complete
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I intercepted the help with "helpmenu" option in the completion funciton (in b1d694c)
Do you think it is enough ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, help menu should be able to handle the new kind of data.
In the values function for xrepo install, I return an array of objects with value
, description
and versions
fields. I use value and description to build completion in json format (I put versions for an eventual later update of xrepo install completion).
For xrepo install help, it's useless to put values in help menu, but in other command completions like xrepo remove or xmake build for example, it could be interesting to change values function to also return name and description. Therefore, help menu have to handle those.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I intercepted the help with "helpmenu" option in the completion funciton (in b1d694c)
Do you think it is enough ?
sure
How should I test it, I run |
Here is some script to add in your shell profile file : # xrepo completion
$xrepo_script = {
param($wordToComplete, $commandAst, $cursorPosition)
xmake lua 'private.xrepo.complete' $cursorPosition json $commandAst.ToString() | ConvertFrom-Json | Sort-Object -Property value | ForEach-Object {
$hasdesc = [bool] $_.psobject.Properties['description']
$desc = $hasdesc ? " - $($_.description)" : ""
[System.Management.Automation.CompletionResult]::new($_.value, "$($_.value)$desc", 'ParameterValue', $_.value)
}
}
Register-ArgumentCompleter -Native -CommandName xrepo -ScriptBlock $xrepo_script
# xmake completion
$xmake_script = {
param($wordToComplete, $commandAst, $cursorPosition)
xmake lua 'private.utils.complete' $cursorPosition json $commandAst.ToString() | ConvertFrom-Json | Sort-Object -Property value | ForEach-Object {
$hasdesc = [bool] $_.psobject.Properties['description']
$desc = $hasdesc ? " - $($_.description)" : ""
[System.Management.Automation.CompletionResult]::new($_.value, "$($_.value)$desc", 'ParameterValue', $_.value)
}
}
Register-ArgumentCompleter -Native -CommandName xmake -ScriptBlock $xmake_script For Nu shell let external_completer = {|spans|
{
xmake: { XMAKE_SKIP_HISTORY=1 XMAKE_ROOT=y xmake lua 'private.utils.complete' 0 'nospace-json' $spans | from json | sort-by value }
xrepo: { xmake lua 'private.xrepo.complete' 0 'json' $spans | from json | sort-by value }
} | get $spans.0 | each {|it| do $it}
}
let-env config = {
# ...
completions: {
case_sensitive: false # set to true to enable case-sensitive completions
quick: true # set this to false to prevent auto-selecting completions when only one remains
partial: true # set this to false to prevent partial filling of the prompt
algorithm: "fuzzy" # prefix or fuzzy
external: {
enable: true # set to false to prevent nushell looking into $env.PATH to find more suggestions, `false` recommended for WSL users as this look up my be very slow
max_results: 100 # setting it lower can improve completion performance at the cost of omitting some options
completer: $external_completer # check 'carapace_completer' above as an example
}
}
# ...
} On Zsh (adapted from ~/.xmake/profile) # zsh parameter completion for xmake
_xmake_zsh_complete()
{
local completions=("$(XMAKE_SKIP_HISTORY=1 XMAKE_ROOT=y xmake lua private.utils.complete 0 nospace "$words")")
reply=( "${(ps:\n:)completions}" )
}
compctl -f -S "" -K _xmake_zsh_complete xmake
# zsh parameter completion for xrepo
_xrepo_zsh_complete()
{
local completions=("$(xmake lua private.xrepo.complete 0 nospace "$words")")
reply=( "${(ps:\n:)completions}" )
}
compctl -f -S "" -K _xrepo_zsh_complete xrepo |
I use my shell is bash. cd xmake
./configure
make
./scripts/get.sh __local__ __install_only__
xrepo install z -> tab .. |
I surely can implement xrepo completion in |
well, I need add this script to register-completions.sh
|
Yes, as the xrepo completion work like xmake completion, it should work just fine. Tell me, what are |
XMAKE_ROOT Allow users to use xmake under root mode. XMAKE_SKIP_HISTORY=1 skip xmake command record. |
I added complete in register-completions.sh, but I cannot add it in ps1, because I have no environment to test it. You can add and test it. |
Ok i'll do it, |
Try |
Add completion on packages for
xrepo install
command.Add a cache file to quick search over packages in repositories