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)
Simple repro from https://developercommunity.visualstudio.com/t/Razor-Formatting-Feature-internal-error/11041869#T-ND11043454:
We emit this to Roslyn as:
And that gets formatted as:
On the face of it, that looks okay, but when we emit
()=>{for the start of the multi-line expression, we just setSkipPreviousLineto 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
CheckForNewLineslogic, 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)