OmniSharp / omnisharp-emacs

Troll coworkers - use Emacs at work for csharp!
GNU General Public License v3.0
514 stars 94 forks source link

No autocomplete #433

Closed ibeckermayer closed 6 years ago

ibeckermayer commented 6 years ago

I am currently unable to get autocomplete to work for csharp layer in spacemacs.

I have the following in my dotspacemacs/user-config:

(global-company-mode)
  (eval-after-load
      'company
    '(add-to-list 'company-backends 'company-omnisharp))
  (add-hook 'csharp-mode-hook #'company-mode)

yet when I go into a .cs file, company autocomplete does not show up at all. The only autocomplete I can get is when I use comments, and then it does not use my default company behavior.

Here is an example of my company-diag output:

Emacs 25.3.2 (x86_64-pc-linux-gnu) of 2017-09-12 on lcy01-32
Company 0.9.6

company-backends: ((company-omnisharp :with company-yasnippet)
 (company-dabbrev-code company-gtags company-etags company-keywords :with company-yasnippet)
 (company-files :with company-yasnippet)
 (company-dabbrev :with company-yasnippet))

Used backend: (company-omnisharp :with company-yasnippet)

Major mode: csharp-mode
Prefix: #("Syst" 0 1
  (fontified t)
  1 2
  (fontified t)
  2 3
  (fontified t)
  3 4
  (fontified t))

Completions: none

Here's an example of the company-diag output on a vhdl file where it is working properly

Emacs 25.3.2 (x86_64-pc-linux-gnu) of 2017-09-12 on lcy01-32
Company 0.9.6

company-backends: (company-bbdb company-nxml company-css company-eclim company-semantic company-clang company-xcode company-cmake company-capf company-files
          (company-dabbrev-code company-gtags company-etags company-keywords)
          company-oddmuse company-dabbrev)

Used backend: (company-dabbrev-code company-gtags company-etags company-keywords)

Major mode: vhdl-mode
Prefix: #("ou" 0 2
  (fontified t))

Completions:
  "output"
  "outp_and16"
  "output"
  "outp_and"
  "output"
  "outp_and"
  "outp_and16"
razzmatazz commented 6 years ago

which version of spacemacs are you using? 0.200.x or 0.300.x (develop) ?

the develop/0.300.x version has layer with updated settings.. 0.200.x has an outdated layer

ibeckermayer commented 6 years ago

I see! Yes, I've been using 0.200.x. I'll have to confirm that this fixes it once I get to my work computer. If it does, I'll also PR a change in the spacemacs section of the README, since this was a big headache for me yesterday.

ibeckermayer commented 6 years ago

@razzmatazz Unfortunately, despite upgrading to 0.300.x the issue persists exactly as before. Anything else I could try? It seems as if it's specific to the company-omnisharp :with company-yasnippet backend, since it's working in all my other files that don't use this backend. Is there any other information I should give you to help identify the issue?

razzmatazz commented 6 years ago

@ibeckermayer not sure why do you need this (global-company-mode .. thing? Could you try removing it? I.e. things should work out of the box on spacemacs.

Also, do you get something in *omnisharp-debug* buffer? Does the server start properly?

ibeckermayer commented 6 years ago

@razzmatazz I took out the global company mode thing, but the same issue remains. I don't have an *omnisharp-debug* buffer but I do have an *ominisharp-log* buffer whose output is below:

[17:05:45] Starting OmniSharpServer using project folder/solution file: /home/ibeckermayer/Documents/EZTest/EZTest.sln
[17:05:45] Using server binary on /home/ibeckermayer/bin/omnisharp-linux/omnisharp/OmniSharp.exe
[17:05:45] INFORMATION: OmniSharp.Stdio.Host, Starting OmniSharp on ubuntu 16.4 (x64)
[17:05:45] INFORMATION: OmniSharp.MSBuild.Discovery.MSBuildLocator, Located 2 MSBuild instance(s)
            1: Mono 15.0 - "/usr/lib/mono/msbuild/15.0/bin"
            2: StandAlone 15.0 - "/home/ibeckermayer/bin/omnisharp-linux/omnisharp/msbuild/15.0/Bin"
[17:05:45] INFORMATION: OmniSharp.MSBuild.Discovery.MSBuildLocator, Registered MSBuild instance: Mono 15.0 - "/usr/lib/mono/msbuild/15.0/bin"
            CscToolPath = /home/ibeckermayer/bin/omnisharp-linux/omnisharp/msbuild/15.0/Bin/Roslyn
            CscToolExe = csc.exe
[17:05:46] INFORMATION: OmniSharp.Cake.CakeProjectSystem, Detecting Cake files in '/home/ibeckermayer/Documents/EZTest'.
[17:05:46] INFORMATION: OmniSharp.Cake.CakeProjectSystem, Could not find any Cake files
[17:05:46] INFORMATION: OmniSharp.DotNet.DotNetProjectSystem, Initializing in /home/ibeckermayer/Documents/EZTest
[17:05:46] INFORMATION: OmniSharp.DotNet.DotNetProjectSystem, Auto package restore: False
[17:05:46] INFORMATION: OmniSharp.DotNet.DotNetProjectSystem, Update workspace context
[17:05:46] INFORMATION: OmniSharp.DotNet.DotNetProjectSystem, Resolving projects references
[17:05:46] INFORMATION: OmniSharp.MSBuild.ProjectSystem, Detecting projects in '/home/ibeckermayer/Documents/EZTest/EZTest.sln'.
[17:05:46] INFORMATION: OmniSharp.Script.ScriptProjectSystem, Detecting CSX files in '/home/ibeckermayer/Documents/EZTest'.
[17:05:46] INFORMATION: OmniSharp.Script.ScriptProjectSystem, Could not find any CSX files
[17:05:46] INFORMATION: OmniSharp.Stdio.Host, Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpWorkspaceOptionsProvider
[17:05:46] INFORMATION: OmniSharp.Stdio.Host, Configuration finished.
[17:05:46] INFORMATION: OmniSharp.Stdio.Host, Omnisharp server running using Stdio at location '/home/ibeckermayer/Documents/EZTest' on host -1.
[17:05:48] <-- 1 /typelookup: ((Type) (Documentation) (StructuredDocumentation))
[17:05:48] <-- 2 /autocomplete: []
[17:05:55] <-- 3 /autocomplete: []

Omnisharp was quite an ordeal to get working, but it is now working as far as I can tell. Does anything in that output suggest otherwise?

razzmatazz commented 6 years ago

@ibeckermayer Sorry, I meant omnisharp-log–you were right.

Do you have any .csproj referenced in your .sln file?

It should say something like this on the log:

[11:59:26] INFORMATION: OmniSharp.MSBuild.MSBuildProjectSystem, Loading project: /Users/[....]/Something.csproj

and then down below on the log:

[12:00:42] INFORMATION: OmniSharp.MSBuild.MSBuildProjectSystem, Update project: Something

Could you check your .sln file?

ibeckermayer commented 6 years ago

@razzmatazz

Ok now we're getting somewhere. I'm running everything on Ubuntu and have no experience with Microsoft API's. I was able to generate a .sln file using dotnet new sln, which I figured out I needed because I was getting omnisharp-server errors on spacemacs startup without it. Now it sounds like I need to create a .csproj file as well? I tried it with dotnet new web, which did create a .csproj file but didn't solve the problem.

There seems to be limited documentation on how to configure everything manually, since most people are working in Visual Studio which appears to take care of most of this stuff behind the scenes. For example, I tried dotnet new web but it's not clear to me that that's the correct option. When I run dotnet new -l I have all of these options but I'm unsure of which one to choose for my application:

Templates                                         Short Name       Language          Tags               
--------------------------------------------------------------------------------------------------------
Console Application                               console          [C#], F#, VB      Common/Console     
Class library                                     classlib         [C#], F#, VB      Common/Library     
Unit Test Project                                 mstest           [C#], F#, VB      Test/MSTest        
xUnit Test Project                                xunit            [C#], F#, VB      Test/xUnit         
ASP.NET Core Empty                                web              [C#], F#          Web/Empty          
ASP.NET Core Web App (Model-View-Controller)      mvc              [C#], F#          Web/MVC            
ASP.NET Core Web App                              razor            [C#]              Web/MVC/Razor Pages
ASP.NET Core with Angular                         angular          [C#]              Web/MVC/SPA        
ASP.NET Core with React.js                        react            [C#]              Web/MVC/SPA        
ASP.NET Core with React.js and Redux              reactredux       [C#]              Web/MVC/SPA        
ASP.NET Core Web API                              webapi           [C#], F#          Web/WebAPI         
global.json file                                  globaljson                         Config             
NuGet Config                                      nugetconfig                        Config             
Web Config                                        webconfig                          Config             
Solution File                                     sln                                Solution           
Razor Page                                        page                               Web/ASP.NET        
MVC ViewImports                                   viewimports                        Web/ASP.NET        
MVC ViewStart                                     viewstart                          Web/ASP.NET        

Here are my files:

.csproj:

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

  <PropertyGroup>
    <TargetFramework>netcoreapp2.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <Folder Include="wwwroot\" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.7" />
  </ItemGroup>

</Project>

.sln:

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26124.0
MinimumVisualStudioVersion = 15.0.26124.0
Global
    GlobalSection(SolutionConfigurationPlatforms) = preSolution
        Debug|Any CPU = Debug|Any CPU
        Debug|x64 = Debug|x64
        Debug|x86 = Debug|x86
        Release|Any CPU = Release|Any CPU
        Release|x64 = Release|x64
        Release|x86 = Release|x86
    EndGlobalSection
    GlobalSection(SolutionProperties) = preSolution
        HideSolutionNode = FALSE
    EndGlobalSection
EndGlobal

omnisharp-log

[11:50:18] Starting OmniSharpServer using project folder/solution file: /home/ibeckermayer/Documents/EZTest/EZTest.sln
[11:50:18] Using server binary on /home/ibeckermayer/bin/omnisharp-linux/omnisharp/OmniSharp.exe
[11:50:18] INFORMATION: OmniSharp.Stdio.Host, Starting OmniSharp on ubuntu 16.4 (x64)
[11:50:18] INFORMATION: OmniSharp.MSBuild.Discovery.MSBuildLocator, Located 2 MSBuild instance(s)
            1: Mono 15.0 - "/usr/lib/mono/msbuild/15.0/bin"
            2: StandAlone 15.0 - "/home/ibeckermayer/bin/omnisharp-linux/omnisharp/msbuild/15.0/Bin"
[11:50:18] INFORMATION: OmniSharp.MSBuild.Discovery.MSBuildLocator, Registered MSBuild instance: Mono 15.0 - "/usr/lib/mono/msbuild/15.0/bin"
            CscToolPath = /home/ibeckermayer/bin/omnisharp-linux/omnisharp/msbuild/15.0/Bin/Roslyn
            CscToolExe = csc.exe
[11:50:18] INFORMATION: OmniSharp.Cake.CakeProjectSystem, Detecting Cake files in '/home/ibeckermayer/Documents/EZTest'.
[11:50:18] INFORMATION: OmniSharp.Cake.CakeProjectSystem, Could not find any Cake files
[11:50:18] INFORMATION: OmniSharp.DotNet.DotNetProjectSystem, Initializing in /home/ibeckermayer/Documents/EZTest
[11:50:18] INFORMATION: OmniSharp.DotNet.DotNetProjectSystem, Auto package restore: False
[11:50:18] INFORMATION: OmniSharp.DotNet.DotNetProjectSystem, Update workspace context
[11:50:18] INFORMATION: OmniSharp.DotNet.DotNetProjectSystem, Resolving projects references
[11:50:18] INFORMATION: OmniSharp.MSBuild.ProjectSystem, Detecting projects in '/home/ibeckermayer/Documents/EZTest/EZTest.sln'.
[11:50:18] INFORMATION: OmniSharp.Script.ScriptProjectSystem, Detecting CSX files in '/home/ibeckermayer/Documents/EZTest'.
[11:50:18] INFORMATION: OmniSharp.Script.ScriptProjectSystem, Could not find any CSX files
[11:50:18] INFORMATION: OmniSharp.Stdio.Host, Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpWorkspaceOptionsProvider
[11:50:18] INFORMATION: OmniSharp.Stdio.Host, Configuration finished.
[11:50:18] INFORMATION: OmniSharp.Stdio.Host, Omnisharp server running using Stdio at location '/home/ibeckermayer/Documents/EZTest' on host -1.
[11:50:21] <-- 1 /typelookup: ((Type) (Documentation) (StructuredDocumentation))
[11:50:22] <-- 2 /typelookup: ((Type) (Documentation) (StructuredDocumentation))
[11:50:23] <-- 3 /typelookup: ((Type) (Documentation) (StructuredDocumentation))
[11:50:25] <-- 4 /autocomplete: []
[11:50:25] <-- 5 /autocomplete: []
[11:50:25] <-- 6 /typelookup: ((Type) (Documentation) (StructuredDocumentation))
razzmatazz commented 6 years ago

you need to add .csproj file to the .sln file so it would load it:

ibeckermayer commented 6 years ago

Ok perfect, that fixed it! Thanks for bearing with me. Do you know of any tutorials that give you a basic rundown of how to use dotnet properly?