Skip to content

Commit 3e7b134

Browse files
committed
languages: csharp init with omnisharp and csharp_ls
1 parent 0aa557d commit 3e7b134

File tree

6 files changed

+179
-3
lines changed

6 files changed

+179
-3
lines changed

configuration.nix

+1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ isMaximal: {
7575
enable = isMaximal;
7676
crates.enable = isMaximal;
7777
};
78+
csharp.enable = isMaximal;
7879
};
7980

8081
visuals = {

docs/release-notes/rl-0.7.md

+11-3
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,9 @@ To migrate to `nixfmt`, simply change `vim.languages.nix.format.type` to
189189
- Add sorting function options for completion sources under
190190
[](#opt-vim.autocomplete.nvim-cmp.setupOpts.sorting.comparators)
191191

192+
- Add C# support under `vim.languages.csharp`, with support for both
193+
omnisharp-roslyn and csharp-language-server.
194+
192195
[Neovim documentation on `vim.cmd`]: https://neovim.io/doc/user/lua.html#vim.cmd()
193196

194197
- Make Neovim's configuration file entirely Lua based. This comes with a few
@@ -230,7 +233,8 @@ To migrate to `nixfmt`, simply change `vim.languages.nix.format.type` to
230233
`vim.languages.ts.extensions.ts-error-translator` to aid with Typescript
231234
development.
232235

233-
- Add [neo-tree.nvim] as an alternative file-tree plugin. It will be available under `vim.filetree.neo-tree`, similar to nvimtree.
236+
- Add [neo-tree.nvim] as an alternative file-tree plugin. It will be available
237+
under `vim.filetree.neo-tree`, similar to nvimtree.
234238

235239
- Add `nvf-print-config` & `nvf-print-config-path` helper scripts to Neovim
236240
closure. Both of those scripts have been automatically added to your PATH upon
@@ -298,5 +302,9 @@ To migrate to `nixfmt`, simply change `vim.languages.nix.format.type` to
298302

299303
[nezia1](https://github.com/nezia1):
300304

301-
- Add [biome](https://github.com/biomejs/biome) support for Typescript, CSS and Svelte. Enable them via [](#opt-vim.languages.ts.format.type), [](#opt-vim.languages.css.format.type) and [](#opt-vim.languages.svelte.format.type) respectively.
302-
- Replace [nixpkgs-fmt](https://github.com/nix-community/nixpkgs-fmt) with [nixfmt](https://github.com/NixOS/nixfmt) (nixfmt-rfc-style).
305+
- Add [biome](https://github.com/biomejs/biome) support for Typescript, CSS and
306+
Svelte. Enable them via [](#opt-vim.languages.ts.format.type),
307+
[](#opt-vim.languages.css.format.type) and
308+
[](#opt-vim.languages.svelte.format.type) respectively.
309+
- Replace [nixpkgs-fmt](https://github.com/nix-community/nixpkgs-fmt) with
310+
[nixfmt](https://github.com/NixOS/nixfmt) (nixfmt-rfc-style).

flake.lock

+34
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

+10
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,16 @@
211211
flake = false;
212212
};
213213

214+
plugin-omnisharp-extended = {
215+
url = "github:Hoffs/omnisharp-extended-lsp.nvim";
216+
flake = false;
217+
};
218+
219+
plugin-csharpls-extended = {
220+
url = "github:Decodetalkers/csharpls-extended-lsp.nvim";
221+
flake = false;
222+
};
223+
214224
# Copying/Registers
215225
plugin-registers = {
216226
url = "github:tversteeg/registers.nvim";

modules/plugins/languages/csharp.nix

+122
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
{
2+
lib,
3+
pkgs,
4+
config,
5+
options,
6+
...
7+
}: let
8+
inherit (builtins) attrNames;
9+
inherit (lib.options) mkEnableOption mkOption;
10+
inherit (lib.types) either listOf package str enum;
11+
inherit (lib.modules) mkIf mkMerge;
12+
inherit (lib.lists) isList;
13+
inherit (lib.strings) optionalString;
14+
inherit (lib.nvim.types) mkGrammarOption;
15+
inherit (lib.nvim.lua) expToLua;
16+
17+
lspKeyConfig = config.vim.lsp.mappings;
18+
lspKeyOptions = options.vim.lsp.mappings;
19+
mkLspBinding = optionName: action: let
20+
key = lspKeyConfig.${optionName};
21+
desc = lspKeyOptions.${optionName}.description;
22+
in
23+
optionalString (key != null) "vim.keymap.set('n', '${key}', ${action}, {buffer=bufnr, noremap=true, silent=true, desc='${desc}'})";
24+
25+
# Omnisharp doesn't have colors in popup docs for some reason, and I've also
26+
# seen mentions of it being way slower, so someone finds missing
27+
# functionality, this will be the default.
28+
defaultServer = "csharp_ls";
29+
servers = {
30+
omnisharp = {
31+
package = pkgs.omnisharp-roslyn;
32+
internalFormatter = true;
33+
lspConfig = ''
34+
lspconfig.omnisharp.setup {
35+
capabilities = capabilities,
36+
on_attach = function(client, bufnr)
37+
default_on_attach(client, bufnr)
38+
39+
local oe = require("omnisharp_extended")
40+
${mkLspBinding "goToDefinition" "oe.lsp_definition"}
41+
${mkLspBinding "goToType" "oe.lsp_type_definition"}
42+
${mkLspBinding "listReferences" "oe.lsp_references"}
43+
${mkLspBinding "listImplementations" "oe.lsp_implementation"}
44+
end,
45+
cmd = ${
46+
if isList cfg.lsp.package
47+
then expToLua cfg.lsp.package
48+
else "{'${cfg.lsp.package}/bin/OmniSharp'}"
49+
}
50+
}
51+
'';
52+
};
53+
54+
csharp_ls = {
55+
package = pkgs.csharp-ls;
56+
internalFormatter = true;
57+
lspConfig = ''
58+
local extended_handler = require("csharpls_extended").handler
59+
60+
lspconfig.csharp_ls.setup {
61+
capabilities = capabilities,
62+
on_attach = default_on_attach,
63+
handlers = {
64+
["textDocument/definition"] = extended_handler,
65+
["textDocument/typeDefinition"] = extended_handler
66+
},
67+
cmd = ${
68+
if isList cfg.lsp.package
69+
then expToLua cfg.lsp.package
70+
else "{'${cfg.lsp.package}/bin/csharp-ls'}"
71+
}
72+
}
73+
'';
74+
};
75+
};
76+
77+
extraServerPlugins = {
78+
omnisharp = ["omnisharp-extended"];
79+
csharp_ls = ["csharpls-extended"];
80+
};
81+
82+
cfg = config.vim.languages.csharp;
83+
in {
84+
options = {
85+
vim.languages.csharp = {
86+
enable = mkEnableOption "C# language support";
87+
88+
treesitter = {
89+
enable = mkEnableOption "C# treesitter" // {default = config.vim.languages.enableTreesitter;};
90+
package = mkGrammarOption pkgs "c-sharp";
91+
};
92+
93+
lsp = {
94+
enable = mkEnableOption "C# LSP support" // {default = config.vim.languages.enableLSP;};
95+
server = mkOption {
96+
description = "C# LSP server to use";
97+
type = enum (attrNames servers);
98+
default = defaultServer;
99+
};
100+
101+
package = mkOption {
102+
description = "C# LSP server package, or the command to run as a list of strings";
103+
type = either package (listOf str);
104+
default = servers.${cfg.lsp.server}.package;
105+
};
106+
};
107+
};
108+
};
109+
110+
config = mkIf cfg.enable (mkMerge [
111+
(mkIf cfg.treesitter.enable {
112+
vim.treesitter.enable = true;
113+
vim.treesitter.grammars = [cfg.treesitter.package];
114+
})
115+
116+
(mkIf cfg.lsp.enable {
117+
vim.startPlugins = extraServerPlugins.${cfg.lsp.server} or [];
118+
vim.lsp.lspconfig.enable = true;
119+
vim.lsp.lspconfig.sources.csharp-lsp = servers.${cfg.lsp.server}.lspConfig;
120+
})
121+
]);
122+
}

modules/plugins/languages/default.nix

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ in {
2828
./ts.nix
2929
./typst.nix
3030
./zig.nix
31+
./csharp.nix
3132
];
3233

3334
options.vim.languages = {

0 commit comments

Comments
 (0)