dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
19.13k stars 4.04k forks source link

[LSP] Tests should validate client behavior #51101

Open dibarbet opened 3 years ago

dibarbet commented 3 years ago

Currently, all the LSP unit tests validate the json payload that is expected to be returned from the server, e.g. http://sourceroslyn.io/#Microsoft.CodeAnalysis.LanguageServer.Protocol.UnitTests/Completion/CompletionTests.cs,41

We should instead figure out a way to have the unit tests run through an LSP client to validate the actual behavior when we return our response.

For the test client we'd need to be able to

  1. Tell the client to invoke a particular LSP request at a location in a document (and have the doc sync'd to the server)
  2. Have the client apply the response to the document so we can validate that we got the expected result

We may be able to re-use the VS LSP client library, but we'd need to figure out a way to setup the infrastructure it requires to run (e.g. text views, content types, etc)

dibarbet commented 3 years ago

I was under the erroneous assumption that normal completion tests use editor commit behavior. But it looks like we just 'fake' it ourselves - http://sourceroslyn.io/#Microsoft.CodeAnalysis.EditorFeatures.Test.Utilities/Completion/AbstractCompletionProviderTests.cs,565

I think what should happen at least for these, is to mirror this, but instead of calling completion apis, we call LSP (and fake LSP commit as well). Then we can have two paths and run all the tests through both.