mirror of
https://github.com/NotAShelf/nvf.git
synced 2025-09-06 02:11:33 +00:00
language/csharp: migration to vim.lsp.servers
This commit is contained in:
parent
b4f34299ce
commit
fa3a65025d
1 changed files with 101 additions and 49 deletions
|
@ -5,14 +5,16 @@
|
||||||
options,
|
options,
|
||||||
...
|
...
|
||||||
}: let
|
}: let
|
||||||
inherit (builtins) attrNames;
|
inherit (builtins) attrNames concatMap;
|
||||||
inherit (lib.options) mkEnableOption mkOption;
|
inherit (lib.options) mkEnableOption mkOption;
|
||||||
inherit (lib.types) either listOf package str enum;
|
inherit (lib.types) listOf enum;
|
||||||
inherit (lib.modules) mkIf mkMerge;
|
inherit (lib.modules) mkIf mkMerge;
|
||||||
inherit (lib.lists) isList;
|
inherit (lib.meta) getExe;
|
||||||
|
inherit (lib.generators) mkLuaInline;
|
||||||
inherit (lib.strings) optionalString;
|
inherit (lib.strings) optionalString;
|
||||||
inherit (lib.nvim.types) mkGrammarOption;
|
inherit (lib.nvim.types) mkGrammarOption;
|
||||||
inherit (lib.nvim.lua) expToLua;
|
inherit (lib.nvim.lua) toLuaObject;
|
||||||
|
inherit (lib.nvim.attrsets) mapListToAttrs;
|
||||||
|
|
||||||
lspKeyConfig = config.vim.lsp.mappings;
|
lspKeyConfig = config.vim.lsp.mappings;
|
||||||
lspKeyOptions = options.vim.lsp.mappings;
|
lspKeyOptions = options.vim.lsp.mappings;
|
||||||
|
@ -25,52 +27,104 @@
|
||||||
# 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;
|
cmd = mkLuaInline ''
|
||||||
internalFormatter = true;
|
{
|
||||||
lspConfig = ''
|
${toLuaObject (getExe pkgs.omnisharp-roslyn)},
|
||||||
lspconfig.omnisharp.setup {
|
'-z', -- https://github.com/OmniSharp/omnisharp-vscode/pull/4300
|
||||||
capabilities = capabilities,
|
'--hostPID',
|
||||||
on_attach = function(client, bufnr)
|
tostring(vim.fn.getpid()),
|
||||||
|
'DotNet:enablePackageRestore=false',
|
||||||
|
'--encoding',
|
||||||
|
'utf-8',
|
||||||
|
'--languageserver',
|
||||||
|
}
|
||||||
|
'';
|
||||||
|
filetypes = ["cs" "vb"];
|
||||||
|
root_markers = [".sln" ".csproj" "omnisharp.json" "function.json"];
|
||||||
|
init_options = {};
|
||||||
|
capabilities = {
|
||||||
|
workspace = {
|
||||||
|
workspaceFolders = false; # https://github.com/OmniSharp/omnisharp-roslyn/issues/909
|
||||||
|
};
|
||||||
|
};
|
||||||
|
on_attach = mkLuaInline ''
|
||||||
|
function(client, bufnr)
|
||||||
default_on_attach(client, bufnr)
|
default_on_attach(client, bufnr)
|
||||||
|
|
||||||
local oe = require("omnisharp_extended")
|
local oe = require("omnisharp_extended")
|
||||||
${mkLspBinding "goToDefinition" "oe.lsp_definition"}
|
${mkLspBinding "goToDefinition" "oe.lsp_definition"}
|
||||||
${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'}"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
'';
|
'';
|
||||||
|
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 = {
|
csharp_ls = {
|
||||||
package = pkgs.csharp-ls;
|
cmd = [(lib.getExe pkgs.csharp-ls)];
|
||||||
internalFormatter = true;
|
filetypes = ["cs"];
|
||||||
lspConfig = ''
|
root_dir = mkLuaInline ''
|
||||||
local extended_handler = require("csharpls_extended").handler
|
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
|
||||||
|
|
||||||
lspconfig.csharp_ls.setup {
|
local fname = vim.api.nvim_buf_get_name(bufnr)
|
||||||
capabilities = capabilities,
|
on_dir(find_root_pattern(fname, "%.sln$") or find_root_pattern(fname, "%.csproj$"))
|
||||||
on_attach = default_on_attach,
|
end
|
||||||
handlers = {
|
|
||||||
["textDocument/definition"] = extended_handler,
|
|
||||||
["textDocument/typeDefinition"] = extended_handler
|
|
||||||
},
|
|
||||||
cmd = ${
|
|
||||||
if isList cfg.lsp.package
|
|
||||||
then expToLua cfg.lsp.package
|
|
||||||
else "{'${cfg.lsp.package}/bin/csharp-ls'}"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
'';
|
'';
|
||||||
|
init_options = {
|
||||||
|
AutomaticWorkspaceInit = true;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -92,16 +146,10 @@ 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 = mkOption {
|
||||||
description = "C# LSP server to use";
|
description = "C# LSP server to use";
|
||||||
type = enum (attrNames servers);
|
type = listOf (enum (attrNames servers));
|
||||||
default = defaultServer;
|
default = defaultServers;
|
||||||
};
|
|
||||||
|
|
||||||
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 +162,13 @@ in {
|
||||||
})
|
})
|
||||||
|
|
||||||
(mkIf cfg.lsp.enable {
|
(mkIf cfg.lsp.enable {
|
||||||
vim.startPlugins = extraServerPlugins.${cfg.lsp.server} or [];
|
vim.startPlugins = concatMap (server: extraServerPlugins.${server}) cfg.lsp.servers;
|
||||||
vim.lsp.lspconfig.enable = true;
|
vim.lsp.servers =
|
||||||
vim.lsp.lspconfig.sources.csharp-lsp = servers.${cfg.lsp.server}.lspConfig;
|
mapListToAttrs (name: {
|
||||||
|
inherit name;
|
||||||
|
value = servers.${name};
|
||||||
|
})
|
||||||
|
cfg.lsp.servers;
|
||||||
})
|
})
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue