Add -did-you-mean-limit:N

```
-did-you-mean-limit:<integer>
        Sets the maximum number of suggestions the compiler provides.
        Must be an integer >0.
        If not set, the default limit is 10.
```
e.g. with a limit of 5

```
W:/Scratch/main.odin(44:7) Error: Undeclared name 'B1' for type 'E'
	e = .B1
	     ^^
	Suggestion: Did you mean?
		A23
		A02
		A19
		A20
		A21
		... and 25 more ...
```
This commit is contained in:
Jeroen van Rijn
2026-02-13 15:15:03 +01:00
parent f7f19e5ebe
commit 6386b395de
3 changed files with 33 additions and 0 deletions

View File

@@ -153,13 +153,19 @@ gb_internal bool is_load_directive_call(Ast *call) {
gb_internal LoadDirectiveResult check_load_directive(CheckerContext *c, Operand *operand, Ast *call, Type *type_hint, bool err_on_not_found);
gb_internal void check_did_you_mean_print(DidYouMeanAnswers *d, char const *prefix = "") {
int limit = build_context.did_you_mean_limit;
auto results = did_you_mean_results(d);
int count = 0;
if (results.count != 0) {
error_line("\tSuggestion: Did you mean?\n");
for (auto const &result : results) {
String const &target = result.target;
error_line("\t\t%s%.*s\n", prefix, LIT(target));
// error_line("\t\t%.*s %td\n", LIT(target), results[i].distance);
if (limit > 0 && ++count == limit) {
error_line("\t\t... and %td more ...", results.count - limit);
break;
}
}
}
}