Skip to content

Commit

Permalink
Merge pull request #73902 from dibarbet/code_lens_throw
Browse files Browse the repository at this point in the history
Throw when there is a syntax version mismatch in codelens
  • Loading branch information
dibarbet authored Jun 13, 2024
2 parents c42c063 + e227111 commit 0447e0c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<ICodeLensMemberFinder>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.CodeLens, LSP.CodeLens>(LSP.Methods.CodeLensResolveName, firstCodeLens, CancellationToken.None);
Assert.NotNull(firstDocumentResult2?.Command?.Title);
var firstDocumentResult2 = Assert.ThrowsAsync<StreamJsonRpc.RemoteInvocationException>(async () => await testLspServer.ExecuteRequestAsync<LSP.CodeLens, LSP.CodeLens>(LSP.Methods.CodeLensResolveName, firstCodeLens, CancellationToken.None));
Assert.False(testLspServer.GetServerAccessor().HasShutdownStarted());
}

[Theory, CombinatorialData]
Expand Down

0 comments on commit 0447e0c

Please sign in to comment.