diff --git a/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorCSharpFormattingBenchmark.cs b/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorCSharpFormattingBenchmark.cs index 4cfa36773c0..2d965e9ce51 100644 --- a/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorCSharpFormattingBenchmark.cs +++ b/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorCSharpFormattingBenchmark.cs @@ -9,7 +9,7 @@ using System.Threading; using System.Threading.Tasks; using BenchmarkDotNet.Attributes; -using Microsoft.AspNetCore.Razor.LanguageServer.Formatting; +using Microsoft.CodeAnalysis.Razor.Formatting; using Microsoft.CodeAnalysis.Razor.ProjectSystem; using Microsoft.CodeAnalysis.Text; using Microsoft.VisualStudio.LanguageServer.Protocol; diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/AdhocWorkspaceFactory.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/AdhocWorkspaceFactory.cs index f0c5badb420..b279b5959db 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/AdhocWorkspaceFactory.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/AdhocWorkspaceFactory.cs @@ -2,10 +2,10 @@ // Licensed under the MIT license. See License.txt in the project root for license information. using System.Collections.Immutable; -using Microsoft.AspNetCore.Razor.LanguageServer.Common; using Microsoft.AspNetCore.Razor.LanguageServer.Hosting; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Host; +using Microsoft.CodeAnalysis.Razor.Workspaces; namespace Microsoft.AspNetCore.Razor.LanguageServer; diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/AutoInsert/AutoClosingTagOnAutoInsertProvider.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/AutoInsert/AutoClosingTagOnAutoInsertProvider.cs index e216c899d0d..ae288e14de1 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/AutoInsert/AutoClosingTagOnAutoInsertProvider.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/AutoInsert/AutoClosingTagOnAutoInsertProvider.cs @@ -8,6 +8,7 @@ using Microsoft.AspNetCore.Razor.Language; using Microsoft.AspNetCore.Razor.Language.Syntax; using Microsoft.AspNetCore.Razor.LanguageServer.Formatting; +using Microsoft.CodeAnalysis.Razor.Formatting; using Microsoft.CodeAnalysis.Text; using Microsoft.VisualStudio.LanguageServer.Protocol; diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/AutoInsert/CloseTextTagOnAutoInsertProvider.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/AutoInsert/CloseTextTagOnAutoInsertProvider.cs index 8ce976721ee..f6ff6ff95e1 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/AutoInsert/CloseTextTagOnAutoInsertProvider.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/AutoInsert/CloseTextTagOnAutoInsertProvider.cs @@ -8,6 +8,7 @@ using Microsoft.AspNetCore.Razor.Language.Legacy; using Microsoft.AspNetCore.Razor.Language.Syntax; using Microsoft.AspNetCore.Razor.LanguageServer.Formatting; +using Microsoft.CodeAnalysis.Razor.Formatting; using Microsoft.CodeAnalysis.Text; using Microsoft.VisualStudio.LanguageServer.Protocol; diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/AutoInsert/IOnAutoInsertProvider.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/AutoInsert/IOnAutoInsertProvider.cs index 5e83a82a646..d45bfe02d8d 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/AutoInsert/IOnAutoInsertProvider.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/AutoInsert/IOnAutoInsertProvider.cs @@ -3,6 +3,7 @@ using System.Diagnostics.CodeAnalysis; using Microsoft.AspNetCore.Razor.LanguageServer.Formatting; +using Microsoft.CodeAnalysis.Razor.Formatting; using Microsoft.VisualStudio.LanguageServer.Protocol; namespace Microsoft.AspNetCore.Razor.LanguageServer.AutoInsert; diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/AutoInsert/OnAutoInsertEndpoint.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/AutoInsert/OnAutoInsertEndpoint.cs index 30565f8c181..cbcef4ece99 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/AutoInsert/OnAutoInsertEndpoint.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/AutoInsert/OnAutoInsertEndpoint.cs @@ -13,6 +13,7 @@ using Microsoft.AspNetCore.Razor.PooledObjects; using Microsoft.AspNetCore.Razor.Threading; using Microsoft.CodeAnalysis.Razor.DocumentMapping; +using Microsoft.CodeAnalysis.Razor.Formatting; using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.CodeAnalysis.Razor.Workspaces; diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CSharp/DefaultCSharpCodeActionResolver.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CSharp/DefaultCSharpCodeActionResolver.cs index 9e62f694a04..8c44e462dc1 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CSharp/DefaultCSharpCodeActionResolver.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CSharp/DefaultCSharpCodeActionResolver.cs @@ -9,6 +9,7 @@ using Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Models; using Microsoft.AspNetCore.Razor.LanguageServer.Formatting; using Microsoft.AspNetCore.Razor.LanguageServer.Hosting; +using Microsoft.CodeAnalysis.Razor.Formatting; using Microsoft.CodeAnalysis.Razor.ProjectSystem; using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.CodeAnalysis.Razor.Workspaces; diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/CodeBlockService.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/CodeBlockService.cs index a01cc5ba960..01869f6106e 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/CodeBlockService.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/CodeBlockService.cs @@ -9,6 +9,7 @@ using Microsoft.AspNetCore.Razor.LanguageServer.Hosting; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Razor; +using Microsoft.CodeAnalysis.Razor.Formatting; using Microsoft.CodeAnalysis.Text; using Microsoft.VisualStudio.LanguageServer.Protocol; @@ -49,7 +50,7 @@ public static TextEdit[] CreateFormattedTextEdit(RazorCodeDocument code, string || !csharpCodeBlock.Children.TryGetCloseBraceNode(out var closeBrace)) { // No well-formed @code block exists. Generate the method within an @code block at the end of the file and conduct manual formatting. - var indentedMethod = FormattingUtilities.AddIndentationToMethod(templateWithMethodSignature, options, startingIndent: 0); + var indentedMethod = FormattingUtilities.AddIndentationToMethod(templateWithMethodSignature, options.TabSize, options.InsertSpaces, startingIndent: 0); var codeBlockStartText = "@code {" + Environment.NewLine; var sourceText = code.Source.Text; var lastCharacterLocation = sourceText.Lines[^1]; @@ -112,7 +113,8 @@ private static string FormatMethodInCodeBlock( var numCharacterBefore = codeBlockSourceLocation.CharacterIndex - 5; var formattedGeneratedMethod = FormattingUtilities.AddIndentationToMethod( method, - options, + options.TabSize, + options.InsertSpaces, codeBlockStartAbsoluteIndex, numCharacterBefore, source); diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/GenerateMethodCodeActionResolver.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/GenerateMethodCodeActionResolver.cs index 86af5075d71..34a71cd61b9 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/GenerateMethodCodeActionResolver.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/GenerateMethodCodeActionResolver.cs @@ -18,6 +18,7 @@ using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Razor; using Microsoft.CodeAnalysis.Razor.DocumentMapping; +using Microsoft.CodeAnalysis.Razor.Formatting; using Microsoft.CodeAnalysis.Razor.ProjectSystem; using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.VisualStudio.LanguageServer.Protocol; @@ -107,7 +108,8 @@ razorClassName is null || var classLocationLineSpan = @class.GetLocation().GetLineSpan(); var formattedMethod = FormattingUtilities.AddIndentationToMethod( templateWithMethodSignature, - _razorLSPOptionsMonitor.CurrentValue, + _razorLSPOptionsMonitor.CurrentValue.TabSize, + _razorLSPOptionsMonitor.CurrentValue.InsertSpaces, @class.SpanStart, classLocationLineSpan.StartLinePosition.Character, content); diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Completion/Delegation/DelegatedCompletionItemResolver.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Completion/Delegation/DelegatedCompletionItemResolver.cs index f977eb4b4ff..4f3ae959b27 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Completion/Delegation/DelegatedCompletionItemResolver.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Completion/Delegation/DelegatedCompletionItemResolver.cs @@ -8,6 +8,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Razor.LanguageServer.Formatting; using Microsoft.AspNetCore.Razor.LanguageServer.Hosting; +using Microsoft.CodeAnalysis.Razor.Formatting; using Microsoft.CodeAnalysis.Razor.ProjectSystem; using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.VisualStudio.LanguageServer.Protocol; diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Extensions/IServiceCollectionExtensions.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Extensions/IServiceCollectionExtensions.cs index 38dfdb87dfb..851e04822aa 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Extensions/IServiceCollectionExtensions.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Extensions/IServiceCollectionExtensions.cs @@ -23,6 +23,7 @@ using Microsoft.AspNetCore.Razor.ProjectEngineHost; using Microsoft.CodeAnalysis.Razor.Completion; using Microsoft.CodeAnalysis.Razor.DocumentMapping; +using Microsoft.CodeAnalysis.Razor.Formatting; using Microsoft.CodeAnalysis.Razor.ProjectSystem; using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.CodeAnalysis.Razor.SemanticTokens; @@ -63,10 +64,10 @@ public static void AddFormattingServices(this IServiceCollection services) // Formatting Passes services.AddSingleton(); services.AddSingleton(); - services.AddSingleton(); + services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); - services.AddSingleton(); + services.AddSingleton(); services.AddHandlerWithCapabilities(); services.AddHandlerWithCapabilities(); diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/DocumentFormattingEndpoint.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/DocumentFormattingEndpoint.cs index 1c074702874..d25fff093bc 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/DocumentFormattingEndpoint.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/DocumentFormattingEndpoint.cs @@ -6,6 +6,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Razor.Language; using Microsoft.AspNetCore.Razor.LanguageServer.EndpointContracts; +using Microsoft.CodeAnalysis.Razor.Formatting; using Microsoft.VisualStudio.LanguageServer.Protocol; namespace Microsoft.AspNetCore.Razor.LanguageServer.Formatting; diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/DocumentOnTypeFormattingEndpoint.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/DocumentOnTypeFormattingEndpoint.cs index 77c5b6a37ae..c165d829a7a 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/DocumentOnTypeFormattingEndpoint.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/DocumentOnTypeFormattingEndpoint.cs @@ -10,6 +10,7 @@ using Microsoft.AspNetCore.Razor.Language; using Microsoft.AspNetCore.Razor.LanguageServer.EndpointContracts; using Microsoft.CodeAnalysis.Razor.DocumentMapping; +using Microsoft.CodeAnalysis.Razor.Formatting; using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.CodeAnalysis.Text; diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/DocumentRangeFormattingEndpoint.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/DocumentRangeFormattingEndpoint.cs index 414a1bf1ef5..4fa0207619b 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/DocumentRangeFormattingEndpoint.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/DocumentRangeFormattingEndpoint.cs @@ -6,6 +6,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Razor.Language; using Microsoft.AspNetCore.Razor.LanguageServer.EndpointContracts; +using Microsoft.CodeAnalysis.Razor.Formatting; using Microsoft.VisualStudio.LanguageServer.Protocol; namespace Microsoft.AspNetCore.Razor.LanguageServer.Formatting; diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/HtmlFormatter.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/HtmlFormatter.cs index 288afdeacac..2b613a183e9 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/HtmlFormatter.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/HtmlFormatter.cs @@ -7,6 +7,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Razor.LanguageServer.Hosting; using Microsoft.AspNetCore.Razor.TextDifferencing; +using Microsoft.CodeAnalysis.Razor.Formatting; using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.CodeAnalysis.Razor.Protocol.Formatting; using Microsoft.CodeAnalysis.Text; diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/HtmlFormattingPass.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/HtmlFormattingPass.cs index f522ea5790c..3b3b4023e40 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/HtmlFormattingPass.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/HtmlFormattingPass.cs @@ -9,6 +9,7 @@ using Microsoft.AspNetCore.Razor.Language.Syntax; using Microsoft.AspNetCore.Razor.LanguageServer.Hosting; using Microsoft.CodeAnalysis.Razor.DocumentMapping; +using Microsoft.CodeAnalysis.Razor.Formatting; using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.CodeAnalysis.Text; diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/LspCSharpOnTypeFormattingPass.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/LspCSharpOnTypeFormattingPass.cs new file mode 100644 index 00000000000..c163bc336d7 --- /dev/null +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/LspCSharpOnTypeFormattingPass.cs @@ -0,0 +1,39 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT license. See License.txt in the project root for license information. + +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Razor.Language; +using Microsoft.AspNetCore.Razor.LanguageServer.CodeActions; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.Razor.DocumentMapping; +using Microsoft.CodeAnalysis.Razor.Formatting; +using Microsoft.CodeAnalysis.Razor.Logging; +using Microsoft.CodeAnalysis.Text; +using Microsoft.VisualStudio.LanguageServer.Protocol; + +namespace Microsoft.AspNetCore.Razor.LanguageServer.Formatting; + +internal sealed class LspCSharpOnTypeFormattingPass( + IDocumentMappingService documentMappingService, + ILoggerFactory loggerFactory) + : CSharpOnTypeFormattingPassBase(documentMappingService, loggerFactory) +{ + + protected override async Task AddUsingStatementEditsIfNecessaryAsync(CodeAnalysis.Razor.Formatting.FormattingContext context, RazorCodeDocument codeDocument, SourceText csharpText, TextEdit[] textEdits, SourceText originalTextWithChanges, TextEdit[] finalEdits, CancellationToken cancellationToken) + { + if (context.AutomaticallyAddUsings) + { + // Because we need to parse the C# code twice for this operation, lets do a quick check to see if its even necessary + if (textEdits.Any(e => e.NewText.IndexOf("using") != -1)) + { + var usingStatementEdits = await AddUsingsCodeActionProviderHelper.GetUsingStatementEditsAsync(codeDocument, csharpText, originalTextWithChanges, cancellationToken).ConfigureAwait(false); + finalEdits = [.. usingStatementEdits, .. finalEdits]; + } + } + + return finalEdits; + } +} diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/LspRazorFormattingPass.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/LspRazorFormattingPass.cs new file mode 100644 index 00000000000..49731bf21a1 --- /dev/null +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/LspRazorFormattingPass.cs @@ -0,0 +1,15 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT license. See License.txt in the project root for license information. + +using Microsoft.CodeAnalysis.Razor.DocumentMapping; +using Microsoft.CodeAnalysis.Razor.Formatting; + +namespace Microsoft.AspNetCore.Razor.LanguageServer.Formatting; + +internal sealed class LspRazorFormattingPass( + IDocumentMappingService documentMappingService, + RazorLSPOptionsMonitor optionsMonitor) + : RazorFormattingPassBase(documentMappingService) +{ + protected override bool CodeBlockBraceOnNextLine => optionsMonitor.CurrentValue.CodeBlockBraceOnNextLine; +} diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ILoggerExtensions.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ILoggerExtensions.cs index 27c85a48882..f09716a0c38 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ILoggerExtensions.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ILoggerExtensions.cs @@ -9,54 +9,3 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer; -internal static class ILoggerExtensions -{ - public static bool TestOnlyLoggingEnabled = false; - - [Conditional("DEBUG")] - public static void LogTestOnly(this ILogger logger, ref TestLogMessageInterpolatedStringHandler handler) - { - if (TestOnlyLoggingEnabled) - { - logger.Log(LogLevel.Debug, handler.ToString(), exception: null); - } - } -} - -[InterpolatedStringHandler] -internal ref struct TestLogMessageInterpolatedStringHandler -{ - private PooledObject _builder; - - public TestLogMessageInterpolatedStringHandler(int literalLength, int _, out bool isEnabled) - { - isEnabled = ILoggerExtensions.TestOnlyLoggingEnabled; - if (isEnabled) - { - _builder = StringBuilderPool.GetPooledObject(); - _builder.Object.EnsureCapacity(literalLength); - } - } - - public void AppendLiteral(string s) - { - _builder.Object.Append(s); - } - - public void AppendFormatted(T t) - { - _builder.Object.Append(t?.ToString() ?? "[null]"); - } - - public void AppendFormatted(T t, string format) - { - _builder.Object.AppendFormat(format, t); - } - - public override string ToString() - { - var result = _builder.Object.ToString(); - _builder.Dispose(); - return result; - } -} diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/InlineCompletion/InlineCompletionEndPoint.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/InlineCompletion/InlineCompletionEndPoint.cs index 0a452d66217..0993fac51f9 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/InlineCompletion/InlineCompletionEndPoint.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/InlineCompletion/InlineCompletionEndPoint.cs @@ -14,6 +14,7 @@ using Microsoft.AspNetCore.Razor.LanguageServer.Formatting; using Microsoft.AspNetCore.Razor.LanguageServer.Hosting; using Microsoft.CodeAnalysis.Razor.DocumentMapping; +using Microsoft.CodeAnalysis.Razor.Formatting; using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.CodeAnalysis.Razor.Protocol.Completion; diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/SR.resx b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/SR.resx index 1fb4ef212c8..ad72987e68f 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/SR.resx +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/SR.resx @@ -126,42 +126,21 @@ Create component from tag - - Diagnostics after: - - - Diagnostics before: - Document {0} was not found. - - Edit at {0} adds the non-whitespace content '{1}'. - - - Edit at {0} deletes the non-whitespace content '{1}'. - Extract block to code behind File was externally modified: {0} - - A format operation is being abandoned because it would introduce or remove one of more diagnostics. - - - A format operation is being abandoned because it would add or delete non-whitespace content. - Generate Async Event Handler '{0}' Generate Event Handler '{0}' - - Razor language services not configured properly, missing language service '{0}'. - Not available in diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.cs.xlf b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.cs.xlf index 20bb58692c9..05e18dd9493 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.cs.xlf +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.cs.xlf @@ -17,31 +17,11 @@ Vytvořit komponentu ze značky - - Diagnostics after: - Diagnostika po: - - - - Diagnostics before: - Diagnostika před: - - Document {0} was not found. Dokument {0} nebyl nalezen. - - Edit at {0} adds the non-whitespace content '{1}'. - Úprava na {0} přidá neprázdný obsah {1}. - - - - Edit at {0} deletes the non-whitespace content '{1}'. - Úprava na {0} odstraní neprázdný obsah {1}. - - Extract block to code behind Extrahovat blok do kódu na pozadí @@ -52,16 +32,6 @@ Došlo k externí úpravě souboru: {0} - - A format operation is being abandoned because it would introduce or remove one of more diagnostics. - Operace formátování je ukončována, protože by zavedla nebo odebrala jednu z více diagnostik. - - - - A format operation is being abandoned because it would add or delete non-whitespace content. - Operace formátování je ukončována, protože by přidala nebo odstranila neprázdný obsah. - - Generate Async Event Handler '{0}' Generovat asynchronní obslužnou rutinu události {0} @@ -72,11 +42,6 @@ Generovat obslužnou rutinu události {0} - - Razor language services not configured properly, missing language service '{0}'. - Služby jazyka Razor nejsou správně nakonfigurované, chybí služba jazyka {0}. - - Not available in Není k dispozici v diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.de.xlf b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.de.xlf index c886ab68c2f..ec8d65eaadd 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.de.xlf +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.de.xlf @@ -17,31 +17,11 @@ Komponente aus Tag erstellen - - Diagnostics after: - Diagnose nach: - - - - Diagnostics before: - Diagnose vor: - - Document {0} was not found. Dokument „{0}“ wurde nicht gefunden. - - Edit at {0} adds the non-whitespace content '{1}'. - Das Bearbeiten bei {0} fügt den Nicht-Leerraum-Inhalt "{1}" hinzu. - - - - Edit at {0} deletes the non-whitespace content '{1}'. - Das Bearbeiten bei {0} löscht den Nicht-Leerraum-Inhalt "{1}". - - Extract block to code behind Block auf CodeBehind extrahieren @@ -52,16 +32,6 @@ Datei wurde extern modifiziert: {0}. - - A format operation is being abandoned because it would introduce or remove one of more diagnostics. - Ein Formatierungsvorgang wird abgebrochen, weil er eine oder mehrere Diagnosen einführen oder entfernen würde. - - - - A format operation is being abandoned because it would add or delete non-whitespace content. - Ein Formatierungsvorgang wird abgebrochen, da er Nicht-Leerraum-Inhalte hinzufügen oder löschen würde. - - Generate Async Event Handler '{0}' Asynchronen Ereignishandler "{0}" generieren @@ -72,11 +42,6 @@ Ereignishandler "{0}" generieren - - Razor language services not configured properly, missing language service '{0}'. - Razor-Sprachdienste sind nicht ordnungsgemäß konfiguriert, der Sprachdienst "{0}" fehlt. - - Not available in Nicht verfügbar in diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.es.xlf b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.es.xlf index 7b2b4b26587..a5682b0ee0d 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.es.xlf +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.es.xlf @@ -17,31 +17,11 @@ Crear un componente a partir de la etiqueta - - Diagnostics after: - Diagnósticos después de: - - - - Diagnostics before: - Diagnósticos antes de: - - Document {0} was not found. No se encontró el documento {0}. - - Edit at {0} adds the non-whitespace content '{1}'. - Editar en {0}agregar el contenido que no es un espacio en blanco "{1}" . - - - - Edit at {0} deletes the non-whitespace content '{1}'. - Editar en {0} eliminar el contenido que no es un espacio en blanco "{1}" . - - Extract block to code behind Extraer el bloque al código subyacente @@ -52,16 +32,6 @@ El archivo se modificó externamente: {0} - - A format operation is being abandoned because it would introduce or remove one of more diagnostics. - Se está abandonando una operación de formato porque introduciría o quitaría uno de más diagnósticos. - - - - A format operation is being abandoned because it would add or delete non-whitespace content. - Se está abandonando una operación de formato porque agregaría o eliminaría contenido que no es un espacio en blanco. - - Generate Async Event Handler '{0}' Generar controlador de eventos asincrónicos ''{0}'' @@ -72,11 +42,6 @@ Generar controlador de eventos ''{0}'' - - Razor language services not configured properly, missing language service '{0}'. - Los servicios de lenguaje Razor no están configurados correctamente; falta el servicio de idioma "{0}". - - Not available in No disponible en diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.fr.xlf b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.fr.xlf index d6ecf5e41ae..62b80c7f26d 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.fr.xlf +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.fr.xlf @@ -17,31 +17,11 @@ Créer un composant à partir de la balise - - Diagnostics after: - Diagnostics après : - - - - Diagnostics before: - Diagnostics avant : - - Document {0} was not found. Le document {0} est introuvable. - - Edit at {0} adds the non-whitespace content '{1}'. - Modifier à {0} ajoute le contenu autre qu’un espace « {1} ». - - - - Edit at {0} deletes the non-whitespace content '{1}'. - Modifier à {0} supprime le contenu autre qu’un espace « {1} ». - - Extract block to code behind Extraire le bloc vers le code-behind @@ -52,16 +32,6 @@ Le fichier a été modifié en externe : {0} - - A format operation is being abandoned because it would introduce or remove one of more diagnostics. - Une opération de formatage est en cours d’abandon, car elle introduit ou supprime un ou plusieurs diagnostics. - - - - A format operation is being abandoned because it would add or delete non-whitespace content. - Une opération de formatage est en cours d’abandon, car elle ajouterait ou supprimerait du contenu qui n’est pas un espace blanc. - - Generate Async Event Handler '{0}' Générer le gestionnaire d’événements asynchrone « {0} » @@ -72,11 +42,6 @@ Générer le gestionnaire d’événements '{0}' - - Razor language services not configured properly, missing language service '{0}'. - Les services de langage Razor ne sont pas configurés correctement, le service de langage «{0}» manquant. - - Not available in Non disponible dans diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.it.xlf b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.it.xlf index 32f81ab0c1c..d8f8e84cf39 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.it.xlf +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.it.xlf @@ -17,31 +17,11 @@ Crea componente da tag - - Diagnostics after: - Diagnostica dopo: - - - - Diagnostics before: - Diagnostica prima di: - - Document {0} was not found. Impossibile trovare il documento{0}. - - Edit at {0} adds the non-whitespace content '{1}'. - La modifica in {0} aggiunge contenuti diversi da spazi vuoti '{1}'. - - - - Edit at {0} deletes the non-whitespace content '{1}'. - La modifica in {0} elimina contenuti diversi da spazi vuoti '{1}'. - - Extract block to code behind Estrai il blocco in code-behind @@ -52,16 +32,6 @@ Il file è stato modificato esternamente: {0} - - A format operation is being abandoned because it would introduce or remove one of more diagnostics. - È in corso l'abbandono di un'operazione di formato perché comporterebbe l'introduzione o la rimozione di una o più operazioni di diagnostica. - - - - A format operation is being abandoned because it would add or delete non-whitespace content. - È in corso l'abbandono di un'operazione di formattazione perché aggiungerebbe o eliminerebbe contenuto diverso da spazi vuoti. - - Generate Async Event Handler '{0}' Genera gestore dell'evento '{0}' asincrono @@ -72,11 +42,6 @@ Genera gestore dell'evento '{0}' - - Razor language services not configured properly, missing language service '{0}'. - I servizi di linguaggio Razor non sono configurati correttamente. Manca il servizio di linguaggio '{0}'. - - Not available in Non disponibili in diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.ja.xlf b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.ja.xlf index 08fba968925..e8997eb83db 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.ja.xlf +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.ja.xlf @@ -17,31 +17,11 @@ タグからコンポーネントを作成する - - Diagnostics after: - 次の時間が経過した後の診断: - - - - Diagnostics before: - 次の時間以前の診断: - - Document {0} was not found. ドキュメント {0}が見つかりませんでした。 - - Edit at {0} adds the non-whitespace content '{1}'. - {0} で編集すると空白以外のスペース '{1}' が追加されます。 - - - - Edit at {0} deletes the non-whitespace content '{1}'. - {0} で削除すると空白以外のスペース '{1}' が追加されます。 - - Extract block to code behind ブロック抽出から分離コード @@ -52,16 +32,6 @@ ファイルが外部で変更されました: {0} - - A format operation is being abandoned because it would introduce or remove one of more diagnostics. - 書式設定操作は、さらに診断の 1 つを導入または削除するため、破棄されています。 - - - - A format operation is being abandoned because it would add or delete non-whitespace content. - 書式設定操作は、空白以外のコンテンツを追加または削除するため、破棄されています。 - - Generate Async Event Handler '{0}' 非同期イベント ハンドラー '{0}' の生成 @@ -72,11 +42,6 @@ イベント ハンドラー '{0}' の生成 - - Razor language services not configured properly, missing language service '{0}'. - Razor 言語サービスが正しく構成されていません。言語サービス '{0}' がありません。 - - Not available in 次では使用できません: diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.ko.xlf b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.ko.xlf index 2642eb6486d..51c6c0c3d67 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.ko.xlf +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.ko.xlf @@ -17,31 +17,11 @@ 태그에서 구성 요소 만들기 - - Diagnostics after: - 다음 이후 진단: - - - - Diagnostics before: - 다음 이전 진단: - - Document {0} was not found. 문서 {0}을(를) 찾을 수 없습니다. - - Edit at {0} adds the non-whitespace content '{1}'. - {0}에서 편집은 공백이 아닌 콘텐츠 '{1}'을(를) 추가합니다. - - - - Edit at {0} deletes the non-whitespace content '{1}'. - {0}에서 편집은 공백이 아닌 콘텐츠 '{1}'을(를) 삭제합니다. - - Extract block to code behind 코드 숨김에 블록 추출 @@ -52,16 +32,6 @@ {0}의 파일이 외부에서 수정되었습니다. - - A format operation is being abandoned because it would introduce or remove one of more diagnostics. - 서식 작업이 중단되는 이유는 진단 중 하나를 더 도입하거나 제거할 수 있기 때문입니다. - - - - A format operation is being abandoned because it would add or delete non-whitespace content. - 공백이 아닌 콘텐츠를 추가하거나 삭제하기 때문에 형식 작업이 중단됩니다. - - Generate Async Event Handler '{0}' 비동기 이벤트 처리기 '{0}' 생성 @@ -72,11 +42,6 @@ 이벤트 처리기 '{0}' 생성 - - Razor language services not configured properly, missing language service '{0}'. - Razor 언어 서비스가 제대로 구성되지 않았습니다. 언어 서비스 '{0}'이(가) 없습니다. - - Not available in 에서 사용할 수 없음 diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.pl.xlf b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.pl.xlf index fc746b124d2..08bc0df0bab 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.pl.xlf +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.pl.xlf @@ -17,31 +17,11 @@ Utwórz składnik z tagu - - Diagnostics after: - Diagnostyka po: - - - - Diagnostics before: - Diagnostyka przed: - - Document {0} was not found. Nie znaleziono {0} dokumentu. - - Edit at {0} adds the non-whitespace content '{1}'. - Edycja na stronie {0} dodaje zawartość bez białych znaków „{1}”. - - - - Edit at {0} deletes the non-whitespace content '{1}'. - Edycja na stronie {0} usuwa zawartość bez białych znaków „{1}”. - - Extract block to code behind Wyodrębnij blok do kodu znajdującego się poza @@ -52,16 +32,6 @@ Plik został zmodyfikowany na zewnątrz: {0} - - A format operation is being abandoned because it would introduce or remove one of more diagnostics. - Operacja formatowania jest porzucana, ponieważ spowodowałaby wprowadzenie lub usunięcie jednej z większej liczby diagnostyki. - - - - A format operation is being abandoned because it would add or delete non-whitespace content. - Operacja formatowania jest porzucana, ponieważ doda lub usunie zawartość bez białych znaków. - - Generate Async Event Handler '{0}' Generuj asynchroniczny program obsługi zdarzeń „{0}” @@ -72,11 +42,6 @@ Generuj obsługę zdarzeń „{0}” - - Razor language services not configured properly, missing language service '{0}'. - Usługi języka dla składni Razor nie zostały prawidłowo skonfigurowane — brak usługi językowej "{0}". - - Not available in Niedostępne w diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.pt-BR.xlf b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.pt-BR.xlf index 9380bdda8f2..39d5779ee15 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.pt-BR.xlf +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.pt-BR.xlf @@ -17,31 +17,11 @@ Criar componente a partir da marca - - Diagnostics after: - Diagnóstico após: - - - - Diagnostics before: - Diagnóstico antes: - - Document {0} was not found. O documento {0} não foi encontrado. - - Edit at {0} adds the non-whitespace content '{1}'. - Editar em {0} adiciona o conteúdo que não é espaço em branco ''{1}''. - - - - Edit at {0} deletes the non-whitespace content '{1}'. - Editar em {0} exclui o conteúdo que não é espaço em branco ''{1}''. - - Extract block to code behind Extrair o bloco para codificar atrás @@ -52,16 +32,6 @@ O arquivo foi modificado externamente: {0} - - A format operation is being abandoned because it would introduce or remove one of more diagnostics. - Uma operação de formato está sendo abandonada porque introduziria ou removeria um ou mais diagnósticos. - - - - A format operation is being abandoned because it would add or delete non-whitespace content. - Uma operação de formato está sendo abandonada porque adicionaria ou excluiria conteúdo que não é espaço em branco. - - Generate Async Event Handler '{0}' Gerar Manipulador de Eventos Assíncronos '{0}' @@ -72,11 +42,6 @@ Gerar manipulador de eventos '{0}' - - Razor language services not configured properly, missing language service '{0}'. - Serviços de Linguagem Razor não configurados corretamente, serviço de linguagem '{0}' ausente. - - Not available in Não disponível em diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.ru.xlf b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.ru.xlf index 3cd2089390d..15646d4c15f 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.ru.xlf +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.ru.xlf @@ -17,31 +17,11 @@ Создание компонента из тега - - Diagnostics after: - Диагностика после: - - - - Diagnostics before: - Диагностика до: - - Document {0} was not found. Документ {0} не найден. - - Edit at {0} adds the non-whitespace content '{1}'. - Редактирование {0} добавляет содержимое, не являющееся пробелами "{1}". - - - - Edit at {0} deletes the non-whitespace content '{1}'. - Редактирование {0} удаляет содержимое, не являющееся пробелами "{1}". - - Extract block to code behind Извлечь блок в код программной части @@ -52,16 +32,6 @@ Файл был изменен извне: {0} - - A format operation is being abandoned because it would introduce or remove one of more diagnostics. - Операция форматирования отменяется, поскольку она вводит или удаляет одну или несколько диагностик. - - - - A format operation is being abandoned because it would add or delete non-whitespace content. - Операция форматирования отменяется, поскольку она может добавить или удалить содержимое, отличное от пробелов. - - Generate Async Event Handler '{0}' Создать обработчик асинхронных событий "{0}" @@ -72,11 +42,6 @@ Создать обработчик событий "{0}" - - Razor language services not configured properly, missing language service '{0}'. - Языковые службы Razor настроены неправильно, отсутствует языковая служба "{0}". - - Not available in Недоступно в diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.tr.xlf b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.tr.xlf index 350cc2a946a..9527d1e496b 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.tr.xlf +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.tr.xlf @@ -17,31 +17,11 @@ Etiketten bileşen oluştur - - Diagnostics after: - Şundan sonraki tanılama: - - - - Diagnostics before: - Şundan önceki tanılama: - - Document {0} was not found. Belge {0} bulunamadı. - - Edit at {0} adds the non-whitespace content '{1}'. - {0} konumunda düzenleme, '{1}' boşluk dışı içeriğini ekler. - - - - Edit at {0} deletes the non-whitespace content '{1}'. - {0} konumunda düzenleme, '{1}' boşluk dışı içeriğini siler. - - Extract block to code behind Bloğu arkadaki koda ayıkla @@ -52,16 +32,6 @@ Dosya dışarıdan değiştirildi: {0} - - A format operation is being abandoned because it would introduce or remove one of more diagnostics. - Bir veya daha fazla tanılamayı ortaya çıkarabileceği veya kaldırabileceği için biçimlendirme işlemi bırakılıyor. - - - - A format operation is being abandoned because it would add or delete non-whitespace content. - Boşluk dışı içeriği ekleyebileceği veya silebileceği için biçimlendirme işlemi bırakıl. - - Generate Async Event Handler '{0}' '{0}' Asenkron Olay İşleyicisini Oluştur @@ -72,11 +42,6 @@ '{0}' Olay İşleyicisi Oluştur - - Razor language services not configured properly, missing language service '{0}'. - Razor dil hizmetleri düzgün yapılandırılmadı, '{0}' dil hizmeti eksik. - - Not available in Şurada kullanılamaz: diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.zh-Hans.xlf b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.zh-Hans.xlf index 02e7c59af60..c20d488e323 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.zh-Hans.xlf +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.zh-Hans.xlf @@ -17,31 +17,11 @@ 从标记创建组件 - - Diagnostics after: - 诊断后: - - - - Diagnostics before: - 诊断前: - - Document {0} was not found. 找不到文档 {0}。 - - Edit at {0} adds the non-whitespace content '{1}'. - 于 {0} 编辑,添加非空格内容“{1}”。 - - - - Edit at {0} deletes the non-whitespace content '{1}'. - 于 {0} 编辑,删除非空格内容“{1}”。 - - Extract block to code behind 将块提取到代码隐藏中 @@ -52,16 +32,6 @@ 已从外部修改了文件: {0}。 - - A format operation is being abandoned because it would introduce or remove one of more diagnostics. - 正在放弃格式操作,因为它会引入或删除其他诊断之一。 - - - - A format operation is being abandoned because it would add or delete non-whitespace content. - 正在放弃格式操作,因为它会添加或删除非空格内容。 - - Generate Async Event Handler '{0}' 生成异步事件处理程序“{0}” @@ -72,11 +42,6 @@ 生成事件处理程序 "{0}" - - Razor language services not configured properly, missing language service '{0}'. - Razor 语言服务未正确配置,缺少语言服务 "{0}"。 - - Not available in 在以下位置不可用 diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.zh-Hant.xlf b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.zh-Hant.xlf index c283c24de51..5eb30910966 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.zh-Hant.xlf +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.zh-Hant.xlf @@ -17,31 +17,11 @@ 從標籤建立元件 - - Diagnostics after: - 在以下事項之後的診斷: - - - - Diagnostics before: - 在以下事項之前的診斷: - - Document {0} was not found. 找不到文件 {0}。 - - Edit at {0} adds the non-whitespace content '{1}'. - 在 {0} 處編輯將新增非空白內容 '{1}'。 - - - - Edit at {0} deletes the non-whitespace content '{1}'. - 在 {0} 處編輯將刪除非空白內容 '{1}'。 - - Extract block to code behind 擷取區塊以在後方編碼 @@ -52,16 +32,6 @@ 已在外部修改檔案: {0} - - A format operation is being abandoned because it would introduce or remove one of more diagnostics. - 將放棄格式化作業,因為它將引入或移除一個或多個診斷。 - - - - A format operation is being abandoned because it would add or delete non-whitespace content. - 將放棄格式化作業,因為它將新增或删除非空白內容。 - - Generate Async Event Handler '{0}' 產生非同步事件處理常式 '{0}' @@ -72,11 +42,6 @@ 產生事件處理常式 '{0}' - - Razor language services not configured properly, missing language service '{0}'. - 未正確設定 Razor 語言服務,遺漏語言服務 '{0}'。 - - Not available in 無法使用於 diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Common/AdhocLanguageServices.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/AdhocLanguageServices.cs similarity index 90% rename from src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Common/AdhocLanguageServices.cs rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/AdhocLanguageServices.cs index 1aea1e54e3f..f3976c29ed0 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Common/AdhocLanguageServices.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/AdhocLanguageServices.cs @@ -4,9 +4,8 @@ using System; using System.Collections.Immutable; using Microsoft.CodeAnalysis.Host; -using Microsoft.CodeAnalysis.Razor; -namespace Microsoft.AspNetCore.Razor.LanguageServer.Common; +namespace Microsoft.CodeAnalysis.Razor.Workspaces; internal sealed class AdhocLanguageServices( AdhocWorkspaceServices workspaceServices, diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Common/AdhocServices.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/AdhocServices.cs similarity index 96% rename from src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Common/AdhocServices.cs rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/AdhocServices.cs index 45364d4990c..7445136553a 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Common/AdhocServices.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/AdhocServices.cs @@ -4,10 +4,10 @@ using System; using System.Collections.Immutable; using System.Reflection; -using Microsoft.CodeAnalysis; +using Microsoft.AspNetCore.Razor; using Microsoft.CodeAnalysis.Host; -namespace Microsoft.AspNetCore.Razor.LanguageServer.Common; +namespace Microsoft.CodeAnalysis.Razor.Workspaces; internal sealed class AdhocServices : HostServices { diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Common/AdhocWorkspaceServices.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/AdhocWorkspaceServices.cs similarity index 95% rename from src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Common/AdhocWorkspaceServices.cs rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/AdhocWorkspaceServices.cs index 629f30c4852..1bc19ebb363 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Common/AdhocWorkspaceServices.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/AdhocWorkspaceServices.cs @@ -4,11 +4,9 @@ using System; using System.Collections.Generic; using System.Collections.Immutable; -using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Host; -using Microsoft.CodeAnalysis.Razor; -namespace Microsoft.AspNetCore.Razor.LanguageServer.Common; +namespace Microsoft.CodeAnalysis.Razor.Workspaces; internal sealed class AdhocWorkspaceServices : HostWorkspaceServices { diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/CSharpFormatter.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/CSharpFormatter.cs similarity index 99% rename from src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/CSharpFormatter.cs rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/CSharpFormatter.cs index f87c51192c1..fbef2ed9e2a 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/CSharpFormatter.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/CSharpFormatter.cs @@ -17,7 +17,7 @@ using Microsoft.VisualStudio.LanguageServer.Protocol; using Range = Microsoft.VisualStudio.LanguageServer.Protocol.Range; -namespace Microsoft.AspNetCore.Razor.LanguageServer.Formatting; +namespace Microsoft.CodeAnalysis.Razor.Formatting; internal sealed class CSharpFormatter(IDocumentMappingService documentMappingService) { diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/CSharpFormattingPass.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/CSharpFormattingPass.cs similarity index 98% rename from src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/CSharpFormattingPass.cs rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/CSharpFormattingPass.cs index 7db855f9bd1..e061b305aaf 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/CSharpFormattingPass.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/CSharpFormattingPass.cs @@ -15,7 +15,7 @@ using Microsoft.CodeAnalysis.Text; using Microsoft.VisualStudio.LanguageServer.Protocol; -namespace Microsoft.AspNetCore.Razor.LanguageServer.Formatting; +namespace Microsoft.CodeAnalysis.Razor.Formatting; internal sealed class CSharpFormattingPass( IDocumentMappingService documentMappingService, diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/CSharpFormattingPassBase.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/CSharpFormattingPassBase.cs similarity index 99% rename from src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/CSharpFormattingPassBase.cs rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/CSharpFormattingPassBase.cs index 590189a5362..27b38a0e31a 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/CSharpFormattingPassBase.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/CSharpFormattingPassBase.cs @@ -16,7 +16,9 @@ using Microsoft.VisualStudio.LanguageServer.Protocol; using Range = Microsoft.VisualStudio.LanguageServer.Protocol.Range; -namespace Microsoft.AspNetCore.Razor.LanguageServer.Formatting; +namespace Microsoft.CodeAnalysis.Razor.Formatting; + +using SyntaxNode = Microsoft.AspNetCore.Razor.Language.Syntax.SyntaxNode; internal abstract class CSharpFormattingPassBase : FormattingPassBase { diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/CSharpOnTypeFormattingPass.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/CSharpOnTypeFormattingPassBase.cs similarity index 95% rename from src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/CSharpOnTypeFormattingPass.cs rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/CSharpOnTypeFormattingPassBase.cs index bad1194d899..8e17fba8298 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/CSharpOnTypeFormattingPass.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/CSharpOnTypeFormattingPassBase.cs @@ -7,10 +7,10 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; +using Microsoft.AspNetCore.Razor; using Microsoft.AspNetCore.Razor.Language; using Microsoft.AspNetCore.Razor.Language.Legacy; using Microsoft.AspNetCore.Razor.Language.Syntax; -using Microsoft.AspNetCore.Razor.LanguageServer.CodeActions; using Microsoft.AspNetCore.Razor.PooledObjects; using Microsoft.AspNetCore.Razor.TextDifferencing; using Microsoft.CodeAnalysis; @@ -21,16 +21,17 @@ using Microsoft.CodeAnalysis.Text; using Microsoft.VisualStudio.LanguageServer.Protocol; using Range = Microsoft.VisualStudio.LanguageServer.Protocol.Range; -using SyntaxNode = Microsoft.AspNetCore.Razor.Language.Syntax.SyntaxNode; -namespace Microsoft.AspNetCore.Razor.LanguageServer.Formatting; +namespace Microsoft.CodeAnalysis.Razor.Formatting; + +using SyntaxNode = Microsoft.AspNetCore.Razor.Language.Syntax.SyntaxNode; -internal sealed class CSharpOnTypeFormattingPass( +internal abstract class CSharpOnTypeFormattingPassBase( IDocumentMappingService documentMappingService, ILoggerFactory loggerFactory) : CSharpFormattingPassBase(documentMappingService) { - private readonly ILogger _logger = loggerFactory.GetOrCreateLogger(); + private readonly ILogger _logger = loggerFactory.GetOrCreateLogger(); public async override Task ExecuteAsync(FormattingContext context, FormattingResult result, CancellationToken cancellationToken) { @@ -207,20 +208,7 @@ public async override Task ExecuteAsync(FormattingContext cont return new FormattingResult(finalEdits); } - private static async Task AddUsingStatementEditsIfNecessaryAsync(FormattingContext context, RazorCodeDocument codeDocument, SourceText csharpText, TextEdit[] textEdits, SourceText originalTextWithChanges, TextEdit[] finalEdits, CancellationToken cancellationToken) - { - if (context.AutomaticallyAddUsings) - { - // Because we need to parse the C# code twice for this operation, lets do a quick check to see if its even necessary - if (textEdits.Any(e => e.NewText.IndexOf("using") != -1)) - { - var usingStatementEdits = await AddUsingsCodeActionProviderHelper.GetUsingStatementEditsAsync(codeDocument, csharpText, originalTextWithChanges, cancellationToken).ConfigureAwait(false); - finalEdits = [.. usingStatementEdits, .. finalEdits]; - } - } - - return finalEdits; - } + protected abstract Task AddUsingStatementEditsIfNecessaryAsync(FormattingContext context, RazorCodeDocument codeDocument, SourceText csharpText, TextEdit[] textEdits, SourceText originalTextWithChanges, TextEdit[] finalEdits, CancellationToken cancellationToken); // Returns the minimal TextSpan that encompasses all the differences between the old and the new text. private static SourceText ApplyChangesAndTrackChange(SourceText oldText, IEnumerable changes, out TextSpan spanBeforeChange, out TextSpan spanAfterChange) diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/FormattingBlockKind.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/FormattingBlockKind.cs similarity index 84% rename from src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/FormattingBlockKind.cs rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/FormattingBlockKind.cs index 50ac3e691f8..ff80c2cc1e9 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/FormattingBlockKind.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/FormattingBlockKind.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the MIT license. See License.txt in the project root for license information. -namespace Microsoft.AspNetCore.Razor.LanguageServer.Formatting; +namespace Microsoft.CodeAnalysis.Razor.Formatting; internal enum FormattingBlockKind { diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/FormattingContentValidationPass.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/FormattingContentValidationPass.cs similarity index 97% rename from src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/FormattingContentValidationPass.cs rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/FormattingContentValidationPass.cs index ff1eccb1f1c..7973e9d0df3 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/FormattingContentValidationPass.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/FormattingContentValidationPass.cs @@ -11,7 +11,7 @@ using Microsoft.CodeAnalysis.Text; using Microsoft.VisualStudio.LanguageServer.Protocol; -namespace Microsoft.AspNetCore.Razor.LanguageServer.Formatting; +namespace Microsoft.CodeAnalysis.Razor.Formatting; internal sealed class FormattingContentValidationPass( IDocumentMappingService documentMappingService, diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/FormattingContext.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/FormattingContext.cs similarity index 97% rename from src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/FormattingContext.cs rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/FormattingContext.cs index 9e1c13b6e92..e5329eccbc7 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/FormattingContext.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/FormattingContext.cs @@ -9,17 +9,20 @@ using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Razor.Language; +using Microsoft.AspNetCore.Razor.Language.Syntax; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Razor.ProjectSystem; +using Microsoft.CodeAnalysis.Razor.Workspaces; using Microsoft.CodeAnalysis.Text; using Microsoft.VisualStudio.LanguageServer.Protocol; -namespace Microsoft.AspNetCore.Razor.LanguageServer.Formatting; +namespace Microsoft.CodeAnalysis.Razor.Formatting; -internal class FormattingContext : IDisposable +internal sealed class FormattingContext : IDisposable { private readonly IAdhocWorkspaceFactory _workspaceFactory; private Document? _csharpWorkspaceDocument; + private AdhocWorkspace? _csharpWorkspace; private IReadOnlyList? _formattingSpans; @@ -296,8 +299,8 @@ private static void DEBUG_ValidateComponents(RazorCodeDocument oldCodeDocument, return; } - var oldTagHelperElements = oldCodeDocument.GetSyntaxTree().Root.DescendantNodesAndSelf().OfType().Count(); - var newTagHelperElements = newCodeDocument.GetSyntaxTree().Root.DescendantNodesAndSelf().OfType().Count(); + var oldTagHelperElements = oldCodeDocument.GetSyntaxTree().Root.DescendantNodesAndSelf().OfType().Count(); + var newTagHelperElements = newCodeDocument.GetSyntaxTree().Root.DescendantNodesAndSelf().OfType().Count(); Debug.Assert(oldTagHelperElements == newTagHelperElements, $"Previous context had {oldTagHelperElements} components, new only has {newTagHelperElements}."); } diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/FormattingDiagnosticValidationPass.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/FormattingDiagnosticValidationPass.cs similarity index 98% rename from src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/FormattingDiagnosticValidationPass.cs rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/FormattingDiagnosticValidationPass.cs index 8f7cfda5c60..64bf765dd73 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/FormattingDiagnosticValidationPass.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/FormattingDiagnosticValidationPass.cs @@ -13,7 +13,7 @@ using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.VisualStudio.LanguageServer.Protocol; -namespace Microsoft.AspNetCore.Razor.LanguageServer.Formatting; +namespace Microsoft.CodeAnalysis.Razor.Formatting; internal sealed class FormattingDiagnosticValidationPass( IDocumentMappingService documentMappingService, diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/FormattingOptionsExtensions.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/FormattingOptionsExtensions.cs similarity index 89% rename from src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/FormattingOptionsExtensions.cs rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/FormattingOptionsExtensions.cs index 5271e0f9ec1..63fcae2af9d 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/FormattingOptionsExtensions.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/FormattingOptionsExtensions.cs @@ -4,7 +4,7 @@ using Microsoft.CodeAnalysis.ExternalAccess.Razor; using Microsoft.VisualStudio.LanguageServer.Protocol; -namespace Microsoft.AspNetCore.Razor.LanguageServer.Formatting; +namespace Microsoft.CodeAnalysis.Razor.Formatting; internal static class FormattingOptionsExtensions { diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/FormattingPassBase.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/FormattingPassBase.cs similarity index 93% rename from src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/FormattingPassBase.cs rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/FormattingPassBase.cs index 8f0f6e1dc86..535649ec766 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/FormattingPassBase.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/FormattingPassBase.cs @@ -5,12 +5,11 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Razor.Language; -using Microsoft.AspNetCore.Razor.LanguageServer.Hosting; using Microsoft.CodeAnalysis.Razor.DocumentMapping; using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.VisualStudio.LanguageServer.Protocol; -namespace Microsoft.AspNetCore.Razor.LanguageServer.Formatting; +namespace Microsoft.CodeAnalysis.Razor.Formatting; internal abstract class FormattingPassBase(IDocumentMappingService documentMappingService) : IFormattingPass { diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/FormattingResult.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/FormattingResult.cs similarity index 86% rename from src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/FormattingResult.cs rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/FormattingResult.cs index 7dc0c87c222..e8db79e5204 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/FormattingResult.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/FormattingResult.cs @@ -5,9 +5,9 @@ using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.VisualStudio.LanguageServer.Protocol; -namespace Microsoft.AspNetCore.Razor.LanguageServer.Formatting; +namespace Microsoft.CodeAnalysis.Razor.Formatting; -internal struct FormattingResult +internal readonly struct FormattingResult { public FormattingResult(TextEdit[] edits, RazorLanguageKind kind = RazorLanguageKind.Razor) { diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/FormattingSpan.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/FormattingSpan.cs similarity index 96% rename from src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/FormattingSpan.cs rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/FormattingSpan.cs index 0afa79033e6..6ceb2a138a6 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/FormattingSpan.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/FormattingSpan.cs @@ -3,7 +3,7 @@ using Microsoft.CodeAnalysis.Text; -namespace Microsoft.AspNetCore.Razor.LanguageServer.Formatting; +namespace Microsoft.CodeAnalysis.Razor.Formatting; internal class FormattingSpan { diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/FormattingSpanKind.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/FormattingSpanKind.cs similarity index 80% rename from src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/FormattingSpanKind.cs rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/FormattingSpanKind.cs index 707683355aa..24d4e98b82b 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/FormattingSpanKind.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/FormattingSpanKind.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the MIT license. See License.txt in the project root for license information. -namespace Microsoft.AspNetCore.Razor.LanguageServer.Formatting; +namespace Microsoft.CodeAnalysis.Razor.Formatting; internal enum FormattingSpanKind { diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/FormattingUtilities.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/FormattingUtilities.cs similarity index 74% rename from src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/FormattingUtilities.cs rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/FormattingUtilities.cs index 9cd27d17513..7e57a27d3fc 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/FormattingUtilities.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/FormattingUtilities.cs @@ -2,9 +2,8 @@ // Licensed under the MIT license. See License.txt in the project root for license information. using Microsoft.AspNetCore.Razor.Language; -using Microsoft.AspNetCore.Razor.LanguageServer.Hosting; -namespace Microsoft.AspNetCore.Razor.LanguageServer.Formatting; +namespace Microsoft.CodeAnalysis.Razor.Formatting; internal static class FormattingUtilities { @@ -17,19 +16,20 @@ internal static class FormattingUtilities /// /// The method to add indenting to. The method should be marked with where an indent is wanted /// - /// - /// The that contains information about indenting. + /// + /// The indentation size + /// + /// + /// Use spaces for indentation. /// /// /// The size of the any existing indent. /// /// The indented method. - public static string AddIndentationToMethod(string method, RazorLSPOptions options, int startingIndent) + public static string AddIndentationToMethod(string method, int tabSize, bool insertSpaces, int startingIndent) { - var indentSize = options.TabSize; - var insertSpaces = options.InsertSpaces; - var initialIndent = GetIndentationString(startingIndent, insertSpaces, indentSize); - var indent = GetIndentationString(indentSize, insertSpaces, indentSize); + var initialIndent = GetIndentationString(startingIndent, insertSpaces, tabSize); + var indent = GetIndentationString(tabSize, insertSpaces, tabSize); return method.Replace(InitialIndent, initialIndent).Replace(Indent, indent); } @@ -40,8 +40,11 @@ public static string AddIndentationToMethod(string method, RazorLSPOptions optio /// The method to add indenting to. The method should be marked with where an indent is wanted /// and where some initial indent is needed. /// - /// - /// The that contains information about indenting. + /// + /// The indentation size + /// + /// + /// Use spaces for indentation. /// /// /// The absolute index of the beginning of the class in the C# file the method will be added to. @@ -53,14 +56,14 @@ public static string AddIndentationToMethod(string method, RazorLSPOptions optio /// The contents of the C# file. /// /// The indented method. - public static string AddIndentationToMethod(string method, RazorLSPOptions options, int startAbsoluteIndex, int numCharacterBefore, string source) + public static string AddIndentationToMethod(string method, int tabSize, bool insertSpaces, int startAbsoluteIndex, int numCharacterBefore, string source) { var startingIndent = 0; for (var i = 1; i <= numCharacterBefore; i++) { if (source[startAbsoluteIndex - i] == '\t') { - startingIndent += options.TabSize; + startingIndent += tabSize; } else { @@ -68,7 +71,7 @@ public static string AddIndentationToMethod(string method, RazorLSPOptions optio } } - return AddIndentationToMethod(method, options, startingIndent); + return AddIndentationToMethod(method, tabSize, insertSpaces, startingIndent); } /// @@ -78,9 +81,10 @@ public static string AddIndentationToMethod(string method, RazorLSPOptions optio /// The method to add indenting to. The method should be marked with where an indent is wanted /// and where some initial indent is needed. /// - /// - /// The that contains information about indenting. + /// + /// The indentation size /// + /// /// /// The absolute index of the beginning of the code block in the Razor file where the method will be added to. /// @@ -91,14 +95,14 @@ public static string AddIndentationToMethod(string method, RazorLSPOptions optio /// The of the razor file the method is being added to. /// /// The indented method. - public static string AddIndentationToMethod(string method, RazorLSPOptions options, int startAbsoluteIndex, int numCharacterBefore, RazorSourceDocument source) + public static string AddIndentationToMethod(string method, int tabSize, bool insertSpaces, int startAbsoluteIndex, int numCharacterBefore, RazorSourceDocument source) { var startingIndent = 0; for (var i = 1; i <= numCharacterBefore; i++) { if (source.Text[startAbsoluteIndex - i] == '\t') { - startingIndent += options.TabSize; + startingIndent += tabSize; } else { @@ -106,7 +110,7 @@ public static string AddIndentationToMethod(string method, RazorLSPOptions optio } } - return AddIndentationToMethod(method, options, startingIndent); + return AddIndentationToMethod(method, tabSize, insertSpaces, startingIndent); } /// @@ -114,7 +118,7 @@ public static string AddIndentationToMethod(string method, RazorLSPOptions optio /// /// An amount of characters to represent the indentation. /// Whether spaces are used for indentation. - /// The size of a tab. + /// The size of a tab and indentation. /// A whitespace string representation indentation. public static string GetIndentationString(int indentation, bool insertSpaces, int tabSize) { diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/FormattingVisitor.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/FormattingVisitor.cs similarity index 96% rename from src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/FormattingVisitor.cs rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/FormattingVisitor.cs index f670882725b..dacc33a58dc 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/FormattingVisitor.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/FormattingVisitor.cs @@ -7,14 +7,18 @@ using System.Linq; using Microsoft.AspNetCore.Razor.Language; using Microsoft.AspNetCore.Razor.Language.Components; -using Microsoft.AspNetCore.Razor.Language.Extensions; using Microsoft.AspNetCore.Razor.Language.Syntax; -using Microsoft.CodeAnalysis.Razor.Workspaces; using Microsoft.CodeAnalysis.Text; -namespace Microsoft.AspNetCore.Razor.LanguageServer.Formatting; +using RazorSyntaxTokenList = Microsoft.AspNetCore.Razor.Language.Syntax.SyntaxList; +using RazorSyntaxWalker = Microsoft.AspNetCore.Razor.Language.Syntax.SyntaxWalker; -internal class FormattingVisitor : SyntaxWalker +namespace Microsoft.CodeAnalysis.Razor.Formatting; + +// There is already RazorSyntaxNode so not following that pattern for this alias +using SyntaxNode = Microsoft.AspNetCore.Razor.Language.Syntax.SyntaxNode; + +internal class FormattingVisitor : RazorSyntaxWalker { private const string HtmlTag = "html"; @@ -318,7 +322,7 @@ public override void VisitMarkupAttributeBlock(MarkupAttributeBlockSyntax node) { WriteBlock(node, FormattingBlockKind.Markup, n => { - var equalsSyntax = SyntaxFactory.MarkupTextLiteral(new SyntaxList(node.EqualsToken), chunkGenerator: null); + var equalsSyntax = SyntaxFactory.MarkupTextLiteral(new RazorSyntaxTokenList(node.EqualsToken), chunkGenerator: null); var mergedAttributePrefix = SyntaxUtilities.MergeTextLiterals(node.NamePrefix, node.Name, node.NameSuffix, equalsSyntax, node.ValuePrefix); Visit(mergedAttributePrefix); Visit(node.Value); @@ -330,7 +334,7 @@ public override void VisitMarkupTagHelperAttribute(MarkupTagHelperAttributeSynta { WriteBlock(node, FormattingBlockKind.Tag, n => { - var equalsSyntax = SyntaxFactory.MarkupTextLiteral(new SyntaxList(node.EqualsToken), chunkGenerator: null); + var equalsSyntax = SyntaxFactory.MarkupTextLiteral(new RazorSyntaxTokenList(node.EqualsToken), chunkGenerator: null); var mergedAttributePrefix = SyntaxUtilities.MergeTextLiterals(node.NamePrefix, node.Name, node.NameSuffix, equalsSyntax, node.ValuePrefix); Visit(mergedAttributePrefix); Visit(node.Value); diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/IFormattingPass.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/IFormattingPass.cs similarity index 87% rename from src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/IFormattingPass.cs rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/IFormattingPass.cs index 1c88df4ae32..cebfed8ad87 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/IFormattingPass.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/IFormattingPass.cs @@ -4,7 +4,7 @@ using System.Threading; using System.Threading.Tasks; -namespace Microsoft.AspNetCore.Razor.LanguageServer.Formatting; +namespace Microsoft.CodeAnalysis.Razor.Formatting; internal interface IFormattingPass { diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/IRazorFormattingService.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/IRazorFormattingService.cs similarity index 95% rename from src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/IRazorFormattingService.cs rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/IRazorFormattingService.cs index 9048b915931..a5001dddd02 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/IRazorFormattingService.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/IRazorFormattingService.cs @@ -7,7 +7,7 @@ using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.VisualStudio.LanguageServer.Protocol; -namespace Microsoft.AspNetCore.Razor.LanguageServer.Formatting; +namespace Microsoft.CodeAnalysis.Razor.Formatting; internal interface IRazorFormattingService { diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/IndentationContext.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/IndentationContext.cs similarity index 96% rename from src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/IndentationContext.cs rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/IndentationContext.cs index fadd42bf76a..f688f92c5bb 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/IndentationContext.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/IndentationContext.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the MIT license. See License.txt in the project root for license information. -namespace Microsoft.AspNetCore.Razor.LanguageServer.Formatting; +namespace Microsoft.CodeAnalysis.Razor.Formatting; internal class IndentationContext { diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/RazorFormattingPass.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/RazorFormattingPassBase.cs similarity index 94% rename from src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/RazorFormattingPass.cs rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/RazorFormattingPassBase.cs index 0fe7872f2d9..883538508d2 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/RazorFormattingPass.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/RazorFormattingPassBase.cs @@ -6,6 +6,7 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; +using Microsoft.AspNetCore.Razor; using Microsoft.AspNetCore.Razor.Language; using Microsoft.AspNetCore.Razor.Language.Components; using Microsoft.AspNetCore.Razor.Language.Extensions; @@ -14,15 +15,17 @@ using Microsoft.CodeAnalysis.Text; using Microsoft.VisualStudio.LanguageServer.Protocol; -namespace Microsoft.AspNetCore.Razor.LanguageServer.Formatting; +using RazorRazorSyntaxNodeList = Microsoft.AspNetCore.Razor.Language.Syntax.SyntaxList; +using RazorSyntaxNodeList = Microsoft.AspNetCore.Razor.Language.Syntax.SyntaxList; -internal sealed class RazorFormattingPass( - IDocumentMappingService documentMappingService, - RazorLSPOptionsMonitor optionsMonitor) +namespace Microsoft.CodeAnalysis.Razor.Formatting; + +using SyntaxNode = AspNetCore.Razor.Language.Syntax.SyntaxNode; + +internal abstract class RazorFormattingPassBase( + IDocumentMappingService documentMappingService) : FormattingPassBase(documentMappingService) { - private readonly RazorLSPOptionsMonitor _optionsMonitor = optionsMonitor; - // Run after the C# formatter pass. public override int Order => DefaultOrder - 4; @@ -63,6 +66,8 @@ public async override Task ExecuteAsync(FormattingContext cont return new FormattingResult(finalEdits); } + protected abstract bool CodeBlockBraceOnNextLine { get; } + private IEnumerable FormatRazor(FormattingContext context, RazorSyntaxTree syntaxTree) { var edits = new List(); @@ -72,7 +77,7 @@ private IEnumerable FormatRazor(FormattingContext context, RazorSyntax { // Disclaimer: CSharpCodeBlockSyntax is used a _lot_ in razor so these methods are probably // being overly careful to only try to format syntax forms they care about. - TryFormatCSharpBlockStructure(context, edits, source, node); + TryFormatCSharpBlockStructure(context, edits, source, node); // TODO TryFormatSingleLineDirective(edits, source, node); TryFormatBlocks(context, edits, source, node); } @@ -126,7 +131,7 @@ directiveCode.Children is [RazorDirectiveSyntax directive] && return false; - static bool TryGetWhitespace(SyntaxList children, [NotNullWhen(true)] out CSharpStatementLiteralSyntax? whitespaceBeforeSectionName, [NotNullWhen(true)] out UnclassifiedTextLiteralSyntax? whitespaceAfterSectionName) + static bool TryGetWhitespace(RazorRazorSyntaxNodeList children, [NotNullWhen(true)] out CSharpStatementLiteralSyntax? whitespaceBeforeSectionName, [NotNullWhen(true)] out UnclassifiedTextLiteralSyntax? whitespaceAfterSectionName) { // If there is whitespace between the directive and the section name, and the section name and the brace, they will be in the first child // and third child of the 6 total children @@ -266,7 +271,7 @@ private void TryFormatCSharpBlockStructure(FormattingContext context, List children, [NotNullWhen(true)] out UnclassifiedTextLiteralSyntax? whitespace) + static bool TryGetLeadingWhitespace(RazorRazorSyntaxNodeList children, [NotNullWhen(true)] out UnclassifiedTextLiteralSyntax? whitespace) { // If there is whitespace between the directive and the brace, it will be in the first child // of the 4 total children @@ -327,7 +332,7 @@ private static void TryFormatSingleLineDirective(List edits, RazorSour } } - static bool IsSingleLineDirective(SyntaxNode node, out SyntaxList children) + static bool IsSingleLineDirective(SyntaxNode node, out RazorSyntaxNodeList children) { if (node is CSharpCodeBlockSyntax content && node.Parent?.Parent is RazorDirectiveSyntax directive && diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/RazorFormattingService.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/RazorFormattingService.cs similarity index 99% rename from src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/RazorFormattingService.cs rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/RazorFormattingService.cs index 7989815323b..1b14b3fa013 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/RazorFormattingService.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/RazorFormattingService.cs @@ -11,11 +11,12 @@ using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Razor.ProjectSystem; using Microsoft.CodeAnalysis.Razor.Protocol; +using Microsoft.CodeAnalysis.Razor.Workspaces; using Microsoft.CodeAnalysis.Text; using Microsoft.VisualStudio.LanguageServer.Protocol; using Range = Microsoft.VisualStudio.LanguageServer.Protocol.Range; -namespace Microsoft.AspNetCore.Razor.LanguageServer.Formatting; +namespace Microsoft.CodeAnalysis.Razor.Formatting; internal class RazorFormattingService : IRazorFormattingService { diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/IAdhocWorkspaceFactory.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/IAdhocWorkspaceFactory.cs similarity index 78% rename from src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/IAdhocWorkspaceFactory.cs rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/IAdhocWorkspaceFactory.cs index 084a0b01ae9..d84d3f46073 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/IAdhocWorkspaceFactory.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/IAdhocWorkspaceFactory.cs @@ -1,10 +1,9 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the MIT license. See License.txt in the project root for license information. -using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Host; -namespace Microsoft.AspNetCore.Razor.LanguageServer; +namespace Microsoft.CodeAnalysis.Razor.Workspaces; internal interface IAdhocWorkspaceFactory { diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Logging/ILoggerExtensions.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Logging/ILoggerExtensions.cs index 8f46e524a91..ced31bd8ea3 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Logging/ILoggerExtensions.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Logging/ILoggerExtensions.cs @@ -2,7 +2,10 @@ // Licensed under the MIT license. See License.txt in the project root for license information. using System; +using System.Diagnostics; using System.Runtime.CompilerServices; +using System.Text; +using Microsoft.AspNetCore.Razor.PooledObjects; namespace Microsoft.CodeAnalysis.Razor.Logging; @@ -184,3 +187,56 @@ public static void LogCritical(this ILogger logger, string message) } } } + +internal static class ITestOnlyLoggerExtensions +{ + public static bool TestOnlyLoggingEnabled = false; + + [Conditional("DEBUG")] + public static void LogTestOnly(this ILogger logger, ref TestLogMessageInterpolatedStringHandler handler) + { + if (TestOnlyLoggingEnabled) + { + logger.Log(LogLevel.Debug, handler.ToString(), exception: null); + } + } +} + +[InterpolatedStringHandler] +internal ref struct TestLogMessageInterpolatedStringHandler +{ + private PooledObject _builder; + + public TestLogMessageInterpolatedStringHandler(int literalLength, int _, out bool isEnabled) + { + isEnabled = ITestOnlyLoggerExtensions.TestOnlyLoggingEnabled; + if (isEnabled) + { + _builder = StringBuilderPool.GetPooledObject(); + _builder.Object.EnsureCapacity(literalLength); + } + } + + public void AppendLiteral(string s) + { + _builder.Object.Append(s); + } + + public void AppendFormatted(T t) + { + _builder.Object.Append(t?.ToString() ?? "[null]"); + } + + public void AppendFormatted(T t, string format) + { + _builder.Object.AppendFormat(format, t); + } + + public override string ToString() + { + var result = _builder.Object.ToString(); + _builder.Dispose(); + return result; + } +} + diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/SR.resx b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/SR.resx index 6acddbbd1bb..ac9ac407183 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/SR.resx +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/SR.resx @@ -142,4 +142,25 @@ Attempted to visit a RazorMetaCode other than '{' or '}'. + + A format operation is being abandoned because it would add or delete non-whitespace content. + + + Edit at {0} adds the non-whitespace content '{1}'. + + + Edit at {0} deletes the non-whitespace content '{1}'. + + + A format operation is being abandoned because it would introduce or remove one of more diagnostics. + + + Diagnostics before: + + + Diagnostics after: + + + Razor language services not configured properly, missing language service '{0}'. + \ No newline at end of file diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.cs.xlf b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.cs.xlf index c361c43a7a9..462c200ab35 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.cs.xlf +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.cs.xlf @@ -7,6 +7,16 @@ Hodnota nesmí být null ani prázdný řetězec. + + Diagnostics after: + Diagnostics after: + + + + Diagnostics before: + Diagnostics before: + + directive direktiva @@ -19,11 +29,36 @@ [Tab] pro navigaci mezi elementy, [Enter] pro dokončení + + Edit at {0} adds the non-whitespace content '{1}'. + Edit at {0} adds the non-whitespace content '{1}'. + + + + Edit at {0} deletes the non-whitespace content '{1}'. + Edit at {0} deletes the non-whitespace content '{1}'. + + + + A format operation is being abandoned because it would introduce or remove one of more diagnostics. + A format operation is being abandoned because it would introduce or remove one of more diagnostics. + + + + A format operation is being abandoned because it would add or delete non-whitespace content. + A format operation is being abandoned because it would add or delete non-whitespace content. + + Invalid offset. Neplatný posun + + Razor language services not configured properly, missing language service '{0}'. + Razor language services not configured properly, missing language service '{0}'. + + Character '{0}' outside of the {1} range of '{2}' was queried. The document may not be up to date. Proběhl dotaz na znak {0} mimo rozsah {1} v {2}. Dokument nemusí být aktuální. diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.de.xlf b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.de.xlf index e4c85ebf1b0..3a727a4f3dc 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.de.xlf +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.de.xlf @@ -7,6 +7,16 @@ Der Wert darf nicht NULL oder eine leere Zeichenfolge sein. + + Diagnostics after: + Diagnostics after: + + + + Diagnostics before: + Diagnostics before: + + directive Direktive @@ -19,11 +29,36 @@ [Registerkarte] ein, um zwischen Elementen zu navigieren, [EINGABETASTE], um den Vorgang abzuschließen + + Edit at {0} adds the non-whitespace content '{1}'. + Edit at {0} adds the non-whitespace content '{1}'. + + + + Edit at {0} deletes the non-whitespace content '{1}'. + Edit at {0} deletes the non-whitespace content '{1}'. + + + + A format operation is being abandoned because it would introduce or remove one of more diagnostics. + A format operation is being abandoned because it would introduce or remove one of more diagnostics. + + + + A format operation is being abandoned because it would add or delete non-whitespace content. + A format operation is being abandoned because it would add or delete non-whitespace content. + + Invalid offset. Ungültiger Offset. + + Razor language services not configured properly, missing language service '{0}'. + Razor language services not configured properly, missing language service '{0}'. + + Character '{0}' outside of the {1} range of '{2}' was queried. The document may not be up to date. Das Zeichen "{0}" außerhalb des {1} Bereichs von "{2}" wurde abgefragt. Das Dokument ist möglicherweise nicht auf dem neuesten Stand. diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.es.xlf b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.es.xlf index ac1640b0d1a..007ccba3f61 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.es.xlf +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.es.xlf @@ -7,6 +7,16 @@ El valor no puede ser nulo ni una cadena vacía. + + Diagnostics after: + Diagnostics after: + + + + Diagnostics before: + Diagnostics before: + + directive directiva @@ -19,11 +29,36 @@ [Tab] para navegar entre elementos, [Entrar] para completar + + Edit at {0} adds the non-whitespace content '{1}'. + Edit at {0} adds the non-whitespace content '{1}'. + + + + Edit at {0} deletes the non-whitespace content '{1}'. + Edit at {0} deletes the non-whitespace content '{1}'. + + + + A format operation is being abandoned because it would introduce or remove one of more diagnostics. + A format operation is being abandoned because it would introduce or remove one of more diagnostics. + + + + A format operation is being abandoned because it would add or delete non-whitespace content. + A format operation is being abandoned because it would add or delete non-whitespace content. + + Invalid offset. Desplazamiento no válido. + + Razor language services not configured properly, missing language service '{0}'. + Razor language services not configured properly, missing language service '{0}'. + + Character '{0}' outside of the {1} range of '{2}' was queried. The document may not be up to date. Se consultó el carácter '{0}' fuera del intervalo {1} de '{2}'. Es posible que el documento no esté actualizado. diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.fr.xlf b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.fr.xlf index 326606e77da..33866cc0cc5 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.fr.xlf +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.fr.xlf @@ -7,6 +7,16 @@ La valeur ne peut pas être Null ni être une chaîne vide. + + Diagnostics after: + Diagnostics after: + + + + Diagnostics before: + Diagnostics before: + + directive directif @@ -19,11 +29,36 @@ [Tab] pour naviguer entre les éléments, [Entrée] pour terminer + + Edit at {0} adds the non-whitespace content '{1}'. + Edit at {0} adds the non-whitespace content '{1}'. + + + + Edit at {0} deletes the non-whitespace content '{1}'. + Edit at {0} deletes the non-whitespace content '{1}'. + + + + A format operation is being abandoned because it would introduce or remove one of more diagnostics. + A format operation is being abandoned because it would introduce or remove one of more diagnostics. + + + + A format operation is being abandoned because it would add or delete non-whitespace content. + A format operation is being abandoned because it would add or delete non-whitespace content. + + Invalid offset. Décalage non valide. + + Razor language services not configured properly, missing language service '{0}'. + Razor language services not configured properly, missing language service '{0}'. + + Character '{0}' outside of the {1} range of '{2}' was queried. The document may not be up to date. Le caractère « {0} » en dehors de la plage {1} de « {2} » a été interrogé. Le document n’est peut-être pas à jour. diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.it.xlf b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.it.xlf index 6ad13e1266b..a5db731142a 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.it.xlf +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.it.xlf @@ -7,6 +7,16 @@ Il valore non può essere null o una stringa vuota. + + Diagnostics after: + Diagnostics after: + + + + Diagnostics before: + Diagnostics before: + + directive direttiva @@ -19,11 +29,36 @@ [Tab] per spostarsi tra gli elementi, [INVIO] per completare + + Edit at {0} adds the non-whitespace content '{1}'. + Edit at {0} adds the non-whitespace content '{1}'. + + + + Edit at {0} deletes the non-whitespace content '{1}'. + Edit at {0} deletes the non-whitespace content '{1}'. + + + + A format operation is being abandoned because it would introduce or remove one of more diagnostics. + A format operation is being abandoned because it would introduce or remove one of more diagnostics. + + + + A format operation is being abandoned because it would add or delete non-whitespace content. + A format operation is being abandoned because it would add or delete non-whitespace content. + + Invalid offset. Offset non valido. + + Razor language services not configured properly, missing language service '{0}'. + Razor language services not configured properly, missing language service '{0}'. + + Character '{0}' outside of the {1} range of '{2}' was queried. The document may not be up to date. È stata eseguita una query sul carattere '{0}' non compresa nell'intervallo {1} di '{2}'. Il documento potrebbe non essere aggiornato. diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.ja.xlf b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.ja.xlf index 1bf560bfc01..57aec54f7e8 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.ja.xlf +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.ja.xlf @@ -7,6 +7,16 @@ 値を null または空の文字列にすることはできません。 + + Diagnostics after: + Diagnostics after: + + + + Diagnostics before: + Diagnostics before: + + directive ディレクティブ @@ -19,11 +29,36 @@ [Tab] を挿入して要素間を移動します。[Enter] を押して完了します + + Edit at {0} adds the non-whitespace content '{1}'. + Edit at {0} adds the non-whitespace content '{1}'. + + + + Edit at {0} deletes the non-whitespace content '{1}'. + Edit at {0} deletes the non-whitespace content '{1}'. + + + + A format operation is being abandoned because it would introduce or remove one of more diagnostics. + A format operation is being abandoned because it would introduce or remove one of more diagnostics. + + + + A format operation is being abandoned because it would add or delete non-whitespace content. + A format operation is being abandoned because it would add or delete non-whitespace content. + + Invalid offset. 無効なオフセットです。 + + Razor language services not configured properly, missing language service '{0}'. + Razor language services not configured properly, missing language service '{0}'. + + Character '{0}' outside of the {1} range of '{2}' was queried. The document may not be up to date. '{2}' の {1} 範囲外の文字 '{0}' がクエリされました。ドキュメントが最新ではない可能性があります。 diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.ko.xlf b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.ko.xlf index 06678b884ef..c81294f8ae2 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.ko.xlf +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.ko.xlf @@ -7,6 +7,16 @@ 값은 null이거나 빈 문자열일 수 없습니다. + + Diagnostics after: + Diagnostics after: + + + + Diagnostics before: + Diagnostics before: + + directive 지시문 @@ -19,11 +29,36 @@ 요소 간에 탐색하려면 [Tab], 완료하려면 [Enter] + + Edit at {0} adds the non-whitespace content '{1}'. + Edit at {0} adds the non-whitespace content '{1}'. + + + + Edit at {0} deletes the non-whitespace content '{1}'. + Edit at {0} deletes the non-whitespace content '{1}'. + + + + A format operation is being abandoned because it would introduce or remove one of more diagnostics. + A format operation is being abandoned because it would introduce or remove one of more diagnostics. + + + + A format operation is being abandoned because it would add or delete non-whitespace content. + A format operation is being abandoned because it would add or delete non-whitespace content. + + Invalid offset. 오프셋이 유효하지 않습니다. + + Razor language services not configured properly, missing language service '{0}'. + Razor language services not configured properly, missing language service '{0}'. + + Character '{0}' outside of the {1} range of '{2}' was queried. The document may not be up to date. '{2}'의 {1} 범위를 벗어나는 문자 '{0}'이(가) 쿼리되었습니다. 문서가 최신이 아닐 수 있습니다. diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.pl.xlf b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.pl.xlf index 545df5b9e0c..70b8f7c8f5a 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.pl.xlf +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.pl.xlf @@ -7,6 +7,16 @@ Wartość nie może być wartością null ani pustym ciągiem. + + Diagnostics after: + Diagnostics after: + + + + Diagnostics before: + Diagnostics before: + + directive dyrektywa @@ -19,11 +29,36 @@ [Tab], aby przechodzić między elementami, [Enter], aby zakończyć + + Edit at {0} adds the non-whitespace content '{1}'. + Edit at {0} adds the non-whitespace content '{1}'. + + + + Edit at {0} deletes the non-whitespace content '{1}'. + Edit at {0} deletes the non-whitespace content '{1}'. + + + + A format operation is being abandoned because it would introduce or remove one of more diagnostics. + A format operation is being abandoned because it would introduce or remove one of more diagnostics. + + + + A format operation is being abandoned because it would add or delete non-whitespace content. + A format operation is being abandoned because it would add or delete non-whitespace content. + + Invalid offset. Nieprawidłowe przesunięcie. + + Razor language services not configured properly, missing language service '{0}'. + Razor language services not configured properly, missing language service '{0}'. + + Character '{0}' outside of the {1} range of '{2}' was queried. The document may not be up to date. Zbadano znak „{0}” poza zakresem {1} „{2}”. Dokument może być nieaktualny. diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.pt-BR.xlf b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.pt-BR.xlf index 4ea9bcfdb46..f16f7b45466 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.pt-BR.xlf +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.pt-BR.xlf @@ -7,6 +7,16 @@ O valor não pode ser nulo ou uma cadeia de caracteres vazia. + + Diagnostics after: + Diagnostics after: + + + + Diagnostics before: + Diagnostics before: + + directive diretiva @@ -19,11 +29,36 @@ [Tab] para navegar entre elementos, [Enter] para concluir + + Edit at {0} adds the non-whitespace content '{1}'. + Edit at {0} adds the non-whitespace content '{1}'. + + + + Edit at {0} deletes the non-whitespace content '{1}'. + Edit at {0} deletes the non-whitespace content '{1}'. + + + + A format operation is being abandoned because it would introduce or remove one of more diagnostics. + A format operation is being abandoned because it would introduce or remove one of more diagnostics. + + + + A format operation is being abandoned because it would add or delete non-whitespace content. + A format operation is being abandoned because it would add or delete non-whitespace content. + + Invalid offset. Deslocamento inválido. + + Razor language services not configured properly, missing language service '{0}'. + Razor language services not configured properly, missing language service '{0}'. + + Character '{0}' outside of the {1} range of '{2}' was queried. The document may not be up to date. O caractere '{0}' fora do {1} intervalo de '{2}' foi consultado. É possível que o documento não esteja atualizado. diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.ru.xlf b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.ru.xlf index 80ff88d8217..f328aeb5dcd 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.ru.xlf +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.ru.xlf @@ -7,6 +7,16 @@ Значение не может быть NULL или пустой строкой. + + Diagnostics after: + Diagnostics after: + + + + Diagnostics before: + Diagnostics before: + + directive директива @@ -19,11 +29,36 @@ [Tab] для перемещения между элементами, нажмите [ВВОД] для завершения + + Edit at {0} adds the non-whitespace content '{1}'. + Edit at {0} adds the non-whitespace content '{1}'. + + + + Edit at {0} deletes the non-whitespace content '{1}'. + Edit at {0} deletes the non-whitespace content '{1}'. + + + + A format operation is being abandoned because it would introduce or remove one of more diagnostics. + A format operation is being abandoned because it would introduce or remove one of more diagnostics. + + + + A format operation is being abandoned because it would add or delete non-whitespace content. + A format operation is being abandoned because it would add or delete non-whitespace content. + + Invalid offset. Недопустимое смещение. + + Razor language services not configured properly, missing language service '{0}'. + Razor language services not configured properly, missing language service '{0}'. + + Character '{0}' outside of the {1} range of '{2}' was queried. The document may not be up to date. Запрошен символ "{0}" за пределами диапазона {1} "{2}". Возможно, документ не обновлен. diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.tr.xlf b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.tr.xlf index 7ff9ebb6980..238b1750f89 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.tr.xlf +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.tr.xlf @@ -7,6 +7,16 @@ Değer null veya boş bir dize olamaz. + + Diagnostics after: + Diagnostics after: + + + + Diagnostics before: + Diagnostics before: + + directive yönerge @@ -19,11 +29,36 @@ öğeler arasında gezinmek için [Tab], tamamlamak için [Enter] seçeneğini belirleyin + + Edit at {0} adds the non-whitespace content '{1}'. + Edit at {0} adds the non-whitespace content '{1}'. + + + + Edit at {0} deletes the non-whitespace content '{1}'. + Edit at {0} deletes the non-whitespace content '{1}'. + + + + A format operation is being abandoned because it would introduce or remove one of more diagnostics. + A format operation is being abandoned because it would introduce or remove one of more diagnostics. + + + + A format operation is being abandoned because it would add or delete non-whitespace content. + A format operation is being abandoned because it would add or delete non-whitespace content. + + Invalid offset. Geçersiz uzaklık. + + Razor language services not configured properly, missing language service '{0}'. + Razor language services not configured properly, missing language service '{0}'. + + Character '{0}' outside of the {1} range of '{2}' was queried. The document may not be up to date. '{2}' {1} aralığının dışındaki '{0}' karakteri sorgulandı. Belge güncel olmayabilir. diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.zh-Hans.xlf b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.zh-Hans.xlf index 8ca80d39e8a..c913c3de99a 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.zh-Hans.xlf +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.zh-Hans.xlf @@ -7,6 +7,16 @@ 值不能为 null 或空字符串。 + + Diagnostics after: + Diagnostics after: + + + + Diagnostics before: + Diagnostics before: + + directive 指令 @@ -19,11 +29,36 @@ 按 [Tab] 在元素之间导航,按 [Enter] 以完成 + + Edit at {0} adds the non-whitespace content '{1}'. + Edit at {0} adds the non-whitespace content '{1}'. + + + + Edit at {0} deletes the non-whitespace content '{1}'. + Edit at {0} deletes the non-whitespace content '{1}'. + + + + A format operation is being abandoned because it would introduce or remove one of more diagnostics. + A format operation is being abandoned because it would introduce or remove one of more diagnostics. + + + + A format operation is being abandoned because it would add or delete non-whitespace content. + A format operation is being abandoned because it would add or delete non-whitespace content. + + Invalid offset. 偏移无效。 + + Razor language services not configured properly, missing language service '{0}'. + Razor language services not configured properly, missing language service '{0}'. + + Character '{0}' outside of the {1} range of '{2}' was queried. The document may not be up to date. 查询了“{2}”的 {1} 范围外的字符“{0}”。文档可能不是最新的。 diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.zh-Hant.xlf b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.zh-Hant.xlf index 9eb3c67d7a0..c469cd01f4b 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.zh-Hant.xlf +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.zh-Hant.xlf @@ -7,6 +7,16 @@ 值不能為 Null 或空字串。 + + Diagnostics after: + Diagnostics after: + + + + Diagnostics before: + Diagnostics before: + + directive 指示詞 @@ -19,11 +29,36 @@ [Tab] 在元素之間瀏覽,[Enter] 完成 + + Edit at {0} adds the non-whitespace content '{1}'. + Edit at {0} adds the non-whitespace content '{1}'. + + + + Edit at {0} deletes the non-whitespace content '{1}'. + Edit at {0} deletes the non-whitespace content '{1}'. + + + + A format operation is being abandoned because it would introduce or remove one of more diagnostics. + A format operation is being abandoned because it would introduce or remove one of more diagnostics. + + + + A format operation is being abandoned because it would add or delete non-whitespace content. + A format operation is being abandoned because it would add or delete non-whitespace content. + + Invalid offset. 位移無效。 + + Razor language services not configured properly, missing language service '{0}'. + Razor language services not configured properly, missing language service '{0}'. + + Character '{0}' outside of the {1} range of '{2}' was queried. The document may not be up to date. 已查詢 '{2}' 的 {1} 範圍以外的字元 '{0}'。文件可能不是最新。 diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/Formatting/RemoteCSharpOnTypeFormattingPass.cs b/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/Formatting/RemoteCSharpOnTypeFormattingPass.cs new file mode 100644 index 00000000000..6d4e33d0af8 --- /dev/null +++ b/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/Formatting/RemoteCSharpOnTypeFormattingPass.cs @@ -0,0 +1,27 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT license. See License.txt in the project root for license information. + +using System.Diagnostics; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Razor.Language; +using Microsoft.CodeAnalysis.Razor.DocumentMapping; +using Microsoft.CodeAnalysis.Razor.Formatting; +using Microsoft.CodeAnalysis.Razor.Logging; +using Microsoft.CodeAnalysis.Text; +using Microsoft.VisualStudio.LanguageServer.Protocol; + +namespace Microsoft.AspNetCore.Razor.LanguageServer.Formatting; + +internal sealed class RemoteCSharpOnTypeFormattingPass( + IDocumentMappingService documentMappingService, + ILoggerFactory loggerFactory) + : CSharpOnTypeFormattingPassBase(documentMappingService, loggerFactory) +{ + protected override Task AddUsingStatementEditsIfNecessaryAsync(CodeAnalysis.Razor.Formatting.FormattingContext context, RazorCodeDocument codeDocument, SourceText csharpText, TextEdit[] textEdits, SourceText originalTextWithChanges, TextEdit[] finalEdits, CancellationToken cancellationToken) + { + Debug.Fail("Implement this when code actions are migrated to cohosting"); + + return Task.FromResult(finalEdits); + } +} diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/Formatting/RemoteRazorFormattingPass.cs b/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/Formatting/RemoteRazorFormattingPass.cs new file mode 100644 index 00000000000..500d610a99e --- /dev/null +++ b/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/Formatting/RemoteRazorFormattingPass.cs @@ -0,0 +1,15 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT license. See License.txt in the project root for license information. + +using Microsoft.CodeAnalysis.Razor.DocumentMapping; +using Microsoft.CodeAnalysis.Razor.Formatting; + +namespace Microsoft.AspNetCore.Razor.LanguageServer.Formatting; + +internal sealed class RemoteRazorFormattingPass( + IDocumentMappingService documentMappingService) + : RazorFormattingPassBase(documentMappingService) +{ + // TODO: properly plumb this through + protected override bool CodeBlockBraceOnNextLine => true; +} diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/RemoteAdhocWorkspaceFactory.cs b/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/RemoteAdhocWorkspaceFactory.cs new file mode 100644 index 00000000000..232561f871f --- /dev/null +++ b/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/RemoteAdhocWorkspaceFactory.cs @@ -0,0 +1,23 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT license. See License.txt in the project root for license information. + +using System.Collections.Immutable; +using Microsoft.CodeAnalysis.Host; +using Microsoft.CodeAnalysis.Razor.Workspaces; + +namespace Microsoft.CodeAnalysis.Remote.Razor; + +internal sealed class RemoteAdhocWorkspaceFactory(HostServices hostServices) : IAdhocWorkspaceFactory +{ + public AdhocWorkspace Create(params IWorkspaceService[] workspaceServices) + { + workspaceServices ??= []; + + var services = AdhocServices.Create( + workspaceServices: workspaceServices.ToImmutableArray(), + languageServices: ImmutableArray.Empty, + fallbackServices: hostServices); + + return new AdhocWorkspace(services); + } +} diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/AutoInsert/OnAutoInsertEndpointTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/AutoInsert/OnAutoInsertEndpointTest.cs index 57a48de76b4..d5c57f9abff 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/AutoInsert/OnAutoInsertEndpointTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/AutoInsert/OnAutoInsertEndpointTest.cs @@ -5,8 +5,8 @@ using System.Diagnostics.CodeAnalysis; using System.Threading.Tasks; using Microsoft.AspNetCore.Razor.Language; -using Microsoft.AspNetCore.Razor.LanguageServer.Formatting; using Microsoft.AspNetCore.Razor.LanguageServer.Test; +using Microsoft.CodeAnalysis.Razor.Formatting; using Microsoft.VisualStudio.LanguageServer.Protocol; using Xunit; using Xunit.Abstractions; diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/AutoInsert/RazorOnAutoInsertProviderTestBase.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/AutoInsert/RazorOnAutoInsertProviderTestBase.cs index cef29ea2d43..2d77fa619a3 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/AutoInsert/RazorOnAutoInsertProviderTestBase.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/AutoInsert/RazorOnAutoInsertProviderTestBase.cs @@ -6,11 +6,10 @@ using System; using System.Collections.Generic; using Microsoft.AspNetCore.Razor.Language; -using Microsoft.AspNetCore.Razor.LanguageServer.Formatting; using Microsoft.AspNetCore.Razor.LanguageServer.Test; using Microsoft.AspNetCore.Razor.Test.Common.LanguageServer; +using Microsoft.CodeAnalysis.Razor.Formatting; using Microsoft.CodeAnalysis.Razor.ProjectSystem; -using Microsoft.CodeAnalysis.Razor.Workspaces; using Microsoft.CodeAnalysis.Testing; using Microsoft.CodeAnalysis.Text; using Microsoft.VisualStudio.LanguageServer.Protocol; diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CSharp/DefaultCSharpCodeActionResolverTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CSharp/DefaultCSharpCodeActionResolverTest.cs index 6062be141b2..8ee8500337e 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CSharp/DefaultCSharpCodeActionResolverTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CSharp/DefaultCSharpCodeActionResolverTest.cs @@ -9,9 +9,9 @@ using Microsoft.AspNetCore.Mvc.Razor.Extensions; using Microsoft.AspNetCore.Razor.Language; using Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Models; -using Microsoft.AspNetCore.Razor.LanguageServer.Formatting; using Microsoft.AspNetCore.Razor.LanguageServer.Hosting; using Microsoft.AspNetCore.Razor.Test.Common.LanguageServer; +using Microsoft.CodeAnalysis.Razor.Formatting; using Microsoft.CodeAnalysis.Razor.ProjectSystem; using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.CodeAnalysis.Razor.Protocol.CodeActions; diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CodeActionEndToEndTest.NetFx.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CodeActionEndToEndTest.NetFx.cs index 33b35e3df98..1090b3672e3 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CodeActionEndToEndTest.NetFx.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CodeActionEndToEndTest.NetFx.cs @@ -23,6 +23,7 @@ using Microsoft.AspNetCore.Razor.Utilities; using Microsoft.CodeAnalysis.ExternalAccess.Razor; using Microsoft.CodeAnalysis.Razor; +using Microsoft.CodeAnalysis.Razor.Formatting; using Microsoft.CodeAnalysis.Razor.ProjectSystem; using Microsoft.CodeAnalysis.Razor.Protocol.CodeActions; using Microsoft.CodeAnalysis.Razor.Workspaces; diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Completion/Delegation/DelegatedCompletionItemResolverTest.NetFx.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Completion/Delegation/DelegatedCompletionItemResolverTest.NetFx.cs index 90b3f93b7db..c84c82b3b9a 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Completion/Delegation/DelegatedCompletionItemResolverTest.NetFx.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Completion/Delegation/DelegatedCompletionItemResolverTest.NetFx.cs @@ -13,6 +13,7 @@ using Microsoft.AspNetCore.Razor.LanguageServer.Test; using Microsoft.AspNetCore.Razor.Test.Common.LanguageServer; using Microsoft.AspNetCore.Razor.Test.Common.Mef; +using Microsoft.CodeAnalysis.Razor.Formatting; using Microsoft.CodeAnalysis.Razor.ProjectSystem; using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.CodeAnalysis.Testing; diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting/TestRazorFormattingService.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting/TestRazorFormattingService.cs index 648e368f8a8..8b29589d7d2 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting/TestRazorFormattingService.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting/TestRazorFormattingService.cs @@ -6,6 +6,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Razor.Language; using Microsoft.AspNetCore.Razor.LanguageServer.Hosting; +using Microsoft.CodeAnalysis.Razor.Formatting; using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.CodeAnalysis.Razor.ProjectSystem; diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting_NetFx/FormattingContentValidationPassTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting_NetFx/FormattingContentValidationPassTest.cs index d42f0778dc8..ba5973a36ef 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting_NetFx/FormattingContentValidationPassTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting_NetFx/FormattingContentValidationPassTest.cs @@ -8,6 +8,7 @@ using Microsoft.AspNetCore.Razor.Language; using Microsoft.AspNetCore.Razor.LanguageServer.Test; using Microsoft.AspNetCore.Razor.Test.Common.LanguageServer; +using Microsoft.CodeAnalysis.Razor.Formatting; using Microsoft.CodeAnalysis.Razor.ProjectSystem; using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.CodeAnalysis.Text; diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting_NetFx/FormattingDiagnosticValidationPassTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting_NetFx/FormattingDiagnosticValidationPassTest.cs index c0f06e9831e..60adc04a1fc 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting_NetFx/FormattingDiagnosticValidationPassTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting_NetFx/FormattingDiagnosticValidationPassTest.cs @@ -7,6 +7,7 @@ using Microsoft.AspNetCore.Razor.Language; using Microsoft.AspNetCore.Razor.LanguageServer.Test; using Microsoft.AspNetCore.Razor.Test.Common.LanguageServer; +using Microsoft.CodeAnalysis.Razor.Formatting; using Microsoft.CodeAnalysis.Razor.ProjectSystem; using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.CodeAnalysis.Text; diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting_NetFx/FormattingLanguageServerTestBase.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting_NetFx/FormattingLanguageServerTestBase.cs index 25a4ba44e63..54ae3aa7ff7 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting_NetFx/FormattingLanguageServerTestBase.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting_NetFx/FormattingLanguageServerTestBase.cs @@ -10,6 +10,7 @@ using Microsoft.AspNetCore.Razor.Language.CodeGeneration; using Microsoft.AspNetCore.Razor.Test.Common.LanguageServer; using Microsoft.AspNetCore.Razor.Threading; +using Microsoft.CodeAnalysis.Razor.Formatting; using Microsoft.CodeAnalysis.Razor.ProjectSystem; using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.VisualStudio.LanguageServer.Protocol; diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting_NetFx/FormattingTestBase.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting_NetFx/FormattingTestBase.cs index 112e7ae0016..497b2b175d9 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting_NetFx/FormattingTestBase.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting_NetFx/FormattingTestBase.cs @@ -18,6 +18,7 @@ using Microsoft.AspNetCore.Razor.Test.Common.Workspaces; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Razor; +using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.CodeAnalysis.Razor.ProjectSystem; using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.CodeAnalysis.Testing; @@ -35,7 +36,7 @@ public class FormattingTestBase : RazorToolingIntegrationTestBase public FormattingTestBase(ITestOutputHelper testOutput) : base(testOutput) { - ILoggerExtensions.TestOnlyLoggingEnabled = true; + ITestOnlyLoggerExtensions.TestOnlyLoggingEnabled = true; } private protected async Task RunFormattingTestAsync( diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting_NetFx/HtmlFormattingTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting_NetFx/HtmlFormattingTest.cs index e38685d7468..08f596cf0ad 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting_NetFx/HtmlFormattingTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting_NetFx/HtmlFormattingTest.cs @@ -8,6 +8,7 @@ using Microsoft.AspNetCore.Razor.Language; using Microsoft.AspNetCore.Razor.PooledObjects; using Microsoft.AspNetCore.Razor.Test.Common; +using Microsoft.CodeAnalysis.Razor.Formatting; using Xunit; using Xunit.Abstractions; diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting_NetFx/RazorFormattingServiceTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting_NetFx/RazorFormattingServiceTest.cs index 889ecd2cfaa..67a2f3e182d 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting_NetFx/RazorFormattingServiceTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting_NetFx/RazorFormattingServiceTest.cs @@ -5,6 +5,7 @@ using System.Linq; using Microsoft.AspNetCore.Razor.Test.Common; +using Microsoft.CodeAnalysis.Razor.Formatting; using Microsoft.CodeAnalysis.Text; using Microsoft.VisualStudio.LanguageServer.Protocol; using Xunit; diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting_NetFx/TestRazorFormattingService.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting_NetFx/TestRazorFormattingService.cs index 12c22645152..11e6b4f1553 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting_NetFx/TestRazorFormattingService.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting_NetFx/TestRazorFormattingService.cs @@ -10,6 +10,7 @@ using Microsoft.AspNetCore.Razor.Test.Common; using Microsoft.AspNetCore.Razor.Test.Common.LanguageServer; using Microsoft.AspNetCore.Razor.Test.Common.Workspaces; +using Microsoft.CodeAnalysis.Razor.Formatting; using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.CodeAnalysis.Razor.ProjectSystem; using Moq; @@ -56,8 +57,8 @@ public static async Task CreateWithFullSupportAsync( { new HtmlFormattingPass(mappingService, client, versionCache, loggerFactory), new CSharpFormattingPass(mappingService, loggerFactory), - new CSharpOnTypeFormattingPass(mappingService, loggerFactory), - new RazorFormattingPass(mappingService, optionsMonitor), + new LspCSharpOnTypeFormattingPass(mappingService, loggerFactory), + new LspRazorFormattingPass(mappingService, optionsMonitor), new FormattingDiagnosticValidationPass(mappingService, loggerFactory), new FormattingContentValidationPass(mappingService, loggerFactory), }; diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/TestAdhocWorkspaceFactory.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/TestAdhocWorkspaceFactory.cs index c90a7f4a3b2..6011f4a4982 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/TestAdhocWorkspaceFactory.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/TestAdhocWorkspaceFactory.cs @@ -5,6 +5,7 @@ using Microsoft.AspNetCore.Razor.Test.Common.Workspaces; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Host; +using Microsoft.CodeAnalysis.Razor.Workspaces; namespace Microsoft.AspNetCore.Razor.LanguageServer.Test;