OmniSharp / omnisharp-vim

Vim omnicompletion (intellisense) and more for C#
http://www.omnisharp.net
MIT License
1.7k stars 169 forks source link

Code actions not working for certain actions with SDK 6.0.201 #764

Closed christopher-lawrence closed 2 years ago

christopher-lawrence commented 2 years ago

Issue

This might be for the roslyn team, but I'll start here.

Not all code actions seem to be working with the latest SDK (v 6.0.201). By "not working" I mean that there is no pop-up when I run my key binding.

Actions I have found not working:

When I added a global.json file and downgraded to v6.0.101 these actions started to work again.

There are some code actions that do seem to work--have a popup:

Environment

dotnet --info .NET SDK (reflecting any global.json): Version: 6.0.201 Commit: ef49f6213a

Runtime Environment: OS Name: Mac OS X OS Version: 12.2 OS Platform: Darwin RID: osx.12-x64 Base Path: /usr/local/share/dotnet/sdk/6.0.101/

Host (useful for support): Version: 6.0.3 Commit: c24d9a9c91

.NET SDKs installed: 2.1.810 [/usr/local/share/dotnet/sdk] 3.1.201 [/usr/local/share/dotnet/sdk] 3.1.302 [/usr/local/share/dotnet/sdk] 5.0.100 [/usr/local/share/dotnet/sdk] 5.0.201 [/usr/local/share/dotnet/sdk] 5.0.401 [/usr/local/share/dotnet/sdk] 6.0.101 [/usr/local/share/dotnet/sdk] 6.0.201 [/usr/local/share/dotnet/sdk]

.NET runtimes installed: Microsoft.AspNetCore.All 2.1.22 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.1.22 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.3 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.6 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.4 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.10 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.1 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.3 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.NETCore.App 2.1.22 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.3 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.6 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.4 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.10 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.1 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.3 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

To install additional .NET runtimes or SDKs: https://aka.ms/dotnet-download

nickspoons commented 2 years ago

It does sound like an OmniSharp-roslyn issue.

Check your log for server errors: :OmniSharpOpenLog

christopher-lawrence commented 2 years ago

This failure message appears in the log after trying to bring up the code actions prompt.

[fail]: OmniSharp.Stdio.Host
   13         ************  Response (142.3033ms) ************
   14 {
   15   "Request_seq": 1164,
   16   "Command": "/v2/getcodeactions",
   17   "Running": true,
   18   "Success": false,
   19   "Message": "\"System.Reflection.ReflectionTypeLoadException: Exception of type 'System.Reflection.ReflectionTypeLoadException' was thrown.\\nCould not load file or assembly 'Microsoft.CodeAnalysis, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies.\\n  at (wrapper man      aged-to-native) System.Reflection.Assembly.GetTypes(System.Reflection.Assembly,bool)\\n  at System.Reflection.Assembly.GetTypes () [0x00000] in <36514b14425c4337b446653c547aa9c3>:0 \\n  at System.Reflection.Assembly+<get_DefinedTypes>d__127.MoveNext () [0x0001e] in <36514b14425c4337b446653c547aa9c3>:0 \\n  at Sys      tem.Linq.Enumerable+SelectManySingleSelectorIterator`2[TSource,TResult].MoveNext () [0x0006f] in <14c1495deda74532849f8ec10b438611>:0 \\n  at System.Linq.Enumerable+WhereSelectEnumerableIterator`2[TSource,TResult].MoveNext () [0x00059] in <14c1495deda74532849f8ec10b438611>:0 \\n  at System.Linq.Enumerable+WhereEn      umerableIterator`1[TSource].MoveNext () [0x0004e] in <14c1495deda74532849f8ec10b438611>:0 \\n  at System.Collections.Generic.LargeArrayBuilder`1[T].AddRange (System.Collections.Generic.IEnumerable`1[T] items) [0x0003d] in <14c1495deda74532849f8ec10b438611>:0 \\n  at System.Collections.Generic.SparseArrayBuilder`1      [T].AddRange (System.Collections.Generic.IEnumerable`1[T] items) [0x00000] in <14c1495deda74532849f8ec10b438611>:0 \\n  at System.Collections.Generic.SparseArrayBuilder`1[T].ReserveOrAdd (System.Collections.Generic.IEnumerable`1[T] items) [0x00017] in <14c1495deda74532849f8ec10b438611>:0 \\n  at System.Linq.Enume      rable+Concat2Iterator`1[TSource].ToArray () [0x00015] in <14c1495deda74532849f8ec10b438611>:0 \\n  at System.Linq.Enumerable.ToArray[TSource] (System.Collections.Generic.IEnumerable`1[T] source) [0x0001f] in <14c1495deda74532849f8ec10b438611>:0 \\n  at System.Collections.Immutable.ImmutableArray.CreateRange[T] (S      ystem.Collections.Generic.IEnumerable`1[T] items) [0x0004d] in <be358f84962848a48784e4a9d001abe1>:0 \\n  at System.Collections.Immutable.ImmutableArray.ToImmutableArray[TSource] (System.Collections.Generic.IEnumerable`1[T] items) [0x0000f] in <be358f84962848a48784e4a9d001abe1>:0 \\n  at OmniSharp.Roslyn.CSharp.Se      rvices.Refactoring.V2.CachingCodeFixProviderForProjects.LoadFrom (Microsoft.CodeAnalysis.Project project) [0x000d5] in <7833e4dfb11c41969fc8bb341c494975>:0 \\n  at OmniSharp.Roslyn.CSharp.Services.Refactoring.V2.CachingCodeFixProviderForProjects.GetAllCodeFixesForProject (Microsoft.CodeAnalysis.ProjectId projectI      d) [0x00045] in <7833e4dfb11c41969fc8bb341c494975>:0 \\n  at OmniSharp.Roslyn.CSharp.Services.Refactoring.V2.BaseCodeActionService`2[TRequest,TResponse].GetSortedCodeFixProviders (Microsoft.CodeAnalysis.Document document) [0x00011] in <7833e4dfb11c41969fc8bb341c494975>:0 \\n  at OmniSharp.Roslyn.CSharp.Services.R      efactoring.V2.BaseCodeActionService`2[TRequest,TResponse].AppendFixesAsync (Microsoft.CodeAnalysis.Document document, Microsoft.CodeAnalysis.Text.TextSpan span, System.Collections.Generic.IEnumerable`1[T] diagnostics, System.Collections.Generic.List`1[T] codeActions) [0x0003e] in <7833e4dfb11c41969fc8bb341c494975      >:0 \\n  at OmniSharp.Roslyn.CSharp.Services.Refactoring.V2.BaseCodeActionService`2[TRequest,TResponse].CollectCodeFixesActions (Microsoft.CodeAnalysis.Document document, Microsoft.CodeAnalysis.Text.TextSpan span, System.Collections.Generic.List`1[T] codeActions) [0x001c1] in <7833e4dfb11c41969fc8bb341c494975>:0       \\n  at OmniSharp.Roslyn.CSharp.Services.Refactoring.V2.BaseCodeActionService`2[TRequest,TResponse].GetAvailableCodeActions (OmniSharp.Models.V2.CodeActions.ICodeActionRequest request) [0x001a4] in <7833e4dfb11c41969fc8bb341c494975>:0 \\n  at OmniSharp.Roslyn.CSharp.Services.Refactoring.V2.GetCodeActionsService.H      andle (OmniSharp.Models.V2.CodeActions.GetCodeActionsRequest request) [0x0006b] in <7833e4dfb11c41969fc8bb341c494975>:0 \\n  at OmniSharp.Endpoint.EndpointHandler`2[TRequest,TResponse].GetFirstNotEmptyResponseFromHandlers (OmniSharp.Endpoint.Exports.ExportHandler`2[TRequest,TResponse][] handlers, TRequest request      ) [0x00099] in <5f96298298f74346ad96eb79547a94e4>:0 \\n  at OmniSharp.Endpoint.EndpointHandler`2[TRequest,TResponse].HandleRequestForLanguage (System.String language, TRequest request, OmniSharp.Protocol.RequestPacket packet) [0x00163] in <5f96298298f74346ad96eb79547a94e4>:0 \\n  at OmniSharp.Endpoint.EndpointHan      dler`2[TRequest,TResponse].Process (OmniSharp.Protocol.RequestPacket packet, OmniSharp.Endpoint.LanguageModel model, Newtonsoft.Json.Linq.JToken requestObject) [0x0024b] in <5f96298298f74346ad96eb79547a94e4>:0 \\n  at OmniSharp.Stdio.Host.HandleRequest (System.String json, Microsoft.Extensions.Logging.ILogger log      ger) [0x000f3] in <25aad3e40a2c409a9df3868c7895a306>:0 \\nSystem.TypeLoadException: Could not load file or assembly 'Microsoft.CodeAnalysis, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies.\"",
   20   "Body": null,
   21   "Seq": 131,
   22   "Type": "response"
   23 }
nickspoons commented 2 years ago

Ok that's definitely on the server side then. I was wondering if there were warnings or failures earlier on about incompatible SDK versions.

christopher-lawrence commented 2 years ago

The problem was due to my version of Roslyn being out of date. After running :OmniSharpInstall to get the latest version code actions began working as expected.

I wonder if there should be a check for a new version of Roslyn and prompt the user similar to when it is found to not be installed?