First, we need the required LSP (Omnisharp) for Neovim; this is pretty straightforward depending on how you manage LSPs on your Neovim. I simply use Mason.nvim to install my LSPs. I have my dotfiles here -> https://github.com/Saladin1812/dotfiles. I use the nvchad base configuration.
My config/lspconfig.lua ->
require("nvchad.configs.lspconfig").defaults()
local servers = { "html", "cssls", "pyright", "zls", "taplo", "nil_ls", "ols", "omnisharp" }
vim.lsp.enable(servers)
Here I have added omnisharp for the LSP.
Now, to configure syntax highlighting I simply use nvim-treesitter. Here in my plugins/init.lua ->
{
"nvim-treesitter/nvim-treesitter",
opts = {
ensure_installed = {
"vim",
"lua",
"vimdoc",
"html",
"css",
"json",
"go",
"python",
"rust",
"odin",
"zig",
"toml",
"dart",
"c_sharp",
},
},
},
Here I have simply added c_sharp to make sure I have syntax highlighting.
Now we need a couple of extra extensions to make sure we are good to go. The first is ahmedkhalf/project.nvim required for automatically cd into the project directory. This is important because when nvim with the socket listener is launched, we need it to automatically cd into our Unity project directory with .sln & .csproj at the root. This is required for LSP to work. We can also cd into the project. And launch nvim with the socket listener, but this requires us to manually cd into the project every time we want to work with our project, which is simply not ideal for most all tho mostly I find myself doing it manually either way. Also, keep in mind that sometimes your LSP may attach before project.nvim kicks in. In that case, simply restart your LSP server by doing :LspRestart. Here in my plugins/init.lua ->
{
"ahmedkhalf/project.nvim",
lazy = false,
config = function()
require("project_nvim").setup {}
end,
},
The other plugin we absolutely need is apyra/nvim-unity-sync. This is by the same person who created the Unity nvim plugin. This automatically updates our .csproj file whenever any C# files are created, deleted, or renamed. This also provides a couple of useful commands for manually managing our .csproj. However, for me, I never had to run those commands manually. Here in my plugins/init.lua
{
"apyra/nvim-unity-sync",
lazy = false,
config = function()
require("unity.plugin").setup()
end,
},
Also, it's really beneficial to install Unity Snippets to work with Luasnip. I have created cs.lua for Unity Snippets here -> https://github.com/Saladin1812/dotfiles/blob/main/.config/nvim/lua/snippets/cs.lua. And I have enabled it in my chadrc.lua ->
vim.g.lua_snippets_path = vim.fn.stdpath "config" .. "/lua/snippets"
Make sure to use the correct path where you have saved your snippets. As I am using Nvchad, it comes with Luasnip. However, enable the L3MON4D3/LuaSnip plugin if you have to.