C# code completion with Emacs & Eglot using Omnisharp

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Noah-Huppert


I recently switched from GDScript to C# and have been trying to setup my Emacs editor to have code completion. Emacs has a plugin called eglot which tries to provide code completion support. Behind the scenes eglot is using a tool called Omnisharp to gain intelligence about the C# code.

I was able to get eglot with Omnisharp working with my C# files. However there is one problem: The code completion has no knowledge of any of the Godot types.

As a test I setup Visual Studio Code as my external editor and clicked the edit script button in Godot. It launched Visual Studio Code with my C# file and had code completion with complete knowledge of the Godot C# types.

I’m not quite sure how it works under the hood but I did find a .sln file for my Godot project and the .mono directory with assemblies/GodotSharp.{dll,pdb,xml}. I think this is how Visual Studio Code was able to find out about Godot C# types.

I then tried configuring eglot to launch Omnisharp with knowledge of the .sln file. The Omnisharp docs point to a way telling Omnisharp about a .sln file. My hope was that this .sln file would tell Omnisharp about the Godot C# dll, pdb, and xml files.

Unfortunately eglot did not seem to like Omnisharp being launched in this fashion.

My question is twofold:

  1. How exactly does Visual Studio Code know about Godot C# types? Is my assumption correct that I need the code completion to know about the .sln, dll, pdb, and xml files for it to have definitions of Godot C# types?
  2. Has anyone configured Emacs with eglot C# autocomplete who could potentially guide me in my setup.


Since posting my question I figured out how to get this setup working, I hope this solution may be able to help someone in the future.
In my case I had to do 2 things to solve this issue. Item #2 might not be relevant but I want to post it just in case it is and others have this issue.

  1. Ensure that the OmniSharp binary is being run in your project’s directory. Due to the way I had installed OmniSharp (on Linux so it was a bit custom through a package manager) the OmniSharp binary was being run with a working directory of /usr/local/bin. This meant it couldn’t find my solution file because I was giving a relative path. I figured this out when I saw an error message from the OmniSharp LSP server which said it couldn’t find the myproject.sln file. Once I editted my install to make OmniSharp run in my project directory I was able to get eglot working.
  2. I installed the Mono version of OmnisSharp. I’m not quite sure if this is absolutely required, but I think it makes sense because Godot uses Mono and I assume there is some formatting difference of Mono vs .NET dll files which might have caused the Godot dll files to not be read properly.

Eglot docs for godot type