diff --git a/.editorconfig b/.editorconfig index 8276c0a72fd..acf22f6ebb2 100644 --- a/.editorconfig +++ b/.editorconfig @@ -226,3 +226,10 @@ dotnet_style_prefer_inferred_tuple_names = true:suggestion dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion dotnet_style_operator_placement_when_wrapping = beginning_of_line dotnet_style_prefer_compound_assignment = true:suggestion + +# IDE0036: Order modifiers +csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:suggestion +dotnet_diagnostic.IDE0036.severity = warning + +# CA1052: Static holder types should be Static or NotInheritable +dotnet_diagnostic.CA1052.severity = warning \ No newline at end of file diff --git a/src/Compiler/.editorconfig b/src/Compiler/.editorconfig index 3976daa2908..1dd754373bb 100644 --- a/src/Compiler/.editorconfig +++ b/src/Compiler/.editorconfig @@ -85,6 +85,9 @@ dotnet_diagnostic.CA1018.severity = warning # CA1047: Do not declare protected member in sealed type dotnet_diagnostic.CA1047.severity = warning +# CA1052: Static holder types should be Static or NotInheritable +dotnet_diagnostic.CA1052.severity = warning + # CA1305: Specify IFormatProvider dotnet_diagnostic.CA1305.severity = none diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/ViewComponentTagHelperDescriptorFactoryTest.cs b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/ViewComponentTagHelperDescriptorFactoryTest.cs index 2162c07fb64..0b91b471d9c 100644 --- a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/ViewComponentTagHelperDescriptorFactoryTest.cs +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/ViewComponentTagHelperDescriptorFactoryTest.cs @@ -463,7 +463,7 @@ public class DerivedViewComponentWithAmbiguity : AsyncViewComponentWithNonGeneri public string Invoke() => null; } -public class StaticInvokeAsyncViewComponent +public static class StaticInvokeAsyncViewComponent { public static Task InvokeAsync() => null; } diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/TestTagHelperDescriptors.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/TestTagHelperDescriptors.cs index 85d9d549423..ba1c364f297 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/TestTagHelperDescriptors.cs +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/TestTagHelperDescriptors.cs @@ -8,7 +8,7 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests; -public class TestTagHelperDescriptors +public static class TestTagHelperDescriptors { public static TagHelperCollection SimpleTagHelperDescriptors { diff --git a/src/Compiler/tools/RazorSyntaxGenerator/Program.cs b/src/Compiler/tools/RazorSyntaxGenerator/Program.cs index ba1d4da6292..1818ce3c4d5 100644 --- a/src/Compiler/tools/RazorSyntaxGenerator/Program.cs +++ b/src/Compiler/tools/RazorSyntaxGenerator/Program.cs @@ -5,14 +5,13 @@ using System; using System.IO; -using System.Reflection; using System.Text; using System.Xml; using System.Xml.Serialization; namespace RazorSyntaxGenerator; -public class Program +public static class Program { public static int Main(string[] args) { diff --git a/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/Resources.cs b/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/Resources.cs index fb1e3f10aa1..c4aced88f59 100644 --- a/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/Resources.cs +++ b/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/Resources.cs @@ -10,8 +10,8 @@ namespace Microsoft.AspNetCore.Razor.Microbenchmarks; internal static class Resources { - private readonly static Dictionary<(string Name, string? Folder), string> s_textMap = new(); - private readonly static Dictionary<(string Name, string? Folder), byte[]> s_bytesMap = new(); + private static readonly Dictionary<(string Name, string? Folder), string> s_textMap = new(); + private static readonly Dictionary<(string Name, string? Folder), byte[]> s_bytesMap = new(); private static string GetResourceName(string name, string? folder) => folder is not null diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/Hover/CohostHoverEndpoint.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/Hover/CohostHoverEndpoint.cs index 6c470af58b9..9d62106b52d 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/Hover/CohostHoverEndpoint.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/Hover/CohostHoverEndpoint.cs @@ -52,7 +52,7 @@ public ImmutableArray GetRegistrations(VSInternalClientCapabilitie protected override RazorTextDocumentIdentifier? GetRazorTextDocumentIdentifier(TextDocumentPositionParams request) => request.TextDocument.ToRazorTextDocumentIdentifier(); - protected async override Task HandleRequestAsync(TextDocumentPositionParams request, TextDocument razorDocument, CancellationToken cancellationToken) + protected override async Task HandleRequestAsync(TextDocumentPositionParams request, TextDocument razorDocument, CancellationToken cancellationToken) { var position = LspFactory.CreatePosition(request.Position.ToLinePosition()); diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/InlayHints/CohostInlayHintResolveEndpoint.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/InlayHints/CohostInlayHintResolveEndpoint.cs index 85d83d39d14..b9c16963657 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/InlayHints/CohostInlayHintResolveEndpoint.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/InlayHints/CohostInlayHintResolveEndpoint.cs @@ -51,7 +51,7 @@ internal class CohostInlayHintResolveEndpoint( return data.TextDocument; } - protected async override Task HandleRequestAsync(InlayHint request, TextDocument razorDocument, CancellationToken cancellationToken) + protected override async Task HandleRequestAsync(InlayHint request, TextDocument razorDocument, CancellationToken cancellationToken) { var razorData = GetInlayHintResolveData(request).AssumeNotNull(); var razorPosition = request.Position; diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/LinkedEditingRange/CohostLinkedEditingRangeEndpoint.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/LinkedEditingRange/CohostLinkedEditingRangeEndpoint.cs index 77c182db8a7..fd2a82c8402 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/LinkedEditingRange/CohostLinkedEditingRangeEndpoint.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/LinkedEditingRange/CohostLinkedEditingRangeEndpoint.cs @@ -51,7 +51,7 @@ public ImmutableArray GetRegistrations(VSInternalClientCapabilitie protected override RazorTextDocumentIdentifier? GetRazorTextDocumentIdentifier(LinkedEditingRangeParams request) => request.TextDocument.ToRazorTextDocumentIdentifier(); - protected async override Task HandleRequestAsync(LinkedEditingRangeParams request, TextDocument razorDocument, CancellationToken cancellationToken) + protected override async Task HandleRequestAsync(LinkedEditingRangeParams request, TextDocument razorDocument, CancellationToken cancellationToken) { var linkedRanges = await _remoteServiceInvoker.TryInvokeAsync( razorDocument.Project.Solution, diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/Navigation/CohostGoToDefinitionEndpoint.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/Navigation/CohostGoToDefinitionEndpoint.cs index e857a9b4540..720fc6c98ed 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/Navigation/CohostGoToDefinitionEndpoint.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/Navigation/CohostGoToDefinitionEndpoint.cs @@ -56,7 +56,7 @@ public ImmutableArray GetRegistrations(VSInternalClientCapabilitie protected override RazorTextDocumentIdentifier? GetRazorTextDocumentIdentifier(TextDocumentPositionParams request) => request.TextDocument.ToRazorTextDocumentIdentifier(); - protected async override Task?> HandleRequestAsync(TextDocumentPositionParams request, TextDocument razorDocument, CancellationToken cancellationToken) + protected override async Task?> HandleRequestAsync(TextDocumentPositionParams request, TextDocument razorDocument, CancellationToken cancellationToken) { var position = LspFactory.CreatePosition(request.Position.ToLinePosition()); diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/OnAutoInsert/CohostOnAutoInsertEndpoint.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/OnAutoInsert/CohostOnAutoInsertEndpoint.cs index 70a2c662078..4463f42e57d 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/OnAutoInsert/CohostOnAutoInsertEndpoint.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/OnAutoInsert/CohostOnAutoInsertEndpoint.cs @@ -85,7 +85,7 @@ public ImmutableArray GetRegistrations(VSInternalClientCapabilitie protected override RazorTextDocumentIdentifier? GetRazorTextDocumentIdentifier(VSInternalDocumentOnAutoInsertParams request) => request.TextDocument.ToRazorTextDocumentIdentifier(); - protected async override Task HandleRequestAsync(VSInternalDocumentOnAutoInsertParams request, TextDocument razorDocument, CancellationToken cancellationToken) + protected override async Task HandleRequestAsync(VSInternalDocumentOnAutoInsertParams request, TextDocument razorDocument, CancellationToken cancellationToken) { _logger.LogDebug($"Resolving auto-insertion for {razorDocument.FilePath}"); diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/SignatureHelp/CohostSignatureHelpEndpoint.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/SignatureHelp/CohostSignatureHelpEndpoint.cs index 52a0e7e79d2..b85d9803c05 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/SignatureHelp/CohostSignatureHelpEndpoint.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/SignatureHelp/CohostSignatureHelpEndpoint.cs @@ -56,7 +56,7 @@ public ImmutableArray GetRegistrations(VSInternalClientCapabilitie protected override RazorTextDocumentIdentifier? GetRazorTextDocumentIdentifier(SignatureHelpParams request) => request.TextDocument.ToRazorTextDocumentIdentifier(); - protected async override Task HandleRequestAsync(SignatureHelpParams request, TextDocument razorDocument, CancellationToken cancellationToken) + protected override async Task HandleRequestAsync(SignatureHelpParams request, TextDocument razorDocument, CancellationToken cancellationToken) { // Return nothing if "Parameter Information" option is disabled unless signature help is invoked explicitly via command as opposed to typing or content change if (request.Context is { TriggerKind: not SignatureHelpTriggerKind.Invoked } && diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/RazorCodeActionFactory.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/RazorCodeActionFactory.cs index 6255943cfb8..adf7ad6cdba 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/RazorCodeActionFactory.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/RazorCodeActionFactory.cs @@ -10,20 +10,20 @@ namespace Microsoft.CodeAnalysis.Razor.CodeActions.Razor; internal static class RazorCodeActionFactory { - private readonly static Guid s_addComponentUsingTelemetryId = new("6c5416b7-7be7-49ee-aa60-904385be676f"); - private readonly static Guid s_fullyQualifyComponentTelemetryId = new("3d9abe36-7d10-4e08-8c18-ad88baa9a923"); - private readonly static Guid s_createComponentFromTagTelemetryId = new("a28e0baa-a4d5-4953-a817-1db586035841"); - private readonly static Guid s_createExtractToCssTelemetryId = new("a3773518-35ff-455c-a8c2-d6adaf1d2c48"); - private readonly static Guid s_createExtractToCodeBehindTelemetryId = new("f63167f7-fdc6-450f-8b7b-b240892f4a27"); - private readonly static Guid s_createExtractToComponentTelemetryId = new("af67b0a3-f84b-4808-97a7-b53e85b22c64"); - private readonly static Guid s_simplifyComponentTelemetryId = new("2207f68c-419e-4baa-8493-2e7769e5c91d"); - private readonly static Guid s_generateEventHandlerTelemetryId = new("c14fa003-c752-45fc-bb29-3a123ae5ecef"); - private readonly static Guid s_generateAsyncEventHandlerTelemetryId = new("9058ca47-98e2-4f11-bf7c-a16a444dd939"); - private readonly static Guid s_promoteUsingDirectiveTelemetryId = new("751f9012-e37b-444a-9211-b4ebce91d96e"); - private readonly static Guid s_removeUnnecessaryDirectivesTelemetryId = new("92bbd4a4-6076-4742-b90b-9b480e6a23ec"); - private readonly static Guid s_wrapAttributesTelemetryId = new("1df50ba6-4ed1-40d8-8fe2-1c4c1b08e8b5"); - private readonly static Guid s_simplifyFullyQualifiedComponentTelemetryId = new("f8640324-2037-49fd-9697-2227690c33c3"); - private readonly static Guid s_sortAndConsolidateUsingsTelemetryId = new("a3dc8f52-7e1b-4a09-9c6d-2f5e7a8b3c01"); + private static readonly Guid s_addComponentUsingTelemetryId = new("6c5416b7-7be7-49ee-aa60-904385be676f"); + private static readonly Guid s_fullyQualifyComponentTelemetryId = new("3d9abe36-7d10-4e08-8c18-ad88baa9a923"); + private static readonly Guid s_createComponentFromTagTelemetryId = new("a28e0baa-a4d5-4953-a817-1db586035841"); + private static readonly Guid s_createExtractToCssTelemetryId = new("a3773518-35ff-455c-a8c2-d6adaf1d2c48"); + private static readonly Guid s_createExtractToCodeBehindTelemetryId = new("f63167f7-fdc6-450f-8b7b-b240892f4a27"); + private static readonly Guid s_createExtractToComponentTelemetryId = new("af67b0a3-f84b-4808-97a7-b53e85b22c64"); + private static readonly Guid s_simplifyComponentTelemetryId = new("2207f68c-419e-4baa-8493-2e7769e5c91d"); + private static readonly Guid s_generateEventHandlerTelemetryId = new("c14fa003-c752-45fc-bb29-3a123ae5ecef"); + private static readonly Guid s_generateAsyncEventHandlerTelemetryId = new("9058ca47-98e2-4f11-bf7c-a16a444dd939"); + private static readonly Guid s_promoteUsingDirectiveTelemetryId = new("751f9012-e37b-444a-9211-b4ebce91d96e"); + private static readonly Guid s_removeUnnecessaryDirectivesTelemetryId = new("92bbd4a4-6076-4742-b90b-9b480e6a23ec"); + private static readonly Guid s_wrapAttributesTelemetryId = new("1df50ba6-4ed1-40d8-8fe2-1c4c1b08e8b5"); + private static readonly Guid s_simplifyFullyQualifiedComponentTelemetryId = new("f8640324-2037-49fd-9697-2227690c33c3"); + private static readonly Guid s_sortAndConsolidateUsingsTelemetryId = new("a3dc8f52-7e1b-4a09-9c6d-2f5e7a8b3c01"); public static RazorVSInternalCodeAction CreateWrapAttributes(RazorCodeActionResolutionParams resolutionParams) => new RazorVSInternalCodeAction diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Utilities/StreamExtensions.NetCore.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Utilities/StreamExtensions.NetCore.cs deleted file mode 100644 index d86f0d382c3..00000000000 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Utilities/StreamExtensions.NetCore.cs +++ /dev/null @@ -1,56 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; -using System.Buffers; -using System.Diagnostics; -using System.IO; -using System.Text; -using System.Threading; -using System.Threading.Tasks; - -namespace Microsoft.CodeAnalysis.Razor.Utilities; - -internal static class StreamExtensions -{ - public static Task WriteStringAsync(this Stream stream, string text, Encoding? encoding, CancellationToken cancellationToken) - { - Debug.Assert(stream.CanWrite); - encoding ??= Encoding.UTF8; - - var byteCount = encoding.GetMaxByteCount(text.Length); - using var _ = ArrayPool.Shared.GetPooledArray(byteCount, out var byteArray); - - var usedBytes = encoding.GetBytes(text, byteArray); - - stream.WriteSize(usedBytes); - return stream.WriteAsync(byteArray, 0, usedBytes, cancellationToken); - } - - public static async Task ReadStringAsync(this Stream stream, Encoding? encoding, CancellationToken cancellationToken) - { - Debug.Assert(stream.CanRead); - encoding ??= Encoding.UTF8; - - var length = stream.ReadSize(); - - using var _ = ArrayPool.Shared.GetPooledArray(length, out var encodedBytes); - - await stream.ReadExactlyAsync(encodedBytes, 0, length, cancellationToken).ConfigureAwait(false); - return encoding.GetString(encodedBytes, 0, length); - } - - public static void WriteSize(this Stream stream, int length) - { - Span sizeBytes = stackalloc byte[4]; - BitConverter.TryWriteBytes(sizeBytes, length); - stream.Write(sizeBytes); - } - - public unsafe static int ReadSize(this Stream stream) - { - Span bytes = stackalloc byte[4]; - stream.ReadExactly(bytes); - return BitConverter.ToInt32(bytes); - } -} diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/RemoteWorkspaceProvider.cs b/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/RemoteWorkspaceProvider.cs index 7613c84e558..5bc731c03c9 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/RemoteWorkspaceProvider.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/RemoteWorkspaceProvider.cs @@ -33,7 +33,7 @@ public Workspace GetWorkspace() /// public static class TestAccessor { - public async static Task InitializeRemoteExportProviderBuilderAsync(string localSettingsDirectory, TraceSource traceLogger, CancellationToken cancellationToken) + public static async Task InitializeRemoteExportProviderBuilderAsync(string localSettingsDirectory, TraceSource traceLogger, CancellationToken cancellationToken) { return await RemoteExportProviderBuilder.InitializeAsync(localSettingsDirectory, traceLogger, cancellationToken).ConfigureAwait(false); } diff --git a/src/Razor/src/Microsoft.VisualStudio.LanguageServer.ContainedLanguage/DefaultLSPRequestInvoker.cs b/src/Razor/src/Microsoft.VisualStudio.LanguageServer.ContainedLanguage/DefaultLSPRequestInvoker.cs index b8a4102e9da..9c4e1618c60 100644 --- a/src/Razor/src/Microsoft.VisualStudio.LanguageServer.ContainedLanguage/DefaultLSPRequestInvoker.cs +++ b/src/Razor/src/Microsoft.VisualStudio.LanguageServer.ContainedLanguage/DefaultLSPRequestInvoker.cs @@ -43,7 +43,7 @@ public override Task>> ReinvokeRequestOnMulti return RequestMultipleServerCoreAsync(method, parameters, cancellationToken); } - public async override Task> ReinvokeRequestOnServerAsync( + public override async Task> ReinvokeRequestOnServerAsync( string method, string languageServerName, TIn parameters, diff --git a/src/Razor/src/Microsoft.VisualStudio.LanguageServer.ContainedLanguage/InviolableEditTag.cs b/src/Razor/src/Microsoft.VisualStudio.LanguageServer.ContainedLanguage/InviolableEditTag.cs index 9b72259d783..fb06ca98633 100644 --- a/src/Razor/src/Microsoft.VisualStudio.LanguageServer.ContainedLanguage/InviolableEditTag.cs +++ b/src/Razor/src/Microsoft.VisualStudio.LanguageServer.ContainedLanguage/InviolableEditTag.cs @@ -10,5 +10,5 @@ internal class InviolableEditTag : IInviolableEditTag { private InviolableEditTag() { } - public readonly static IInviolableEditTag Instance = new InviolableEditTag(); + public static readonly IInviolableEditTag Instance = new InviolableEditTag(); } diff --git a/src/Razor/src/Microsoft.VisualStudio.LanguageServer.ContainedLanguage/MessageInterception/DefaultInterceptorManager.cs b/src/Razor/src/Microsoft.VisualStudio.LanguageServer.ContainedLanguage/MessageInterception/DefaultInterceptorManager.cs index d5db15b9e53..0fe7bf0aa25 100644 --- a/src/Razor/src/Microsoft.VisualStudio.LanguageServer.ContainedLanguage/MessageInterception/DefaultInterceptorManager.cs +++ b/src/Razor/src/Microsoft.VisualStudio.LanguageServer.ContainedLanguage/MessageInterception/DefaultInterceptorManager.cs @@ -74,7 +74,7 @@ public override bool HasInterceptor(string methodName, string contentType) return false; } - public async override Task ProcessGenericInterceptorsAsync(string methodName, TJsonToken message, string contentType, CancellationToken cancellationToken) + public override async Task ProcessGenericInterceptorsAsync(string methodName, TJsonToken message, string contentType, CancellationToken cancellationToken) where TJsonToken : default { _ = message ?? throw new ArgumentNullException(nameof(message)); diff --git a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/LanguageClient/Cohost/CohostDocumentPullDiagnosticsEndpoint.cs b/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/LanguageClient/Cohost/CohostDocumentPullDiagnosticsEndpoint.cs index 284fbbb52f1..f1cba5c0fa5 100644 --- a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/LanguageClient/Cohost/CohostDocumentPullDiagnosticsEndpoint.cs +++ b/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/LanguageClient/Cohost/CohostDocumentPullDiagnosticsEndpoint.cs @@ -67,7 +67,7 @@ public ImmutableArray GetRegistrations(VSInternalClientCapabilitie protected override RazorTextDocumentIdentifier? GetRazorTextDocumentIdentifier(VSInternalDocumentDiagnosticsParams request) => request.TextDocument?.ToRazorTextDocumentIdentifier(); - protected async override Task HandleRequestAsync(VSInternalDocumentDiagnosticsParams request, TextDocument razorDocument, CancellationToken cancellationToken) + protected override async Task HandleRequestAsync(VSInternalDocumentDiagnosticsParams request, TextDocument razorDocument, CancellationToken cancellationToken) { if (request.QueryingDiagnosticKind?.Value == VSInternalDiagnosticKind.Task.Value) { diff --git a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/LanguageClient/Options/SettingsNames.cs b/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/LanguageClient/Options/SettingsNames.cs index a7f5e4ad565..b596cc81622 100644 --- a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/LanguageClient/Options/SettingsNames.cs +++ b/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/LanguageClient/Options/SettingsNames.cs @@ -7,16 +7,16 @@ internal static class SettingsNames { public const string UnifiedCollection = "languages.razor.advanced"; - public static readonly string FormatOnType = UnifiedCollection + ".formatOnType"; - public static readonly string AutoClosingTags = UnifiedCollection + ".autoClosingTags"; - public static readonly string AutoInsertAttributeQuotes = UnifiedCollection + ".autoInsertAttributeQuotes"; - public static readonly string ColorBackground = UnifiedCollection + ".colorBackground"; - public static readonly string CodeBlockBraceOnNextLine = UnifiedCollection + ".codeBlockBraceOnNextLine"; - public static readonly string AttributeIndentStyle = UnifiedCollection + ".attributeIndentStyle"; - public static readonly string CommitElementsWithSpace = UnifiedCollection + ".commitElementsWithSpace"; - public static readonly string Snippets = UnifiedCollection + ".snippets"; - public static readonly string LogLevel = UnifiedCollection + ".logLevel"; - public static readonly string FormatOnPaste = UnifiedCollection + ".formatOnPaste"; + public const string FormatOnType = UnifiedCollection + ".formatOnType"; + public const string AutoClosingTags = UnifiedCollection + ".autoClosingTags"; + public const string AutoInsertAttributeQuotes = UnifiedCollection + ".autoInsertAttributeQuotes"; + public const string ColorBackground = UnifiedCollection + ".colorBackground"; + public const string CodeBlockBraceOnNextLine = UnifiedCollection + ".codeBlockBraceOnNextLine"; + public const string AttributeIndentStyle = UnifiedCollection + ".attributeIndentStyle"; + public const string CommitElementsWithSpace = UnifiedCollection + ".commitElementsWithSpace"; + public const string Snippets = UnifiedCollection + ".snippets"; + public const string LogLevel = UnifiedCollection + ".logLevel"; + public const string FormatOnPaste = UnifiedCollection + ".formatOnPaste"; public static readonly string[] AllSettings = [ diff --git a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/ProjectSystem/IUnconfiguredProjectCommonServices.cs b/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/ProjectSystem/IUnconfiguredProjectCommonServices.cs deleted file mode 100644 index d4c2d5d2d17..00000000000 --- a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/ProjectSystem/IUnconfiguredProjectCommonServices.cs +++ /dev/null @@ -1,24 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using Microsoft.VisualStudio.ProjectSystem; - -namespace Microsoft.VisualStudio.Razor.ProjectSystem; - -// This defines the set of services that we frequently need for working with UnconfiguredProject. -// -// We're following a somewhat common pattern for code that uses CPS. It's really easy to end up -// relying on service location inside CPS, which can be hard to test. This approach makes it easy -// for us to build reusable mocks instead. -internal interface IUnconfiguredProjectCommonServices -{ - IProjectAsynchronousTasksService TasksService { get; } - - IProjectThreadingService ThreadingService { get; } - - UnconfiguredProject UnconfiguredProject { get; } - - IProjectFaultHandlerService FaultHandlerService { get; } - - IActiveConfigurationGroupSubscriptionService ActiveConfigurationGroupSubscriptionService { get; } -} diff --git a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/ProjectSystem/UnconfiguredProjectCommonServices.cs b/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/ProjectSystem/UnconfiguredProjectCommonServices.cs deleted file mode 100644 index 43a4d0b9d41..00000000000 --- a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/ProjectSystem/UnconfiguredProjectCommonServices.cs +++ /dev/null @@ -1,57 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; -using System.ComponentModel.Composition; -using Microsoft.VisualStudio.ProjectSystem; - -namespace Microsoft.VisualStudio.Razor.ProjectSystem; - -[Export(typeof(IUnconfiguredProjectCommonServices))] -internal class UnconfiguredProjectCommonServices : IUnconfiguredProjectCommonServices -{ - [ImportingConstructor] - public UnconfiguredProjectCommonServices( - [Import(ExportContractNames.Scopes.UnconfiguredProject)] IProjectAsynchronousTasksService tasksService, - IProjectThreadingService threadingService, - UnconfiguredProject unconfiguredProject, - IProjectFaultHandlerService faultHandlerService, - IActiveConfigurationGroupSubscriptionService activeConfigurationGroupSubscriptionService) - { - if (tasksService is null) - { - throw new ArgumentNullException(nameof(tasksService)); - } - - if (threadingService is null) - { - throw new ArgumentNullException(nameof(threadingService)); - } - - if (unconfiguredProject is null) - { - throw new ArgumentNullException(nameof(unconfiguredProject)); - } - - if (activeConfigurationGroupSubscriptionService is null) - { - throw new ArgumentNullException(nameof(activeConfigurationGroupSubscriptionService)); - } - - TasksService = tasksService; - ThreadingService = threadingService; - UnconfiguredProject = unconfiguredProject; - FaultHandlerService = faultHandlerService; - ActiveConfigurationGroupSubscriptionService = activeConfigurationGroupSubscriptionService; - } - - public IProjectAsynchronousTasksService TasksService { get; } - - public IProjectThreadingService ThreadingService { get; } - - public UnconfiguredProject UnconfiguredProject { get; } - - public IProjectFaultHandlerService FaultHandlerService { get; } - - public IActiveConfigurationGroupSubscriptionService ActiveConfigurationGroupSubscriptionService { get; } -} diff --git a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/Remote/RemoteServiceInvoker.cs b/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/Remote/RemoteServiceInvoker.cs index 32ca7d73e96..5d20fa941f8 100644 --- a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/Remote/RemoteServiceInvoker.cs +++ b/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/Remote/RemoteServiceInvoker.cs @@ -103,7 +103,7 @@ private Task GetClientAsync(CancellationToken c ? _lazyJsonClient.GetValueAsync(cancellationToken) : _lazyMessagePackClient.GetValueAsync(cancellationToken); - private async static Task GetMessagePackClientAsync(IWorkspaceProvider workspaceProvider, CancellationToken cancellationToken) + private static async Task GetMessagePackClientAsync(IWorkspaceProvider workspaceProvider, CancellationToken cancellationToken) { var workspace = workspaceProvider.GetWorkspace(); @@ -119,7 +119,7 @@ private async static Task GetMessagePackClientAsync(IWork ?? throw new InvalidOperationException($"Couldn't retrieve {nameof(RazorRemoteHostClient)} for MessagePack serialization."); } - private async static Task GetJsonClientAsync(IWorkspaceProvider workspaceProvider, CancellationToken cancellationToken) + private static async Task GetJsonClientAsync(IWorkspaceProvider workspaceProvider, CancellationToken cancellationToken) { var workspace = workspaceProvider.GetWorkspace(); diff --git a/src/Razor/src/Microsoft.VisualStudioCode.RazorExtension/Endpoints/DocumentPullDiagnosticsEndpoint.cs b/src/Razor/src/Microsoft.VisualStudioCode.RazorExtension/Endpoints/DocumentPullDiagnosticsEndpoint.cs index ecf6cf2cf87..bdf568d0d25 100644 --- a/src/Razor/src/Microsoft.VisualStudioCode.RazorExtension/Endpoints/DocumentPullDiagnosticsEndpoint.cs +++ b/src/Razor/src/Microsoft.VisualStudioCode.RazorExtension/Endpoints/DocumentPullDiagnosticsEndpoint.cs @@ -62,7 +62,7 @@ public ImmutableArray GetRegistrations(VSInternalClientCapabilitie protected override RazorTextDocumentIdentifier? GetRazorTextDocumentIdentifier(DocumentDiagnosticParams request) => request.TextDocument?.ToRazorTextDocumentIdentifier(); - protected async override Task HandleRequestAsync(DocumentDiagnosticParams request, TextDocument razorDocument, CancellationToken cancellationToken) + protected override async Task HandleRequestAsync(DocumentDiagnosticParams request, TextDocument razorDocument, CancellationToken cancellationToken) { var results = await GetDiagnosticsAsync(razorDocument, cancellationToken).ConfigureAwait(false); diff --git a/src/Razor/test/Directory.Build.props b/src/Razor/test/Directory.Build.props index f67f09af218..10c04e70077 100644 --- a/src/Razor/test/Directory.Build.props +++ b/src/Razor/test/Directory.Build.props @@ -8,5 +8,6 @@ $(StandardTestTfms) net472;$(StandardTestTfms) LatestMajor + true diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/Editor_NetFx/StringTextSnapshot.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/Editor_NetFx/StringTextSnapshot.cs index 4fc96a1cc38..e2973d9998a 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/Editor_NetFx/StringTextSnapshot.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/Editor_NetFx/StringTextSnapshot.cs @@ -215,7 +215,7 @@ public SnapshotLine(string contentWithLineBreak, int start, ITextSnapshot owner) { _content = _content[..^2]; } - else if(_content.Length > 0 && SyntaxFacts.IsNewLine(_content[^1])) + else if (_content.Length > 0 && SyntaxFacts.IsNewLine(_content[^1])) { _content = _content[..^1]; } diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/Editor_NetFx/TestEdit.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/Editor_NetFx/TestEdit.cs index bbb937f8085..4775d0e7bae 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/Editor_NetFx/TestEdit.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/Editor_NetFx/TestEdit.cs @@ -8,7 +8,7 @@ namespace Microsoft.AspNetCore.Razor.Test.Common.Editor; public class TestEdit { - public TestEdit(SourceChange change, ITextSnapshot oldSnapshot, ITextSnapshot newSnapshot) + public TestEdit(SourceChange change, ITextSnapshot oldSnapshot, ITextSnapshot newSnapshot) { Change = change; OldSnapshot = oldSnapshot; diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/Mef/TestExportJoinableTaskContext.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/Mef/TestExportJoinableTaskContext.cs index 46b32123ec2..e9a85b6e0ac 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/Mef/TestExportJoinableTaskContext.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/Mef/TestExportJoinableTaskContext.cs @@ -47,13 +47,13 @@ private static (JoinableTaskContext joinableTaskContext, SynchronizationContext Thread mainThread; SynchronizationContext synchronizationContext; #if NETFRAMEWORK - if (SynchronizationContext.Current is DispatcherSynchronizationContext) - { - // The current thread is the main thread, and provides a suitable synchronization context - mainThread = Thread.CurrentThread; - synchronizationContext = SynchronizationContext.Current; - } - else + if (SynchronizationContext.Current is DispatcherSynchronizationContext) + { + // The current thread is the main thread, and provides a suitable synchronization context + mainThread = Thread.CurrentThread; + synchronizationContext = SynchronizationContext.Current; + } + else #endif { // The current thread is not known to be the main thread; we have no way to know if the @@ -69,7 +69,9 @@ private static (JoinableTaskContext joinableTaskContext, SynchronizationContext } [Export] +#pragma warning disable IDE0052 // Used by MEF composition. private JoinableTaskContext JoinableTaskContext +#pragma warning restore IDE0052 // Used by MEF composition. { get; } diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/RazorTestResources.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/RazorTestResources.cs index 259167cd7ff..ba029379bfd 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/RazorTestResources.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/RazorTestResources.cs @@ -10,8 +10,8 @@ namespace Microsoft.AspNetCore.Razor.Test.Common; internal static class RazorTestResources { - private readonly static Dictionary<(string Name, string? Folder), string> s_textMap = new(); - private readonly static Dictionary<(string Name, string? Folder), byte[]> s_bytesMap = new(); + private static readonly Dictionary<(string Name, string? Folder), string> s_textMap = new(); + private static readonly Dictionary<(string Name, string? Folder), byte[]> s_bytesMap = new(); private static string GetResourceName(string name, string? folder) => folder is not null diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/SimpleTagHelpers.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/SimpleTagHelpers.cs index 03255601eb5..c48746e62e7 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/SimpleTagHelpers.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/SimpleTagHelpers.cs @@ -1,7 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using System.Collections.Immutable; using Microsoft.AspNetCore.Razor.Language; using Microsoft.AspNetCore.Razor.Language.Components; diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/Workspaces/TestWorkspace.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/Workspaces/TestWorkspace.cs index 41753bfddab..e143249e198 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/Workspaces/TestWorkspace.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/Workspaces/TestWorkspace.cs @@ -29,7 +29,7 @@ public static AdhocWorkspace CreateWithDiagnosticAnalyzers(ExportProvider export var workspace = Create(hostServices); - AddAnalyzersToWorkspace(workspace, exportProvider); + AddAnalyzersToWorkspace(workspace); return workspace; } @@ -48,7 +48,7 @@ public static AdhocWorkspace Create(HostServices? services, Action @@ -107,7 +103,6 @@ await RunFormattingTestAsync( [Fact] public async Task FormatsComponentTag_WithExplicitExpression() { - var tagHelpers = GetComponents(); await RunFormattingTestAsync( input: """ @@ -136,7 +131,6 @@ await RunFormattingTestAsync( [Fact] public async Task FormatsComponentTag_WithExplicitExpression_FormatsInside() { - var tagHelpers = GetComponents(); await RunFormattingTestAsync( input: """ @@ -165,7 +159,6 @@ await RunFormattingTestAsync( [Fact] public async Task FormatsComponentTag_WithExplicitExpression_MovesStart() { - var tagHelpers = GetComponents(); await RunFormattingTestAsync( input: """ diff --git a/src/Razor/test/Microsoft.CodeAnalysis.Razor.CohostingShared.Test/Mapping/RazorEditServiceTest.cs b/src/Razor/test/Microsoft.CodeAnalysis.Razor.CohostingShared.Test/Mapping/RazorEditServiceTest.cs index a8039624504..2b1b7105a55 100644 --- a/src/Razor/test/Microsoft.CodeAnalysis.Razor.CohostingShared.Test/Mapping/RazorEditServiceTest.cs +++ b/src/Razor/test/Microsoft.CodeAnalysis.Razor.CohostingShared.Test/Mapping/RazorEditServiceTest.cs @@ -25,7 +25,7 @@ public class RazorEditServiceTest(ITestOutputHelper testOutput) : CohostEndpoint { private IRazorEditService? _razorEditService; - protected async override Task InitializeAsync() + protected override async Task InitializeAsync() { await base.InitializeAsync(); diff --git a/src/Razor/test/Microsoft.CodeAnalysis.Razor.CohostingShared.Test/ProjectAvailabilityTests.cs b/src/Razor/test/Microsoft.CodeAnalysis.Razor.CohostingShared.Test/ProjectAvailabilityTests.cs index 1952c983a84..dd36a305573 100644 --- a/src/Razor/test/Microsoft.CodeAnalysis.Razor.CohostingShared.Test/ProjectAvailabilityTests.cs +++ b/src/Razor/test/Microsoft.CodeAnalysis.Razor.CohostingShared.Test/ProjectAvailabilityTests.cs @@ -1,7 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using System.IO; using System.Threading.Tasks; using Microsoft.AspNetCore.Razor.Test.Common; using Microsoft.CodeAnalysis.Remote.Razor; diff --git a/src/Razor/test/Microsoft.CodeAnalysis.Razor.CohostingShared.Test/RazorDocumentMappingServiceTest.cs b/src/Razor/test/Microsoft.CodeAnalysis.Razor.CohostingShared.Test/RazorDocumentMappingServiceTest.cs index 4a947efbfab..903f3fa0bfd 100644 --- a/src/Razor/test/Microsoft.CodeAnalysis.Razor.CohostingShared.Test/RazorDocumentMappingServiceTest.cs +++ b/src/Razor/test/Microsoft.CodeAnalysis.Razor.CohostingShared.Test/RazorDocumentMappingServiceTest.cs @@ -1,7 +1,9 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#if DEBUG using System; +#endif using System.Collections.Immutable; using Microsoft.AspNetCore.Razor.Language; using Microsoft.AspNetCore.Razor.Test.Common; diff --git a/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/Completion/BlazorDataAttributeCompletionItemProviderTest.cs b/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/Completion/BlazorDataAttributeCompletionItemProviderTest.cs index d99e9c8aa55..153c0b6b75a 100644 --- a/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/Completion/BlazorDataAttributeCompletionItemProviderTest.cs +++ b/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/Completion/BlazorDataAttributeCompletionItemProviderTest.cs @@ -6,7 +6,6 @@ using Microsoft.AspNetCore.Razor.Language.IntegrationTests; using Microsoft.AspNetCore.Razor.Language.Syntax; using Microsoft.AspNetCore.Razor.Test.Common; -using Microsoft.AspNetCore.Razor.Test.Common.LanguageServer; using Xunit; using Xunit.Abstractions; diff --git a/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/Tooltip/TestComponentAvailabilityService.cs b/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/Tooltip/TestComponentAvailabilityService.cs index 4421ec3276d..c3ea8eaef64 100644 --- a/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/Tooltip/TestComponentAvailabilityService.cs +++ b/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/Tooltip/TestComponentAvailabilityService.cs @@ -12,9 +12,9 @@ namespace Microsoft.CodeAnalysis.Razor.Tooltip; internal sealed class TestComponentAvailabilityService : IComponentAvailabilityService +{ + public Task> GetComponentAvailabilityAsync(string documentFilePath, string typeName, CancellationToken cancellationToken) { - public Task> GetComponentAvailabilityAsync(string documentFilePath, string typeName, CancellationToken cancellationToken) - { - return SpecializedTasks.EmptyImmutableArray<(IProjectSnapshot Project, bool IsAvailable)>(); - } + return SpecializedTasks.EmptyImmutableArray<(IProjectSnapshot Project, bool IsAvailable)>(); } +} diff --git a/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/Utilities/StreamExtensionTests.NetCore.cs b/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/Utilities/StreamExtensionTests.NetCore.cs deleted file mode 100644 index 4b5665e2974..00000000000 --- a/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/Utilities/StreamExtensionTests.NetCore.cs +++ /dev/null @@ -1,59 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System.IO; -using System.Text; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Razor.Test.Common; -using Xunit; -using Xunit.Abstractions; - -namespace Microsoft.CodeAnalysis.Razor.Utilities; - -public class StreamExtensionTests(ITestOutputHelper testOutputHelper) : ToolingTestBase(testOutputHelper) -{ - [Theory] - [InlineData(0)] - [InlineData(int.MaxValue)] - [InlineData(int.MinValue)] - [InlineData(-500)] - [InlineData(500)] - public void SizeFunctions(int size) - { - using var stream = new MemoryStream(); - - stream.WriteSize(size); - stream.Position = 0; - - Assert.Equal(size, stream.ReadSize()); - } - - public static TheoryData StringFunctionData = new TheoryData - { - { "", null }, - { "hello", null }, - { "", Encoding.UTF8 }, - { "hello", Encoding.UTF8 }, - { "", Encoding.ASCII }, - { "hello", Encoding.ASCII }, - { "", Encoding.UTF32 }, - { "hello", Encoding.UTF32 }, - { "", Encoding.Unicode }, - { "hello", Encoding.Unicode }, - { "", Encoding.BigEndianUnicode }, - { "hello", Encoding.BigEndianUnicode }, - }; - - [Theory] - [MemberData(nameof(StringFunctionData))] - public async Task StringFunctions(string expected, Encoding? encoding) - { - using var stream = new MemoryStream(); - - await stream.WriteStringAsync(expected, encoding, DisposalToken); - stream.Position = 0; - - var actual = await stream.ReadStringAsync(encoding, DisposalToken); - Assert.Equal(expected, actual); - } -} diff --git a/src/Razor/test/Microsoft.CodeAnalysis.Remote.Razor.Test/RazorServicesTest.cs b/src/Razor/test/Microsoft.CodeAnalysis.Remote.Razor.Test/RazorServicesTest.cs index c049de62edc..226b839d081 100644 --- a/src/Razor/test/Microsoft.CodeAnalysis.Remote.Razor.Test/RazorServicesTest.cs +++ b/src/Razor/test/Microsoft.CodeAnalysis.Remote.Razor.Test/RazorServicesTest.cs @@ -22,7 +22,7 @@ public class RazorServicesTest(ITestOutputHelper testOutputHelper) : ToolingTest private const string Prefix = "IRemote"; private const string Suffix = "Service"; - private readonly static XmlDocument s_servicesFile = LoadServicesFile(); + private static readonly XmlDocument s_servicesFile = LoadServicesFile(); [Theory] [MemberData(nameof(MessagePackServices))] diff --git a/src/Razor/test/Microsoft.VisualStudio.LanguageServer.ContainedLanguage.Test/VirtualDocumentFactoryBaseTest.cs b/src/Razor/test/Microsoft.VisualStudio.LanguageServer.ContainedLanguage.Test/VirtualDocumentFactoryBaseTest.cs index c4011f8a2ca..b990f567644 100644 --- a/src/Razor/test/Microsoft.VisualStudio.LanguageServer.ContainedLanguage.Test/VirtualDocumentFactoryBaseTest.cs +++ b/src/Razor/test/Microsoft.VisualStudio.LanguageServer.ContainedLanguage.Test/VirtualDocumentFactoryBaseTest.cs @@ -96,7 +96,7 @@ private class TestVirtualDocumentFactory : VirtualDocumentFactoryBase public const string LanguageFileNameSuffixConst = "__virtual.test"; public static IContentType LanguageLSPContentTypeInstance { get; } = new TestContentType(LanguageContentTypeNameConst); - public static Dictionary LanguageBufferPropertiesInstance = new() { {"testKey", "testValue"} }; + public static Dictionary LanguageBufferPropertiesInstance = new() { { "testKey", "testValue" } }; public TestVirtualDocumentFactory( IContentTypeRegistryService contentTypeRegistryService, diff --git a/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/Cohost/CohostOnTypeFormattingEndpointTest.cs b/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/Cohost/CohostOnTypeFormattingEndpointTest.cs index 490bba93d68..0078394bed1 100644 --- a/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/Cohost/CohostOnTypeFormattingEndpointTest.cs +++ b/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/Cohost/CohostOnTypeFormattingEndpointTest.cs @@ -11,7 +11,6 @@ using Microsoft.CodeAnalysis.Razor.Formatting; using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.CodeAnalysis.Razor.Remote; -using Microsoft.VisualStudio.Razor.Settings; using Roslyn.Test.Utilities; using Xunit; using Xunit.Abstractions; diff --git a/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/LanguageClient/RazorContentTypeChangeListenerTest.cs b/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/LanguageClient/RazorContentTypeChangeListenerTest.cs index c50589abba3..fba7b6b2d70 100644 --- a/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/LanguageClient/RazorContentTypeChangeListenerTest.cs +++ b/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/LanguageClient/RazorContentTypeChangeListenerTest.cs @@ -7,7 +7,6 @@ using Microsoft.AspNetCore.Razor.Test.Common; using Microsoft.VisualStudio.LanguageServer.ContainedLanguage; using Microsoft.VisualStudio.Text; -using Microsoft.VisualStudio.Text.Editor; using Microsoft.VisualStudio.TextManager.Interop; using Microsoft.VisualStudio.Utilities; using Moq; diff --git a/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/ProjectSystem/ItemCollection.cs b/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/ProjectSystem/ItemCollection.cs deleted file mode 100644 index aa0c1f7bc42..00000000000 --- a/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/ProjectSystem/ItemCollection.cs +++ /dev/null @@ -1,70 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -#nullable disable - -using System; -using System.Collections.Generic; -using System.Collections.Immutable; -using Microsoft.VisualStudio.ProjectSystem; -using Microsoft.VisualStudio.ProjectSystem.Properties; -using Xunit; - -namespace Microsoft.VisualStudio.Razor.ProjectSystem; - -internal class ItemCollection -{ - private readonly string _ruleName; - private readonly Dictionary> _items; - - public ItemCollection(string ruleName) - { - _ruleName = ruleName; - _items = new Dictionary>(); - } - - public void Item(string item) - { - Item(item, new Dictionary()); - } - - public void Item(string item, Dictionary properties) - { - _items[item] = properties; - } - - public void RemoveItem(string item) - { - _items.Remove(item); - } - - public void Property(string item, string key) - { - _items[item][key] = null; - } - - public void Property(string item, string key, string value) - { - _items[item][key] = value; - } - - public TestProjectRuleSnapshot ToSnapshot() - { - return TestProjectRuleSnapshot.CreateItems(_ruleName, _items); - } - - public TestProjectChangeDescription ToChange() - { - return ToChange(new TestProjectRuleSnapshot( - _ruleName, - ImmutableDictionary>.Empty, - ImmutableDictionary.Empty, - ImmutableDictionary.Empty)); - } - - public TestProjectChangeDescription ToChange(IProjectRuleSnapshot before) - { - Assert.Equal(_ruleName, before.RuleName); - return new TestProjectChangeDescription(before, ToSnapshot()); - } -} diff --git a/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/ProjectSystem/PropertyCollection.cs b/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/ProjectSystem/PropertyCollection.cs deleted file mode 100644 index 79e71af8bc4..00000000000 --- a/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/ProjectSystem/PropertyCollection.cs +++ /dev/null @@ -1,53 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -#nullable disable - -using System; -using System.Collections.Generic; -using System.Collections.Immutable; -using Microsoft.VisualStudio.ProjectSystem; -using Microsoft.VisualStudio.ProjectSystem.Properties; - -namespace Microsoft.VisualStudio.Razor.ProjectSystem; - -internal class PropertyCollection -{ - private readonly string _ruleName; - private readonly Dictionary _properties; - - public PropertyCollection(string ruleName) - { - _ruleName = ruleName; - _properties = new Dictionary(); - } - - public void Property(string key) - { - _properties[key] = null; - } - - public void Property(string key, string value) - { - _properties[key] = value; - } - - public TestProjectRuleSnapshot ToSnapshot() - { - return TestProjectRuleSnapshot.CreateProperties(_ruleName, _properties); - } - - public TestProjectChangeDescription ToChange() - { - return ToChange(new TestProjectRuleSnapshot( - _ruleName, - ImmutableDictionary>.Empty, - ImmutableDictionary.Empty, - ImmutableDictionary.Empty)); - } - - public TestProjectChangeDescription ToChange(IProjectRuleSnapshot before) - { - return new TestProjectChangeDescription(before, ToSnapshot()); - } -} diff --git a/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/ProjectSystem/TestProjectChangeDescription.cs b/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/ProjectSystem/TestProjectChangeDescription.cs deleted file mode 100644 index 3564bf0a749..00000000000 --- a/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/ProjectSystem/TestProjectChangeDescription.cs +++ /dev/null @@ -1,101 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -#nullable disable - -using System.Collections.Generic; -using System.Collections.Immutable; -using Microsoft.VisualStudio.ProjectSystem; -using Microsoft.VisualStudio.ProjectSystem.Properties; - -namespace Microsoft.VisualStudio.Razor.ProjectSystem; - -internal class TestProjectChangeDescription : IProjectChangeDescription -{ - public TestProjectChangeDescription(IProjectRuleSnapshot before, IProjectRuleSnapshot after) - { - Before = before; - After = after; - - Difference = Diff.Create(before, after); - } - - public IProjectRuleSnapshot Before { get; } - - public IProjectChangeDiff Difference { get; } - - public IProjectRuleSnapshot After { get; } - - private class Diff : IProjectChangeDiff - { - public static Diff Create(IProjectRuleSnapshot before, IProjectRuleSnapshot after) - { - var addedItems = new HashSet(after.Items.Keys); - addedItems.ExceptWith(before.Items.Keys); - - var removedItems = new HashSet(before.Items.Keys); - removedItems.ExceptWith(after.Items.Keys); - - // changed items must be present in both sets, but have different properties. - var changedItems = new HashSet(before.Items.Keys); - changedItems.IntersectWith(after.Items.Keys); - changedItems.RemoveWhere(key => - { - var x = before.Items[key]; - var y = after.Items[key]; - - if (x.Count != y.Count) - { - return true; - } - - foreach (var kvp in x) - { - if (!y.Contains(kvp)) - { - return true; - } - } - - return false; - }); - - var changedProperties = new HashSet(before.Properties.Keys); - changedProperties.RemoveWhere(key => - { - var x = before.Properties[key]; - var y = after.Properties[key]; - return Equals(x, y); - }); - - return new Diff() - { - AddedItems = addedItems.ToImmutableHashSet(), - RemovedItems = removedItems.ToImmutableHashSet(), - ChangedItems = changedItems.ToImmutableHashSet(), - - // We ignore renamed items. - RenamedItems = ImmutableDictionary.Empty, - - ChangedProperties = changedProperties.ToImmutableHashSet(), - }; - } - - public IImmutableSet AddedItems { get; private set; } - - public IImmutableSet RemovedItems { get; private set; } - - public IImmutableSet ChangedItems { get; private set; } - - public IImmutableDictionary RenamedItems { get; private set; } - - public IImmutableSet ChangedProperties { get; private set; } - - public bool AnyChanges => - AddedItems.Count > 0 || - RemovedItems.Count > 0 || - ChangedItems.Count > 0 || - RenamedItems.Count > 0 || - ChangedProperties.Count > 0; - } -} diff --git a/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/ProjectSystem/TestProjectRuleSnapshot.cs b/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/ProjectSystem/TestProjectRuleSnapshot.cs deleted file mode 100644 index 1841f60b144..00000000000 --- a/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/ProjectSystem/TestProjectRuleSnapshot.cs +++ /dev/null @@ -1,53 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -#nullable disable - -using System; -using System.Collections.Generic; -using System.Collections.Immutable; -using Microsoft.VisualStudio.ProjectSystem; -using Microsoft.VisualStudio.ProjectSystem.Properties; - -namespace Microsoft.VisualStudio.Razor.ProjectSystem; - -internal class TestProjectRuleSnapshot : IProjectRuleSnapshot -{ - public static TestProjectRuleSnapshot CreateProperties(string ruleName, Dictionary properties) - { - return new TestProjectRuleSnapshot( - ruleName, - items: ImmutableDictionary>.Empty, - properties: properties.ToImmutableDictionary(), - dataSourceVersions: ImmutableDictionary.Empty); - } - - public static TestProjectRuleSnapshot CreateItems(string ruleName, Dictionary> items) - { - return new TestProjectRuleSnapshot( - ruleName, - items: items.ToImmutableDictionary(kvp => kvp.Key, kvp => (IImmutableDictionary)kvp.Value.ToImmutableDictionary()), - properties: ImmutableDictionary.Empty, - dataSourceVersions: ImmutableDictionary.Empty); - } - - public TestProjectRuleSnapshot( - string ruleName, - IImmutableDictionary> items, - IImmutableDictionary properties, - IImmutableDictionary dataSourceVersions) - { - RuleName = ruleName; - Items = items; - Properties = properties; - DataSourceVersions = dataSourceVersions; - } - - public string RuleName { get; } - - public IImmutableDictionary> Items { get; } - - public IImmutableDictionary Properties { get; } - - public IImmutableDictionary DataSourceVersions { get; } -} diff --git a/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/ProjectSystem/TestProjectSystemServices.cs b/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/ProjectSystem/TestProjectSystemServices.cs deleted file mode 100644 index 0a0bbe42ce6..00000000000 --- a/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/ProjectSystem/TestProjectSystemServices.cs +++ /dev/null @@ -1,758 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -#nullable disable - -using System; -using System.Collections.Generic; -using System.Collections.Immutable; -using System.Linq; -using System.Reflection; -using System.Text; -using System.Threading; -using System.Threading.Tasks; -using System.Threading.Tasks.Dataflow; -using System.Xml; -using Microsoft.Build.Execution; -using Microsoft.Build.Framework; -using Microsoft.Build.Framework.XamlTypes; -using Microsoft.CodeAnalysis; -using Microsoft.VisualStudio.ProjectSystem; -using Microsoft.VisualStudio.ProjectSystem.Properties; -using Microsoft.VisualStudio.ProjectSystem.References; -using Microsoft.VisualStudio.Threading; -using Moq; - -namespace Microsoft.VisualStudio.Razor.ProjectSystem; - -internal class TestProjectSystemServices : IUnconfiguredProjectCommonServices -{ - public TestProjectSystemServices(string fullPath, params TestPropertyData[] data) - { - ProjectService = new TestProjectService(); - ThreadingService = (TestThreadingService)ProjectService.Services.ThreadingPolicy; - - UnconfiguredProject = new TestUnconfiguredProject(ProjectService, fullPath); - ProjectService.LoadedUnconfiguredProjects.Add(UnconfiguredProject); - - ActiveConfiguredProject = new TestConfiguredProject(UnconfiguredProject, data); - UnconfiguredProject.LoadedConfiguredProjects.Add(ActiveConfiguredProject); - - ActiveConfigurationGroupSubscriptionService = new TestActiveConfigurationGroupSubscriptionService(); - - TasksService = new TestProjectAsynchronousTasksService(ProjectService, UnconfiguredProject, ActiveConfiguredProject); - - FaultHandlerService = new TestProjectFaultHandlerService(); - } - - public ProjectServices Services { get; } - - public TestProjectService ProjectService { get; } - - public TestUnconfiguredProject UnconfiguredProject { get; } - - public TestConfiguredProject ActiveConfiguredProject { get; } - - public TestActiveConfigurationGroupSubscriptionService ActiveConfigurationGroupSubscriptionService { get; } - - public TestProjectAsynchronousTasksService TasksService { get; } - - public TestThreadingService ThreadingService { get; } - - public TestProjectFaultHandlerService FaultHandlerService { get; } - - IActiveConfigurationGroupSubscriptionService IUnconfiguredProjectCommonServices.ActiveConfigurationGroupSubscriptionService => ActiveConfigurationGroupSubscriptionService; - - IProjectAsynchronousTasksService IUnconfiguredProjectCommonServices.TasksService => TasksService; - - IProjectThreadingService IUnconfiguredProjectCommonServices.ThreadingService => ThreadingService; - - UnconfiguredProject IUnconfiguredProjectCommonServices.UnconfiguredProject => UnconfiguredProject; - - IProjectFaultHandlerService IUnconfiguredProjectCommonServices.FaultHandlerService => FaultHandlerService; - - public IProjectVersionedValue CreateUpdate(params TestProjectChangeDescription[] descriptions) - { - return new ProjectVersionedValue( - value: new ProjectSubscriptionUpdate( - projectChanges: descriptions.ToImmutableDictionary(d => d.After.RuleName, d => (IProjectChangeDescription)d), - projectConfiguration: ActiveConfiguredProject.ProjectConfiguration), - dataSourceVersions: ImmutableDictionary.Empty); - } - - public class TestProjectService : IProjectService - { - public TestProjectService() - { - LoadedUnconfiguredProjects = new List(); - - var services = new Mock(MockBehavior.Strict); - services.Setup(s => s.ProjectService).Returns(this); - services.Setup(s => s.ThreadingPolicy).Returns(new TestThreadingService()); - Services = services.Object; - } - - public List LoadedUnconfiguredProjects { get; } - - public ProjectServices Services { get; } - - IEnumerable IProjectService.LoadedUnconfiguredProjects => throw new NotImplementedException(); - - ProjectServices IProjectService.Services => Services; - - IProjectCapabilitiesScope IProjectService.Capabilities => throw new NotImplementedException(); - - Task IProjectService.LoadProjectAsync(string projectLocation, IImmutableSet projectCapabilities) - { - throw new NotImplementedException(); - } - - Task IProjectService.LoadProjectAsync(XmlReader reader, IImmutableSet projectCapabilities) - { - throw new NotImplementedException(); - } - - Task IProjectService.LoadProjectAsync(string projectLocation, bool delayAutoLoad, IImmutableSet projectCapabilities) - { - throw new NotImplementedException(); - } - - Task IProjectService.UnloadProjectAsync(UnconfiguredProject project) - { - throw new NotImplementedException(); - } - } - - public class TestUnconfiguredProject : UnconfiguredProject - { - public TestUnconfiguredProject(TestProjectService projectService, string fullPath) - { - ProjectService = projectService; - FullPath = fullPath; - - LoadedConfiguredProjects = new List(); - } - - public TestProjectService ProjectService { get; } - - public string FullPath { get; set; } - - public List LoadedConfiguredProjects { get; } - - public UnconfiguredProjectServices Services => throw new NotImplementedException(); - - string UnconfiguredProject.FullPath => FullPath; - - bool UnconfiguredProject.RequiresReloadForExternalFileChange => throw new NotImplementedException(); - - IProjectCapabilitiesScope UnconfiguredProject.Capabilities => throw new NotImplementedException(); - - IProjectService UnconfiguredProject.ProjectService => ProjectService; - - IEnumerable UnconfiguredProject.LoadedConfiguredProjects => LoadedConfiguredProjects; - - bool UnconfiguredProject.IsLoading => throw new NotImplementedException(); - - event AsyncEventHandler UnconfiguredProject.ProjectUnloading - { - add - { - throw new NotImplementedException(); - } - - remove - { - throw new NotImplementedException(); - } - } - - event AsyncEventHandler UnconfiguredProject.ProjectRenaming - { - add - { - } - - remove - { - } - } - - event AsyncEventHandler UnconfiguredProject.ProjectRenamedOnWriter - { - add - { - throw new NotImplementedException(); - } - - remove - { - throw new NotImplementedException(); - } - } - - event AsyncEventHandler UnconfiguredProject.ProjectRenamed - { - add - { - throw new NotImplementedException(); - } - - remove - { - throw new NotImplementedException(); - } - } - - Task UnconfiguredProject.CanRenameAsync(string newFilePath) - { - throw new NotImplementedException(); - } - - Task UnconfiguredProject.GetFileEncodingAsync() - { - throw new NotImplementedException(); - } - - Task UnconfiguredProject.GetIsDirtyAsync() - { - throw new NotImplementedException(); - } - - Task UnconfiguredProject.GetSuggestedConfiguredProjectAsync() - { - throw new NotImplementedException(); - } - - Task UnconfiguredProject.LoadConfiguredProjectAsync(string name, IImmutableDictionary configurationProperties) - { - throw new NotImplementedException(); - } - - Task UnconfiguredProject.LoadConfiguredProjectAsync(ProjectConfiguration projectConfiguration) - { - throw new NotImplementedException(); - } - - Task UnconfiguredProject.ReloadAsync(bool immediately) - { - throw new NotImplementedException(); - } - - Task UnconfiguredProject.RenameAsync(string newFilePath) - { - throw new NotImplementedException(); - } - - Task UnconfiguredProject.SaveAsync(string filePath) - { - throw new NotImplementedException(); - } - - Task UnconfiguredProject.SaveCopyAsync(string filePath, Encoding fileEncoding) - { - throw new NotImplementedException(); - } - - Task UnconfiguredProject.SaveUserFileAsync() - { - throw new NotImplementedException(); - } - - Task UnconfiguredProject.SetFileEncodingAsync(Encoding value) - { - throw new NotImplementedException(); - } - } - - public class TestConfiguredProject : ConfiguredProject - { - public TestConfiguredProject(TestUnconfiguredProject unconfiguredProject, TestPropertyData[] data) - { - UnconfiguredProject = unconfiguredProject; - - var services = new Mock(MockBehavior.Strict); - services.Setup(s => s.AdditionalRuleDefinitions).Returns(new TestAdditionalRuleDefinitionsService()); - services.Setup(s => s.PropertyPagesCatalog).Returns(new TestPropertyPagesCatalogProvider(new TestPropertyPagesCatalog(data))); - services.Setup(s => s.ProjectService).Returns(UnconfiguredProject.ProjectService); - Services = services.Object; - - ProjectConfiguration = new StandardProjectConfiguration( - "Debug|AnyCPU", - ImmutableDictionary.Empty.Add("Configuration", "Debug").Add("Platform", "AnyCPU")); - } - - public TestUnconfiguredProject UnconfiguredProject { get; } - - public ProjectConfiguration ProjectConfiguration { get; } - - public ConfiguredProjectServices Services { get; } - - IComparable ConfiguredProject.ProjectVersion => throw new NotImplementedException(); - - IReceivableSourceBlock ConfiguredProject.ProjectVersionBlock => throw new NotImplementedException(); - - ProjectConfiguration ConfiguredProject.ProjectConfiguration => ProjectConfiguration; - - IProjectCapabilitiesScope ConfiguredProject.Capabilities => throw new NotImplementedException(); - - UnconfiguredProject ConfiguredProject.UnconfiguredProject => UnconfiguredProject; - - ConfiguredProjectServices ConfiguredProject.Services => Services; - - event AsyncEventHandler ConfiguredProject.ProjectUnloading - { - add - { - throw new NotImplementedException(); - } - - remove - { - throw new NotImplementedException(); - } - } - - event EventHandler ConfiguredProject.ProjectChanged - { - add - { - throw new NotImplementedException(); - } - - remove - { - throw new NotImplementedException(); - } - } - - event EventHandler ConfiguredProject.ProjectChangedSynchronous - { - add - { - throw new NotImplementedException(); - } - - remove - { - throw new NotImplementedException(); - } - } - - void ConfiguredProject.NotifyProjectChange() - { - throw new NotImplementedException(); - } - } - - public class TestAdditionalRuleDefinitionsService : IAdditionalRuleDefinitionsService - { - IProjectVersionedValue IAdditionalRuleDefinitionsService.AdditionalRuleDefinitions => throw new NotImplementedException(); - - IReceivableSourceBlock> IProjectValueDataSource.SourceBlock => throw new NotImplementedException(); - - ISourceBlock> IProjectValueDataSource.SourceBlock => throw new NotImplementedException(); - - NamedIdentity IProjectValueDataSource.DataSourceKey => throw new NotImplementedException(); - - IComparable IProjectValueDataSource.DataSourceVersion => throw new NotImplementedException(); - - bool IAdditionalRuleDefinitionsService.AddRuleDefinition(string path, string context) - { - return false; - } - - bool IAdditionalRuleDefinitionsService.AddRuleDefinition(Rule rule, string context) - { - return false; - } - - IDisposable IJoinableProjectValueDataSource.Join() - { - throw new NotImplementedException(); - } - - bool IAdditionalRuleDefinitionsService.RemoveRuleDefinition(string path) - { - return false; - } - - bool IAdditionalRuleDefinitionsService.RemoveRuleDefinition(Rule rule) - { - return false; - } - } - - public class TestPropertyPagesCatalogProvider : IPropertyPagesCatalogProvider - { - public TestPropertyPagesCatalogProvider(TestPropertyPagesCatalog catalog) - { - Catalog = catalog; - CatalogsByContext = new Dictionary() - { - { "Project", catalog }, - }; - } - - public TestPropertyPagesCatalog Catalog { get; } - - public Dictionary CatalogsByContext { get; } - - public IReceivableSourceBlock> SourceBlock => throw new NotImplementedException(); - - public NamedIdentity DataSourceKey => throw new NotImplementedException(); - - public IComparable DataSourceVersion => throw new NotImplementedException(); - - ISourceBlock> IProjectValueDataSource.SourceBlock => throw new NotImplementedException(); - - public Task GetCatalogAsync(string name, CancellationToken cancellationToken = default) - { - return Task.FromResult(CatalogsByContext[name]); - } - - public Task> GetCatalogsAsync(CancellationToken cancellationToken = default) - { - return Task.FromResult>(CatalogsByContext.ToImmutableDictionary()); - } - - public IPropertyPagesCatalog GetMemoryOnlyCatalog(string context) - { - return Catalog; - } - - public IDisposable Join() - { - throw new NotImplementedException(); - } - } - - public class TestActiveConfigurationGroupSubscriptionService : IActiveConfigurationGroupSubscriptionService - { - public TestActiveConfigurationGroupSubscriptionService() - { - SourceBlock = new BufferBlock>(); - } - - public BufferBlock> SourceBlock { get; } - - ConfigurationSubscriptionSources IActiveConfigurationGroupSubscriptionService.Current { get; } - - IReceivableSourceBlock> IProjectValueDataSource.SourceBlock => SourceBlock; - - ISourceBlock> IProjectValueDataSource.SourceBlock => SourceBlock; - - NamedIdentity IProjectValueDataSource.DataSourceKey { get; } - - IComparable IProjectValueDataSource.DataSourceVersion { get; } - - IDisposable IJoinableProjectValueDataSource.Join() => null; - } - - public class TestProjectFaultHandlerService : IProjectFaultHandlerService - { - Task IProjectFaultHandlerService.HandleFaultAsync(Exception ex, ErrorReportSettings watsonReportSettings, ProjectFaultSeverity severity, UnconfiguredProject project) => throw new NotImplementedException(); - - void IProjectFaultHandlerService.RegisterFaultHandler(Task task, ErrorReportSettings watsonReportSettings, ProjectFaultSeverity severity, UnconfiguredProject project) => throw new NotImplementedException(); - - void IProjectFaultHandlerService.RegisterFaultHandler(Task task, ErrorReportSettings watsonReportSettings, ProjectFaultSeverity severity, UnconfiguredProject project) => throw new NotImplementedException(); - - Task IProjectFaultHandlerService.ReportUserFaultAsync(Exception ex, ProjectFaultSeverity severity, UnconfiguredProject project) => throw new NotImplementedException(); - } - - public class TestProjectValueDataSource : IProjectValueDataSource - { - public TestProjectValueDataSource(BufferBlock> sourceBlock) - { - SourceBlock = sourceBlock; - } - - public BufferBlock> SourceBlock { get; } - - IReceivableSourceBlock> IProjectValueDataSource.SourceBlock => SourceBlock; - - ISourceBlock> IProjectValueDataSource.SourceBlock => throw new NotImplementedException(); - - NamedIdentity IProjectValueDataSource.DataSourceKey => throw new NotImplementedException(); - - IComparable IProjectValueDataSource.DataSourceVersion => throw new NotImplementedException(); - - IDisposable IJoinableProjectValueDataSource.Join() - { - throw new NotImplementedException(); - } - } - - public class TestPropertyPagesCatalog : IPropertyPagesCatalog - { - private readonly Dictionary _data; - - public TestPropertyPagesCatalog(TestPropertyData[] data) - { - _data = new Dictionary(); - foreach (var category in data.GroupBy(p => p.Category)) - { - _data.Add( - category.Key, - CreateRule(category.Select(property => CreateProperty(property.PropertyName, property.Value, property.SetValues)))); - } - } - - private static IRule CreateRule(IEnumerable properties) - { - var rule = new Mock(MockBehavior.Strict); - rule - .Setup(o => o.GetProperty(It.IsAny())) - .Returns((string propertyName) => properties.FirstOrDefault(p => p.Name == propertyName)); - - return rule.Object; - } - - private static IProperty CreateProperty(string name, object value, List setValues = null) - { - var property = new Mock(MockBehavior.Strict); - property.SetupGet(o => o.Name) - .Returns(name); - - property.Setup(o => o.GetValueAsync()) - .ReturnsAsync(value); - - property.As().Setup(p => p.GetEvaluatedValueAtEndAsync()).ReturnsAsync(value.ToString()); - property.As().Setup(p => p.GetEvaluatedValueAsync()).ReturnsAsync(value.ToString()); - - if (setValues != null) - { - property - .Setup(p => p.SetValueAsync(It.IsAny())) - .Callback(obj => setValues.Add(obj)) - .Returns(() => Task.CompletedTask); - } - - return property.Object; - } - - IRule IPropertyPagesCatalog.BindToContext(string schemaName, string file, string itemType, string itemName) - { - _data.TryGetValue(schemaName, out var value); - return value; - } - - IRule IPropertyPagesCatalog.BindToContext(string schemaName, IProjectPropertiesContext context) - { - throw new NotImplementedException(); - } - - IRule IPropertyPagesCatalog.BindToContext(string schemaName, ProjectInstance projectInstance, string itemType, string itemName) - { - throw new NotImplementedException(); - } - - IRule IPropertyPagesCatalog.BindToContext(string schemaName, ProjectInstance projectInstance, ITaskItem taskItem) - { - throw new NotImplementedException(); - } - - IReadOnlyCollection IPropertyPagesCatalog.GetProjectLevelPropertyPagesSchemas() - { - throw new NotImplementedException(); - } - - IReadOnlyCollection IPropertyPagesCatalog.GetPropertyPagesSchemas() - { - throw new NotImplementedException(); - } - - IReadOnlyCollection IPropertyPagesCatalog.GetPropertyPagesSchemas(string itemType) - { - throw new NotImplementedException(); - } - - IReadOnlyCollection IPropertyPagesCatalog.GetPropertyPagesSchemas(IEnumerable paths) - { - throw new NotImplementedException(); - } - - Rule IPropertyPagesCatalog.GetSchema(string schemaName) - { - throw new NotImplementedException(); - } - } - - public class TestAssemblyReferencesService : IAssemblyReferencesService - { - public TestAssemblyReferencesService() - { - ResolvedReferences = new List(); - } - - public List ResolvedReferences { get; } - - Task> IAssemblyReferencesService.AddAsync(AssemblyName assemblyName, string assemblyPath) - { - throw new NotImplementedException(); - } - - Task IAssemblyReferencesService.CanResolveAsync(AssemblyName assemblyName, string assemblyPath) - { - throw new NotImplementedException(); - } - - Task IAssemblyReferencesService.ContainsAsync(AssemblyName assemblyName, string assemblyPath) - { - throw new NotImplementedException(); - } - - Task IAssemblyReferencesService.GetResolvedReferenceAsync(AssemblyName assemblyName, string assemblyPath) - { - throw new NotImplementedException(); - } - - Task IResolvableReferencesService.GetResolvedReferenceAsync(IUnresolvedAssemblyReference unresolvedReference) - { - throw new NotImplementedException(); - } - - Task> IResolvableReferencesService.GetResolvedReferencesAsync() - { - return Task.FromResult>(ResolvedReferences.ToImmutableHashSet()); - } - - Task IAssemblyReferencesService.GetUnresolvedReferenceAsync(AssemblyName assemblyName, string assemblyPath) - { - throw new NotImplementedException(); - } - - Task IResolvableReferencesService.GetUnresolvedReferenceAsync(IAssemblyReference resolvedReference) - { - throw new NotImplementedException(); - } - - Task> IResolvableReferencesService.GetUnresolvedReferencesAsync() - { - throw new NotImplementedException(); - } - - Task IAssemblyReferencesService.RemoveAsync(AssemblyName assemblyName, string assemblyPath) - { - throw new NotImplementedException(); - } - - Task IResolvableReferencesService.RemoveAsync(IUnresolvedAssemblyReference reference) - { - throw new NotImplementedException(); - } - - Task IResolvableReferencesService.RemoveAsync(IEnumerable references) - { - throw new NotImplementedException(); - } - } - - public class TestProjectAsynchronousTasksService : IProjectAsynchronousTasksService, IProjectContext - { - public CancellationToken UnloadCancellationToken => CancellationToken.None; - - public TestProjectAsynchronousTasksService( - IProjectService projectService, - UnconfiguredProject unconfiguredProject, - ConfiguredProject configuredProject) - { - ProjectService = projectService; - UnconfiguredProject = unconfiguredProject; - ConfiguredProject = configuredProject; - } - - public IProjectService ProjectService { get; } - - public UnconfiguredProject UnconfiguredProject { get; } - - public ConfiguredProject ConfiguredProject { get; } - - public Task DrainCriticalTaskQueueAsync(bool drainCurrentQueueOnly = false, bool throwExceptions = false, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task DrainTaskQueueAsync(bool drainCurrentQueueOnly = false, bool throwExceptions = false, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public Task DrainTaskQueueAsync(ProjectCriticalOperation operation, bool drainCurrentQueueOnly = false, bool throwExceptions = false, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public bool IsTaskQueueEmpty(ProjectCriticalOperation projectCriticalOperation) - { - throw new NotImplementedException(); - } - - public void RegisterAsyncTask(JoinableTask joinableTask, bool registerFaultHandler = false) - { - } - - public void RegisterAsyncTask(Task task, bool registerFaultHandler = false) - { - } - - public void RegisterAsyncTask(JoinableTask joinableTask, ProjectCriticalOperation operationFlags, bool registerFaultHandler = false) - { - } - - public void RegisterCriticalAsyncTask(JoinableTask joinableTask, bool registerFaultHandler = false) - { - } - } - - public class TestThreadingService : IProjectThreadingService - { - public TestThreadingService() - { - JoinableTaskContext = new JoinableTaskContextNode(new JoinableTaskContext()); - JoinableTaskFactory = new JoinableTaskFactory(JoinableTaskContext.Context); - } - - public JoinableTaskContextNode JoinableTaskContext { get; } - - public JoinableTaskFactory JoinableTaskFactory { get; } - - public bool IsOnMainThread => throw new NotImplementedException(); - - public void ExecuteSynchronously(Func asyncAction) - { - asyncAction().GetAwaiter().GetResult(); - } - - public T ExecuteSynchronously(Func> asyncAction) - { -#pragma warning disable VSTHRD002 // Avoid problematic synchronous waits - return asyncAction().GetAwaiter().GetResult(); -#pragma warning restore VSTHRD002 // Avoid problematic synchronous waits - } - - public void Fork( - Func asyncAction, - JoinableTaskFactory factory = null, - UnconfiguredProject unconfiguredProject = null, - ConfiguredProject configuredProject = null, - ErrorReportSettings watsonReportSettings = null, - ProjectFaultSeverity faultSeverity = ProjectFaultSeverity.Recoverable, - ForkOptions options = ForkOptions.Default) - { - throw new NotImplementedException(); - } - - public IDisposable SuppressProjectExecutionContext() - { - throw new NotImplementedException(); - } - - public void VerifyOnUIThread() - { - if (!JoinableTaskContext.IsOnMainThread) - { - throw new InvalidOperationException("This isn't the main thread."); - } - } - } -} diff --git a/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/ProjectSystem/TestPropertyData.cs b/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/ProjectSystem/TestPropertyData.cs deleted file mode 100644 index 7345eb62c2a..00000000000 --- a/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/ProjectSystem/TestPropertyData.cs +++ /dev/null @@ -1,19 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -#nullable disable - -using System.Collections.Generic; - -namespace Microsoft.VisualStudio.Razor.ProjectSystem; - -public class TestPropertyData -{ - public string Category { get; set; } - - public string PropertyName { get; set; } - - public object Value { get; set; } - - public List SetValues { get; } -} diff --git a/src/Razor/test/Microsoft.VisualStudio.Razor.IntegrationTests/InProcess/EditorInProcess_Completion.cs b/src/Razor/test/Microsoft.VisualStudio.Razor.IntegrationTests/InProcess/EditorInProcess_Completion.cs index 2e9adfdd607..76d3e18deb7 100644 --- a/src/Razor/test/Microsoft.VisualStudio.Razor.IntegrationTests/InProcess/EditorInProcess_Completion.cs +++ b/src/Razor/test/Microsoft.VisualStudio.Razor.IntegrationTests/InProcess/EditorInProcess_Completion.cs @@ -135,6 +135,7 @@ public async Task DismissCompletionSessionsAsync(CancellationToken cancellationT lastSessionResetTime = stopWatch.ElapsedMilliseconds; return asyncCompletion.TriggerCompletion(textView, new CompletionTrigger(CompletionTriggerReason.Invoke, textView.TextSnapshot), textView.Caret.Position.BufferPosition, cancellationToken); } + void OpenOrUpdate(IAsyncCompletionSession currentSession) { // Preserve insertion semantics for active sessions so filtering and uniqueness still diff --git a/src/Razor/test/Microsoft.VisualStudio.Razor.IntegrationTests/MEFComponentTests.cs b/src/Razor/test/Microsoft.VisualStudio.Razor.IntegrationTests/MEFComponentTests.cs index 4bb811274d2..a28a13f6d64 100644 --- a/src/Razor/test/Microsoft.VisualStudio.Razor.IntegrationTests/MEFComponentTests.cs +++ b/src/Razor/test/Microsoft.VisualStudio.Razor.IntegrationTests/MEFComponentTests.cs @@ -4,7 +4,6 @@ using System; using System.IO; using System.Text; -using System.Windows.Documents; using Xunit; using Xunit.Abstractions; @@ -57,8 +56,11 @@ public static void EnsureCompositionCreation() private static bool IsAllowedFailure(string error) { - return - // No allowed failures. Yay! - false; + return error switch + { + // This isn't real, obviously, but stops build warnings about unused parameters + "Example allowed error" => true, + _ => false + }; } } diff --git a/src/Razor/test/Microsoft.VisualStudio.Razor.IntegrationTests/Semantic/RazorSemanticTokensTests.cs b/src/Razor/test/Microsoft.VisualStudio.Razor.IntegrationTests/Semantic/RazorSemanticTokensTests.cs index 7b52d519c51..9ef9a5ac60e 100644 --- a/src/Razor/test/Microsoft.VisualStudio.Razor.IntegrationTests/Semantic/RazorSemanticTokensTests.cs +++ b/src/Razor/test/Microsoft.VisualStudio.Razor.IntegrationTests/Semantic/RazorSemanticTokensTests.cs @@ -21,8 +21,6 @@ namespace Microsoft.VisualStudio.Razor.IntegrationTests; public class RazorSemanticTokensTests(ITestOutputHelper testOutputHelper) : AbstractRazorEditorTest(testOutputHelper) { - private static readonly AsyncLocal s_fileName = new(); - private static string? s_projectPath; // WARNING: If you leave this as "true" it will cause the semantic tokens tests to change their expected values. diff --git a/src/Razor/test/Microsoft.VisualStudioCode.Razor.IntegrationTests/CompletionTests.cs b/src/Razor/test/Microsoft.VisualStudioCode.Razor.IntegrationTests/CompletionTests.cs index c3e558beec3..31cd8251c30 100644 --- a/src/Razor/test/Microsoft.VisualStudioCode.Razor.IntegrationTests/CompletionTests.cs +++ b/src/Razor/test/Microsoft.VisualStudioCode.Razor.IntegrationTests/CompletionTests.cs @@ -34,6 +34,7 @@ public Task CSharpCompletion_InCodeBlock_ShowsCSharpItems() => ScreenshotOnFailu // If not visible yet, trigger explicitly hasCompletions = await TestServices.Completion.TriggerAsync(); } + Assert.True(hasCompletions, "Expected completion list to appear"); // Assert - look for currentCount in completions diff --git a/src/Razor/test/Microsoft.VisualStudioCode.Razor.IntegrationTests/Services/CompletionServices.cs b/src/Razor/test/Microsoft.VisualStudioCode.Razor.IntegrationTests/Services/CompletionServices.cs index ffa967ab2df..b08411ffaa0 100644 --- a/src/Razor/test/Microsoft.VisualStudioCode.Razor.IntegrationTests/Services/CompletionServices.cs +++ b/src/Razor/test/Microsoft.VisualStudioCode.Razor.IntegrationTests/Services/CompletionServices.cs @@ -107,6 +107,7 @@ public async Task> GetItemsAsync() { TestServices.Logger.Log($"First few items: {string.Join(", ", results.Take(5))}"); } + return results; } diff --git a/src/Razor/test/Microsoft.VisualStudioCode.Razor.IntegrationTests/Services/DiagnosticsServices.cs b/src/Razor/test/Microsoft.VisualStudioCode.Razor.IntegrationTests/Services/DiagnosticsServices.cs index a515e4fc143..b25e70100c6 100644 --- a/src/Razor/test/Microsoft.VisualStudioCode.Razor.IntegrationTests/Services/DiagnosticsServices.cs +++ b/src/Razor/test/Microsoft.VisualStudioCode.Razor.IntegrationTests/Services/DiagnosticsServices.cs @@ -69,7 +69,7 @@ await Helper.WaitForConditionAsync( public async Task OpenProblemsPanelAsync() { await TestServices.Editor.ExecuteCommandAsync("View: Toggle Problems"); - + // Wait for panel to be visible - VS Code uses .markers-panel for the problems panel await TestServices.Playwright.Page.Locator(".markers-panel") .WaitForAsync(new LocatorWaitForOptions diff --git a/src/Razor/test/Microsoft.VisualStudioCode.Razor.IntegrationTests/Services/EditorService.cs b/src/Razor/test/Microsoft.VisualStudioCode.Razor.IntegrationTests/Services/EditorService.cs index c33f5ecebe4..959dd5cf953 100644 --- a/src/Razor/test/Microsoft.VisualStudioCode.Razor.IntegrationTests/Services/EditorService.cs +++ b/src/Razor/test/Microsoft.VisualStudioCode.Razor.IntegrationTests/Services/EditorService.cs @@ -80,6 +80,7 @@ public async Task WaitForEditorTextChangeAsync() { // Use original if we can't read } + TestServices.Logger.Log($"WaitForEditorTextChangeAsync: AFTER contents (fallback, {currentContents.Length} chars):\n{currentContents}"); return currentContents; } diff --git a/src/Razor/test/Microsoft.VisualStudioCode.Razor.IntegrationTests/Services/NavigationServices.cs b/src/Razor/test/Microsoft.VisualStudioCode.Razor.IntegrationTests/Services/NavigationServices.cs index d7dcabdaadc..d2d4c648d9c 100644 --- a/src/Razor/test/Microsoft.VisualStudioCode.Razor.IntegrationTests/Services/NavigationServices.cs +++ b/src/Razor/test/Microsoft.VisualStudioCode.Razor.IntegrationTests/Services/NavigationServices.cs @@ -1,8 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using Microsoft.Playwright; - namespace Microsoft.VisualStudioCode.Razor.IntegrationTests.Services; /// diff --git a/src/Razor/test/Microsoft.VisualStudioCode.Razor.IntegrationTests/Services/VSCodeService.Installer.cs b/src/Razor/test/Microsoft.VisualStudioCode.Razor.IntegrationTests/Services/VSCodeService.Installer.cs index c084ca891ec..413744a2f2a 100644 --- a/src/Razor/test/Microsoft.VisualStudioCode.Razor.IntegrationTests/Services/VSCodeService.Installer.cs +++ b/src/Razor/test/Microsoft.VisualStudioCode.Razor.IntegrationTests/Services/VSCodeService.Installer.cs @@ -229,6 +229,7 @@ public async Task InstallExtensionAsync(string vscodePath, string extensionId, s process.Kill(entireProcessTree: true); } catch { } + throw new TimeoutException($"Extension installation timed out after 3 minutes for {extensionId}"); } } @@ -297,6 +298,7 @@ public async Task IsExtensionInstalledAsync(string vscodePath, string exte process.Kill(entireProcessTree: true); } catch { } + testServices.Logger.Log("Timeout checking extensions, assuming not installed"); return false; } diff --git a/src/Shared/Microsoft.AspNetCore.Razor.Test.Common/Language/IntegrationTests/RazorDiagnosticSerializer.cs b/src/Shared/Microsoft.AspNetCore.Razor.Test.Common/Language/IntegrationTests/RazorDiagnosticSerializer.cs index bc2dc69d02f..719333830a5 100644 --- a/src/Shared/Microsoft.AspNetCore.Razor.Test.Common/Language/IntegrationTests/RazorDiagnosticSerializer.cs +++ b/src/Shared/Microsoft.AspNetCore.Razor.Test.Common/Language/IntegrationTests/RazorDiagnosticSerializer.cs @@ -5,7 +5,7 @@ namespace Microsoft.AspNetCore.Razor.Language; -public class RazorDiagnosticSerializer +public static class RazorDiagnosticSerializer { public static string Serialize(RazorDiagnostic diagnostic) { diff --git a/src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared/StringExtensions.cs b/src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared/StringExtensions.cs index 89b5e8eee0b..5a214d9ce3a 100644 --- a/src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared/StringExtensions.cs +++ b/src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared/StringExtensions.cs @@ -664,7 +664,7 @@ public static string Build(TState state, MemoryBuilderAction - public unsafe static string Create(int length, TState state, SpanAction action) + public static unsafe string Create(int length, TState state, SpanAction action) { ArgHelper.ThrowIfNegative(length);