Fix Elvish completions generation

The `display-suffix` option for `edit:complex-candidate` was [deprecated in Elvish v0.14.0][1] and
removed in v0.15.0 (latest version is v0.16.3), so this commit changes the Elvish completions
generation to use the `display` option instead.

Additionally, this commit changes assignments to use the `var` and `set` keywords as using
`name = value` without these keywords ('legacy assignment form') [will be deprecated][2].

[1]: https://elv.sh/blog/0.14.0-release-notes.html
[2]: https://elv.sh/ref/language.html#legacy-assignment-form
This commit is contained in:
cherryblossom 2021-09-24 22:22:17 +10:00
parent 5580e8c465
commit f77dceaf69
No known key found for this signature in database
GPG key ID: 03B34648D6DEB639
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'