Skip to content

Extend did-you-mean suggester to flags and enum values (#1582) - #2232

Merged
Widthdom merged 8 commits into
mainfrom
fix-issue1582
May 16, 2026
Merged

Extend did-you-mean suggester to flags and enum values (#1582)#2232
Widthdom merged 8 commits into
mainfrom
fix-issue1582

Conversation

@Widthdom

Copy link
Copy Markdown
Owner

Summary

  • Extends the existing Damerau-Levenshtein "Did you mean" suggester (previously only used by the subcommand router in ConsoleUi) to unknown long flags on index, backfill-fold, find, and every search / graph query family path that already reports "is not supported" — handles both --paht src/** and inline --paht=src/** forms.
  • Wires WriteLangHint, WriteKindHint, WriteGraphReferenceKindHint, and a new WriteValidateKindHint into the existing zero-result / unknown-value branches so typos in --lang, --kind, and graph reference-kind values now print Did you mean: ... to stderr. WriteLangHint falls back to ReferenceExtractor.GetSupportedLanguages() when the indexed-language set is empty, and suppresses self-suggestions when the closest candidate equals the user's input.
  • MCP error responses for unknown enumerated values (currently the suggest_improvement category argument) now also carry a structured result.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.
  • Manual CLI smoke against the local index:
    • cdidx index --rebildDid 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.csDid you mean: --path?
    • cdidx search foo --lang csarpDid you mean: --lang csharp?
    • cdidx search foo --lang java (Java not indexed) → no self-suggestion.
    • cdidx validate --kind replacement_chraDid you mean: --kind replacement_char?

Documentation / changelog

  • changelog.d/unreleased/1582.changed.md — bilingual fragment describing the new "Did you mean" coverage, the inline =value handling, the language fallback, the validate --kind allowlist, and the MCP result.data.similar_values payload.

Adversarial review

Two adversarial-review rounds with Codex were completed per .codex/workflows/issue-fix.md:

  • Round 1 surfaced three findings (no language suggestion in RunSearch, missing find/inline-=value handling, silent validate --kind typo). All addressed in commit e6403a7d.
  • Round 2 surfaced one regression (WriteLangHint could self-suggest when the user supplied a supported-but-not-indexed language). Addressed in commit 2a2e13fd, with a RunSearch_LangNotIndexedButSupported_DoesNotSelfSuggest_Issue1582 regression test.

After Round 2, --watch / --debounce from the freshly-merged origin/main were also added to AcceptedIndexFlags to keep the suggester aligned with the parser's switch cases (commit 563b0461).

Follow-up candidates

  • None — every accepted-flag array and enum allowlist on this branch was verified against the live parser/indexer at HEAD.

Widthdom and others added 8 commits May 16, 2026 14:13
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
@Widthdom
Widthdom merged commit cd5f51e into main May 16, 2026
7 checks passed
@Widthdom
Widthdom deleted the fix-issue1582 branch May 16, 2026 16:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Did-you-mean suggestions limited to subcommands; absent for flags and values

1 participant