diff --git a/src/LanguageServer/Protocol/Handler/CodeLens/CodeLensResolveHandler.cs b/src/LanguageServer/Protocol/Handler/CodeLens/CodeLensResolveHandler.cs index 0d9a44337ffad..a36bc0f6d91e9 100644 --- a/src/LanguageServer/Protocol/Handler/CodeLens/CodeLensResolveHandler.cs +++ b/src/LanguageServer/Protocol/Handler/CodeLens/CodeLensResolveHandler.cs @@ -9,6 +9,7 @@ using Microsoft.CodeAnalysis.Shared.Extensions; using LSP = Roslyn.LanguageServer.Protocol; using System.Text.Json; +using StreamJsonRpc; namespace Microsoft.CodeAnalysis.LanguageServer.Handler.CodeLens; @@ -48,11 +49,13 @@ public LSP.TextDocumentIdentifier GetTextDocumentIdentifier(LSP.CodeLens request ] }; - // If the request is for an older version of the document, return a request with '- references' + // If the request is for an older version of the document, throw an exception so the client knows to re-query us. if (resolveData.SyntaxVersion != currentDocumentSyntaxVersion.ToString()) { - context.TraceInformation($"Requested syntax version {resolveData.SyntaxVersion} does not match current version {currentDocumentSyntaxVersion}"); - return request; + throw new LocalRpcException($"Resolve version '{resolveData.SyntaxVersion}' does not match current version '{currentDocumentSyntaxVersion}'") + { + ErrorCode = LspErrorCodes.ContentModified + }; } var codeLensMemberFinder = document.GetRequiredLanguageService(); diff --git a/src/LanguageServer/ProtocolUnitTests/CodeLens/CSharpCodeLensTests.cs b/src/LanguageServer/ProtocolUnitTests/CodeLens/CSharpCodeLensTests.cs index 0472b4349df1b..853cd7ef7225e 100644 --- a/src/LanguageServer/ProtocolUnitTests/CodeLens/CSharpCodeLensTests.cs +++ b/src/LanguageServer/ProtocolUnitTests/CodeLens/CSharpCodeLensTests.cs @@ -395,8 +395,8 @@ void UseM() await testLspServer.InsertTextAsync(documentUri, (0, 0, "A")); // Assert that we don't crash when sending an old request to a new document - var firstDocumentResult2 = await testLspServer.ExecuteRequestAsync(LSP.Methods.CodeLensResolveName, firstCodeLens, CancellationToken.None); - Assert.NotNull(firstDocumentResult2?.Command?.Title); + var firstDocumentResult2 = Assert.ThrowsAsync(async () => await testLspServer.ExecuteRequestAsync(LSP.Methods.CodeLensResolveName, firstCodeLens, CancellationToken.None)); + Assert.False(testLspServer.GetServerAccessor().HasShutdownStarted()); } [Theory, CombinatorialData]