Skip to content

Formatting fails for block bodied lambdas in event handler attributes #12785

@davidwengier

Description

@davidwengier

Simple repro from https://developercommunity.visualstudio.com/t/Razor-Formatting-Feature-internal-error/11041869#T-ND11043454:

<button @onclick="()=>{
StateHasChanged();}">
</button>

We emit this to Roslyn as:

{ // so <button> causes indentation
()=>{
StateHasChanged();
} /* */ //finishing off the multiline expressionj
} // Finish <button>

And that gets formatted as:

{ // so <button> causes indentation
    () =>
    {
        StateHasChanged();
    } /* */ //finishing off the multiline expressionj
} // Finish <button>

On the face of it, that looks okay, but when we emit ()=>{ for the start of the multi-line expression, we just set SkipPreviousLine to true. Of course, in this case we would need to skip 2 previous lines, but we don't have a way to detect that, nor specify it.

The real fix is actually to use our existing CheckForNewLines logic, which will consume formatted lines until we've seen all of the original text, but that doesn't currently get triggered because the ()=>{ line we're emitting is not considered for formatting at all. That's the key bit that needs to change (I think)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions