OmniSharp / omnisharp-emacs

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

Company: typelookup/autocomplete request failed #400

Closed BrutalBirdie closed 6 years ago

BrutalBirdie commented 6 years ago

4.13.11-1-ARCH emacsclient 25.3 dotnet-runtime-2.0 1:2.0.0-3 dotnet-sdk-2.0 1:2.0.2-1

[11:41:46] Starting OmniSharpServer using project folder/solution file: /home/eha/Dokumente/Schule/AS/KW_38/TowersOfHanoi.sln
[11:41:46] using server binary on /home/eha/.emacs.d/.cache/omnisharp/server/v1.26.0/run
[11:41:46] INFORMATION: OmniSharp.MSBuild.Discovery.MSBuildLocator, Located 1 MSBuild instance(s)
            1: StandAlone 15.0 - "/home/eha/.emacs.d/.cache/omnisharp/server/v1.26.0/omnisharp/msbuild/15.0/Bin"
[11:41:46] INFORMATION: OmniSharp.MSBuild.Discovery.MSBuildLocator, MSBUILD_EXE_PATH environment variable set to '/home/eha/.emacs.d/.cache/omnisharp/server/v1.26.0/omnisharp/msbuild/15.0/Bin/MSBuild.dll'
[11:41:46] INFORMATION: OmniSharp.MSBuild.Discovery.MSBuildLocator, Registered MSBuild instance: StandAlone 15.0 - "/home/eha/.emacs.d/.cache/omnisharp/server/v1.26.0/omnisharp/msbuild/15.0/Bin"
            MSBuildExtensionsPath = /home/eha/.emacs.d/.cache/omnisharp/server/v1.26.0/omnisharp/msbuild
            CscToolPath = /home/eha/.emacs.d/.cache/omnisharp/server/v1.26.0/omnisharp/msbuild/15.0/Bin/Roslyn
            CscToolExe = csc.exe
            MSBuildToolsPath = /home/eha/.emacs.d/.cache/omnisharp/server/v1.26.0/omnisharp/msbuild/15.0/Bin
            TargetFrameworkRootPath = /usr/lib/mono/xbuild-frameworks
[11:41:48] INFORMATION: OmniSharp.Cake.CakeProjectSystem, Detecting Cake files in '/home/eha/Dokumente/Schule/AS/KW_38'.
[11:41:48] INFORMATION: OmniSharp.Cake.CakeProjectSystem, Could not find any Cake files
[11:41:48] INFORMATION: OmniSharp.DotNet.DotNetProjectSystem, Initializing in /home/eha/Dokumente/Schule/AS/KW_38
[11:41:48] INFORMATION: OmniSharp.DotNet.DotNetProjectSystem, Auto package restore: False
[11:41:48] INFORMATION: OmniSharp.DotNet.DotNetProjectSystem, Update workspace context
[11:41:48] INFORMATION: OmniSharp.DotNet.DotNetProjectSystem, Resolving projects references
[11:41:48] INFORMATION: OmniSharp.MSBuild.MSBuildProjectSystem, Detecting projects in '/home/eha/Dokumente/Schule/AS/KW_38/TowersOfHanoi.sln'.
[11:41:48] ERROR: OmniSharp.Stdio.Program, The project system 'OmniSharp.MSBuild.MSBuildProjectSystem' threw exception during initialization.
OmniSharp.MSBuild.SolutionParsing.InvalidSolutionFileException: Solution header should be on first or second line.
  at OmniSharp.MSBuild.SolutionParsing.SolutionFile.ParseHeaderAndVersion (OmniSharp.MSBuild.SolutionParsing.Scanner scanner) [0x0004b] in <7eebd6127211482184f71eccc0953823>:0 
  at OmniSharp.MSBuild.SolutionParsing.SolutionFile.Parse (System.String text) [0x00015] in <7eebd6127211482184f71eccc0953823>:0 
  at OmniSharp.MSBuild.SolutionParsing.SolutionFile.ParseFile (System.String path) [0x00006] in <7eebd6127211482184f71eccc0953823>:0 
  at OmniSharp.MSBuild.MSBuildProjectSystem.GetProjectPathsFromSolution (System.String solutionFilePath) [0x0001b] in <7eebd6127211482184f71eccc0953823>:0 
  at OmniSharp.MSBuild.MSBuildProjectSystem.GetInitialProjectPaths () [0x0002f] in <7eebd6127211482184f71eccc0953823>:0 
  at OmniSharp.MSBuild.MSBuildProjectSystem.Initalize (Microsoft.Extensions.Configuration.IConfiguration configuration) [0x0004b] in <7eebd6127211482184f71eccc0953823>:0 
  at OmniSharp.WorkspaceInitializer.Initialize (System.IServiceProvider serviceProvider, System.Composition.Hosting.CompositionHost compositionHost, Microsoft.Extensions.Configuration.IConfiguration configuration, Microsoft.Extensions.Logging.ILogger logger) [0x00079] in <fc86425b83fa4820a94c3447774fdb30>:0 
[11:41:48] INFORMATION: OmniSharp.Script.ScriptProjectSystem, Detecting CSX files in '/home/eha/Dokumente/Schule/AS/KW_38'.
[11:41:48] INFORMATION: OmniSharp.Script.ScriptProjectSystem, Could not find any CSX files
[11:41:48] INFORMATION: OmniSharp.Stdio.Program, Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpWorkspaceOptionsProvider
[11:41:48] INFORMATION: OmniSharp.Stdio.Program, Configuration finished.
[11:41:48] INFORMATION: OmniSharp.Stdio.Program, Omnisharp server running using Stdio at location '/home/eha/Dokumente/Schule/AS/KW_38' on host -1.
[11:41:48] <-- 1 /typelookup: request failed
[11:41:49] <-- 2 /codecheck: request failed
[11:41:51] <-- 3 /typelookup: request failed
[11:41:52] <-- 5 /typelookup: request failed
[11:41:52] <-- 4 /autocomplete: request failed
[11:41:56] <-- 6 /autocomplete: request failed
[11:41:56] <-- 7 /typelookup: request failed
[11:41:59] <-- 8 /autocomplete: request failed
[11:41:59] <-- 9 /typelookup: request failed
[11:42:00] <-- 10 /autocomplete: request failed
[11:42:00] <-- 11 /typelookup: request failed
[11:42:14] <-- 12 /typelookup: request failed
razzmatazz commented 6 years ago

@BrutalBirdie do you have a well-formed solution file? as it appears omnisharp has not managed to find any projects in the solution and complains that:

OmniSharp.MSBuild.SolutionParsing.InvalidSolutionFileException: Solution header should be on first or second line.

could you paste the contents of /home/eha/Dokumente/Schule/AS/KW_38/TowersOfHanoi.sln ?

BrutalBirdie commented 6 years ago

It is actually a .cs file I just renamed it to .sln I just read more documentation about dotnet c# visual studio code etc.

Do I have to create a new project via dotnet new console dotnet restore ? Why does the omnisharp server only start with .sln files ? and not with .cs files?

razzmatazz commented 6 years ago

You need to have both .sln and .csproj files, in some cases you can avoid a .sln, though. A plain .cs file is not enough, and a .cs file cannot be subsitituted for a .sln or .csproj file (which is in XML) as the basic project structure for C# requires a .csproj in the root directory of the project file to define properties of the project (dependency packages/projects, constants, target framework, etc.).

Solution file is used to combine multiple projects into a solution (among other things) – you may want to check out dotnet sln command as well, https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-sln

So yes, you need to create a .csproj file (via dotnet new) and then a solution file for the project to be properly loadable in omnisharp.

BrutalBirdie commented 6 years ago

Will try that and report back

BrutalBirdie commented 6 years ago

Emacs .emacs (.init) file

;; Linenumbering
(global-linum-mode)

;; Gloabal Companymode
(global-company-mode 1)

;; GlobalFlyCheckSetting
(global-flycheck-mode)

;; Omnisharp
(add-hook 'csharp-mode-hook 'omnisharp-mode)

(eval-after-load
 'company
 '(add-to-list 'company-backends 'company-omnisharp))
(setq omnisharp-server-executable-path "/home/eha/.emacs.d/.cache/omnisharp/server/v1.26.0/run")

(provide '.emacs)
;;; .emacs ends here

My steps. I created a new project mkdir Test cd Test dotnet new console dotnet restore dotnet net sln

ls -lah

drwxr-xr-x 3 eha users 4.0K Nov  8 12:12 .
drwxr-xr-x 6 eha users 4.0K Nov  8 12:05 ..
-rw-r--r-- 1 eha users  186 Nov  8 12:12 Program.cs
-rw-r--r-- 1 eha users  178 Nov  8 12:12 Test.csproj
-rw-r--r-- 1 eha users  540 Nov  8 12:12 Test.sln
drwxr-xr-x 2 eha users 4.0K Nov  8 12:12 obj

Now I open the Program.cs with Emacs Start the omnisharp server omnisharp-start-omnisharp-server I select the Test.sln file Try to TAB complete

[12:16:58] Starting OmniSharpServer using project folder/solution file: /home/eha/Dokumente/Schule/AS/KW_38/Test/Test.sln
[12:16:58] using server binary on /home/eha/.emacs.d/.cache/omnisharp/server/v1.26.0/run
[12:16:59] INFORMATION: OmniSharp.MSBuild.Discovery.MSBuildLocator, Located 1 MSBuild instance(s)
            1: StandAlone 15.0 - "/home/eha/.emacs.d/.cache/omnisharp/server/v1.26.0/omnisharp/msbuild/15.0/Bin"
[12:16:59] INFORMATION: OmniSharp.MSBuild.Discovery.MSBuildLocator, MSBUILD_EXE_PATH environment variable set to '/home/eha/.emacs.d/.cache/omnisharp/server/v1.26.0/omnisharp/msbuild/15.0/Bin/MSBuild.dll'
[12:16:59] INFORMATION: OmniSharp.MSBuild.Discovery.MSBuildLocator, Registered MSBuild instance: StandAlone 15.0 - "/home/eha/.emacs.d/.cache/omnisharp/server/v1.26.0/omnisharp/msbuild/15.0/Bin"
            MSBuildExtensionsPath = /home/eha/.emacs.d/.cache/omnisharp/server/v1.26.0/omnisharp/msbuild
            CscToolPath = /home/eha/.emacs.d/.cache/omnisharp/server/v1.26.0/omnisharp/msbuild/15.0/Bin/Roslyn
            CscToolExe = csc.exe
            MSBuildToolsPath = /home/eha/.emacs.d/.cache/omnisharp/server/v1.26.0/omnisharp/msbuild/15.0/Bin
            TargetFrameworkRootPath = /usr/lib/mono/xbuild-frameworks
[12:17:00] INFORMATION: OmniSharp.Cake.CakeProjectSystem, Detecting Cake files in '/home/eha/Dokumente/Schule/AS/KW_38/Test'.
[12:17:00] INFORMATION: OmniSharp.Cake.CakeProjectSystem, Could not find any Cake files
[12:17:00] INFORMATION: OmniSharp.DotNet.DotNetProjectSystem, Initializing in /home/eha/Dokumente/Schule/AS/KW_38/Test
[12:17:00] INFORMATION: OmniSharp.DotNet.DotNetProjectSystem, Auto package restore: False
[12:17:00] INFORMATION: OmniSharp.DotNet.DotNetProjectSystem, Update workspace context
[12:17:00] INFORMATION: OmniSharp.DotNet.DotNetProjectSystem, Resolving projects references
[12:17:00] INFORMATION: OmniSharp.MSBuild.MSBuildProjectSystem, Detecting projects in '/home/eha/Dokumente/Schule/AS/KW_38/Test/Test.sln'.
[12:17:00] INFORMATION: OmniSharp.Script.ScriptProjectSystem, Detecting CSX files in '/home/eha/Dokumente/Schule/AS/KW_38/Test'.
[12:17:00] INFORMATION: OmniSharp.Script.ScriptProjectSystem, Could not find any CSX files
[12:17:00] INFORMATION: OmniSharp.Stdio.Program, Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpWorkspaceOptionsProvider
[12:17:00] INFORMATION: OmniSharp.Stdio.Program, Configuration finished.
[12:17:00] INFORMATION: OmniSharp.Stdio.Program, Omnisharp server running using Stdio at location '/home/eha/Dokumente/Schule/AS/KW_38/Test' on host -1.
[12:17:37] <-- 1 /codecheck: ((QuickFixes . []))
[12:17:40] <-- 2 /codecheck: ((QuickFixes . []))
[12:17:40] <-- 3 /autocomplete: []
[12:17:40] <-- 4 /typelookup: ((Type) (Documentation))
[12:17:41] <-- 5 /codecheck: ((QuickFixes . []))
BrutalBirdie commented 6 years ago

I have to RTFM! Myself... dotnet sln add Test.sln Test.csproj Now emacs. Thanks for the hint. https://puu.sh/yhoN5/9006831f16.png

BrutalBirdie commented 6 years ago

Just for summary. (Maybe add this to the Docs?)

Create a working dir

mkdir Test

go into the dir

cd Test

Create a new project (example is a console app)

dotnet new console

dotnet restore

Create a solution file

dotnet new sln

Add the solution to your project

dotnet sln add Test.sln Test.csproj