dotnet / vscode-csharp

Official C# support for Visual Studio Code
MIT License
2.83k stars 654 forks source link

Project information is lost after language server restart with C# devkit #5882

Open dibarbet opened 1 year ago

dibarbet commented 1 year ago

When using C# devkit, invoking the command '.NET Restart Language Server' will cause the project information to get lost.

Details

When the C# extension's server restarts, it is able to reconnect to the brokered service bridge created by devkit. However on the devkit side, the project system doesn't realize that we've restarted and that it needs to re-send all the project information.

One potential fix here is for devkit to listen to the availability changed event of the C# project brokered service. When it detects that the service disappears, then comes back it would know we've lost the project info and that it needs to re-send.

Alternatively we could add some other channel to let devkit know that we need new project information.

Workaround

When using devkit, don't use the '.NET Restart Language Server' command, instead use Reload Window to cause both devkit and the C# extension to restart.

cc @tmeschter

jasonmalinowski commented 11 months ago

One potential fix here is for devkit to listen to the availability changed event of the C# project brokered service. When it detects that the service disappears, then comes back it would know we've lost the project info and that it needs to re-send.

This seems reasonable to me unless there's some other reason not to do it this way.

nev-21 commented 1 month ago

I have a problem maybe realated with this issue.

When i use ".NET Restart Language Server", the lint is not working anymore for c# files. So i have to do a Reload Window or Developer: Restart Extension Host

ajwells128 commented 1 month ago

My bug report (https://github.com/microsoft/vscode-dotnettools/issues/897) got closed as a dupe of this one. I was reporting two issues, though, and I'm not certain they're both captured here.

The primary issue I encountered is that the Language Server wasn't tracking new files -- they were instead being tracked under "workspace MiscellaneousFiles".

The secondary issue I encountered is this one, that restarting the Language Server lost project information.

Will fixing the lost project information also address the first issue, that new files are being treated as Miscellaneous rather than as source code for the project in which they exist? If not, it seems that should be written as a separate issue.

nev-21 commented 1 month ago

Yeah, I have tested disabling "C# DevKit", and everything works after run ".NET Restart Language Server"

nev-21 commented 1 month ago

I've found a workaround.

I have a simple solution with 2 projects (1 ConsoleApp, and 1 Source Generator). After "dotnet build" the files are generated, then I make a ".NET Restart Lang...." in order generated files are recognized, but the lint crashes (I think many things stop working).

So the workaround... You have to manually: disable then enable c#DevKit Extension, once each time you open vscode or reload window. Then you work normally. In my case I run dotnet build and make a ".NET Restart Lang...." and the lint works.

This bug is weird.