Skip to content

Commit 2c800ff

Browse files
committed
don't crash if same hero is specified twice in a query
1 parent 878d948 commit 2c800ff

2 files changed

Lines changed: 13 additions & 17 deletions

File tree

DataTool/Helper/ScopedSpellCheck.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ private void CommitSpellCheck() {
2727
}
2828

2929
public string? TryGetSuggestion(string? text) {
30-
CommitSpellCheck();
31-
3230
if (text == null || text == "*") {
3331
// nothing to check
3432
return null;
3533
}
34+
35+
CommitSpellCheck();
3636

3737
var correctedStr = m_symSpell!.Lookup(text, SymSpell.Verbosity.Closest);
3838
if (correctedStr.Count == 0 || correctedStr[0].term == text) {
@@ -47,6 +47,6 @@ public void LogSpellCheck(string? text) {
4747
var suggestion = TryGetSuggestion(text);
4848
if (suggestion == null) return;
4949

50-
Warn("SpellCheck", $"Did you mean \"{suggestion}\"?");
50+
Warn("SpellCheck", $"Did you mean \"{suggestion}\" ?");
5151
}
5252
}

DataTool/IQueryParser.cs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -90,17 +90,13 @@ public bool ShouldDo(string name, Dictionary<string, TagExpectedValue>? expected
9090
}
9191

9292
public record ParsedHero {
93-
public required Dictionary<string, ParsedArg> Types;
93+
public readonly IgnoreCaseDict<ParsedArg> Types = [];
9494
public bool Matched = false;
9595
}
9696

9797
public class ParsedNameSet {
98-
private readonly IgnoreCaseDict<ParsedName> Map;
98+
private readonly IgnoreCaseDict<ParsedName> Map = [];
9999
public int Count => Map.Count;
100-
101-
public ParsedNameSet() {
102-
Map = new IgnoreCaseDict<ParsedName>();
103-
}
104100

105101
public void Add(ReadOnlySpan<char> value) {
106102
Add(value.ToString());
@@ -309,7 +305,7 @@ protected virtual void QueryHelp(List<QueryType> types) {
309305
}
310306
}
311307

312-
protected Dictionary<string, ParsedHero>? ParseQuery(
308+
protected IgnoreCaseDict<ParsedHero>? ParseQuery(
313309
ICLIFlags flags,
314310
List<QueryType> queryTypes,
315311
IgnoreCaseDict<string>? queryNameOverrides = null,
@@ -335,7 +331,7 @@ protected virtual void QueryHelp(List<QueryType> types) {
335331
var inputArguments = flags.Positionals.AsSpan(3);
336332
if (inputArguments.Length == 0) return null;
337333

338-
Dictionary<string, ParsedHero> output = new IgnoreCaseDict<ParsedHero>();
334+
var output = new IgnoreCaseDict<ParsedHero>();
339335

340336
foreach (string opt in inputArguments) {
341337
if (opt.StartsWith("--")) continue; // ok so this is a flag
@@ -351,10 +347,10 @@ protected virtual void QueryHelp(List<QueryType> types) {
351347
hero = nameForThisLocale;
352348
}
353349

354-
var heroOutput = new IgnoreCaseDict<ParsedArg>();
355-
output[hero] = new ParsedHero {
356-
Types = heroOutput
357-
};
350+
if (!output.TryGetValue(hero, out var parsedHero)) {
351+
parsedHero = new ParsedHero();
352+
output.Add(hero, parsedHero);
353+
}
358354

359355
var afterHero = split.AsSpan(1);
360356
if (afterHero.Length == 0) {
@@ -365,7 +361,7 @@ protected virtual void QueryHelp(List<QueryType> types) {
365361
var parsedArg = new ParsedArg(type);
366362
PopulateDefaultTags(type, parsedArg);
367363

368-
heroOutput.Add(type.Name, parsedArg);
364+
parsedHero.Types.Add(type.Name, parsedArg);
369365
}
370366
continue;
371367
}
@@ -388,7 +384,7 @@ protected virtual void QueryHelp(List<QueryType> types) {
388384

389385
foreach (QueryType queryType in typesMatchingName) {
390386
var parsedArg = new ParsedArg(queryType);
391-
heroOutput.Add(queryType.Name, parsedArg);
387+
parsedHero.Types.Add(queryType.Name, parsedArg);
392388
// todo: using .Add here can of course fail but we would previously only use the 2nd occurrence.. its better to explode
393389

394390
// todo: rewrite this parse loop...

0 commit comments

Comments
 (0)