Index completion metadata by canonical node

This commit is contained in:
2026-11-03 13:13:20 +00:00
parent 5227049de6
commit f4ed4c4839
5 changed files with 25 additions and 18 deletions

View File

@@ -26,7 +26,7 @@ func resolveCompletionContext(snapshot *routingSnapshot, completed []string, cur
context.route = resolveEnteredRoute(completed, snapshot)
switch context.route.kind {
case routeCanonical:
context.command = completionCommand(snapshot.metadata, context.route.canonicalPath)
context.command = completionCommand(snapshot, context.route.canonicalPath)
if context.command == nil || len(context.route.args) < len(context.route.canonicalPath) {
context.command = nil
return context
@@ -42,22 +42,20 @@ func resolveCompletionContext(snapshot *routingSnapshot, completed []string, cur
return context
}
func completionCommand(root *commandmeta.Command, path commandpath.Path) *commandmeta.Command {
current := root
func completionCommand(snapshot *routingSnapshot, path commandpath.Path) *commandmeta.Command {
if len(path) == 0 {
return snapshot.metadata
}
children := snapshot.canonical
var node *canonicalNode
for _, name := range path {
if current == nil {
node = children[name]
if node == nil {
return nil
}
var next *commandmeta.Command
for _, child := range current.Children {
if child.Name == name {
next = child
break
}
}
current = next
children = node.children
}
return current
return node.metadata
}
func completionChildren(snapshot *routingSnapshot, context completionContext) []commandmeta.CompletionChoice {