From f4423f18abc94efb8a95a4bb06b8e2773d0404e9 Mon Sep 17 00:00:00 2001 From: CaueAnjos <141049846+CaueAnjos@users.noreply.github.com> Date: Fri, 17 Apr 2026 13:32:47 -0300 Subject: [PATCH] lsp/presets/csharp_ls: int --- modules/plugins/lsp/presets/csharp_ls.nix | 51 +++++++++++++++++++++++ modules/plugins/lsp/presets/default.nix | 1 + 2 files changed, 52 insertions(+) create mode 100644 modules/plugins/lsp/presets/csharp_ls.nix diff --git a/modules/plugins/lsp/presets/csharp_ls.nix b/modules/plugins/lsp/presets/csharp_ls.nix new file mode 100644 index 00000000..ba0238f5 --- /dev/null +++ b/modules/plugins/lsp/presets/csharp_ls.nix @@ -0,0 +1,51 @@ +{ + config, + lib, + pkgs, + ... +}: let + inherit (lib.meta) getExe; + inherit (lib.modules) mkIf; + inherit (lib.nvim.types) mkLspPresetEnableOption; + inherit (lib.generators) mkLuaInline; + + cfg = config.vim.lsp.presets.csharp_ls; +in { + # HACK: this server should be named `csharp-ls`, but the extension `csharpls-extended-lsp-nvim` only works if it is named `csharp_ls` + options.vim.lsp.presets.csharp_ls = { + enable = mkLspPresetEnableOption "csharp_ls" "C#" []; + }; + + config = mkIf cfg.enable { + vim.lsp.servers.csharp_ls = { + cmd = mkLuaInline '' + function(dispatchers, config) + return vim.lsp.rpc.start({ '${getExe pkgs.csharp-ls}', '--features', 'razor-support' , '--features', 'metadata-uris'}, dispatchers, { + -- csharp-ls attempt to locate sln, slnx or csproj files from cwd, so set cwd to root directory. + -- If cmd_cwd is provided, use it instead. + cwd = config.cmd_cwd or config.root_dir, + env = config.cmd_env, + detached = config.detached, + }) + end + ''; + root_dir = mkLuaInline '' + function(bufnr, on_dir) + local fname = vim.api.nvim_buf_get_name(bufnr) + on_dir(util.root_pattern '*.sln'(fname) or util.root_pattern '*.slnx'(fname) or util.root_pattern '*.csproj'(fname)) + end + ''; + init_options = { + AutomaticWorkspaceInit = true; + }; + get_language_id = mkLuaInline '' + function(_, ft) + if ft == 'cs' then + return 'csharp' + end + return ft + end + ''; + }; + }; +} diff --git a/modules/plugins/lsp/presets/default.nix b/modules/plugins/lsp/presets/default.nix index d3b0bed7..abd8346d 100644 --- a/modules/plugins/lsp/presets/default.nix +++ b/modules/plugins/lsp/presets/default.nix @@ -9,6 +9,7 @@ ./ccls.nix ./clangd.nix ./clojure-lsp.nix + ./csharp_ls.nix ./cue.nix ./dart.nix ./deno.nix