feat: migrate omnisharp to roslyn

This commit is contained in:
Stevan Freeborn
2026-07-30 14:21:19 -05:00
parent b11cf10e31
commit 992c7fe4f1
+54 -58
View File
@@ -3,7 +3,12 @@ return {
"williamboman/mason.nvim", "williamboman/mason.nvim",
lazy = false, lazy = false,
config = function() config = function()
require("mason").setup() require("mason").setup({
registries = {
"github:mason-org/mason-registry",
"github:Crashdummyy/mason-registry",
},
})
end, end,
}, },
{ {
@@ -36,7 +41,6 @@ return {
}, },
{ {
"neovim/nvim-lspconfig", "neovim/nvim-lspconfig",
dependencies = { "hoffs/omnisharp-extended-lsp.nvim" },
lazy = false, lazy = false,
config = function() config = function()
local capabilities = require("cmp_nvim_lsp").default_capabilities() local capabilities = require("cmp_nvim_lsp").default_capabilities()
@@ -85,14 +89,54 @@ return {
vim.lsp.enable("eslint") vim.lsp.enable("eslint")
vim.lsp.config("omnisharp", { vim.lsp.config("roslyn_ls", {
handlers = { settings = {
["textDocument/definition"] = require("omnisharp_extended").handler, ["csharp|projects"] = {
dotnet_enable_file_based_programs = true,
}, },
capabilities = capabilities, },
root_dir = function(bufnr, cb)
local bufname = vim.api.nvim_buf_get_name(bufnr)
-- decompiled files: reuse previous buffer's client root
if bufname:find('[/\\]MetadataAsSource[/\\]') then
local _, endpos = bufname:find('[/\\]MetadataAsSource[/\\]')
if vim.fn.finddir(bufname:sub(1, endpos), vim.uv.os_tmpdir()) ~= '' then
local prev = vim.fn.bufnr('#')
local client = vim.lsp.get_clients({ name = 'roslyn_ls', bufnr = (prev ~= -1 and prev) or nil })[1]
if client then
cb(client.config.root_dir)
return
end
end
end
-- 1) Look for .sln / .slnx
local root = vim.fs.root(bufnr, function(fname)
return fname:match('%.sln[x]?$') ~= nil
end)
-- 2) Look for .csproj
if not root then
root = vim.fs.root(bufnr, function(fname)
return fname:match('%.csproj$') ~= nil
end)
end
-- 3) Fallback: file-based app — use file's parent directory
if not root then
root = vim.uv.fs_realpath(vim.fs.dirname(bufname))
end
if root then
cb(root)
end
end,
}) })
vim.lsp.enable("omnisharp") vim.lsp.enable("roslyn_ls")
vim.lsp.config("fsautocomplete", { vim.lsp.config("fsautocomplete", {
capabilities = capabilities, capabilities = capabilities,
@@ -338,50 +382,9 @@ return {
end end
end end
local omnisharp = require("omnisharp_extended") vim.keymap.set("n", "gd", vim.lsp.buf.definition, { desc = "Go to definition", buffer = ev.buf })
if client.name == "omnisharp" then vim.keymap.set("n", "gD", vim.lsp.buf.declaration, { desc = "Go to declaration", buffer = ev.buf })
vim.keymap.set(
"n",
"gd",
omnisharp.telescope_lsp_definition,
{ desc = "Go to definition", buffer = ev.buf }
)
vim.keymap.set(
"n",
"gi",
omnisharp.telescope_lsp_implementation,
{ desc = "Go to implementation", buffer = ev.buf }
)
vim.keymap.set(
"n",
"gr",
omnisharp.telescope_lsp_references,
{ desc = "Go to references", buffer = ev.buf }
)
vim.keymap.set(
"n",
"<leader>D",
omnisharp.telescope_lsp_type_definition,
{ desc = "Go to type definition", buffer = ev.buf }
)
else
vim.keymap.set(
"n",
"gd",
vim.lsp.buf.definition,
{ desc = "Go to definition", buffer = ev.buf }
)
vim.keymap.set(
"n",
"gD",
vim.lsp.buf.declaration,
{ desc = "Go to declaration", buffer = ev.buf }
)
vim.keymap.set( vim.keymap.set(
"n", "n",
@@ -390,13 +393,7 @@ return {
{ desc = "Go to implementation", buffer = ev.buf } { desc = "Go to implementation", buffer = ev.buf }
) )
vim.keymap.set( vim.keymap.set("n", "gr", vim.lsp.buf.references, { desc = "Go to references", buffer = ev.buf })
"n",
"gr",
vim.lsp.buf.references,
{ desc = "Go to references", buffer = ev.buf }
)
end
vim.api.nvim_create_autocmd({ "FileType" }, { vim.api.nvim_create_autocmd({ "FileType" }, {
callback = function() callback = function()
@@ -472,7 +469,6 @@ return {
vim.fn.setreg("+", table.concat(lines, "\n")) vim.fn.setreg("+", table.concat(lines, "\n"))
vim.notify(string.format("Copied %d diagnostics to clipboard", #diagnostics)) vim.notify(string.format("Copied %d diagnostics to clipboard", #diagnostics))
end, { desc = "Copy buffer diagnostics to clipboard", buffer = ev.buf }) end, { desc = "Copy buffer diagnostics to clipboard", buffer = ev.buf })
vim.keymap.set("n", "K", vim.lsp.buf.hover, { desc = "Display symbol info", buffer = ev.buf }) vim.keymap.set("n", "K", vim.lsp.buf.hover, { desc = "Display symbol info", buffer = ev.buf })