Extend did-you-mean suggester to flags and enum values (#1582) - #2232
Merged
Conversation
Generalize the existing Damerau-Levenshtein subcommand suggester into a reusable ConsoleUi.FindClosestMatch / FindClosestMatches helper, and wire it into the unknown long-flag warnings on index / backfill-fold / search plus --lang / --kind / graph reference-kind enum-value errors. MCP error responses for unknown enumerated values now also carry a structured result.data.similar_values array next to the human-readable "Did you mean" text so MCP clients can offer one-tap recovery without parsing the message string. Same length-aware threshold is reused so off-by-many tokens still print no suggestion. Fixes #1582
- RunSearch: call WriteLangHint in the zero-result branch so `search foo --lang csarp` surfaces `Did you mean: --lang csharp?`. - WriteLangHint: fall back to ReferenceExtractor.GetSupportedLanguages() when the indexed-language set has no match (or is empty for a fresh index), so the suggester works regardless of DB state. - The `find` unsupported-option path + search inline `--foo=bar` form: strip the `=value` portion before matching so `--paht`, `--paht=src`, and `search --paht=src/**` all suggest `--path`. - validate --kind: introduce AllValidValidateKinds allowlist + new WriteValidateKindHint so typos like `--kind replacement_chra` no longer silently mimic a clean repo. - AllValidValidateKinds includes utf16_bom to match FileIndexer emissions. - Tests for the four new behaviors plus updated bilingual changelog. Issue: #1582 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
After round-2 added a `ReferenceExtractor.GetSupportedLanguages()` fallback to `WriteLangHint`, supplying a supported-but-not-indexed language (e.g. `--lang java` against a Java-free repo) would print `Did you mean: --lang java?` because `FindClosestMatch` returns the input verbatim when it is a member of the candidate set. Suppress the "Did you mean" line when the suggested value equals the user-supplied value (case-insensitive). Regression test inserts a csharp-only index and asserts the hint fires without the self-suggestion line. Issue: #1582 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
After merging origin/main, `index` accepts two additional flags (`--watch` and `--debounce`) introduced by the IndexWatchRunner work on main but the AcceptedIndexFlags array on this branch did not include them. That would have caused `cdidx index --waatch` to either emit no suggestion or, worse, suggest a less-similar but listed flag. Add both so the suggestion array is consistent with the parser switch cases. Issue: #1582 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
# Conflicts: # src/CodeIndex/Mcp/McpServer.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ConsoleUi) to unknown long flags onindex,backfill-fold,find, and everysearch/ graph query family path that already reports "is not supported" — handles both--paht src/**and inline--paht=src/**forms.WriteLangHint,WriteKindHint,WriteGraphReferenceKindHint, and a newWriteValidateKindHintinto the existing zero-result / unknown-value branches so typos in--lang,--kind, and graph reference-kind values now printDid you mean: ...to stderr.WriteLangHintfalls back toReferenceExtractor.GetSupportedLanguages()when the indexed-language set is empty, and suppresses self-suggestions when the closest candidate equals the user's input.suggest_improvementcategoryargument) now also carry a structuredresult.data.similar_values: [...]array next to the human-readable text so MCP clients can offer one-tap recovery without parsing the message string.Fixes #1582
Validation
dotnet build -c Release— 0 errors, 0 warnings.dotnet test -c Release— 5088 passed, 3 skipped, 0 failed.cdidx index --rebild→Did you mean: --rebuild?cdidx search foo --paht src/**→Did you mean: --path?cdidx search foo --paht=src/**→Did you mean: --path?cdidx find guard --paht src/Auth.cs→Did you mean: --path?cdidx search foo --lang csarp→Did you mean: --lang csharp?cdidx search foo --lang java(Java not indexed) → no self-suggestion.cdidx validate --kind replacement_chra→Did you mean: --kind replacement_char?Documentation / changelog
changelog.d/unreleased/1582.changed.md— bilingual fragment describing the new "Did you mean" coverage, the inline=valuehandling, the language fallback, thevalidate --kindallowlist, and the MCPresult.data.similar_valuespayload.Adversarial review
Two adversarial-review rounds with Codex were completed per
.codex/workflows/issue-fix.md:RunSearch, missingfind/inline-=valuehandling, silentvalidate --kindtypo). All addressed in commite6403a7d.WriteLangHintcould self-suggest when the user supplied a supported-but-not-indexed language). Addressed in commit2a2e13fd, with aRunSearch_LangNotIndexedButSupported_DoesNotSelfSuggest_Issue1582regression test.After Round 2,
--watch/--debouncefrom the freshly-mergedorigin/mainwere also added toAcceptedIndexFlagsto keep the suggester aligned with the parser's switch cases (commit563b0461).Follow-up candidates