Skip to content

The extension shows no text for a resource name that comes before a longer name on the same line #61

Open

Description

@xperiandri

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:

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:

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

  1. Add the key A to Strings.resx and the key B to Resources.resx.
  2. In a C# file, write the line var text = Strings.A + Resources.B;.
  3. 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

Additional context

Pull request #52 fixes this problem. Four of its tests fail without the fix.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions