Skip to content

Comments

Don't replace the slashes in hint names#12477

Merged
chsienki merged 9 commits intodotnet:mainfrom
chsienki:fix/hint_names
Nov 19, 2025
Merged

Don't replace the slashes in hint names#12477
chsienki merged 9 commits intodotnet:mainfrom
chsienki:fix/hint_names

Conversation

@chsienki
Copy link
Member

@chsienki chsienki commented Nov 11, 2025

Fixes #11578

When the generator was originally written slashes were not allowed in hint names. That restriction was subsequently lifted, and they are valid parts of a hint name now. See here.

@chsienki chsienki requested a review from a team as a code owner November 11, 2025 23:00
{
switch (filePath[i])
{
case ':' or '\\' or '/':
Copy link
Member Author

Choose a reason for hiding this comment

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

':' is covered by the case below anyway.

Copy link
Member

@davidwengier davidwengier left a comment

Choose a reason for hiding this comment

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

I would have thought tests in ComputedTargetPathTest.cs would fail with this, at least.

Either way, can you add this test. I haven't run it, obviously, but it fails without your change, and I think it should pass with it.

    [Theory]
    [InlineData(true, false)]
    [InlineData(true, true)]
    [InlineData(false, false)]
    public async Task TwoDocumentsWithTheSameBaseHintName(bool projectPath, bool generateConfigFile)
    {
        var builder = new RazorProjectBuilder
        {
            ProjectFilePath = projectPath ? TestProjectData.SomeProject.FilePath : null,
            GenerateGlobalConfigFile = generateConfigFile,
            GenerateAdditionalDocumentMetadata = false,
            GenerateMSBuildProjectDirectory = false
        };

        var doc1Id = builder.AddAdditionalDocument(FilePath(@"Pages\Index.razor"), SourceText.From(""));
        var doc2Id = builder.AddAdditionalDocument(FilePath(@"Pages_Index.razor"), SourceText.From(""));

        var solution = LocalWorkspace.CurrentSolution;
        solution = builder.Build(solution);

        var doc1 = solution.GetAdditionalDocument(doc1Id).AssumeNotNull();
        var doc2 = solution.GetAdditionalDocument(doc2Id).AssumeNotNull();

        var generatedDocument = await doc1.Project.TryGetSourceGeneratedDocumentForRazorDocumentAsync(doc1, DisposalToken);
        Assert.NotNull(generatedDocument);
        Assert.Equal($"{s_hintNamePrefix}_Pages\\Index_razor.g.cs", generatedDocument.HintName);

        generatedDocument = await doc2.Project.TryGetSourceGeneratedDocumentForRazorDocumentAsync(doc2, DisposalToken);
        Assert.NotNull(generatedDocument);
        Assert.Equal($"{s_hintNamePrefix}_Pages_Index_razor.g.cs", generatedDocument.HintName);
    }

@chsienki
Copy link
Member Author

@davidwengier Ah they do, I just didn't see them because I was only running the net8.0 tests. Will add the extra test.

Copy link
Member

@davidwengier davidwengier left a comment

Choose a reason for hiding this comment

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

LGTM, on the assumption that the remaining test failures are just things in need of infra or baseline updates

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Source generator should ensure hint names are unique

2 participants