Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,14 @@ protected override void ExecuteCore(RazorCodeDocument codeDocument)
var usingReferences = new List<UsingReference>(visitor.Usings);
for (var j = importedUsings.Count - 1; j >= 0; j--)
{
if (!usingReferences.Contains(importedUsings[j]))
var importedUsing = importedUsings[j];
if (!usingReferences.Contains(importedUsing) &&
// If the using is from the default import, avoid adding it
// if a user using exists which is the same except for the `global::` prefix.
(!TryRemoveGlobalPrefixFromDefaultUsing(in importedUsing, out var trimmedUsing) ||
!usingReferences.Contains(trimmedUsing)))
{
usingReferences.Insert(0, importedUsings[j]);
usingReferences.Insert(0, importedUsing);
}
}

Expand Down Expand Up @@ -125,6 +130,21 @@ protected override void ExecuteCore(RazorCodeDocument codeDocument)
}

codeDocument.SetDocumentIntermediateNode(document);

static bool TryRemoveGlobalPrefixFromDefaultUsing(in UsingReference usingReference, out UsingReference trimmed)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 It's difficult to review the impact of this change in isolation because baselines weren't updated with each change

Copy link
Member Author

@jjonescz jjonescz Feb 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's because this change caused failures - there was a new warning about duplicate usings in the new tests. I don't think anything changed in the old tests. But I could verify that.

{
const string globalPrefix = "global::";
if (usingReference.Source is { FilePath: null } && // the default import has null file path
usingReference.Namespace.StartsWith(globalPrefix, StringComparison.Ordinal))
{
trimmed = new UsingReference(
usingReference.Namespace.Substring(globalPrefix.Length),
usingReference.Source);
return true;
}
trimmed = usingReference;
return false;
}
}

private IReadOnlyList<UsingReference> ImportDirectives(
Expand Down