Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throw when there is a syntax version mismatch in codelens #73902

Merged
merged 2 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading