feat(neovim): add roslyn.nvim support + rzls.nvim

This commit is contained in:
Alexandre Cavalheiro S. Tiago da Silva 2025-02-11 23:38:36 -03:00
parent cfd84bde6a
commit 7025b5fe97
Signed by: wizardlink
GPG key ID: A5767B54367CFBDF
5 changed files with 180 additions and 49 deletions

View file

@ -78,7 +78,9 @@ in
vscode-extensions.ms-vscode.cpptools
# C#
csharp-ls
#csharp-ls Testing roslyn.nvim
roslyn-ls
rzls
csharpier
netcoredbg

View file

@ -55,7 +55,7 @@ return {
"basedpyright",
"clangd",
"cmake",
"csharp_ls",
--"csharp_ls", Testing roslyn.nvim
"cssls",
"denols",
"eslint",

View file

@ -18,9 +18,11 @@ return {
{ import = "astrocommunity.motion.mini-ai" },
{ import = "astrocommunity.motion.mini-surround" },
{ import = "astrocommunity.test.neotest" },
{ import = "astrocommunity.pack.cmake" },
{ import = "astrocommunity.pack.cpp" },
{ import = "astrocommunity.pack.cs" },
-- { import = "astrocommunity.pack.cs" }, Trying out roslyn.nvim
{ import = "astrocommunity.pack.godot" },
{ import = "astrocommunity.pack.html-css" },
{ import = "astrocommunity.pack.json" },

View file

@ -0,0 +1,120 @@
---@type LazySpec
return {
"seblyng/roslyn.nvim",
ft = { "cs", "razor" },
commit = "490fd2d0f76249032ef6ce503e43ccdaeed9616e",
lazy = true,
dependencies = {
{
"tris203/rzls.nvim",
config = function()
---@diagnostic disable-next-line: missing-fields
require("rzls").setup {
path = vim.fn.getnixpath "rzls" .. "/bin/rzls",
}
end,
},
},
opts = function(_, opts)
local rzlspath = vim.fn.getnixpath "rzls"
require("roslyn.config").get()
opts = {
exe = "Microsoft.CodeAnalysis.LanguageServer",
args = {
"--logLevel=Information",
"--extensionLogDirectory=" .. vim.fs.dirname(vim.lsp.get_log_path()),
"--razorSourceGenerator=" .. rzlspath .. "/lib/rzls/Microsoft.CodeAnalysis.Razor.Compiler.dll",
"--razorDesignTimePath=" .. rzlspath .. "/lib/rzls/Targets/Microsoft.NET.Sdk.Razor.DesignTime.targets",
},
---@type vim.lsp.ClientConfig
---@diagnostic disable-next-line: missing-fields
config = {
handlers = require "rzls.roslyn_handlers",
settings = {
["csharp|inlay_hints"] = {
csharp_enable_inlay_hints_for_implicit_object_creation = true,
csharp_enable_inlay_hints_for_implicit_variable_types = true,
csharp_enable_inlay_hints_for_lambda_parameter_types = true,
csharp_enable_inlay_hints_for_types = true,
dotnet_enable_inlay_hints_for_indexer_parameters = true,
dotnet_enable_inlay_hints_for_literal_parameters = true,
dotnet_enable_inlay_hints_for_object_creation_parameters = true,
dotnet_enable_inlay_hints_for_other_parameters = true,
dotnet_enable_inlay_hints_for_parameters = true,
dotnet_suppress_inlay_hints_for_parameters_that_differ_only_by_suffix = true,
dotnet_suppress_inlay_hints_for_parameters_that_match_argument_name = true,
dotnet_suppress_inlay_hints_for_parameters_that_match_method_intent = true,
},
["csharp|code_lens"] = {
dotnet_enable_references_code_lens = true,
},
},
---@class RoslynPatchedClient: vim.lsp.Client
---@field patched boolean?
---@param client RoslynPatchedClient
---@param bufnr integer
on_attach = function(client, bufnr)
-- Call AstroLSP's on_attach so it registers mappings, formatting, etc.
require("astrolsp").on_attach(client, bufnr)
-- HACK: Patch out the `roslyn-ls` LSP client to have proper
-- semantic tokens.
-- This is a snippet of code taken and modified from:
-- https://github.com/seblyng/roslyn.nvim/wiki#semantic-tokens
if client.patched then
return
else
client.patched = true
end
-- let the runtime know the server can do semanticTokens/full now
client.server_capabilities = vim.tbl_deep_extend("force", client.server_capabilities, {
semanticTokensProvider = {
full = true,
},
})
local lsp_request = client.request
client.request = function(method, params, handler, req_bufnr)
if method ~= vim.lsp.protocol.Methods.textDocument_semanticTokens_full then
return lsp_request(method, params, handler, req_bufnr)
end
local target_bufnr = vim.uri_to_bufnr(params.textDocument.uri)
local line_count = vim.api.nvim_buf_line_count(target_bufnr)
local last_line = vim.api.nvim_buf_get_lines(target_bufnr, line_count - 1, line_count, true)[1]
local returnvalue = lsp_request("textDocument/semanticTokens/range", {
textDocument = params.textDocument,
range = {
["start"] = {
line = 0,
character = 0,
},
["end"] = {
line = line_count - 1,
character = string.len(last_line) - 1,
},
},
}, handler, req_bufnr)
return returnvalue
end
end,
},
}
return opts
end,
init = function()
vim.filetype.add {
extension = {
razor = "razor",
cshtml = "razor",
},
}
end,
}

View file

@ -2,50 +2,57 @@
---@type LazySpec
return {
"nvim-treesitter/nvim-treesitter",
opts = function(_, opts)
-- add more things to the ensure_installed table protecting against community packs modifying it
opts.ensure_installed = require("astrocore").list_insert_unique(opts.ensure_installed, {
-- Programming
"c",
"c_sharp",
"cmake",
"cpp",
"css",
"gdscript",
"godot_resource",
"html",
"hyprlang",
"javascript",
"jsdoc",
"lua",
"nim",
"nim_format_string",
"objc",
"proto",
"python",
"svelte",
"tsx",
"typescript",
"vue",
-- Scripting
"bash",
"glsl",
-- Configuring
"dockerfile",
"json",
"jsonc",
"nix",
"vhs",
"yaml",
-- Misc
"cuda",
"markdown",
"markdown_inline",
"query",
-- VIM
"vim",
"vimdoc",
})
end,
"nvim-treesitter/nvim-treesitter",
---@param _ LazyPlugin
---@param opts TSConfig
opts = function(_, opts)
-- disable automatically installing parsers
opts.auto_install = false
-- add more things to the ensure_installed table protecting against community packs modifying it
opts.ensure_installed = require("astrocore").list_insert_unique(opts.ensure_installed --[[@as string[]], {
-- Programming
"c",
"c_sharp",
"cmake",
"cpp",
"css",
"gdscript",
"godot_resource",
"html",
"hyprlang",
"javascript",
"jsdoc",
"lua",
"nim",
"nim_format_string",
"objc",
"proto",
"python",
"razor",
"svelte",
"tsx",
"typescript",
"vue",
-- Scripting
"bash",
"fish",
"glsl",
-- Configuring
"dockerfile",
"json",
"jsonc",
"nix",
"vhs",
"yaml",
-- Misc
"cuda",
"markdown",
"markdown_inline",
"query",
-- VIM
"vim",
"vimdoc",
})
end,
}