Skip to content

Instantly share code, notes, and snippets.

@squk
Last active February 18, 2024 00:06
Show Gist options
  • Save squk/055683bb83d4dbbac418582129f0e3b5 to your computer and use it in GitHub Desktop.
Save squk/055683bb83d4dbbac418582129f0e3b5 to your computer and use it in GitHub Desktop.
GDScript and C# NeoVim LSP Configuration
{
"williamboman/mason-lspconfig.nvim",
dependencies = {
"williamboman/mason.nvim",
"Hoffs/omnisharp-extended-lsp.nvim",
"neovim/nvim-lspconfig",
},
config = function()
require("mason").setup()
require("mason-lspconfig").setup({
automatic_installation = true,
ensure_installed = {
"omnisharp_mono",
},
})
require("lspconfig").gdscript.setup({})
require("mason-lspconfig").setup_handlers({
-- The first entry (without a key) will be the default handler
-- and will be called for each installed server that doesn't have
-- a dedicated handler.
function(server_name) -- default handler (optional)
require("lspconfig")[server_name].setup({})
end,
-- Next, you can provide a dedicated handler for specific servers.
-- For example, a handler override for the `rust_analyzer`:
["omnisharp_mono"] = function()
require("lspconfig").omnisharp.setup({
handlers = {
["textDocument/definition"] = require("omnisharp_extended").handler,
},
-- cmd = { "dotnet", "/path/to/omnisharp/OmniSharp.dll" },
-- Enables support for reading code style, naming convention and analyzer
-- settings from .editorconfig.
enable_editorconfig_support = true,
-- If true, MSBuild project system will only load projects for files that
-- were opened in the editor. This setting is useful for big C# codebases
-- and allows for faster initialization of code navigation features only
-- for projects that are relevant to code that is being edited. With this
-- setting enabled OmniSharp may load fewer projects and may thus display
-- incomplete reference lists for symbols.
enable_ms_build_load_projects_on_demand = false, -- default false
-- Enables support for roslyn analyzers, code fixes and rulesets.
enable_roslyn_analyzers = true, -- default false
-- Specifies whether 'using' directives should be grouped and sorted during
-- document formatting.
organize_imports_on_format = true, -- default false
-- Enables support for showing unimported types and unimported extension
-- methods in completion lists. When committed, the appropriate using
-- directive will be added at the top of the current file. This option can
-- have a negative impact on initial completion responsiveness,
-- particularly for the first few completion sessions after opening a
-- solution.
enable_import_completion = true, -- default false
-- Specifies whether to include preview versions of the .NET SDK when
-- determining which version to use for project loading.
sdk_include_prereleases = true,
-- Only run analyzers against open files when 'enableRoslynAnalyzers' is
-- true
analyze_open_documents_only = true, -- default false
})
end,
})
end,
}
@InfiniteRain
Copy link

InfiniteRain commented Dec 14, 2023

Hey! I came across your configuration and currently am trying to make this work on my MacOS machine. I think I got to a point where our settings are identical but I keep on getting the following error whenever I open a .cs file:

Spawning language server with cmd: `-z` failed. The language server is either not installed, missing from PATH, or not executable.

Do you happen to know what's wrong? I looked into the omnisharp's code and it looks like they're not setting a cmd at all, which makes it run the -z as a command instead. I'm seeing that you didn't set up a cmd either, so how exactly does the C# LSP work for you?

@InfiniteRain
Copy link

I gave it an absolute to a binary that is installed by mason and now I'm getting the following error;

"OmniSharp.CompositionHostBuilder: It looks like the included version of MSBuild is lower than 17.7.0 which is the minimum supported by the configured .NET Core Sdk.\n Try installing MSBuild version 17.7.0 or higher to enable better .NET Core Sdk support.

But Mono doesn't come with an MSBuild this high at all.

@InfiniteRain
Copy link

InfiniteRain commented Dec 14, 2023

The solution was not to use omnisharp-mono at all, and simply stick to omnisharp. I had to still supply a full path to the omnisharp executable in the config, though. Here's the commit: InfiniteRain/nvim@fcf5899

My setup now fully works with Godot's C#!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment