diff --git a/docs/manual/release-notes/rl-0.9.md b/docs/manual/release-notes/rl-0.9.md index a479d6c6..82c5b601 100644 --- a/docs/manual/release-notes/rl-0.9.md +++ b/docs/manual/release-notes/rl-0.9.md @@ -491,7 +491,7 @@ https://github.com/gorbit99/codewindow.nvim [CaueAnjos](https://github.com/caueanjos) -- Add razor support for `roslyn_ls` and `csharp_ls` +- Added razor support for `roslyn_ls` and `csharp_ls` [mputz86](https://github.com/mputz86) diff --git a/modules/plugins/languages/csharp.nix b/modules/plugins/languages/csharp.nix index f606c603..e7ca2d39 100644 --- a/modules/plugins/languages/csharp.nix +++ b/modules/plugins/languages/csharp.nix @@ -2,201 +2,14 @@ lib, pkgs, config, - options, ... }: let - inherit (builtins) attrNames concatMap; + inherit (builtins) concatMap; + inherit (lib) genAttrs; inherit (lib.options) mkEnableOption mkOption literalExpression; - inherit (lib.types) enum; + inherit (lib.types) enum listOf; inherit (lib.modules) mkIf mkMerge; - inherit (lib.meta) getExe; - inherit (lib.generators) mkLuaInline; - inherit (lib.strings) optionalString; - inherit (lib.nvim.types) mkGrammarOption mkPluginSetupOption deprecatedSingleOrListOf; - inherit (lib.nvim.lua) toLuaObject; - inherit (lib.nvim.attrsets) mapListToAttrs; - - lspKeyConfig = config.vim.lsp.mappings; - lspKeyOptions = options.vim.lsp.mappings; - mkLspBinding = optionName: action: let - key = lspKeyConfig.${optionName}; - desc = lspKeyOptions.${optionName}.description; - in - optionalString (key != null) "vim.keymap.set('n', '${key}', ${action}, {buffer=bufnr, noremap=true, silent=true, desc='${desc}'})"; - - defaultServers = ["csharp_ls"]; - servers = { - omnisharp = { - cmd = mkLuaInline '' - { - ${toLuaObject (getExe pkgs.omnisharp-roslyn)}, - '-z', -- https://github.com/OmniSharp/omnisharp-vscode/pull/4300 - '--hostPID', - tostring(vim.fn.getpid()), - 'DotNet:enablePackageRestore=false', - '--encoding', - 'utf-8', - '--languageserver', - } - ''; - filetypes = ["cs" "vb"]; - root_dir = mkLuaInline '' - function(bufnr, on_dir) - local function find_root_pattern(fname, lua_pattern) - return vim.fs.root(0, function(name, path) - return name:match(lua_pattern) - end) - end - - local fname = vim.api.nvim_buf_get_name(bufnr) - on_dir(find_root_pattern(fname, "%.sln$") or find_root_pattern(fname, "%.csproj$")) - end - ''; - init_options = {}; - capabilities = { - workspace = { - workspaceFolders = false; # https://github.com/OmniSharp/omnisharp-roslyn/issues/909 - }; - }; - on_attach = mkLuaInline '' - function(client, bufnr) - local oe = require("omnisharp_extended") - ${mkLspBinding "goToDefinition" "oe.lsp_definition"} - ${mkLspBinding "goToType" "oe.lsp_type_definition"} - ${mkLspBinding "listReferences" "oe.lsp_references"} - ${mkLspBinding "listImplementations" "oe.lsp_implementation"} - end - ''; - settings = { - FormattingOptions = { - # Enables support for reading code style, naming convention and analyzer - # settings from .editorconfig. - EnableEditorConfigSupport = true; - # Specifies whether 'using' directives should be grouped and sorted during - # document formatting. - OrganizeImports = null; - }; - MsBuild = { - # 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. - LoadProjectsOnDemand = null; - }; - RoslynExtensionsOptions = { - # Enables support for roslyn analyzers, code fixes and rulesets. - EnableAnalyzersSupport = null; - # 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. - EnableImportCompletion = null; - # Only run analyzers against open files when 'enableRoslynAnalyzers' is - # true - AnalyzeOpenDocumentsOnly = null; - # Enables the possibility to see the code in external nuget dependencies - EnableDecompilationSupport = null; - }; - RenameOptions = { - RenameInComments = null; - RenameOverloads = null; - RenameInStrings = null; - }; - Sdk = { - # Specifies whether to include preview versions of the .NET SDK when - # determining which version to use for project loading. - IncludePrereleases = true; - }; - }; - }; - - csharp_ls = { - cmd = [(lib.getExe pkgs.csharp-ls) "--features" "razor-support"]; - filetypes = ["cs" "razor"]; - root_dir = mkLuaInline '' - function(bufnr, on_dir) - local function find_root_pattern(fname, lua_pattern) - return vim.fs.root(0, function(name, path) - return name:match(lua_pattern) - end) - end - - local fname = vim.api.nvim_buf_get_name(bufnr) - on_dir(find_root_pattern(fname, "%.sln$") or find_root_pattern(fname, "%.csproj$")) - end - ''; - init_options = { - AutomaticWorkspaceInit = true; - }; - }; - - roslyn_ls = { - cmd = mkLuaInline '' - { - ${toLuaObject (getExe pkgs.roslyn-ls)}, - '--logLevel=Warning', - '--extensionLogDirectory=' .. vim.fs.dirname(vim.lsp.get_log_path()), - '--stdio', - } - ''; - - filetypes = ["cs"]; - root_dir = mkLuaInline '' - function(bufnr, on_dir) - local function find_root_pattern(fname, lua_pattern) - return vim.fs.root(0, function(name, path) - return name:match(lua_pattern) - end) - end - - local fname = vim.api.nvim_buf_get_name(bufnr) - on_dir(find_root_pattern(fname, "%.sln$") or find_root_pattern(fname, "%.csproj$")) - end - ''; - init_options = {}; - }; - - roslyn = let - pkg = pkgs.vscode-extensions.ms-dotnettools.csharp; - pluginRoot = "${pkg}/share/vscode/extensions/ms-dotnettools.csharp"; - exe = "${pluginRoot}/.roslyn/Microsoft.CodeAnalysis.LanguageServer"; - razorSourceGenerator = "${pluginRoot}/.razorExtension/Microsoft.CodeAnalysis.LanguageServer"; - razorDesignTimePath = "${pluginRoot}/.razorExtension/Targets/Microsoft.NET.Sdk.Razor.DesignTime.targets"; - razorExtension = "${pluginRoot}/.razorExtension/Microsoft.VisualStudioCode.RazorExtension.dll"; - in { - cmd = mkLuaInline '' - { - "dotnet", - "${exe}.dll", - "--stdio", - "--logLevel=Information", - "--extensionLogDirectory=" .. vim.fs.dirname(vim.lsp.get_log_path()), - "--razorSourceGenerator=${razorSourceGenerator}", - "--razorDesignTimePath=${razorDesignTimePath}", - "--extension=${razorExtension}", - } - ''; - - filetypes = ["cs" "razor"]; - root_dir = mkLuaInline '' - function(bufnr, on_dir) - local function find_root_pattern(fname, lua_pattern) - return vim.fs.root(0, function(name, path) - return name:match(lua_pattern) - end) - end - - local fname = vim.api.nvim_buf_get_name(bufnr) - on_dir(find_root_pattern(fname, "%.sln$") or find_root_pattern(fname, "%.csproj$")) - end - ''; - init_options = {}; - }; - }; + inherit (lib.nvim.types) mkGrammarOption mkPluginSetupOption; extraServerPlugins = { omnisharp = ["omnisharp-extended-lsp-nvim"]; @@ -204,6 +17,8 @@ roslyn_ls = []; roslyn = ["roslyn-nvim"]; }; + defaultServers = ["csharp-ls"]; + servers = ["csharp-ls" "omnisharp" "roslyn-ls"]; cfg = config.vim.languages.csharp; in { @@ -214,15 +29,15 @@ in { ::: {.note} This feature will not work if the .NET SDK is not installed. - Both `roslyn` (with `roslyn-nvim`) and `csharp_ls` require the .NET SDK to function properly with Razor. + Both `roslyn-ls` (with `roslyn-nvim`) and `csharp-ls` require the .NET SDK to function properly with Razor. Ensure that the .NET SDK is installed. Check for version compatibility for optimal performance. ::: ::: {.warning} - At the moment, only `roslyn`(with roslyn-nvim) provides full Razor support. - `csharp_ls` is limited to `.cshtml` files. + At the moment, only `roslyn-ls`(with roslyn-nvim) provides full Razor support. + `csharp-ls` is limited to `.cshtml` files. ::: ''; @@ -232,7 +47,7 @@ in { Roslyn LSP plugin for neovim ::: {.note} - This feature only works for `roslyn` (not `roslyn_ls`). + This feature only works for `roslyn-ls`. ::: ''; setupOpts = mkPluginSetupOption "roslyn-nvim" {}; @@ -259,7 +74,7 @@ in { }; servers = mkOption { description = "C# LSP server to use"; - type = deprecatedSingleOrListOf "vim.language.csharp.lsp.servers" (enum (attrNames servers)); + type = listOf (enum servers); default = defaultServers; }; }; @@ -288,12 +103,12 @@ in { }, } ''; - lsp.servers = - mapListToAttrs (name: { - inherit name; - value = servers.${name}; - }) - cfg.lsp.servers; + lsp = { + presets = genAttrs cfg.lsp.servers (_: {enable = true;}); + servers = genAttrs cfg.lsp.servers (_: { + filetypes = ["cs" "razor" "vb"]; + }); + }; }; }) (mkIf cfg.extensions.roslyn-nvim.enable {