From 51fbefedeb2512a994e8a5e211402f1cf11801ee Mon Sep 17 00:00:00 2001 From: Adam Ratzman Date: Mon, 10 Apr 2023 12:30:24 -0700 Subject: [PATCH] Return synchronized if seen document version > required document version for resolve action endpoint --- .../DefaultLSPDocumentSynchronizer.cs | 18 ++++++++++++++---- .../LSPDocumentSynchronizer.cs | 3 ++- ...ltRazorLanguageServerCustomMessageTarget.cs | 4 +++- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/Razor/src/Microsoft.VisualStudio.LanguageServer.ContainedLanguage/DefaultLSPDocumentSynchronizer.cs b/src/Razor/src/Microsoft.VisualStudio.LanguageServer.ContainedLanguage/DefaultLSPDocumentSynchronizer.cs index 7a10b7199e..b07e872cf0 100644 --- a/src/Razor/src/Microsoft.VisualStudio.LanguageServer.ContainedLanguage/DefaultLSPDocumentSynchronizer.cs +++ b/src/Razor/src/Microsoft.VisualStudio.LanguageServer.ContainedLanguage/DefaultLSPDocumentSynchronizer.cs @@ -58,13 +58,15 @@ internal class DefaultLSPDocumentSynchronizer : LSPDocumentSynchronizer requiredHostDocumentVersion, hostDocumentUri, rejectOnNewerParallelRequest: true, - cancellationToken); + cancellationToken, + isResolveCodeActionSync: false); public override async Task> TrySynchronizeVirtualDocumentAsync( int requiredHostDocumentVersion, Uri hostDocumentUri, bool rejectOnNewerParallelRequest, - CancellationToken cancellationToken) + CancellationToken cancellationToken, + bool isResolveCodeActionSync = false) where TVirtualDocumentSnapshot : class { if (hostDocumentUri is null) @@ -90,7 +92,7 @@ internal class DefaultLSPDocumentSynchronizer : LSPDocumentSynchronizer } // Currently tracked synchronizing context is not sufficient, need to update a new one. - onSynchronizedTask = documentContext.GetSynchronizationTaskAsync(requiredHostDocumentVersion, rejectOnNewerParallelRequest, cancellationToken); + onSynchronizedTask = documentContext.GetSynchronizationTaskAsync(requiredHostDocumentVersion, rejectOnNewerParallelRequest, cancellationToken, isResolveCodeActionSync); } var onSynchronizedResult = await onSynchronizedTask.ConfigureAwait(false); @@ -279,7 +281,7 @@ internal class DefaultLSPDocumentSynchronizer : LSPDocumentSynchronizer } } - public Task GetSynchronizationTaskAsync(int requiredHostDocumentVersion, bool rejectOnNewerParallelRequest, CancellationToken cancellationToken) + public Task GetSynchronizationTaskAsync(int requiredHostDocumentVersion, bool rejectOnNewerParallelRequest, CancellationToken cancellationToken, bool isResolveCodeActionSync = false) { // Cancel any out-of-date existing synchronizing contexts. @@ -295,6 +297,14 @@ internal class DefaultLSPDocumentSynchronizer : LSPDocumentSynchronizer } } + // TODO this is a partial workaround to fix prefix completion by avoiding sync (which times out during resolve endpoint) if we are currently at a higher version value + // this does not fix postfix completion and should be superceded by eventual synchronization fix + + if (isResolveCodeActionSync && SeenHostDocumentVersion >= requiredHostDocumentVersion) + { + return Task.FromResult(true); + } + var synchronizingContext = new DocumentSynchronizingContext(requiredHostDocumentVersion, rejectOnNewerParallelRequest, _synchronizingTimeout, cancellationToken); _synchronizingContexts.Add(synchronizingContext); return synchronizingContext.OnSynchronizedAsync; diff --git a/src/Razor/src/Microsoft.VisualStudio.LanguageServer.ContainedLanguage/LSPDocumentSynchronizer.cs b/src/Razor/src/Microsoft.VisualStudio.LanguageServer.ContainedLanguage/LSPDocumentSynchronizer.cs index 763d99c608..661c406813 100644 --- a/src/Razor/src/Microsoft.VisualStudio.LanguageServer.ContainedLanguage/LSPDocumentSynchronizer.cs +++ b/src/Razor/src/Microsoft.VisualStudio.LanguageServer.ContainedLanguage/LSPDocumentSynchronizer.cs @@ -20,7 +20,8 @@ internal abstract class LSPDocumentSynchronizer : LSPDocumentChangeListener int requiredHostDocumentVersion, Uri hostDocumentUri, bool rejectOnNewerParallelRequest, - CancellationToken cancellationToken) + CancellationToken cancellationToken, + bool isResolveCodeActionEndpoint = false) where TVirtualDocumentSnapshot : VirtualDocumentSnapshot; [Obsolete] diff --git a/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/DefaultRazorLanguageServerCustomMessageTarget.cs b/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/DefaultRazorLanguageServerCustomMessageTarget.cs index c2c78bd424..79abb95637 100644 --- a/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/DefaultRazorLanguageServerCustomMessageTarget.cs +++ b/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/DefaultRazorLanguageServerCustomMessageTarget.cs @@ -1015,7 +1015,9 @@ internal class DefaultRazorLanguageServerCustomMessageTarget : RazorLanguageServ (synchronized, virtualDocumentSnapshot) = await _documentSynchronizer.TrySynchronizeVirtualDocumentAsync( request.HostDocument.Version, request.HostDocument.Uri, - cancellationToken); + rejectOnNewerParallelRequest: true, + cancellationToken, + isResolveCodeActionEndpoint: true); languageServerName = RazorLSPConstants.RazorCSharpLanguageServerName; } else