Skip sorting flag aliases during completion

This commit is contained in:
2026-11-03 13:15:21 +00:00
parent f4ed4c4839
commit 0acbbf45ad
3 changed files with 33 additions and 8 deletions

View File

@@ -32,12 +32,12 @@ func resolveCompletionContext(snapshot *routingSnapshot, completed []string, cur
return context return context
} }
context.tail = append([]string(nil), context.route.args[len(context.route.canonicalPath):]...) context.tail = append([]string(nil), context.route.args[len(context.route.canonicalPath):]...)
context.aliases = snapshot.flagAliases[context.route.canonicalPath.Key()].neutralRecords() context.aliases = snapshot.flagAliases[context.route.canonicalPath.Key()].lookupRecords()
context.commandPosition = len(context.tail) == 0 context.commandPosition = len(context.tail) == 0
case routeDiscovery: case routeDiscovery:
context.command = &commandmeta.Command{CoreFlags: commandmeta.ReportingFlags()} context.command = &commandmeta.Command{CoreFlags: commandmeta.ReportingFlags()}
context.tail = append([]string(nil), context.route.args...) context.tail = append([]string(nil), context.route.args...)
context.aliases = snapshot.discoveryFlags[context.route.discoveryPath.Key()].neutralRecords() context.aliases = snapshot.discoveryFlags[context.route.discoveryPath.Key()].lookupRecords()
} }
return context return context
} }

View File

@@ -1,7 +1,7 @@
# Shell completion audit remediation # Shell completion audit remediation
Status: six fixes open; two efficiency findings for consideration. The completed invocation reporting audit is retained Status: all eight shell completion findings addressed. The completed
below as historical evidence. invocation reporting audit is retained below as historical evidence.
## Completion review scope ## Completion review scope
@@ -133,7 +133,7 @@ even with `--quiet --debug` in the target words. The equivalent ordinary
inspection with `--quiet` stayed silent. ConfigKit completion included inspection with `--quiet` stayed silent. ConfigKit completion included
`app` and `promptkit` for diff, and additionally `all` for validate, matching `app` and `promptkit` for diff, and additionally `all` for validate, matching
the installed capabilities. No new discrepancy was found in these paths. the installed capabilities. No new discrepancy was found in these paths.
The transport and public metadata findings above remain open. The transport and public metadata findings were open at that review.
### 6. Supply the existing PromptKit smoke kinds as operand hints ### 6. Supply the existing PromptKit smoke kinds as operand hints
@@ -165,7 +165,7 @@ encoding are linear in the candidates and text they inspect or emit. Stage 4
expressly requires checking each suggested child against ordinary alias routing; expressly requires checking each suggested child against ordinary alias routing;
this review does not propose removing or replacing that check. No additional this review does not propose removing or replacing that check. No additional
correctness defect or newly introduced quadratic algorithm was identified within correctness defect or newly introduced quadratic algorithm was identified within
the remaining scope. The six existing findings remain open. the remaining scope. The six existing findings were open at that review.
### 7. Look up canonical completion metadata without scanning siblings ### 7. Look up canonical completion metadata without scanning siblings
@@ -190,7 +190,9 @@ refresh and the selected candidate insertion checks.
### 8. Avoid sorting resolved flag aliases on every completion query ### 8. Avoid sorting resolved flag aliases on every completion query
Priority: P3. Status: for consideration. Priority: P3. Status: complete.
- [x] Completed: Completion builds its lookup records directly from unique resolved aliases in linear time. Existing help ordering is unchanged; scoped and discovery completion checks pass.
[resolveCompletionContext](../../completion_context.go) calls [resolveCompletionContext](../../completion_context.go) calls
[neutralRecords](../../flag_aliases.go) for the selected canonical or discovery [neutralRecords](../../flag_aliases.go) for the selected canonical or discovery
@@ -207,6 +209,15 @@ display order matters and preserve scoped precedence and target availability.
This is a source-level opportunity; no latency or allocation threshold is This is a source-level opportunity; no latency or allocation threshold is
proposed. proposed.
## Shell completion remediation validation
The root and both optional module suites passed in the local workspace, and
the root suite passed with `GOWORK=off`. Both opt-in interactive completion
suites passed with Bash 5.3.9, Zsh 5.9, and Fish 4.2.1. They cover literal
Tab-only input, actual edited arguments, attached and whole-word completion,
path hints, descriptions, and control-like literal choices. The ignored
workspace and module dependency versions were preserved.
--- ---
## Historical invocation reporting audit remediation ## Historical invocation reporting audit remediation

View File

@@ -38,11 +38,25 @@ func (aliases resolvedFlagAliases) neutralRecords() []commandmeta.FlagAlias {
records := make([]commandmeta.FlagAlias, 0, len(keys)) records := make([]commandmeta.FlagAlias, 0, len(keys))
for _, key := range keys { for _, key := range keys {
alias := aliases.bySpelling[key] alias := aliases.bySpelling[key]
records = append(records, commandmeta.FlagAlias{Source: alias.source.token(), Target: alias.target.token()}) records = append(records, alias.neutralRecord())
} }
return records return records
} }
// lookupRecords skips sorting: resolved source spellings are unique and the
// parser's lookup does not depend on record order.
func (aliases resolvedFlagAliases) lookupRecords() []commandmeta.FlagAlias {
records := make([]commandmeta.FlagAlias, 0, len(aliases.bySpelling))
for _, alias := range aliases.bySpelling {
records = append(records, alias.neutralRecord())
}
return records
}
func (alias resolvedFlagAlias) neutralRecord() commandmeta.FlagAlias {
return commandmeta.FlagAlias{Source: alias.source.token(), Target: alias.target.token()}
}
func (spelling capturedFlagSpelling) token() string { func (spelling capturedFlagSpelling) token() string {
if spelling.short { if spelling.short {
return "-" + spelling.name return "-" + spelling.name