From 3d76feadff67a54e0a420832438fe254b0ce88a5 Mon Sep 17 00:00:00 2001 From: Ryan Brandenburg Date: Wed, 19 Oct 2022 17:08:24 -0700 Subject: [PATCH 1/8] Fix shutdown issues from CLaSP --- eng/Versions.props | 2 +- .../RazorCSharpFormattingBenchmark.cs | 4 +- .../RazorSemanticTokensBenchmark.cs | 4 +- .../RazorSemanticTokensScrollingBenchmark.cs | 178 +++++++++--------- .../IServiceCollectionExtensions.cs | 1 - .../RazorLanguageServerWrapper.cs | 6 +- .../RazorLanguageServerClient.cs | 2 - .../RazorLanguageServerTest.cs | 4 +- 8 files changed, 98 insertions(+), 103 deletions(-) diff --git a/eng/Versions.props b/eng/Versions.props index 262a9b129f..9b7d6b9394 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -81,7 +81,7 @@ 4.4.0-2.22424.2 17.4.1008-preview 4.4.0-1.final - 4.5.0-1.22513.3 + 4.5.0-1.22519.14 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 ad0bd84db2..9d82a2b57a 100644 --- a/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorCSharpFormattingBenchmark.cs +++ b/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorCSharpFormattingBenchmark.cs @@ -127,11 +127,11 @@ namespace Microsoft.AspNetCore.Razor.Microbenchmarks.LanguageServer } [GlobalCleanup] - public async Task CleanupServerAsync() + public Task CleanupServerAsync() { File.Delete(_filePath); - await RazorLanguageServer.DisposeAsync(); + return Task.CompletedTask; } private void EnsureServicesInitialized() diff --git a/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorSemanticTokensBenchmark.cs b/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorSemanticTokensBenchmark.cs index 83d3597fea..31c0b25982 100644 --- a/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorSemanticTokensBenchmark.cs +++ b/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorSemanticTokensBenchmark.cs @@ -101,9 +101,9 @@ namespace Microsoft.AspNetCore.Razor.Microbenchmarks.LanguageServer } [GlobalCleanup] - public async Task CleanupServerAsync() + public Task CleanupServerAsync() { - await RazorLanguageServer.DisposeAsync(); + return Task.CompletedTask; } protected internal override void Builder(IServiceCollection collection) diff --git a/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorSemanticTokensScrollingBenchmark.cs b/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorSemanticTokensScrollingBenchmark.cs index b70152ccab..ed3ce25a97 100644 --- a/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorSemanticTokensScrollingBenchmark.cs +++ b/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorSemanticTokensScrollingBenchmark.cs @@ -18,117 +18,117 @@ using static Microsoft.AspNetCore.Razor.Microbenchmarks.LanguageServer.RazorSema namespace Microsoft.AspNetCore.Razor.Microbenchmarks.LanguageServer { - public class RazorSemanticTokensScrollingBenchmark : RazorLanguageServerBenchmarkBase - { - private DefaultRazorSemanticTokensInfoService RazorSemanticTokenService { get; set; } + public class RazorSemanticTokensScrollingBenchmark : RazorLanguageServerBenchmarkBase + { + private DefaultRazorSemanticTokensInfoService RazorSemanticTokenService { get; set; } - private DocumentVersionCache VersionCache { get; set; } + private DocumentVersionCache VersionCache { get; set; } - private DocumentContext DocumentContext { get; set; } + private DocumentContext DocumentContext { get; set; } - private Uri DocumentUri => DocumentContext.Uri; + private Uri DocumentUri => DocumentContext.Uri; - private DocumentSnapshot DocumentSnapshot => DocumentContext.Snapshot; + private DocumentSnapshot DocumentSnapshot => DocumentContext.Snapshot; - private Range Range { get; set; } + private Range Range { get; set; } - private ProjectSnapshotManagerDispatcher ProjectSnapshotManagerDispatcher { get; set; } + private ProjectSnapshotManagerDispatcher ProjectSnapshotManagerDispatcher { get; set; } - private string PagesDirectory { get; set; } + private string PagesDirectory { get; set; } - private string ProjectFilePath { get; set; } + private string ProjectFilePath { get; set; } - private string TargetPath { get; set; } + private string TargetPath { get; set; } - [GlobalSetup(Target = nameof(RazorSemanticTokensRangeScrollingAsync))] - public async Task InitializeRazorSemanticAsync() - { - EnsureServicesInitialized(); + [GlobalSetup(Target = nameof(RazorSemanticTokensRangeScrollingAsync))] + public async Task InitializeRazorSemanticAsync() + { + EnsureServicesInitialized(); - var projectRoot = Path.Combine(RepoRoot, "src", "Razor", "test", "testapps", "ComponentApp"); - ProjectFilePath = Path.Combine(projectRoot, "ComponentApp.csproj"); - PagesDirectory = Path.Combine(projectRoot, "Components", "Pages"); - var filePath = Path.Combine(PagesDirectory, $"FormattingTest.razor"); - TargetPath = "/Components/Pages/FormattingTest.razor"; + var projectRoot = Path.Combine(RepoRoot, "src", "Razor", "test", "testapps", "ComponentApp"); + ProjectFilePath = Path.Combine(projectRoot, "ComponentApp.csproj"); + PagesDirectory = Path.Combine(projectRoot, "Components", "Pages"); + var filePath = Path.Combine(PagesDirectory, $"FormattingTest.razor"); + TargetPath = "/Components/Pages/FormattingTest.razor"; - var documentUri = new Uri(filePath); - var documentSnapshot = GetDocumentSnapshot(ProjectFilePath, filePath, TargetPath); - DocumentContext = new DocumentContext(documentUri, documentSnapshot, version: 1); + var documentUri = new Uri(filePath); + var documentSnapshot = GetDocumentSnapshot(ProjectFilePath, filePath, TargetPath); + DocumentContext = new DocumentContext(documentUri, documentSnapshot, version: 1); - var text = await DocumentSnapshot.GetTextAsync().ConfigureAwait(false); - Range = new Range - { - Start = new Position - { - Line = 0, - Character = 0 - }, - End = new Position - { - Line = text.Lines.Count - 1, - Character = 0 - } - }; - } + var text = await DocumentSnapshot.GetTextAsync().ConfigureAwait(false); + Range = new Range + { + Start = new Position + { + Line = 0, + Character = 0 + }, + End = new Position + { + Line = text.Lines.Count - 1, + Character = 0 + } + }; + } - private const int WindowSize = 10; + private const int WindowSize = 10; - [Benchmark(Description = "Razor Semantic Tokens Range Scrolling")] - public async Task RazorSemanticTokensRangeScrollingAsync() - { - var textDocumentIdentifier = new TextDocumentIdentifier() - { - Uri = DocumentUri - }; - var cancellationToken = CancellationToken.None; - var documentVersion = 1; + [Benchmark(Description = "Razor Semantic Tokens Range Scrolling")] + public async Task RazorSemanticTokensRangeScrollingAsync() + { + var textDocumentIdentifier = new TextDocumentIdentifier() + { + Uri = DocumentUri + }; + var cancellationToken = CancellationToken.None; + var documentVersion = 1; - await UpdateDocumentAsync(documentVersion, DocumentSnapshot).ConfigureAwait(false); + await UpdateDocumentAsync(documentVersion, DocumentSnapshot).ConfigureAwait(false); - var documentLineCount = Range.End.Line; + var documentLineCount = Range.End.Line; - var lineCount = 0; - while (lineCount != documentLineCount) - { - var newLineCount = Math.Min(lineCount + WindowSize, documentLineCount); - var range = new Range - { - Start = new Position(lineCount, 0), - End = new Position(newLineCount, 0) - }; - await RazorSemanticTokenService!.GetSemanticTokensAsync( - textDocumentIdentifier, - range, - DocumentContext, - cancellationToken); + var lineCount = 0; + while (lineCount != documentLineCount) + { + var newLineCount = Math.Min(lineCount + WindowSize, documentLineCount); + var range = new Range + { + Start = new Position(lineCount, 0), + End = new Position(newLineCount, 0) + }; + await RazorSemanticTokenService!.GetSemanticTokensAsync( + textDocumentIdentifier, + range, + DocumentContext, + cancellationToken); - lineCount = newLineCount; - } - } + lineCount = newLineCount; + } + } - private async Task UpdateDocumentAsync(int newVersion, DocumentSnapshot documentSnapshot) - { - await ProjectSnapshotManagerDispatcher!.RunOnDispatcherThreadAsync( - () => VersionCache!.TrackDocumentVersion(documentSnapshot, newVersion), CancellationToken.None).ConfigureAwait(false); - } + private async Task UpdateDocumentAsync(int newVersion, DocumentSnapshot documentSnapshot) + { + await ProjectSnapshotManagerDispatcher!.RunOnDispatcherThreadAsync( + () => VersionCache!.TrackDocumentVersion(documentSnapshot, newVersion), CancellationToken.None).ConfigureAwait(false); + } - [GlobalCleanup] - public async Task CleanupServerAsync() - { - await RazorLanguageServer.DisposeAsync(); - } + [GlobalCleanup] + public Task CleanupServerAsync() + { + return Task.CompletedTask; + } - protected internal override void Builder(IServiceCollection collection) - { + protected internal override void Builder(IServiceCollection collection) + { collection.AddSingleton(); - } + } - private void EnsureServicesInitialized() - { - var languageServer = RazorLanguageServer.GetInnerLanguageServerForTesting(); - RazorSemanticTokenService = (languageServer.GetRequiredService() as TestRazorSemanticTokensInfoService)!; - VersionCache = languageServer.GetRequiredService(); - ProjectSnapshotManagerDispatcher = languageServer.GetRequiredService(); - } - } + private void EnsureServicesInitialized() + { + var languageServer = RazorLanguageServer.GetInnerLanguageServerForTesting(); + RazorSemanticTokenService = (languageServer.GetRequiredService() as TestRazorSemanticTokensInfoService)!; + VersionCache = languageServer.GetRequiredService(); + ProjectSnapshotManagerDispatcher = languageServer.GetRequiredService(); + } + } } 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 f6bc32c5d9..aab56a4142 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Extensions/IServiceCollectionExtensions.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Extensions/IServiceCollectionExtensions.cs @@ -32,7 +32,6 @@ internal static class IServiceCollectionExtensions { services.AddHandler(); services.AddHandler(); - services.AddHandler>(); var razorLifeCycleManager = new RazorLifeCycleManager(razorLanguageServer); services.AddSingleton(razorLifeCycleManager); diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorLanguageServerWrapper.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorLanguageServerWrapper.cs index 77285eaeff..1899d02878 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorLanguageServerWrapper.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorLanguageServerWrapper.cs @@ -14,7 +14,7 @@ using StreamJsonRpc; namespace Microsoft.AspNetCore.Razor.LanguageServer; -internal sealed class RazorLanguageServerWrapper : IAsyncDisposable +internal sealed class RazorLanguageServerWrapper : IDisposable { private readonly RazorLanguageServer _innerServer; private readonly object _disposeLock; @@ -78,10 +78,8 @@ internal sealed class RazorLanguageServerWrapper : IAsyncDisposable return _innerServer.GetRequiredService(); } - public async ValueTask DisposeAsync() + public void Dispose() { - await _innerServer.DisposeAsync(); - lock (_disposeLock) { if (!_disposed) diff --git a/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/RazorLanguageServerClient.cs b/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/RazorLanguageServerClient.cs index 06d1bac9cf..f29ea317c9 100644 --- a/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/RazorLanguageServerClient.cs +++ b/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/RazorLanguageServerClient.cs @@ -196,8 +196,6 @@ namespace Microsoft.VisualStudio.LanguageServerClient.Razor if (_server is not null) { // Server still hasn't shutdown, attempt an ungraceful shutdown. - await _server.DisposeAsync(); - ServerShutdown(); } } diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/RazorLanguageServerTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/RazorLanguageServerTest.cs index 28a3a1fde0..24d0b47246 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/RazorLanguageServerTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/RazorLanguageServerTest.cs @@ -21,10 +21,10 @@ public class RazorLanguageServerTest : TestBase } [Fact] - public async Task AllHandlersRegisteredAsync() + public void AllHandlersRegisteredAsync() { var (clientStream, serverStream) = FullDuplexStream.CreatePair(); - await using var server = RazorLanguageServerWrapper.Create(serverStream, serverStream, Logger); + using var server = RazorLanguageServerWrapper.Create(serverStream, serverStream, Logger); var innerServer = server.GetInnerLanguageServerForTesting(); var handlerProvider = innerServer.GetTestAccessor().GetHandlerProvider(); From 903badea7f8dace1012ac4b41546178117a2a091 Mon Sep 17 00:00:00 2001 From: Ryan Brandenburg Date: Thu, 20 Oct 2022 09:45:01 -0700 Subject: [PATCH 2/8] PR Cleanup --- .../LanguageServer/RazorCSharpFormattingBenchmark.cs | 4 +--- .../LanguageServer/RazorSemanticTokensBenchmark.cs | 6 ------ .../LanguageServer/RazorSemanticTokensScrollingBenchmark.cs | 6 ------ .../RazorLanguageServerTest.cs | 3 +-- 4 files changed, 2 insertions(+), 17 deletions(-) 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 9d82a2b57a..f795f5b3cf 100644 --- a/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorCSharpFormattingBenchmark.cs +++ b/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorCSharpFormattingBenchmark.cs @@ -127,11 +127,9 @@ namespace Microsoft.AspNetCore.Razor.Microbenchmarks.LanguageServer } [GlobalCleanup] - public Task CleanupServerAsync() + public void CleanupServer() { File.Delete(_filePath); - - return Task.CompletedTask; } private void EnsureServicesInitialized() diff --git a/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorSemanticTokensBenchmark.cs b/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorSemanticTokensBenchmark.cs index 31c0b25982..b3e306d8b0 100644 --- a/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorSemanticTokensBenchmark.cs +++ b/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorSemanticTokensBenchmark.cs @@ -100,12 +100,6 @@ namespace Microsoft.AspNetCore.Razor.Microbenchmarks.LanguageServer () => VersionCache.TrackDocumentVersion(documentSnapshot, newVersion), cancellationToken).ConfigureAwait(false); } - [GlobalCleanup] - public Task CleanupServerAsync() - { - return Task.CompletedTask; - } - protected internal override void Builder(IServiceCollection collection) { collection.AddSingleton(); diff --git a/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorSemanticTokensScrollingBenchmark.cs b/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorSemanticTokensScrollingBenchmark.cs index ed3ce25a97..937eb0879e 100644 --- a/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorSemanticTokensScrollingBenchmark.cs +++ b/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorSemanticTokensScrollingBenchmark.cs @@ -112,12 +112,6 @@ namespace Microsoft.AspNetCore.Razor.Microbenchmarks.LanguageServer () => VersionCache!.TrackDocumentVersion(documentSnapshot, newVersion), CancellationToken.None).ConfigureAwait(false); } - [GlobalCleanup] - public Task CleanupServerAsync() - { - return Task.CompletedTask; - } - protected internal override void Builder(IServiceCollection collection) { collection.AddSingleton(); diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/RazorLanguageServerTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/RazorLanguageServerTest.cs index 24d0b47246..19bc5f7e4b 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/RazorLanguageServerTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/RazorLanguageServerTest.cs @@ -36,8 +36,7 @@ public class RazorLanguageServerTest : TestBase // We turn this into a Set to handle cases like Completion where we have two handlers, only one of which will be registered // CLaSP will throw if two handlers register for the same method, so if THAT doesn't hold it's a CLaSP bug, not a Razor bug. var typeMethods = handlerTypes.Select(t => GetMethodFromType(t)).ToHashSet(); - // The shutdown handler is outside of our assembly. - typeMethods.Add("shutdown"); + if (registeredMethods.Length != typeMethods.Count) { var unregisteredHandlers = typeMethods.Where(t => !registeredMethods.Any(m => m.MethodName == t)); From 34eedeb7ca1c1bec74c636702c8ee6ca59faa688 Mon Sep 17 00:00:00 2001 From: Ryan Brandenburg Date: Thu, 20 Oct 2022 10:20:56 -0700 Subject: [PATCH 3/8] Upgrade VS versions and react to changes --- eng/Versions.props | 14 +++++++------- src/Razor/Razor.sln | 3 ++- .../DefaultRemoteTextLoaderFactory.cs | 2 +- .../DocumentSnapshotTextLoader.cs | 2 +- .../ProjectSystem/DefaultRazorProjectService.cs | 4 ++-- .../CSharpVirtualDocumentPublisher.cs | 2 +- .../CSharpTestLspServer.cs | 1 - .../CodeDocumentReferenceHolderTest.cs | 2 +- 8 files changed, 15 insertions(+), 15 deletions(-) diff --git a/eng/Versions.props b/eng/Versions.props index 9b7d6b9394..9eddc25c1a 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -76,9 +76,9 @@ 16.10.57-preview1 1.1.2-beta1.22109.1 - 17.2.32330.158 - 17.3.133-preview - 4.4.0-2.22424.2 + 17.3.32622.426 + 17.4.203-preview + 4.5.0-1.22519.14 17.4.1008-preview 4.4.0-1.final 4.5.0-1.22519.14 @@ -113,14 +113,14 @@ $(MicrosoftVisualStudioShellPackagesVersion) $(MicrosoftVisualStudioShellPackagesVersion) $(MicrosoftVisualStudioShellPackagesVersion) - 17.3.3-alpha + 17.3.19 16.4.137 $(MicrosoftVisualStudioPackagesVersion) $(MicrosoftVisualStudioPackagesVersion) $(MicrosoftVisualStudioPackagesVersion) - 17.3.1-alpha + 17.3.44 16.10.0-preview-1-31008-014 - 17.0.53 + 17.0.58 $(Tooling_HtmlEditorPackageVersion) $(Tooling_HtmlEditorPackageVersion) $(Tooling_HtmlEditorPackageVersion) @@ -135,7 +135,7 @@ 0.19.5 $(OmniSharpExtensionsLanguageServerPackageVersion) 1.39.1 - 2.12.7-alpha + 2.12.27 4.3.0 3.3.3 7.0.0-preview1.22116.1 diff --git a/src/Razor/Razor.sln b/src/Razor/Razor.sln index 95547b1f40..49c8a365c0 100644 --- a/src/Razor/Razor.sln +++ b/src/Razor/Razor.sln @@ -91,6 +91,7 @@ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{4CAC99E0-6ECE-4264-96C3-AF4EEE7BC9D1}" ProjectSection(SolutionItems) = preProject ..\..\.editorconfig = ..\..\.editorconfig + ..\..\eng\Versions.props = ..\..\eng\Versions.props EndProjectSection EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.VisualStudio.Razor.IntegrationTests", "test\Microsoft.VisualStudio.Razor.IntegrationTests\Microsoft.VisualStudio.Razor.IntegrationTests.csproj", "{8CEC0991-259F-4313-B3EF-E398F2B40E61}" @@ -101,7 +102,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RazorDeployment", "src\Razo EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Razor.LanguageServer.Protocol", "src\Microsoft.AspNetCore.Razor.LanguageServer.Protocol\Microsoft.AspNetCore.Razor.LanguageServer.Protocol.csproj", "{093B790B-1283-4EB3-B77E-4F9C4FB2A895}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNetCore.Razor.Common", "src\Microsoft.AspNetCore.Razor.Common\Microsoft.AspNetCore.Razor.Common.csproj", "{95ED6267-9A02-4B52-9EF5-C0BBE183C8FF}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Razor.Common", "src\Microsoft.AspNetCore.Razor.Common\Microsoft.AspNetCore.Razor.Common.csproj", "{95ED6267-9A02-4B52-9EF5-C0BBE183C8FF}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Compiler", "Compiler", "{5B60F564-4AD7-4B70-A887-7D91496799A2}" EndProject diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer.Common/DefaultRemoteTextLoaderFactory.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer.Common/DefaultRemoteTextLoaderFactory.cs index 71b07e8ed0..9b26f86119 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer.Common/DefaultRemoteTextLoaderFactory.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer.Common/DefaultRemoteTextLoaderFactory.cs @@ -50,7 +50,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Common _filePath = filePath; } - public override Task LoadTextAndVersionAsync(Workspace workspace, DocumentId documentId, CancellationToken cancellationToken) + public override Task LoadTextAndVersionAsync(Workspace? workspace, DocumentId? documentId, CancellationToken cancellationToken) { TextAndVersion textAndVersion; diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DocumentSnapshotTextLoader.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DocumentSnapshotTextLoader.cs index 33eb0d3099..3f6c4e32cf 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DocumentSnapshotTextLoader.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DocumentSnapshotTextLoader.cs @@ -23,7 +23,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer _documentSnapshot = documentSnapshot; } - public override async Task LoadTextAndVersionAsync(Workspace workspace, DocumentId documentId, CancellationToken cancellationToken) + public override async Task LoadTextAndVersionAsync(Workspace? workspace, DocumentId? documentId, CancellationToken cancellationToken) { var sourceText = await _documentSnapshot.GetTextAsync(); var textAndVersion = TextAndVersion.Create(sourceText, VersionStamp.Default); diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectSystem/DefaultRazorProjectService.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectSystem/DefaultRazorProjectService.cs index e964819f51..1e5777cc34 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectSystem/DefaultRazorProjectService.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectSystem/DefaultRazorProjectService.cs @@ -497,8 +497,8 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.ProjectSystem _fromDocument = fromDocument ?? throw new ArgumentNullException(nameof(fromDocument)); } public override async Task LoadTextAndVersionAsync( - Workspace workspace, - DocumentId documentId, + Workspace? workspace, + DocumentId? documentId, CancellationToken cancellationToken) { var sourceText = await _fromDocument.GetTextAsync(); diff --git a/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/CSharpVirtualDocumentPublisher.cs b/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/CSharpVirtualDocumentPublisher.cs index a8644055b5..23dd2e7513 100644 --- a/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/CSharpVirtualDocumentPublisher.cs +++ b/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/CSharpVirtualDocumentPublisher.cs @@ -158,7 +158,7 @@ namespace Microsoft.VisualStudio.LanguageServerClient.Razor _filePath = filePath; } - public override Task LoadTextAndVersionAsync(CodeAnalysisWorkspace workspace, DocumentId documentId, CancellationToken cancellationToken) + public override Task LoadTextAndVersionAsync(CodeAnalysisWorkspace? workspace, DocumentId? documentId, CancellationToken cancellationToken) { return Task.FromResult(TextAndVersion.Create(_sourceText, VersionStamp.Default, _filePath)); } diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test.Common/CSharpTestLspServer.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test.Common/CSharpTestLspServer.cs index 3483e3e992..f761fb79c8 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test.Common/CSharpTestLspServer.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test.Common/CSharpTestLspServer.cs @@ -129,7 +129,6 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Test.Common public async ValueTask DisposeAsync() { _testWorkspace.Dispose(); - await _languageServer.DisposeAsync(); _clientRpc.Dispose(); _clientMessageFormatter.Dispose(); diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeDocumentReferenceHolderTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeDocumentReferenceHolderTest.cs index 67d93552b4..eeee234b50 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeDocumentReferenceHolderTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeDocumentReferenceHolderTest.cs @@ -193,7 +193,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer } public override Task LoadTextAndVersionAsync( - Workspace workspace, DocumentId documentId, CancellationToken cancellationToken) + Workspace? workspace, DocumentId? documentId, CancellationToken cancellationToken) { return Task.FromResult(TextAndVersion.Create(_sourceText, VersionStamp.Default, _filePath)); } From 0ff8969a52d6cd7e3867843182f4a1c36fcaecea Mon Sep 17 00:00:00 2001 From: Ryan Brandenburg Date: Thu, 20 Oct 2022 10:41:16 -0700 Subject: [PATCH 4/8] ENVDTE --- NuGet.config | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NuGet.config b/NuGet.config index 28fcda6261..1e97e5860d 100644 --- a/NuGet.config +++ b/NuGet.config @@ -127,6 +127,8 @@ + + From 311fde2db89fe13bcabe0b43561991920189437c Mon Sep 17 00:00:00 2001 From: Ryan Brandenburg Date: Thu, 20 Oct 2022 12:04:27 -0700 Subject: [PATCH 5/8] Revert "Upgrade VS versions and react to changes" This reverts commit 34eedeb7ca1c1bec74c636702c8ee6ca59faa688. --- eng/Versions.props | 14 +++++++------- src/Razor/Razor.sln | 3 +-- .../DefaultRemoteTextLoaderFactory.cs | 2 +- .../DocumentSnapshotTextLoader.cs | 2 +- .../ProjectSystem/DefaultRazorProjectService.cs | 4 ++-- .../CSharpVirtualDocumentPublisher.cs | 2 +- .../CSharpTestLspServer.cs | 1 + .../CodeDocumentReferenceHolderTest.cs | 2 +- 8 files changed, 15 insertions(+), 15 deletions(-) diff --git a/eng/Versions.props b/eng/Versions.props index 9eddc25c1a..9b7d6b9394 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -76,9 +76,9 @@ 16.10.57-preview1 1.1.2-beta1.22109.1 - 17.3.32622.426 - 17.4.203-preview - 4.5.0-1.22519.14 + 17.2.32330.158 + 17.3.133-preview + 4.4.0-2.22424.2 17.4.1008-preview 4.4.0-1.final 4.5.0-1.22519.14 @@ -113,14 +113,14 @@ $(MicrosoftVisualStudioShellPackagesVersion) $(MicrosoftVisualStudioShellPackagesVersion) $(MicrosoftVisualStudioShellPackagesVersion) - 17.3.19 + 17.3.3-alpha 16.4.137 $(MicrosoftVisualStudioPackagesVersion) $(MicrosoftVisualStudioPackagesVersion) $(MicrosoftVisualStudioPackagesVersion) - 17.3.44 + 17.3.1-alpha 16.10.0-preview-1-31008-014 - 17.0.58 + 17.0.53 $(Tooling_HtmlEditorPackageVersion) $(Tooling_HtmlEditorPackageVersion) $(Tooling_HtmlEditorPackageVersion) @@ -135,7 +135,7 @@ 0.19.5 $(OmniSharpExtensionsLanguageServerPackageVersion) 1.39.1 - 2.12.27 + 2.12.7-alpha 4.3.0 3.3.3 7.0.0-preview1.22116.1 diff --git a/src/Razor/Razor.sln b/src/Razor/Razor.sln index 49c8a365c0..95547b1f40 100644 --- a/src/Razor/Razor.sln +++ b/src/Razor/Razor.sln @@ -91,7 +91,6 @@ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{4CAC99E0-6ECE-4264-96C3-AF4EEE7BC9D1}" ProjectSection(SolutionItems) = preProject ..\..\.editorconfig = ..\..\.editorconfig - ..\..\eng\Versions.props = ..\..\eng\Versions.props EndProjectSection EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.VisualStudio.Razor.IntegrationTests", "test\Microsoft.VisualStudio.Razor.IntegrationTests\Microsoft.VisualStudio.Razor.IntegrationTests.csproj", "{8CEC0991-259F-4313-B3EF-E398F2B40E61}" @@ -102,7 +101,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RazorDeployment", "src\Razo EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Razor.LanguageServer.Protocol", "src\Microsoft.AspNetCore.Razor.LanguageServer.Protocol\Microsoft.AspNetCore.Razor.LanguageServer.Protocol.csproj", "{093B790B-1283-4EB3-B77E-4F9C4FB2A895}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Razor.Common", "src\Microsoft.AspNetCore.Razor.Common\Microsoft.AspNetCore.Razor.Common.csproj", "{95ED6267-9A02-4B52-9EF5-C0BBE183C8FF}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNetCore.Razor.Common", "src\Microsoft.AspNetCore.Razor.Common\Microsoft.AspNetCore.Razor.Common.csproj", "{95ED6267-9A02-4B52-9EF5-C0BBE183C8FF}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Compiler", "Compiler", "{5B60F564-4AD7-4B70-A887-7D91496799A2}" EndProject diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer.Common/DefaultRemoteTextLoaderFactory.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer.Common/DefaultRemoteTextLoaderFactory.cs index 9b26f86119..71b07e8ed0 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer.Common/DefaultRemoteTextLoaderFactory.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer.Common/DefaultRemoteTextLoaderFactory.cs @@ -50,7 +50,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Common _filePath = filePath; } - public override Task LoadTextAndVersionAsync(Workspace? workspace, DocumentId? documentId, CancellationToken cancellationToken) + public override Task LoadTextAndVersionAsync(Workspace workspace, DocumentId documentId, CancellationToken cancellationToken) { TextAndVersion textAndVersion; diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DocumentSnapshotTextLoader.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DocumentSnapshotTextLoader.cs index 3f6c4e32cf..33eb0d3099 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DocumentSnapshotTextLoader.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DocumentSnapshotTextLoader.cs @@ -23,7 +23,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer _documentSnapshot = documentSnapshot; } - public override async Task LoadTextAndVersionAsync(Workspace? workspace, DocumentId? documentId, CancellationToken cancellationToken) + public override async Task LoadTextAndVersionAsync(Workspace workspace, DocumentId documentId, CancellationToken cancellationToken) { var sourceText = await _documentSnapshot.GetTextAsync(); var textAndVersion = TextAndVersion.Create(sourceText, VersionStamp.Default); diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectSystem/DefaultRazorProjectService.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectSystem/DefaultRazorProjectService.cs index 1e5777cc34..e964819f51 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectSystem/DefaultRazorProjectService.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectSystem/DefaultRazorProjectService.cs @@ -497,8 +497,8 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.ProjectSystem _fromDocument = fromDocument ?? throw new ArgumentNullException(nameof(fromDocument)); } public override async Task LoadTextAndVersionAsync( - Workspace? workspace, - DocumentId? documentId, + Workspace workspace, + DocumentId documentId, CancellationToken cancellationToken) { var sourceText = await _fromDocument.GetTextAsync(); diff --git a/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/CSharpVirtualDocumentPublisher.cs b/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/CSharpVirtualDocumentPublisher.cs index 23dd2e7513..a8644055b5 100644 --- a/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/CSharpVirtualDocumentPublisher.cs +++ b/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/CSharpVirtualDocumentPublisher.cs @@ -158,7 +158,7 @@ namespace Microsoft.VisualStudio.LanguageServerClient.Razor _filePath = filePath; } - public override Task LoadTextAndVersionAsync(CodeAnalysisWorkspace? workspace, DocumentId? documentId, CancellationToken cancellationToken) + public override Task LoadTextAndVersionAsync(CodeAnalysisWorkspace workspace, DocumentId documentId, CancellationToken cancellationToken) { return Task.FromResult(TextAndVersion.Create(_sourceText, VersionStamp.Default, _filePath)); } diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test.Common/CSharpTestLspServer.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test.Common/CSharpTestLspServer.cs index f761fb79c8..3483e3e992 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test.Common/CSharpTestLspServer.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test.Common/CSharpTestLspServer.cs @@ -129,6 +129,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Test.Common public async ValueTask DisposeAsync() { _testWorkspace.Dispose(); + await _languageServer.DisposeAsync(); _clientRpc.Dispose(); _clientMessageFormatter.Dispose(); diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeDocumentReferenceHolderTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeDocumentReferenceHolderTest.cs index eeee234b50..67d93552b4 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeDocumentReferenceHolderTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeDocumentReferenceHolderTest.cs @@ -193,7 +193,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer } public override Task LoadTextAndVersionAsync( - Workspace? workspace, DocumentId? documentId, CancellationToken cancellationToken) + Workspace workspace, DocumentId documentId, CancellationToken cancellationToken) { return Task.FromResult(TextAndVersion.Create(_sourceText, VersionStamp.Default, _filePath)); } From 3fbdfe3b5d42f54a44d708a5d13a47f9126900e3 Mon Sep 17 00:00:00 2001 From: Ryan Brandenburg Date: Thu, 20 Oct 2022 12:04:30 -0700 Subject: [PATCH 6/8] Revert "ENVDTE" This reverts commit 0ff8969a52d6cd7e3867843182f4a1c36fcaecea. --- NuGet.config | 2 -- 1 file changed, 2 deletions(-) diff --git a/NuGet.config b/NuGet.config index 1e97e5860d..28fcda6261 100644 --- a/NuGet.config +++ b/NuGet.config @@ -127,8 +127,6 @@ - - From 7f6f5b2cef03f0c422919b5c7b864e24b0f7f23d Mon Sep 17 00:00:00 2001 From: Ryan Brandenburg Date: Fri, 21 Oct 2022 09:36:06 -0700 Subject: [PATCH 7/8] Reaction --- .../DefaultRemoteTextLoaderFactory.cs | 2 +- .../DocumentSnapshotTextLoader.cs | 2 +- .../DefaultRazorProjectService.cs | 4 +-- .../CSharpVirtualDocumentPublisher.cs | 2 +- .../RazorLanguageServerClient.cs | 36 +++---------------- 5 files changed, 9 insertions(+), 37 deletions(-) diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer.Common/DefaultRemoteTextLoaderFactory.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer.Common/DefaultRemoteTextLoaderFactory.cs index 71b07e8ed0..9b26f86119 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer.Common/DefaultRemoteTextLoaderFactory.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer.Common/DefaultRemoteTextLoaderFactory.cs @@ -50,7 +50,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Common _filePath = filePath; } - public override Task LoadTextAndVersionAsync(Workspace workspace, DocumentId documentId, CancellationToken cancellationToken) + public override Task LoadTextAndVersionAsync(Workspace? workspace, DocumentId? documentId, CancellationToken cancellationToken) { TextAndVersion textAndVersion; diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DocumentSnapshotTextLoader.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DocumentSnapshotTextLoader.cs index 33eb0d3099..3f6c4e32cf 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DocumentSnapshotTextLoader.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DocumentSnapshotTextLoader.cs @@ -23,7 +23,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer _documentSnapshot = documentSnapshot; } - public override async Task LoadTextAndVersionAsync(Workspace workspace, DocumentId documentId, CancellationToken cancellationToken) + public override async Task LoadTextAndVersionAsync(Workspace? workspace, DocumentId? documentId, CancellationToken cancellationToken) { var sourceText = await _documentSnapshot.GetTextAsync(); var textAndVersion = TextAndVersion.Create(sourceText, VersionStamp.Default); diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectSystem/DefaultRazorProjectService.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectSystem/DefaultRazorProjectService.cs index e964819f51..1e5777cc34 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectSystem/DefaultRazorProjectService.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectSystem/DefaultRazorProjectService.cs @@ -497,8 +497,8 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.ProjectSystem _fromDocument = fromDocument ?? throw new ArgumentNullException(nameof(fromDocument)); } public override async Task LoadTextAndVersionAsync( - Workspace workspace, - DocumentId documentId, + Workspace? workspace, + DocumentId? documentId, CancellationToken cancellationToken) { var sourceText = await _fromDocument.GetTextAsync(); diff --git a/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/CSharpVirtualDocumentPublisher.cs b/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/CSharpVirtualDocumentPublisher.cs index a8644055b5..23dd2e7513 100644 --- a/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/CSharpVirtualDocumentPublisher.cs +++ b/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/CSharpVirtualDocumentPublisher.cs @@ -158,7 +158,7 @@ namespace Microsoft.VisualStudio.LanguageServerClient.Razor _filePath = filePath; } - public override Task LoadTextAndVersionAsync(CodeAnalysisWorkspace workspace, DocumentId documentId, CancellationToken cancellationToken) + public override Task LoadTextAndVersionAsync(CodeAnalysisWorkspace? workspace, DocumentId? documentId, CancellationToken cancellationToken) { return Task.FromResult(TextAndVersion.Create(_sourceText, VersionStamp.Default, _filePath)); } diff --git a/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/RazorLanguageServerClient.cs b/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/RazorLanguageServerClient.cs index f29ea317c9..9c0bf7899c 100644 --- a/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/RazorLanguageServerClient.cs +++ b/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/RazorLanguageServerClient.cs @@ -40,9 +40,7 @@ namespace Microsoft.VisualStudio.LanguageServerClient.Razor private readonly RazorLanguageServerLogHubLoggerProviderFactory _logHubLoggerProviderFactory; private readonly LanguageServerFeatureOptions _languageServerFeatureOptions; private readonly VisualStudioHostServicesProvider? _vsHostWorkspaceServicesProvider; - private readonly object _shutdownLock; private RazorLanguageServerWrapper? _server; - private IDisposable? _serverShutdownDisposable; private LogHubLoggerProvider? _loggerProvider; private readonly ProjectSnapshotManagerDispatcher _projectSnapshotManagerDispatcher; @@ -108,7 +106,6 @@ namespace Microsoft.VisualStudio.LanguageServerClient.Razor _logHubLoggerProviderFactory = logHubLoggerProviderFactory; _languageServerFeatureOptions = languageServerFeatureOptions; _vsHostWorkspaceServicesProvider = vsHostWorkspaceServicesProvider; - _shutdownLock = new object(); _projectSnapshotManagerDispatcher = projectSnapshotManagerDispatcher; } @@ -138,7 +135,7 @@ namespace Microsoft.VisualStudio.LanguageServerClient.Razor var (clientStream, serverStream) = FullDuplexStream.CreatePair(); - await EnsureCleanedUpServerAsync(token).ConfigureAwait(false); + await EnsureCleanedUpServerAsync().ConfigureAwait(false); var traceLevel = GetVerbosity(); @@ -176,44 +173,19 @@ namespace Microsoft.VisualStudio.LanguageServerClient.Razor return result; } - private async Task EnsureCleanedUpServerAsync(CancellationToken token) + private async Task EnsureCleanedUpServerAsync() { - const int WaitForShutdownAttempts = 10; - if (_server is null) { // Server was already cleaned up return; } - var attempts = 0; - while (_server is not null && ++attempts < WaitForShutdownAttempts) - { - // Server failed to shutdown, lets wait a little bit and check again. - await Task.Delay(100, token).ConfigureAwait(false); - } - if (_server is not null) { - // Server still hasn't shutdown, attempt an ungraceful shutdown. - ServerShutdown(); - } - } - - private void ServerShutdown() - { - lock (_shutdownLock) - { - if (_server is null) - { - // Already shutdown - return; - } - _projectConfigurationFilePathStore.Changed -= ProjectConfigurationFilePathStore_Changed; - _serverShutdownDisposable?.Dispose(); - _serverShutdownDisposable = null; - _server = null; + // Server still hasn't shutdown, wait for it to shutdown + await _server.WaitForExitAsync().ConfigureAwait(false); } } From 78095bfd723dda2934088e7af6aaa0cd971fbbcd Mon Sep 17 00:00:00 2001 From: Ryan Brandenburg Date: Fri, 21 Oct 2022 10:35:42 -0700 Subject: [PATCH 8/8] Fix lifecycle situations --- .../LspServices.cs | 2 ++ .../RazorLanguageServerWrapper.cs | 22 ++++++++++++++++--- .../RazorLifeCycleManager.cs | 9 ++++---- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/LspServices.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/LspServices.cs index d4243e9c0e..fd8aac3f14 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/LspServices.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/LspServices.cs @@ -12,6 +12,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer; internal class LspServices : ILspServices { private readonly IServiceProvider _serviceProvider; + public bool IsDisposed = false; public LspServices(IServiceCollection serviceCollection) { @@ -57,6 +58,7 @@ internal class LspServices : ILspServices if (_serviceProvider is IDisposable disposable) { disposable.Dispose(); + IsDisposed = true; } } } diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorLanguageServerWrapper.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorLanguageServerWrapper.cs index 1899d02878..dab5e084e3 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorLanguageServerWrapper.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorLanguageServerWrapper.cs @@ -7,6 +7,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Razor.LanguageServer.Common.Extensions; using Microsoft.CodeAnalysis.Razor; using Microsoft.CodeAnalysis.Razor.Workspaces; +using Microsoft.CommonLanguageServerProtocol.Framework; using Microsoft.Extensions.DependencyInjection; using Microsoft.VisualStudio.LanguageServer.Protocol; using Newtonsoft.Json.Serialization; @@ -68,9 +69,24 @@ internal sealed class RazorLanguageServerWrapper : IDisposable public Task WaitForExitAsync() { - var lifeCycleManager = GetRequiredService(); - - return lifeCycleManager.WaitForExit; + var lspServices = _innerServer.GetLspServices(); + if (lspServices is LspServices razorServices) + { + // If the LSP Server is already disposed it means the server has already exited. + if (razorServices.IsDisposed) + { + return Task.CompletedTask; + } + else + { + var lifeCycleManager = razorServices.GetRequiredService(); + return lifeCycleManager.WaitForExit; + } + } + else + { + throw new NotImplementedException($"LspServices should always be of type {nameof(LspServices)}."); + } } internal T GetRequiredService() where T : notnull diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorLifeCycleManager.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorLifeCycleManager.cs index 4b39cf3eca..62c8771fcc 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorLifeCycleManager.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorLifeCycleManager.cs @@ -16,17 +16,18 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer _languageServer = languageServer; } - public async Task ExitAsync() + public Task ExitAsync() { - await _languageServer.ExitAsync(); var services = _languageServer.GetLspServices(); services.Dispose(); _tcs.TrySetResult(0); + + return Task.CompletedTask; } - public async Task ShutdownAsync(string message = "Shutting down") + public Task ShutdownAsync(string message = "Shutting down") { - await _languageServer.ShutdownAsync(message); + return Task.CompletedTask; } public Task WaitForExit => _tcs.Task;