mirror of
https://github.com/NotAShelf/nvf.git
synced 2025-04-15 00:58:37 +00:00
languages: convert modules to new LSP option set format
Some checks are pending
Check for typos in the source tree / check-typos (push) Waiting to run
Some checks are pending
Check for typos in the source tree / check-typos (push) Waiting to run
This commit is contained in:
parent
c0c98b66fb
commit
00ef9a69e1
5 changed files with 210 additions and 109 deletions
|
@ -4,12 +4,34 @@
|
|||
lib,
|
||||
...
|
||||
}: let
|
||||
inherit (builtins) attrNames;
|
||||
inherit (lib.options) mkEnableOption mkOption;
|
||||
inherit (lib.modules) mkIf mkMerge;
|
||||
inherit (lib.types) package;
|
||||
inherit (lib.types) enum either listOf package str;
|
||||
inherit (lib.lists) isList;
|
||||
inherit (lib.meta) getExe;
|
||||
inherit (lib.generators) mkLuaInline;
|
||||
inherit (lib.nvim.lua) expToLua toLuaObject;
|
||||
inherit (lib.nvim.languages) lspOptions;
|
||||
inherit (lib.nvim.types) mkGrammarOption;
|
||||
|
||||
cfg = config.vim.languages.assembly;
|
||||
|
||||
defaultServer = "asm_lsp";
|
||||
servers = {
|
||||
asm_lsp = {
|
||||
package = pkgs.asm-lsp;
|
||||
options = {
|
||||
capabilities = mkLuaInline "capabilities";
|
||||
on_attach = mkLuaInline "default_on_attach";
|
||||
filetypes = ["asm" "vasm"];
|
||||
cmd =
|
||||
if isList cfg.lsp.package
|
||||
then expToLua cfg.lsp.package
|
||||
else ["${getExe cfg.lsp.package}"];
|
||||
};
|
||||
};
|
||||
};
|
||||
in {
|
||||
options.vim.languages.assembly = {
|
||||
enable = mkEnableOption "Assembly support";
|
||||
|
@ -22,28 +44,46 @@ in {
|
|||
lsp = {
|
||||
enable = mkEnableOption "Assembly LSP support (asm-lsp)" // {default = config.vim.languages.enableLSP;};
|
||||
|
||||
server = mkOption {
|
||||
description = "Assembly LSP server to use";
|
||||
type = enum (attrNames servers);
|
||||
default = defaultServer;
|
||||
};
|
||||
|
||||
package = mkOption {
|
||||
type = package;
|
||||
default = pkgs.asm-lsp;
|
||||
description = "asm-lsp package";
|
||||
description = "asm-lsp LSP server package, or the command to run as a list of strings";
|
||||
example = ''[lib.getExe pkgs.asm-lsp "--quiet"]'';
|
||||
type = either package (listOf str);
|
||||
default = servers.${cfg.lsp.server}.package;
|
||||
};
|
||||
|
||||
options = mkOption {
|
||||
type = lspOptions;
|
||||
default = servers.${cfg.lsp.server}.options;
|
||||
description = ''
|
||||
LSP options for Assembly language support.
|
||||
|
||||
This option is freeform, you may add options that are not set by default
|
||||
and they will be merged into the final table passed to lspconfig.
|
||||
'';
|
||||
};
|
||||
};
|
||||
};
|
||||
config = mkIf cfg.enable (mkMerge [
|
||||
(mkIf cfg.treesitter.enable {
|
||||
vim.treesitter.enable = true;
|
||||
vim.treesitter.grammars = [cfg.treesitter.package];
|
||||
vim.treesitter = {
|
||||
enable = true;
|
||||
grammars = [cfg.treesitter.package];
|
||||
};
|
||||
})
|
||||
|
||||
(mkIf cfg.lsp.enable {
|
||||
vim.lsp.lspconfig.enable = true;
|
||||
vim.lsp.lspconfig.sources.asm-lsp = ''
|
||||
lspconfig.asm_lsp.setup {
|
||||
capabilities = capabilities,
|
||||
on_attach = default_on_attach,
|
||||
cmd = {"${cfg.lsp.package}/bin/asm-lsp"},
|
||||
}
|
||||
'';
|
||||
vim.lsp.lspconfig = {
|
||||
enable = true;
|
||||
sources.asm-lsp = ''
|
||||
lspconfig.${toLuaObject cfg.lsp.server}.setup(${toLuaObject cfg.lsp.options})
|
||||
'';
|
||||
};
|
||||
})
|
||||
]);
|
||||
}
|
||||
|
|
|
@ -7,11 +7,12 @@
|
|||
inherit (builtins) attrNames;
|
||||
inherit (lib.options) mkEnableOption mkOption;
|
||||
inherit (lib.modules) mkIf mkMerge;
|
||||
inherit (lib.types) enum either listOf package str;
|
||||
inherit (lib.lists) isList;
|
||||
inherit (lib.meta) getExe;
|
||||
inherit (lib.types) enum either listOf package str;
|
||||
inherit (lib.nvim.lua) expToLua;
|
||||
inherit (lib.nvim.languages) diagnosticsToLua;
|
||||
inherit (lib.generators) mkLuaInline;
|
||||
inherit (lib.nvim.lua) expToLua toLuaObject;
|
||||
inherit (lib.nvim.languages) diagnosticsToLua lspOptions;
|
||||
inherit (lib.nvim.types) mkGrammarOption diagnostics;
|
||||
|
||||
cfg = config.vim.languages.astro;
|
||||
|
@ -20,17 +21,16 @@
|
|||
servers = {
|
||||
astro = {
|
||||
package = pkgs.astro-language-server;
|
||||
lspConfig = ''
|
||||
lspconfig.astro.setup {
|
||||
capabilities = capabilities;
|
||||
on_attach = attach_keymaps,
|
||||
cmd = ${
|
||||
options = {
|
||||
capabilities = mkLuaInline "capabilities";
|
||||
on_attach = mkLuaInline "attach_keymaps";
|
||||
filetypes = ["astro"];
|
||||
init_options = {typescript = {};};
|
||||
cmd =
|
||||
if isList cfg.lsp.package
|
||||
then expToLua cfg.lsp.package
|
||||
else ''{"${cfg.lsp.package}/bin/astro-ls", "--stdio"}''
|
||||
}
|
||||
}
|
||||
'';
|
||||
else ["${getExe cfg.lsp.package}" "--stdio"];
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -83,8 +83,7 @@ in {
|
|||
|
||||
treesitter = {
|
||||
enable = mkEnableOption "Astro treesitter" // {default = config.vim.languages.enableTreesitter;};
|
||||
|
||||
astroPackage = mkGrammarOption pkgs "astro";
|
||||
package = mkGrammarOption pkgs "astro";
|
||||
};
|
||||
|
||||
lsp = {
|
||||
|
@ -96,6 +95,17 @@ in {
|
|||
default = defaultServer;
|
||||
};
|
||||
|
||||
options = mkOption {
|
||||
type = lspOptions;
|
||||
default = servers.${cfg.lsp.server}.options;
|
||||
description = ''
|
||||
LSP options for Astro language support.
|
||||
|
||||
This option is freeform, you may add options that are not set by default
|
||||
and they will be merged into the final table passed to lspconfig.
|
||||
'';
|
||||
};
|
||||
|
||||
package = mkOption {
|
||||
description = "Astro LSP server package, or the command to run as a list of strings";
|
||||
example = ''[lib.getExe pkgs.astro-language-server "--minify" "--stdio"]'';
|
||||
|
@ -134,12 +144,14 @@ in {
|
|||
config = mkIf cfg.enable (mkMerge [
|
||||
(mkIf cfg.treesitter.enable {
|
||||
vim.treesitter.enable = true;
|
||||
vim.treesitter.grammars = [cfg.treesitter.astroPackage];
|
||||
vim.treesitter.grammars = [cfg.treesitter.package];
|
||||
})
|
||||
|
||||
(mkIf cfg.lsp.enable {
|
||||
vim.lsp.lspconfig.enable = true;
|
||||
vim.lsp.lspconfig.sources.astro-lsp = servers.${cfg.lsp.server}.lspConfig;
|
||||
vim.lsp.lspconfig.sources.astro-lsp = ''
|
||||
lspconfig.${toLuaObject cfg.lsp.server}.setup(${toLuaObject cfg.lsp.options})
|
||||
'';
|
||||
})
|
||||
|
||||
(mkIf cfg.format.enable {
|
||||
|
|
|
@ -7,11 +7,13 @@
|
|||
inherit (builtins) attrNames;
|
||||
inherit (lib.options) mkOption mkEnableOption literalExpression;
|
||||
inherit (lib.modules) mkIf mkMerge;
|
||||
inherit (lib.types) enum either listOf package str bool;
|
||||
inherit (lib.lists) isList;
|
||||
inherit (lib.types) enum either package listOf str bool;
|
||||
inherit (lib.nvim.languages) diagnosticsToLua;
|
||||
inherit (lib.nvim.types) diagnostics mkGrammarOption;
|
||||
inherit (lib.nvim.lua) expToLua;
|
||||
inherit (lib.meta) getExe;
|
||||
inherit (lib.generators) mkLuaInline;
|
||||
inherit (lib.nvim.lua) expToLua toLuaObject;
|
||||
inherit (lib.nvim.languages) diagnosticsToLua lspOptions;
|
||||
inherit (lib.nvim.types) mkGrammarOption diagnostics;
|
||||
|
||||
cfg = config.vim.languages.bash;
|
||||
|
||||
|
@ -19,17 +21,15 @@
|
|||
servers = {
|
||||
bash-ls = {
|
||||
package = pkgs.bash-language-server;
|
||||
lspConfig = ''
|
||||
lspconfig.bashls.setup{
|
||||
capabilities = capabilities;
|
||||
on_attach = default_on_attach;
|
||||
cmd = ${
|
||||
options = {
|
||||
capabilities = mkLuaInline "capabilities";
|
||||
on_attach = mkLuaInline "default_on_attach";
|
||||
filetypes = ["bash" "sh"];
|
||||
cmd =
|
||||
if isList cfg.lsp.package
|
||||
then expToLua cfg.lsp.package
|
||||
else ''{"${cfg.lsp.package}/bin/bash-language-server", "start"}''
|
||||
};
|
||||
}
|
||||
'';
|
||||
else ["${getExe cfg.lsp.package}" "start"];
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -87,6 +87,17 @@ in {
|
|||
type = either package (listOf str);
|
||||
default = pkgs.bash-language-server;
|
||||
};
|
||||
|
||||
options = mkOption {
|
||||
type = lspOptions;
|
||||
default = servers.${cfg.lsp.server}.options;
|
||||
description = ''
|
||||
LSP options for Bash language support.
|
||||
|
||||
This option is freeform, you may add options that are not set by default
|
||||
and they will be merged into the final table passed to lspconfig.
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
format = {
|
||||
|
@ -126,7 +137,9 @@ in {
|
|||
|
||||
(mkIf cfg.lsp.enable {
|
||||
vim.lsp.lspconfig.enable = true;
|
||||
vim.lsp.lspconfig.sources.bash-lsp = servers.${cfg.lsp.server}.lspConfig;
|
||||
vim.lsp.lspconfig.sources.bash-lsp = ''
|
||||
lspconfig.${toLuaObject cfg.lsp.server}.setup(${toLuaObject cfg.lsp.options})
|
||||
'';
|
||||
})
|
||||
|
||||
(mkIf cfg.format.enable {
|
||||
|
|
|
@ -5,48 +5,62 @@
|
|||
...
|
||||
}: let
|
||||
inherit (builtins) attrNames;
|
||||
inherit (lib.lists) isList;
|
||||
inherit (lib.strings) optionalString;
|
||||
inherit (lib.options) mkEnableOption mkOption;
|
||||
inherit (lib.types) bool enum package either listOf str nullOr;
|
||||
inherit (lib.modules) mkIf mkMerge;
|
||||
inherit (lib.nvim.lua) expToLua;
|
||||
inherit (lib.options) mkEnableOption mkOption;
|
||||
inherit (lib.types) bool enum package either listOf str;
|
||||
inherit (lib.lists) isList;
|
||||
inherit (lib.generators) mkLuaInline;
|
||||
inherit (lib.nvim.lua) expToLua toLuaObject;
|
||||
inherit (lib.nvim.types) mkGrammarOption;
|
||||
inherit (lib.nvim.languages) lspOptions;
|
||||
|
||||
inherit (lib.nvim.dag) entryAfter;
|
||||
|
||||
packageToCmd = package: defaultCmd:
|
||||
if isList cfg.lsp.package
|
||||
then expToLua cfg.lsp.package
|
||||
else ''{ "${cfg.lsp.package}/bin/${defaultCmd}" }'';
|
||||
|
||||
cfg = config.vim.languages.clang;
|
||||
|
||||
packageToCmd = package: defaultCmd:
|
||||
if isList package
|
||||
then expToLua package
|
||||
else ''{ "${package}/bin/${defaultCmd}" }'';
|
||||
|
||||
defaultServer = "clangd";
|
||||
servers = {
|
||||
ccls = {
|
||||
package = pkgs.ccls;
|
||||
lspConfig = ''
|
||||
lspconfig.ccls.setup{
|
||||
capabilities = capabilities;
|
||||
on_attach=default_on_attach;
|
||||
cmd = ${packageToCmd cfg.lsp.package "ccls"};
|
||||
${optionalString (cfg.lsp.opts != null) "init_options = ${cfg.lsp.opts}"}
|
||||
}
|
||||
'';
|
||||
options = {
|
||||
capabilities = mkLuaInline "capabilities";
|
||||
on_attach = mkLuaInline "default_on_attach";
|
||||
filetypes = ["c" "cpp" "objc" "objcpp" "cuda"];
|
||||
offset_encoding = "utf-32";
|
||||
cmd =
|
||||
if isList cfg.lsp.package
|
||||
then expToLua cfg.lsp.package
|
||||
else ["${packageToCmd cfg.lsp.package "ccls"}"];
|
||||
single_file_support = false; # upstream default
|
||||
};
|
||||
};
|
||||
|
||||
clangd = {
|
||||
package = pkgs.clang-tools;
|
||||
lspConfig = ''
|
||||
local clangd_cap = capabilities
|
||||
-- use same offsetEncoding as null-ls
|
||||
clangd_cap.offsetEncoding = {"utf-16"}
|
||||
lspconfig.clangd.setup{
|
||||
capabilities = clangd_cap;
|
||||
on_attach=default_on_attach;
|
||||
cmd = ${packageToCmd cfg.lsp.package "clangd"};
|
||||
${optionalString (cfg.lsp.opts != null) "init_options = ${cfg.lsp.opts}"}
|
||||
}
|
||||
'';
|
||||
options = {
|
||||
capabilities = mkLuaInline ''
|
||||
{
|
||||
offsetEncoding = { "utf-8", "utf-16" },
|
||||
textDocument = {
|
||||
completion = {
|
||||
editsNearCursor = true
|
||||
}
|
||||
}
|
||||
'';
|
||||
on_attach = mkLuaInline "default_on_attach";
|
||||
filetypes = ["c" "cpp" "objc" "objcpp" "cuda" "proto"];
|
||||
offset_encoding = "utf-32";
|
||||
cmd =
|
||||
if isList cfg.lsp.package
|
||||
then expToLua cfg.lsp.package
|
||||
else ["${packageToCmd cfg.lsp.package "clangd"}"];
|
||||
single_file_support = false; # upstream default
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -60,6 +74,7 @@
|
|||
command = '${cfg.dap.package}/bin/lldb-dap',
|
||||
name = 'lldb'
|
||||
}
|
||||
|
||||
dap.configurations.cpp = {
|
||||
{
|
||||
name = 'Launch',
|
||||
|
@ -98,10 +113,10 @@ in {
|
|||
};
|
||||
|
||||
lsp = {
|
||||
enable = mkEnableOption "clang LSP support" // {default = config.vim.languages.enableLSP;};
|
||||
enable = mkEnableOption "C/C++ LSP support" // {default = config.vim.languages.enableLSP;};
|
||||
|
||||
server = mkOption {
|
||||
description = "The clang LSP server to use";
|
||||
description = "The C/C++ LSP server to use";
|
||||
type = enum (attrNames servers);
|
||||
default = defaultServer;
|
||||
};
|
||||
|
@ -113,10 +128,15 @@ in {
|
|||
default = servers.${cfg.lsp.server}.package;
|
||||
};
|
||||
|
||||
opts = mkOption {
|
||||
description = "Options to pass to clang LSP server";
|
||||
type = nullOr str;
|
||||
default = null;
|
||||
options = mkOption {
|
||||
type = lspOptions;
|
||||
default = servers.${cfg.lsp.server}.options;
|
||||
description = ''
|
||||
LSP options for C/C++ language support.
|
||||
|
||||
This option is freeform, you may add options that are not set by default
|
||||
and they will be merged into the final table passed to lspconfig.
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -126,11 +146,13 @@ in {
|
|||
type = bool;
|
||||
default = config.vim.languages.enableDAP;
|
||||
};
|
||||
|
||||
debugger = mkOption {
|
||||
description = "clang debugger to use";
|
||||
type = enum (attrNames debuggers);
|
||||
default = defaultDebugger;
|
||||
};
|
||||
|
||||
package = mkOption {
|
||||
description = "clang debugger package.";
|
||||
type = package;
|
||||
|
@ -151,8 +173,9 @@ in {
|
|||
|
||||
(mkIf cfg.lsp.enable {
|
||||
vim.lsp.lspconfig.enable = true;
|
||||
|
||||
vim.lsp.lspconfig.sources.clang-lsp = servers.${cfg.lsp.server}.lspConfig;
|
||||
vim.lsp.lspconfig.sources.clang-lsp = ''
|
||||
lspconfig.${toLuaObject cfg.lsp.server}.setup(${toLuaObject cfg.lsp.options})
|
||||
'';
|
||||
})
|
||||
|
||||
(mkIf cfg.dap.enable {
|
||||
|
|
|
@ -6,13 +6,14 @@
|
|||
...
|
||||
}: let
|
||||
inherit (builtins) attrNames;
|
||||
inherit (lib.options) mkEnableOption mkOption;
|
||||
inherit (lib.types) either listOf package str enum;
|
||||
inherit (lib.modules) mkIf mkMerge;
|
||||
inherit (lib.options) mkOption mkEnableOption;
|
||||
inherit (lib.types) either listOf package str enum;
|
||||
inherit (lib.lists) isList;
|
||||
inherit (lib.strings) optionalString;
|
||||
inherit (lib.generators) mkLuaInline;
|
||||
inherit (lib.nvim.types) mkGrammarOption;
|
||||
inherit (lib.nvim.lua) expToLua;
|
||||
inherit (lib.nvim.lua) expToLua toLuaObject;
|
||||
|
||||
lspKeyConfig = config.vim.lsp.mappings;
|
||||
lspKeyOptions = options.vim.lsp.mappings;
|
||||
|
@ -22,6 +23,11 @@
|
|||
in
|
||||
optionalString (key != null) "vim.keymap.set('n', '${key}', ${action}, {buffer=bufnr, noremap=true, silent=true, desc='${desc}'})";
|
||||
|
||||
packageToCmd = package: defaultCmd:
|
||||
if isList package
|
||||
then expToLua package
|
||||
else ''{ "${package}/bin/${defaultCmd}" }'';
|
||||
|
||||
# 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
|
||||
# functionality, this will be the default.
|
||||
|
@ -30,10 +36,10 @@
|
|||
omnisharp = {
|
||||
package = pkgs.omnisharp-roslyn;
|
||||
internalFormatter = true;
|
||||
lspConfig = ''
|
||||
lspconfig.omnisharp.setup {
|
||||
capabilities = capabilities,
|
||||
on_attach = function(client, bufnr)
|
||||
options = {
|
||||
capabilities = mkLuaInline "capabilities";
|
||||
on_attach = mkLuaInline ''
|
||||
function(client, bufnr)
|
||||
default_on_attach(client, bufnr)
|
||||
|
||||
local oe = require("omnisharp_extended")
|
||||
|
@ -42,35 +48,40 @@
|
|||
${mkLspBinding "listReferences" "oe.lsp_references"}
|
||||
${mkLspBinding "listImplementations" "oe.lsp_implementation"}
|
||||
end,
|
||||
cmd = ${
|
||||
'';
|
||||
filetypes = ["cs" "vb"];
|
||||
cmd =
|
||||
if isList cfg.lsp.package
|
||||
then expToLua cfg.lsp.package
|
||||
else "{'${cfg.lsp.package}/bin/OmniSharp'}"
|
||||
}
|
||||
}
|
||||
'';
|
||||
else ["${packageToCmd cfg.lsp.package "OmniSharp"}"];
|
||||
single_file_support = false; # upstream default
|
||||
init_options = {};
|
||||
handlers = {
|
||||
"textDocument/definition" = mkLuaInline "extended_handler";
|
||||
"textDocument/typeDefinition" = mkLuaInline "extended_handler";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
csharp_ls = {
|
||||
package = pkgs.csharp-ls;
|
||||
internalFormatter = true;
|
||||
lspConfig = ''
|
||||
local extended_handler = require("csharpls_extended").handler
|
||||
|
||||
lspconfig.csharp_ls.setup {
|
||||
capabilities = capabilities,
|
||||
on_attach = default_on_attach,
|
||||
handlers = {
|
||||
["textDocument/definition"] = extended_handler,
|
||||
["textDocument/typeDefinition"] = extended_handler
|
||||
},
|
||||
cmd = ${
|
||||
options = {
|
||||
capabilities = mkLuaInline "capabilities";
|
||||
on_attach = mkLuaInline "default_on_attach";
|
||||
filetypes = ["cs"];
|
||||
offset_encoding = "utf-32";
|
||||
cmd =
|
||||
if isList cfg.lsp.package
|
||||
then expToLua cfg.lsp.package
|
||||
else "{'${cfg.lsp.package}/bin/csharp-ls'}"
|
||||
}
|
||||
}
|
||||
'';
|
||||
else ["${packageToCmd cfg.lsp.package "csharp-ls"}"];
|
||||
single_file_support = false; # upstream default
|
||||
init_options = {AutomaticWorkspaceInit = true;};
|
||||
handlers = {
|
||||
"textDocument/definition" = mkLuaInline "extended_handler";
|
||||
"textDocument/typeDefinition" = mkLuaInline "extended_handler";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -116,7 +127,9 @@ in {
|
|||
(mkIf cfg.lsp.enable {
|
||||
vim.startPlugins = extraServerPlugins.${cfg.lsp.server} or [];
|
||||
vim.lsp.lspconfig.enable = true;
|
||||
vim.lsp.lspconfig.sources.csharp-lsp = servers.${cfg.lsp.server}.lspConfig;
|
||||
vim.lsp.lspconfig.sources.csharp-lsp = ''
|
||||
lspconfig.${toLuaObject cfg.lsp.server}.setup(${toLuaObject cfg.lsp.options})
|
||||
'';
|
||||
})
|
||||
]);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue