Closed marcinjahn closed 1 month ago
Alright, LSP does work, it was an issue with .NET SDK on my side. However.. I do not get the "... initialized" notification anymore once the LSP is ready. Is it just me?
The issue seems to be related with missing dotnet restore
operation. It looks like the plugin should handle such cases (https://github.com/seblj/roslyn.nvim/blob/main/lua/roslyn/init.lua#L40), but in my case it didn't.
When some packages are not installed, the plugin does not display the "Initialized" notification, and it does not prompt to do dotnet restore
neither.
I see this in the logs:
[WARN][2024-07-16 15:43:58] ...m/lsp/client.lua:1023 "server_request: no handler found for" "workspace/_roslyn_projectNeedsRestore"
I still think that 5a639c31e4baa3435e6e480e192b9b739f5dc541 broke something.
Pretty sure that the commit didn't break anything just looking at the diff🤔 The handler that it warns about not being implemented has never been implemented in the plugin, but it should probably be implemented (I just didn't know about it). I'll have a look at how vscode is implementing it when I have time
Do you have a way to easily get the warning of the missing handler? Preferably with creating a new project or something. Or maybe if you have a repo I could try with? I was starting to look into this, and it was a bit difficult to implement the handler without testing anything
Here's how you can reproduce it:
mkdir restore-example
cd restore-example
dotnet new console
dotnet new sln
dotnet sln add .
nvim restore-example.csproj
Then, add any nuget package to the csproj, like:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>restore_example</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Castle.Core" Version="5.1.1" />
</ItemGroup>
</Project>
Save and exit.
Launch nvim and open Program.cs
to start initializing the server. You should see the "Initializing..." message, but not the "Initialized" one.
Also, you should see logs like:
[WARN][2024-07-21 15:01:25] ...lsp/handlers.lua:625 "[LanguageServerProjectSystem] Project /home/mnj/tmp/restore-example/restore-example.csproj has unresolved dependencies\n Castle.Core-5.1.1" [WARN][2024-07-21 15:01:26] ...m/lsp/client.lua:1023 "server_request: no handler found for" "workspace/_roslynprojectNeedsRestore" [ERROR][2024-07-21 15:01:26] ...lsp/handlers.lua:623 "[LanguageServerHost] StreamJsonRpc.RemoteMethodNotFoundException: MethodNotFound\n at StreamJsonRpc.JsonRpc.InvokeCoreAsync[TResult](RequestId id, String targetName, IReadOnlyList
1 arguments, IReadOnlyList
1 positionalArgumentDeclaredTypes, IReadOnlyDictionary`2 namedArgumentDeclaredTypes, CancellationToken cancellationToken, Boolean isParameterObject)\n at Microsoft.CodeAnalysis.LanguageServer.Handler.ClientLanguageServerManager.SendRequestAsync[TParams](String methodName, TParams params, CancellationToken cancellationToken) in //src/LanguageServer/Protocol/Handler/LanguageServerNotificationManager.cs:line 33\n at Microsoft.CodeAnalysis.LanguageServer.HostWorkspace.ProjectDependencyHelper.RestoreProjectsAsync(ImmutableArray1 projectPaths, CancellationToken cancellationToken) in /_/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/ProjectDependencyHelper.cs:line 134\n at Microsoft.CodeAnalysis.LanguageServer.HostWorkspace.LanguageServerProjectSystem.LoadOrReloadProjectsAsync(ImmutableSegmentedList
1 projectPathsToLoadOrReload, CancellationToken cancellationToken) in //src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/LanguageServerProjectSystem.cs:line 191\n at Microsoft.CodeAnalysis.LanguageServer.HostWorkspace.LanguageServerProjectSystem.LoadOrReloadProjectsAsync(ImmutableSegmentedList`1 projectPathsToLoadOrReload, CancellationToken cancellationToken) in //src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/LanguageServerProjectSystem.cs:line 196\n at Roslyn.Utilities.AsyncBatchingWorkQueue1.<>c__DisplayClass2_0.<<Convert>b__0>d.MoveNext() in /_/src/Workspaces/Core/Portable/Shared/Utilities/AsyncBatchingWorkQueue
1.cs:line 38\n--- End of stack trace from previous location ---\n at Roslyn.Utilities.ValueTaskExtensions.VerifyCompleted[T](ValueTask1 task, String message) in /_/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Utilities/ValueTaskExtensions.cs:line 24\n at Roslyn.Utilities.AsyncBatchingWorkQueue
2.ProcessNextBatchAsync() in /_/src/Workspaces/Core/Portable/Shared/Utilities/AsyncBatchingWorkQueue2.cs:line 269\n at Roslyn.Utilities.AsyncBatchingWorkQueue
2.g__ContinueAfterDelayAsync|151(Task lastTask) in //src/Workspaces/Core/Portable/Shared/Utilities/AsyncBatchingWorkQueue 2.cs:line 216\n at Roslyn.Utilities.AsyncBatchingWorkQueue
2.WaitUntilCurrentBatchCompletesAsync() in //src/Workspaces/Core/Portable/Shared/Utilities/AsyncBatchingWorkQueue`2.cs:line 233\n at Microsoft.CodeAnalysis.LanguageServer.HostWorkspace.LanguageServerProjectSystem.OpenSolutionAsync(String solutionFilePath) in //src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/LanguageServerProjectSystem.cs:line 122\n at Microsoft.CodeAnalysis.LanguageServer.HostWorkspace.LanguageServerProjectSystem.OpenSolutionAsync(String solutionFilePath) in //src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/LanguageServerProjectSystem.cs:line 123\n at Microsoft.CommonLanguageServerProtocol.Framework.QueueItem`3.StartRequestAsync(TRequestContext context, IMethodHandler handler, CancellationToken cancellationToken) in //src/LanguageServer/Microsoft.CommonLanguageServerProtocol.Framework/QueueItem.cs:line 148"
Okay I finally got around to implementing this in the latest commit. I think it should work as expected now. It maybe looks a bit weird with the messages printed out to vim.notify. They are coming in after it is initialized, and all of the messages comes at once instead of as it progresses. I also am not 100% sure of the order of the messages🤷♂️ However, I think it is better to print something there as it is doing something behind the scenes, and we should let the user know that it was able to restore the projects
I will close this issue as I believe this is now fixed, but let me know if this doesn't fix your issue
I think 5a639c31e4baa3435e6e480e192b9b739f5dc541 broke the plugin. I get the "Initializing Roslyn for ...sln" notification, but I never get the "... initialized" one. LSP functionalities do not work.