Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Razor pages with preprocessor directives don't format #11372

Open
vsfeedback opened this issue Jan 9, 2025 · 1 comment · May be fixed by #11373
Open

Razor pages with preprocessor directives don't format #11372

vsfeedback opened this issue Jan 9, 2025 · 1 comment · May be fixed by #11373
Assignees
Labels
author: migration bot 🤖 The issue was created by a issue mover bot. The author may not be the actual author untriaged

Comments

@vsfeedback
Copy link

This issue has been moved from a ticket on Developer Community.


When adding a razor script in a Blazor page or component

For example such as:

<EditForm Model="SomeModel">
<DataAnnotationsValidator />
@{#if DEBUG}
 <ValidationSummary />
@{#endif}
</EditForm>
  

The code will not be formatted no matter what, and not just in Visual Studio 2022, also in VS Code
I have attached VS 2022 version info:

VS_2022_Version.txt

VS Code:

> Version: 1.96.2 (user setup)
> Commit: fabdb6a30b49f79a7aba0f2ad9df9b399473380f
> Date: 2024-12-19T10:22:47.216Z
> Electron: 32.2.6
> ElectronBuildId: 10629634
> Chromium: 128.0.6613.186
> Node.js: 20.18.1
> V8: 12.8.374.38-electron.0
> OS: Windows_NT x64 10.0.22631


Original Comments

Nicole Hu [MSFT] on 30/12/2024, 05:00 PM:

We have converted this feedback item to a problem. This change was done to better reflect the feedback’s nature. It will allow other developers to easily find it and engage on it.

Feedback Bot on 30/12/2024, 05:09 PM:

We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.

@dotnet-policy-service dotnet-policy-service bot added untriaged author: migration bot 🤖 The issue was created by a issue mover bot. The author may not be the actual author labels Jan 9, 2025
@davidwengier davidwengier changed the title Razor pages and Blazor components format not working properly Razor pages with preprocessor directives don't format Jan 9, 2025
@davidwengier
Copy link
Contributor

Hitting the following exception:

[CLaSP] [08:52:42.0729661] [null]:                    System.InvalidOperationException: Sequence contains more than one element                      at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source)                      at Microsoft.CodeAnalysis.Razor.Formatting.CSharpFormatter.<GetCSharpIndentationCoreAsync>g__ExtractTriviaAnnotations|7_0(FormattingContext context, SyntaxNode formattedRoot, SourceText formattedText, Dictionary`2 desiredIndentationMap)                      at Microsoft.CodeAnalysis.Razor.Formatting.CSharpFormatter.<GetCSharpIndentationCoreAsync>d__7.MoveNext()                   --- End of stack trace from previous location where exception was thrown ---                      at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()                      at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)                      at Microsoft.CodeAnalysis.Razor.Formatting.CSharpFormatter.<GetCSharpIndentationAsync>d__4.MoveNext()                   --- End of stack trace from previous location where exception was thrown ---                      at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()                      at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)                      at Microsoft.CodeAnalysis.Razor.Formatting.CSharpFormattingPassBase.<AdjustIndentationAsync>d__8.MoveNext()                   --- End of stack trace from previous location where exception was thrown ---                      at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()                      at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)                      at Microsoft.CodeAnalysis.Razor.Formatting.CSharpFormattingPass.<ExecuteCoreAsync>d__3.MoveNext()                   --- End of stack trace from previous location where exception was thrown ---                      at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()                      at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)                      at Microsoft.CodeAnalysis.Razor.Formatting.CSharpFormattingPassBase.<ExecuteAsync>d__6.MoveNext()                   --- End of stack trace from previous location where exception was thrown ---                      at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()                      at Microsoft.CodeAnalysis.Razor.Formatting.RazorFormattingService.<GetDocumentFormattingChangesAsync>d__10.MoveNext()                   --- End of stack trace from previous location where exception was thrown ---                      at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()                      at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)                      at Microsoft.AspNetCore.Razor.LanguageServer.Formatting.DocumentFormattingEndpoint.<HandleRequestAsync>d__8.MoveNext()                   --- End of stack trace from previous location where exception was thrown ---                      at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()                      at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)                      at Microsoft.CommonLanguageServerProtocol.Framework.QueueItem`1.<StartRequestAsync>d__17`2.MoveNext()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author: migration bot 🤖 The issue was created by a issue mover bot. The author may not be the actual author untriaged
Projects
None yet
2 participants