Repository navigation
The extension shows no text for a resource name that comes before a longer name on the same line #61
Description
Describe the bug
A line can use the resource files Strings and Resources. When the shorter name comes first, the first resource gets no text. For Strings.A + Resources.B, only Resources.B gets its text. For Strings.A, Resources.B, Strings.C, the first Strings.A gets no text.
Where
IndexOfAnyAsync returns the first occurrence of the longest name that is in the rest of the line. It does not return the earliest occurrence:
StringResourceVisualizer/src/StringExtensions.cs
Lines 18 to 31 in ee1f1bf
| var valuePositions = new Dictionary<string, int>(); | |
| // Values may be duplicated if multiple apps in the project have resources with the same name. | |
| foreach (var value in values.Distinct()) | |
| { | |
| valuePositions.Add(value, source.IndexOf(value)); | |
| } | |
| if (valuePositions.Any(v => v.Value > -1)) | |
| { | |
| var result = valuePositions.Where(v => v.Value > -1).OrderByDescending(v => v.Key.Length).FirstOrDefault().Value; | |
| return result; | |
| } |
GetAllIndexesAsync continues after that index. The method skips a shorter name that is earlier:
StringResourceVisualizer/src/StringExtensions.cs
Lines 52 to 67 in ee1f1bf
| var startPos = 0; | |
| while (startPos > -1 && startPos <= source.Length) | |
| { | |
| var index = await source.Substring(startPos).IndexOfAnyAsync(values); | |
| if (index > -1) | |
| { | |
| result.Add(startPos + index); | |
| startPos = startPos + index + 1; | |
| } | |
| else | |
| { | |
| break; | |
| } | |
| } |
To Reproduce
- Add the key
AtoStrings.resxand the keyBtoResources.resx. - In a C# file, write the line
var text = Strings.A + Resources.B;. - Look at the line.
Actual behavior
Only Resources.B shows its text.
Expected behavior
Both names show their text, from left to right.
Installed product versions
- Visual Studio: not applicable. The tests in pull request Find a resource name that comes before a longer one on the same line #52 show the problem.
- This extension:
mainat commit ee1f1bf (version 1.23.3). The links in this report point to fixed commits.
Additional context
Pull request #52 fixes this problem. Four of its tests fail without the fix.
Activity