OmniSharp / omnisharp-vim

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

Autocompletion of external packges does not work #686

Closed danrot closed 3 years ago

danrot commented 3 years ago

Hi there!

I have installed omnisharp-vim on Mac OSX in Neovim. The autocomplete feature only seems to work with the .NET framework itself, but I e.g. don't get any autocompletion for Microsoft Entity Framework Core classes. I've been hinted to have a look at the log using the :OmniSharpOpenLog command in vim, which result in this log (including debug messages).

The two lines that especially got my attention are the following:

[warn]: OmniSharp.MSBuild.ProjectManager
        Failed to load project file '/Users/roda/Documents/Teaching/FTB-IDI-BB/anwendungsintegration-und-sicherheit/seminars/04-provide-rest/04-provide-rest.csproj'.
All projects loaded
[fail]: OmniSharp.MSBuild.ProjectManager
        Attempted to update project that is not loaded: /Users/roda/Documents/Teaching/FTB-IDI-BB/anwendungsintegration-und-sicherheit/seminars/04-provide-rest/04-provide-rest.csproj

For some reason it seems the csproj file could not be loaded, so it in turn makes sense, that the auto completion for the added packages does not work. But I don't know why that does not work, the close lines in the log do not help me (but I don't know the project very well).

I am also showing the csproj file here, maybe that gives some idea on what is going south:

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>net5.0</TargetFramework>
    <RootNamespace>_04_provide_rest</RootNamespace>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.3">
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.3" />
    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="5.0.2" />
    <PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="5.0.0-alpha.2" />
    <PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3" />
    <PackageReference Include="System.ValueTuple" Version="4.5.0" />
  </ItemGroup>

</Project>
filipw commented 3 years ago

Can you share the code that reproduces this? There are unfortunately no obvious problems visible in the logs, other than the fact that the project failed to load.

thanks

danrot commented 3 years ago

I have zipped everything together (that's why it is so big, but I was afraid to remove stuff, since it might cause the error). Happens to more or less all of my projects... I create them using the dotnet binary (dotnet new webapi, dotnet add package ...).

04-provide-rest.zip

filipw commented 3 years ago

I just downloaded your solution and it works fine for me. It had some errors related to Microsoft.CodeAnalysis.Analyzers 3.0.0 but after deleting the obj and bin folders, rebuilding with dotnet build and restarting OmniSharp, everything loads fine. Can you retry with these steps?

danrot commented 3 years ago

Just followed these steps, and it is still not working for me... What exactly have you tested? I have e.g. issues with the modelBuilderin the example's CompanyContext. Made a recording of the screen, to avoid any misunderstandings: recording

Note how it can complete the modelBuilder variable, but it does not suggest anything for the modelBuilder. As you can see in the recording the steps you have mentioned don't work either.

filipw commented 3 years ago

This is a server repo, so I only tested OmniSharp server - and it works fine in this case. I am not sure what the VIM extension does in this case, but looks like the problem is there then.

filipw commented 3 years ago

I have transferred it here because to me it looks like a problem with the VIM extension, not the server issue. @nickspoons is opening an individual file supposed to be supported? or are you supposed to start from sln/folder?

danrot commented 3 years ago

Ok, but just to be sure, how can I test if just the server is working on my machine?

And from my understanding I am opening the folder with the sln file, how else should I be handling this?

nickspoons commented 3 years ago

@nickspoons is opening an individual file supposed to be supported? or are you supposed to start from sln/folder?

@filipw Yes, this is how OmniSharp-vim works: you open a .cs file, and OmniSharp-vim looks in parent directories for the .sln or .csproj, and launches the server pointing at the .sln/.csproj.

In this case the solution is being found and started correctly, as can be seen from the 04_provide_rest.sln displayed in the vim statusline in the demo, and the launch command at the start of the log: /Users/roda/.cache/omnisharp-vim/omnisharp-roslyn/run -s /Users/roda/Documents/Teaching/FTB-IDI-BB/anwendungsintegration-und-sicherheit/seminars/04-provide-rest/04-provide-rest.sln -l debug -e utf-8

danrot commented 3 years ago

Is there an easy way for me to test if the server itself is working? I.e. without the vim plugin?

nickspoons commented 3 years ago

Just by running /Users/roda/.cache/omnisharp-vim/omnisharp-roslyn/run -s /Users/roda/Documents/Teaching/FTB-IDI-BB/anwendungsintegration-und-sicherheit/seminars/04-provide-rest/04-provide-rest.sln -l debug -e utf-8 on the command line. But to test actual interaction, you need a client. Testing in vscode would be a useful comparison.

nickspoons commented 3 years ago

@filipw I don't think this is a client issue. I tried just starting the server from the command line and got the same errors as OP. I know you have been working on improvements to the handling of missing SDK/framework errors so I tried pulling the latest OmniSharp-roslyn from git and building (with the latest Visual Studio), and using that server, I can now run the project (on Windows)

asciicast

I suspect the problem has to do with SDK/.NETFramework requirements, but I can't quite work it out.

nickspoons commented 3 years ago

Oh, I just realised that in the process of getting OmniSharp-roslyn to build, I had to install the v5.0.2 SDK and upgrade Visual Studio from 16.7 to 16.9. One of those has helped because I now can run the project with the latest OmniSharp-roslyn release (not just my build of the server).

nickspoons commented 3 years ago

After installing the latest dotnet SDK (v5.0.200) on archlinux with dotnet-install --install-dir /usr/share/dotnet -channel Current using dotnet-install, I can now also run the project there.

danrot commented 3 years ago

I think that was indeed the issue... I've installed dotnet using homebrew. I chose the dotnet package, but that seems to be outdated... Installed the dotnet-sdk package instead, and restarted the server using :OmniSharpRestartServer once more, not it is working 🙂 Thanks for the help!