mirror of
https://github.com/NotAShelf/nvf.git
synced 2025-09-05 18:01:32 +00:00
languages/csharp: convert module
This commit is contained in:
parent
75288f33bc
commit
453bf3eaa3
1 changed files with 66 additions and 53 deletions
|
@ -5,14 +5,14 @@
|
||||||
options,
|
options,
|
||||||
...
|
...
|
||||||
}: let
|
}: let
|
||||||
inherit (builtins) attrNames;
|
inherit (lib.generators) mkLuaInline;
|
||||||
inherit (lib.options) mkEnableOption mkOption;
|
inherit (lib.lists) flatten map;
|
||||||
inherit (lib.types) either listOf package str enum;
|
inherit (lib.options) mkEnableOption;
|
||||||
|
inherit (lib.meta) getExe;
|
||||||
inherit (lib.modules) mkIf mkMerge;
|
inherit (lib.modules) mkIf mkMerge;
|
||||||
inherit (lib.lists) isList;
|
|
||||||
inherit (lib.strings) optionalString;
|
inherit (lib.strings) optionalString;
|
||||||
inherit (lib.nvim.types) mkGrammarOption;
|
inherit (lib.nvim.attrsets) mapListToAttrs;
|
||||||
inherit (lib.nvim.lua) expToLua;
|
inherit (lib.nvim.types) mkGrammarOption mkServersOption;
|
||||||
|
|
||||||
lspKeyConfig = config.vim.lsp.mappings;
|
lspKeyConfig = config.vim.lsp.mappings;
|
||||||
lspKeyOptions = options.vim.lsp.mappings;
|
lspKeyOptions = options.vim.lsp.mappings;
|
||||||
|
@ -25,15 +25,30 @@
|
||||||
# Omnisharp doesn't have colors in popup docs for some reason, and I've also
|
# Omnisharp doesn't have colors in popup docs for some reason, and I've also
|
||||||
# seen mentions of it being way slower, so until someone finds missing
|
# seen mentions of it being way slower, so until someone finds missing
|
||||||
# functionality, this will be the default.
|
# functionality, this will be the default.
|
||||||
defaultServer = "csharp_ls";
|
defaultServers = ["csharp_ls"];
|
||||||
servers = {
|
servers = {
|
||||||
omnisharp = {
|
omnisharp = {
|
||||||
package = pkgs.omnisharp-roslyn;
|
enable = true;
|
||||||
internalFormatter = true;
|
cmd = [(getExe pkgs.omnisharp-roslyn)];
|
||||||
lspConfig = ''
|
filetypes = ["cs"];
|
||||||
lspconfig.omnisharp.setup {
|
root_dir =
|
||||||
capabilities = capabilities,
|
mkLuaInline
|
||||||
on_attach = function(client, bufnr)
|
/*
|
||||||
|
lua
|
||||||
|
*/
|
||||||
|
''
|
||||||
|
function(bufnr, on_dir)
|
||||||
|
local fname = vim.api.nvim_buf_get_name(bufnr)
|
||||||
|
on_dir(util.root_pattern('*.sln', '*.csproj', '.git')(fname))
|
||||||
|
end
|
||||||
|
'';
|
||||||
|
on_attach =
|
||||||
|
mkLuaInline
|
||||||
|
/*
|
||||||
|
lua
|
||||||
|
*/
|
||||||
|
''
|
||||||
|
function(client, bufnr)
|
||||||
default_on_attach(client, bufnr)
|
default_on_attach(client, bufnr)
|
||||||
|
|
||||||
local oe = require("omnisharp_extended")
|
local oe = require("omnisharp_extended")
|
||||||
|
@ -41,36 +56,40 @@
|
||||||
${mkLspBinding "goToType" "oe.lsp_type_definition"}
|
${mkLspBinding "goToType" "oe.lsp_type_definition"}
|
||||||
${mkLspBinding "listReferences" "oe.lsp_references"}
|
${mkLspBinding "listReferences" "oe.lsp_references"}
|
||||||
${mkLspBinding "listImplementations" "oe.lsp_implementation"}
|
${mkLspBinding "listImplementations" "oe.lsp_implementation"}
|
||||||
end,
|
end
|
||||||
cmd = ${
|
'';
|
||||||
if isList cfg.lsp.package
|
|
||||||
then expToLua cfg.lsp.package
|
|
||||||
else "{'${cfg.lsp.package}/bin/OmniSharp'}"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
'';
|
|
||||||
};
|
};
|
||||||
|
|
||||||
csharp_ls = {
|
csharp_ls = {
|
||||||
package = pkgs.csharp-ls;
|
enable = true;
|
||||||
internalFormatter = true;
|
cmd = [(getExe pkgs.csharp-ls)];
|
||||||
lspConfig = ''
|
filetypes = ["cs"];
|
||||||
local extended_handler = require("csharpls_extended").handler
|
root_dir =
|
||||||
|
mkLuaInline
|
||||||
|
/*
|
||||||
|
lua
|
||||||
|
*/
|
||||||
|
''
|
||||||
|
function(bufnr, on_dir)
|
||||||
|
local fname = vim.api.nvim_buf_get_name(bufnr)
|
||||||
|
on_dir(util.root_pattern('*.sln', '*.csproj', '.git')(fname))
|
||||||
|
end
|
||||||
|
'';
|
||||||
|
|
||||||
lspconfig.csharp_ls.setup {
|
handlers = {
|
||||||
capabilities = capabilities,
|
"textDocument/definition" =
|
||||||
on_attach = default_on_attach,
|
mkLuaInline
|
||||||
handlers = {
|
/*
|
||||||
["textDocument/definition"] = extended_handler,
|
lua
|
||||||
["textDocument/typeDefinition"] = extended_handler
|
*/
|
||||||
},
|
"require('csharpls_extended').handler";
|
||||||
cmd = ${
|
"textDocument/typeDefinition" =
|
||||||
if isList cfg.lsp.package
|
mkLuaInline
|
||||||
then expToLua cfg.lsp.package
|
/*
|
||||||
else "{'${cfg.lsp.package}/bin/csharp-ls'}"
|
lua
|
||||||
}
|
*/
|
||||||
}
|
"require('csharpls_extended').handler";
|
||||||
'';
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -92,17 +111,7 @@ in {
|
||||||
|
|
||||||
lsp = {
|
lsp = {
|
||||||
enable = mkEnableOption "C# LSP support" // {default = config.vim.lsp.enable;};
|
enable = mkEnableOption "C# LSP support" // {default = config.vim.lsp.enable;};
|
||||||
server = mkOption {
|
servers = mkServersOption "C#" servers defaultServers;
|
||||||
description = "C# LSP server to use";
|
|
||||||
type = enum (attrNames servers);
|
|
||||||
default = defaultServer;
|
|
||||||
};
|
|
||||||
|
|
||||||
package = mkOption {
|
|
||||||
description = "C# LSP server package, or the command to run as a list of strings";
|
|
||||||
type = either package (listOf str);
|
|
||||||
default = servers.${cfg.lsp.server}.package;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -114,9 +123,13 @@ in {
|
||||||
})
|
})
|
||||||
|
|
||||||
(mkIf cfg.lsp.enable {
|
(mkIf cfg.lsp.enable {
|
||||||
vim.startPlugins = extraServerPlugins.${cfg.lsp.server} or [];
|
vim.startPlugins = flatten (map (s: extraServerPlugins.${s}) cfg.lsp.servers);
|
||||||
vim.lsp.lspconfig.enable = true;
|
vim.lsp.servers =
|
||||||
vim.lsp.lspconfig.sources.csharp-lsp = servers.${cfg.lsp.server}.lspConfig;
|
mapListToAttrs (n: {
|
||||||
|
name = n;
|
||||||
|
value = servers.${n};
|
||||||
|
})
|
||||||
|
cfg.lsp.servers;
|
||||||
})
|
})
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue