feat: add argument tab-completion for extension slash commands

Extensions can now provide a Complete function on CommandDef that supplies
argument suggestions. When the user types a command name followed by a space,
the input popup switches to argument-completion mode, calling Complete with
the partial text and displaying matching suggestions.
This commit is contained in:
Ed Zynda
2026-03-02 15:37:52 +03:00
parent 37e82781b1
commit c40dc2f4fb
6 changed files with 118 additions and 10 deletions
+22
View File
@@ -48,6 +48,28 @@ func Init(api ext.API) {
ctx.PrintInfo(fmt.Sprintf("Bookmarked: %s (at message %d)", label, len(msgs)))
return "", nil
},
Complete: func(prefix string, ctx ext.Context) []string {
// Suggest existing bookmark labels so the user can quickly
// re-bookmark at the same label.
entries := ctx.GetEntries("bookmark")
var labels []string
seen := map[string]bool{}
for _, e := range entries {
var data map[string]any
if err := json.Unmarshal([]byte(e.Data), &data); err != nil {
continue
}
label, _ := data["label"].(string)
if label == "" || seen[label] {
continue
}
if prefix == "" || strings.HasPrefix(strings.ToLower(label), strings.ToLower(prefix)) {
labels = append(labels, label)
seen[label] = true
}
}
return labels
},
})
api.RegisterCommand(ext.CommandDef{