You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using custom completions, the docs suggest to retrieve the correct value from a record based on the context key. If however they choose to use an if statement to select the correct list of completions, it will fail.
What is most peculiar is the lack of consistency by which it will fail. Some examples below will cause an error, some will not.
How to reproduce
Create a module file /tmp/example.nu
Fill /tmp/example.nu with the given contents:
def"nu-complete example top-level-values" [] nothing->list<str> {
[
"bools.are-funky""it-aint.work-for-bools""bad-is.boolean""numbers-work-fine""get-some.numbers-alright""paths-play-funny""paths.not-friendly"
]
}
def"nu-complete example sub-values" [context: string] nothing->list<any> {
let$final_context:string= ($context|str trim|split row""|last)
if ($final_contextin [ # These are boolean types"bools.are-funky""it-aint.work-for-bools""bad-is.boolean"
]) {
["\"true\"", "\"false\""]
} else if ($final_contextin ["numbers-work-fine", "get-some.numbers-alright"]) {
[568101214162024323236525684100104]
} else if ($final_contextin ["paths-play-funny"] or$final_context=="paths.not-friendly") {
(ls|getname|where (($it|path type) =="dir") |each {|it| $it|pathexpand}) |append (
if (((sys).host.name|str downcase|str ends-with"macos") or ((sys).host.name|str downcase|str ends-with"osx")) {
$env.HOME|path join"Library/Caches/brokenexample"
} else if ((sys).host.name|str downcase|str ends-with"windows") {
$env.HOME|path join"AppData/Local/brokenexample/Cache"
} else if ("XDG_CACHE_HOME"in$env) {
$env.XDG_CACHE_HOME|path join"brokenexample"
} else {
$env.HOME|path join".cache/brokenexample"
}
)
}
}
# An example extern that has a broken custom completionexport extern"example" [
top_level_value: string@"nu-complete example top-level-values"# Pick a top_level_value.sub_value: any@"nu-complete example sub-values"# Pick a sub_value based on a top_level_value.
]
Run use /tmp/example.nu * in the nushell terminal
Type example , custom completions will be successful for the top_level_value
Pick one of boolean suggested top_level_values
Attempt tab-completion, it will fail after the first quotemark and present NO RECORDS FOUND
Pick one of the number suggested top_level_values
Attempt tab-completion, it will succeed at displaying all the numbers in the list
Pick one of the path suggested top_level_values
Attempt tab-completion, it will fail after the first matching set of base paths and present NO RECORDS FOUND (E.g. if the list of paths has multiple values that start /home/matt/ that is where it will complete to
Expected behavior
Boolean values are presented correctly and allowed to be autocompleted (E.g. "true", "false")
Path values are presented correctly and allowed to be autocompleted
dataframe, default, sqlite, static-link-openssl, system-clipboard, trash, which
installed_plugins
Additional context
I have attempted to provide enough different values such that these can be ruled out for the error. I suspect there is something going wrong with the if statements and changing the condition from an in to == sometimes fixes the issues.
The text was updated successfully, but these errors were encountered:
Describe the bug
When using custom completions, the docs suggest to retrieve the correct value from a record based on the context key. If however they choose to use an
if
statement to select the correct list of completions, it will fail.What is most peculiar is the lack of consistency by which it will fail. Some examples below will cause an error, some will not.
How to reproduce
/tmp/example.nu
/tmp/example.nu
with the given contents:use /tmp/example.nu *
in the nushell terminalexample
, custom completions will be successful for thetop_level_value
top_level_values
NO RECORDS FOUND
top_level_values
top_level_values
NO RECORDS FOUND
(E.g. if the list of paths has multiple values that start/home/matt/
that is where it will complete toExpected behavior
"true"
,"false"
)Screenshots
Configuration
Additional context
I have attempted to provide enough different values such that these can be ruled out for the error. I suspect there is something going wrong with the
if
statements and changing the condition from anin
to==
sometimes fixes the issues.The text was updated successfully, but these errors were encountered: