From f1ccf855ebfcf253732bbecf36174f1455209b38 Mon Sep 17 00:00:00 2001 From: Ajay Bhargav B Date: Thu, 13 Feb 2020 16:37:15 -0800 Subject: [PATCH] LSP Razor formatting for Razor code block directives (dotnet/aspnetcore-tooling#1573) LSP Razor formatting for Razor code block directives - Support for @code/@functions block formatting - Except when it contains Markup or other Razor constructs - Added a RazorFormattingService which is invoked by the RazorFormattingEndpoint. - Added a custom razor/rangeFormatting command that the server can use to ask the client to format a range of the projected C# or HTML document - Added a CSharpFormatter and HTMLFormatter that invoke the above mentioned command - Added FormattingSpan and its corresponding visitor to represent Razor understanding of indentation - Moved the document mapping code to a separate RazorDocumentMappingService service for ease of use - Added necessary extension methods for convenience. Some of them were copied from Roslyn - Some cleanup - Added a C# test formatter to enable unit testing. Right now it calls Roslyn APIs directly. As far as I've seen its behavior is the same as OmniSharp formatting except it doesn't remove trailing whitespace and empty lines. I am following up with people to understand why that is the case. Added/updated tests \n\nCommit migrated from https://github.com/dotnet/aspnetcore-tooling/commit/62051b9ad7f1bb09b6091bf6b5fd8df30d0ed5b2 --- .../src/ClassifiedSpanVisitor.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/ClassifiedSpanVisitor.cs b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/ClassifiedSpanVisitor.cs index 81edb96152..f162744130 100644 --- a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/ClassifiedSpanVisitor.cs +++ b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/ClassifiedSpanVisitor.cs @@ -18,6 +18,11 @@ namespace Microsoft.AspNetCore.Razor.Language public ClassifiedSpanVisitor(RazorSourceDocument source) { + if (source is null) + { + throw new ArgumentNullException(nameof(source)); + } + _source = source; _spans = new List(); _currentBlockKind = BlockKindInternal.Markup;