Merge pull request #2783 from cherryblossom000/elvish-completions-fix

Fix Elvish completions generation
This commit is contained in:
Pavan Kumar Sunkara 2021-09-24 14:39:00 +01:00 committed by GitHub
commit 9c214a66dc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 20 deletions

View file

@ -25,21 +25,21 @@ impl Generator for Elvish {
use builtin; use builtin;
use str; use str;
edit:completion:arg-completer[{bin_name}] = [@words]{{ set edit:completion:arg-completer[{bin_name}] = [@words]{{
fn spaces [n]{{ fn spaces [n]{{
builtin:repeat $n ' ' | str:join '' builtin:repeat $n ' ' | str:join ''
}} }}
fn cand [text desc]{{ fn cand [text desc]{{
edit:complex-candidate $text &display-suffix=' '(spaces (- 14 (wcswidth $text)))$desc edit:complex-candidate $text &display=$text' '(spaces (- 14 (wcswidth $text)))$desc
}} }}
command = '{bin_name}' var command = '{bin_name}'
for word $words[1..-1] {{ for word $words[1..-1] {{
if (str:has-prefix $word '-') {{ if (str:has-prefix $word '-') {{
break break
}} }}
command = $command';'$word set command = $command';'$word
}} }}
completions = [{subcommands_cases} var completions = [{subcommands_cases}
] ]
$completions[$command] $completions[$command]
}} }}

View file

@ -32,21 +32,21 @@ static ELVISH: &str = r#"
use builtin; use builtin;
use str; use str;
edit:completion:arg-completer[my_app] = [@words]{ set edit:completion:arg-completer[my_app] = [@words]{
fn spaces [n]{ fn spaces [n]{
builtin:repeat $n ' ' | str:join '' builtin:repeat $n ' ' | str:join ''
} }
fn cand [text desc]{ fn cand [text desc]{
edit:complex-candidate $text &display-suffix=' '(spaces (- 14 (wcswidth $text)))$desc edit:complex-candidate $text &display=$text' '(spaces (- 14 (wcswidth $text)))$desc
} }
command = 'my_app' var command = 'my_app'
for word $words[1..-1] { for word $words[1..-1] {
if (str:has-prefix $word '-') { if (str:has-prefix $word '-') {
break break
} }
command = $command';'$word set command = $command';'$word
} }
completions = [ var completions = [
&'my_app'= { &'my_app'= {
cand -h 'Print help information' cand -h 'Print help information'
cand --help 'Print help information' cand --help 'Print help information'
@ -96,21 +96,21 @@ static ELVISH_SPECIAL_CMDS: &str = r#"
use builtin; use builtin;
use str; use str;
edit:completion:arg-completer[my_app] = [@words]{ set edit:completion:arg-completer[my_app] = [@words]{
fn spaces [n]{ fn spaces [n]{
builtin:repeat $n ' ' | str:join '' builtin:repeat $n ' ' | str:join ''
} }
fn cand [text desc]{ fn cand [text desc]{
edit:complex-candidate $text &display-suffix=' '(spaces (- 14 (wcswidth $text)))$desc edit:complex-candidate $text &display=$text' '(spaces (- 14 (wcswidth $text)))$desc
} }
command = 'my_app' var command = 'my_app'
for word $words[1..-1] { for word $words[1..-1] {
if (str:has-prefix $word '-') { if (str:has-prefix $word '-') {
break break
} }
command = $command';'$word set command = $command';'$word
} }
completions = [ var completions = [
&'my_app'= { &'my_app'= {
cand -h 'Print help information' cand -h 'Print help information'
cand --help 'Print help information' cand --help 'Print help information'
@ -185,21 +185,21 @@ static ELVISH_ALIASES: &str = r#"
use builtin; use builtin;
use str; use str;
edit:completion:arg-completer[cmd] = [@words]{ set edit:completion:arg-completer[cmd] = [@words]{
fn spaces [n]{ fn spaces [n]{
builtin:repeat $n ' ' | str:join '' builtin:repeat $n ' ' | str:join ''
} }
fn cand [text desc]{ fn cand [text desc]{
edit:complex-candidate $text &display-suffix=' '(spaces (- 14 (wcswidth $text)))$desc edit:complex-candidate $text &display=$text' '(spaces (- 14 (wcswidth $text)))$desc
} }
command = 'cmd' var command = 'cmd'
for word $words[1..-1] { for word $words[1..-1] {
if (str:has-prefix $word '-') { if (str:has-prefix $word '-') {
break break
} }
command = $command';'$word set command = $command';'$word
} }
completions = [ var completions = [
&'cmd'= { &'cmd'= {
cand -o 'cmd option' cand -o 'cmd option'
cand -O 'cmd option' cand -O 'cmd option'