Restore comparability of completion metadata
This commit is contained in:
@@ -61,7 +61,12 @@ type CompletionChoice struct {
|
||||
// value requests no value suggestions; hints do not constrain accepted input.
|
||||
type CompletionHint struct {
|
||||
kind completionHintKind
|
||||
choices []CompletionChoice
|
||||
choices *completionChoicesData
|
||||
}
|
||||
|
||||
// Keep the public metadata structs comparable without exposing mutable choices.
|
||||
type completionChoicesData struct {
|
||||
values []CompletionChoice
|
||||
}
|
||||
|
||||
type completionHintKind uint8
|
||||
@@ -78,7 +83,11 @@ const (
|
||||
// values and values containing a newline, tab, or NUL cannot be presented as
|
||||
// suggestions, but remain valid input if the command's converter accepts them.
|
||||
func CompleteChoices(choices ...CompletionChoice) CompletionHint {
|
||||
return CompletionHint{kind: completionChoices, choices: append([]CompletionChoice(nil), choices...)}
|
||||
hint := CompletionHint{kind: completionChoices}
|
||||
if len(choices) != 0 {
|
||||
hint.choices = &completionChoicesData{values: append([]CompletionChoice(nil), choices...)}
|
||||
}
|
||||
return hint
|
||||
}
|
||||
|
||||
// CompleteFiles requests shell filename completion.
|
||||
@@ -95,7 +104,10 @@ func bridgeCompletion(hint CompletionHint) commandmeta.CompletionHint {
|
||||
switch hint.kind {
|
||||
case completionChoices:
|
||||
result.Kind = commandmeta.CompletionChoices
|
||||
for _, choice := range hint.choices {
|
||||
if hint.choices == nil {
|
||||
break
|
||||
}
|
||||
for _, choice := range hint.choices.values {
|
||||
result.Choices = append(result.Choices, commandmeta.CompletionChoice{Value: choice.Value, Description: choice.Description})
|
||||
}
|
||||
case completionFiles:
|
||||
|
||||
Reference in New Issue
Block a user