pkgsets/nvim: update lsp config to use opts

This commit is contained in:
Kevin Baensch 2025-03-21 23:55:52 +01:00
parent d8f29e12b5
commit 378da9479f
Signed by: derped
GPG key ID: C0F1D326C7626543
17 changed files with 355 additions and 339 deletions

View file

@ -7,28 +7,17 @@
}@inputs: }@inputs:
lib.mkIf (lib.elem "nvim::lsp" config.machine.pkgs) { lib.mkIf (lib.elem "nvim::lsp" config.machine.pkgs) {
programs.nvim-lazy.lazyPlugins = programs.nvim-lazy.lazyPlugins = [
let
lspServers = lib.concatStrings (
map (path: import "${path}" (inputs // { inherit pkgs; })) (
fn.lst {
path = ((toString ./.) + "/lsp");
fullPath = true;
}
)
);
in
[
# Yaml schema store for yamlls # Yaml schema store for yamlls
{ {
lazy = true; lazy = true;
dir = vPlug: vPlug.SchemaStore-nvim; dir = vPlug: vPlug.SchemaStore-nvim;
} }
{ # {
dir = vPlug: vPlug.cmp-nvim-lsp; # dir = vPlug: vPlug.cmp-nvim-lsp;
lazy = true; # lazy = true;
} # }
{ {
dir = vPlug: vPlug.nvim-lspconfig; dir = vPlug: vPlug.nvim-lspconfig;
@ -39,7 +28,8 @@ lib.mkIf (lib.elem "nvim::lsp" config.machine.pkgs) {
]; ];
dependencies = ( dependencies = (
vPlug: with vPlug; [ vPlug: with vPlug; [
cmp-nvim-lsp # cmp-nvim-lsp
blink-cmp
SchemaStore-nvim SchemaStore-nvim
# coq_nvim # coq_nvim
] ]
@ -67,18 +57,33 @@ lib.mkIf (lib.elem "nvim::lsp" config.machine.pkgs) {
end end
end end
''; '';
opts = {
inlay_hints = {
enabled = true;
};
servers = lib.foldl (l: r: l // r) { } (
lib.map (path: import "${path}" (inputs // { inherit pkgs; })) (
fn.lst {
path = ((toString ./.) + "/lsp");
fullPath = true;
}
)
);
};
config = # lua config = # lua
'' ''
function() function(_, opts)
local lsp_defaults = require('lspconfig').util.default_config local lsp_defaults = require('lspconfig').util.default_config
-- Add cmp_nvim_lsp capabilities settings to lspconfig -- Add cmp_nvim_lsp capabilities settings to lspconfig
-- This should be executed before you configure any language server -- This should be executed before you configure any language server
lsp_defaults.capabilities = vim.tbl_deep_extend( -- lsp_defaults.capabilities = vim.tbl_deep_extend(
'force', -- 'force',
lsp_defaults.capabilities, -- lsp_defaults.capabilities
require('cmp_nvim_lsp').default_capabilities() -- require('cmp_nvim_lsp').default_capabilities()
) -- )
-- LspAttach is where you enable features that only work -- LspAttach is where you enable features that only work
-- if there is a language server active in the file -- if there is a language server active in the file
@ -100,38 +105,19 @@ lib.mkIf (lib.elem "nvim::lsp" config.machine.pkgs) {
end, end,
}) })
-- (Optional) Configure lua language server for neovim
local lspconfig = require('lspconfig') local lspconfig = require('lspconfig')
${lspServers} for server, config in pairs(opts.servers) do
${lib.optionalString (lib.elem "nvim::blink" config.machine.pkgs) # lua
''
-- passing config.capabilities to blink.cmp merges with the capabilities in your
-- `opts[server].capabilities, if you've defined it
config.capabilities = require('blink.cmp').get_lsp_capabilities(config.capabilities)
''
}
lspconfig[server].setup(config)
end
end end
''; '';
opts = {
inlay_hints = {
enabled = true;
};
};
} }
# {
# dir = vPlug: vPlug.lspsaga-nvim;
# config = /* lua */ ''
# function()
# require('lspsaga').setup({
# ui = {
# code_action = "󰌵",
# },
# lightbulb = {
# enable = true,
# enable_in_insert = false,
# virtual_text = false,
# },
# })
# end
# '';
# dependencies = [ "nvim-treesitter" "nvim-web-devicons" ];
# }
# {
# lazy = true;
# dir = vPlug: vPlug.nvim-web-devicons;
# }
]; ];
} }

View file

@ -5,10 +5,12 @@
... ...
}: }:
lib.optionalString (lib.elem "nvim::lsp::bash" config.machine.pkgs) # lua lib.optionalAttrs (lib.elem "nvim::lsp::bash" config.machine.pkgs) {
'' bashls = {
lspconfig.bashls.setup({ cmd = [
cmd = {"${pkgs.nodePackages.bash-language-server}/bin/bash-language-server", "start"}, "${pkgs.nodePackages.bash-language-server}/bin/bash-language-server"
filetypes = {"sh"}, "start"
}) ];
'' filetypes = [ "sh" ];
};
}

View file

@ -5,18 +5,17 @@
... ...
}: }:
lib.optionalString (lib.elem "nvim::lsp::c" config.machine.pkgs) # lua lib.optionalAttrs (lib.elem "nvim::lsp::c" config.machine.pkgs) {
'' ccls = {
lspconfig.ccls.setup { cmd = [ "${pkgs.ccls}/bin/ccls" ];
cmd = { "${pkgs.ccls}/bin/ccls" },
init_options = { init_options = {
compilationDatabaseDirectory = "build"; # compilationDatabaseDirectory = "build";
index = { index = {
threads = 0; threads = 0;
}; };
clang = { clang = {
excludeArgs = { "-frounding-math"} ; excludeArgs = [ "-frounding-math" ];
}; };
} };
} };
'' }

View file

@ -5,9 +5,11 @@
... ...
}: }:
lib.optionalString (lib.elem "nvim::lsp::emmet" config.machine.pkgs) # lua lib.optionalAttrs (lib.elem "nvim::lsp::emmet" config.machine.pkgs) {
'' emmet_language_server = {
lspconfig.emmet_language_server.setup({ cmd = [
cmd = {"${pkgs.emmet-language-server}/bin/emmet-language-server", "--stdio"} "${pkgs.emmet-language-server}/bin/emmet-language-server"
}) "--stdio"
'' ];
};
}

View file

@ -5,9 +5,8 @@
... ...
}: }:
lib.optionalString (lib.elem "nvim::lsp::go" config.machine.pkgs) # lua lib.optionalAttrs (lib.elem "nvim::lsp::go" config.machine.pkgs) {
'' gopls = {
lspconfig.gopls.setup({ cmd = [ "${pkgs.gopls}/bin/gopls" ];
cmd = {"${pkgs.gopls}/bin/gopls"} };
}) }
''

View file

@ -5,9 +5,11 @@
... ...
}: }:
lib.optionalString (lib.elem "nvim::lsp::harper" config.machine.pkgs) # lua lib.optionalAttrs (lib.elem "nvim::lsp::harper" config.machine.pkgs) {
'' harper_ls = {
lspconfig.harper_ls.setup({ cmd = [
cmd = { "${pkgs.harper}/bin/harper-ls", "--stdio" }, "${pkgs.harper}/bin/harper-ls"
}) "--stdio"
'' ];
};
}

View file

@ -5,12 +5,11 @@
... ...
}: }:
lib.optionalString (lib.elem "nvim::lsp::html" config.machine.pkgs) # lua lib.optionalAttrs (lib.elem "nvim::lsp::html" config.machine.pkgs) {
'' # local html_capabilities = vim.lsp.protocol.make_client_capabilities()
local html_capabilities = vim.lsp.protocol.make_client_capabilities() # html_capabilities.textDocument.completion.completionItem.snippetSupport = true
html_capabilities.textDocument.completion.completionItem.snippetSupport = true html = {
lspconfig.html.setup({ capabilities = _: "vim.lsp.protocol.make_client_capabilities()";
capabilities = html_capabilities, cmd = [ "${pkgs.vscode-langservers-extracted}/bin/vscode-html-language-server" ];
cmd = {"${pkgs.vscode-langservers-extracted}/bin/vscode-html-language-server"} };
}) }
''

View file

@ -5,20 +5,23 @@
... ...
}: }:
lib.optionalString (lib.elem "nvim::lsp::ltex" config.machine.pkgs) # lua lib.optionalAttrs (lib.elem "nvim::lsp::ltex" config.machine.pkgs) {
'' ltex = {
lspconfig.ltex.setup({ cmd = [ "${pkgs.ltex-ls}/bin/ltex-ls" ];
cmd = { "${pkgs.ltex-ls}/bin/ltex-ls" },
settings = { settings = {
ltex = { ltex = {
language = "de-DE", language = "de-DE";
}, };
}, };
}) on_attach =
_: # lua
''
function(client, bufnr)
vim.api.nvim_create_user_command( vim.api.nvim_create_user_command(
"LtexLang", "LtexLang",
"lua SetLtexLang(<q-args>)", "lua SetLtexLang(<q-args>)",
{ nargs = 1, desc = "Set ltex-ls language" } { nargs = 1, desc = "Set ltex-ls language" }
) )
'' end'';
};
}

View file

@ -5,22 +5,21 @@
... ...
}: }:
lib.optionalString (lib.elem "nvim::lsp::lua" config.machine.pkgs) # lua lib.optionalAttrs (lib.elem "nvim::lsp::lua" config.machine.pkgs) {
'' lua_ls = {
lspconfig.lua_ls.setup({ cmd = [ "${pkgs.lua-language-server}/bin/lua-language-server" ];
cmd = {"${pkgs.lua-language-server}/bin/lua-language-server"},
settings = { settings = {
Lua = { Lua = {
runtime = { runtime = {
version = 'LuaJIT' version = "LuaJIT";
}, };
workspace = { workspace = {
checkThirdParty = false, checkThirdParty = false;
library = { library = [
vim.env.VIMRUNTIME (_: "vim.env.VIMRUNTIME")
} ];
} };
} };
} };
}) };
'' }

View file

@ -5,9 +5,11 @@
... ...
}: }:
lib.optionalString (lib.elem "nvim::lsp::markdown" config.machine.pkgs) # lua lib.optionalAttrs (lib.elem "nvim::lsp::markdown" config.machine.pkgs) {
'' marksman = {
lspconfig.marksman.setup { cmd = [
cmd = { "${pkgs.marksman}/bin/marksman", "server" }, "${pkgs.marksman}/bin/marksman"
} "server"
'' ];
};
}

View file

@ -5,22 +5,21 @@
... ...
}: }:
lib.optionalString (lib.elem "nvim::lsp::nix-nil" config.machine.pkgs) # lua lib.optionalAttrs (lib.elem "nvim::lsp::nix-nil" config.machine.pkgs) {
'' nil_ls = {
lspconfig.nil_ls.setup({ cmd = [ "${pkgs.nil}/bin/nil" ];
cmd = {"${pkgs.nil}/bin/nil"},
settings = { settings = {
['nil'] = { "['nil']" = {
formatting = { formatting = {
command = { "${pkgs.nixfmt-rfc-style}/bin/nixfmt" } command = [ "${pkgs.nixfmt-rfc-style}/bin/nixfmt" ];
}, };
maxMemoryMB = 4069, maxMemoryMB = 4069;
-- nix = { # nix = {
-- flake = { # flake = {
-- autoEvalInputs = true # autoEvalInputs = true;
-- } # };
-- } # };
} };
} };
}) };
'' }

View file

@ -5,38 +5,42 @@
... ...
}: }:
lib.optionalString (lib.elem "nvim::lsp::nix-nixd" config.machine.pkgs) # lua lib.optionalAttrs (lib.elem "nvim::lsp::nix-nixd" config.machine.pkgs) {
'' nixd = {
lspconfig.nixd.setup({ cmd = [ "${pkgs.nixd}/bin/nixd" ];
cmd = { "${pkgs.nixd}/bin/nixd" },
settings = { settings = {
nixd = { nixd = {
-- on_init = function(client) on_init =
-- local path = client.workspace_folders[1].name _: # lua
''
function(client)
local path = client.workspace_folders[1].name
-- if path == '/path/to/project1' then if path == '/path/to/project1' then
-- client.config.settings["rust-analyzer"].checkOnSave.overrideCommand = { "cargo", "check" } client.config.settings["rust-analyzer"].checkOnSave.overrideCommand = { "cargo", "check" }
-- client.notify("workspace/didChangeConfiguration", { settings = client.config.settings }) client.notify("workspace/didChangeConfiguration", { settings = client.config.settings })
-- end end
-- return true return true
-- end, end
'';
nixpkgs = { nixpkgs = {
expr = 'import (builtins.getFlake ("git+file:///etc/nixos")).inputs.nixpkgs {}', expr = ''import (builtins.getFlake ("git+file:///etc/nixos")).inputs.nixpkgs {}'';
}, };
formatting = { formatting = {
command = { "${pkgs.nixfmt-rfc-style}/bin/nixfmt" }, command = [ "${pkgs.nixfmt-rfc-style}/bin/nixfmt" ];
}, };
options = { options = {
nixos = { nixos = {
expr = '(builtins.getFlake ("git+file:///etc/nixos")).outputs.nixosConfigurations.Lilim.options', expr = ''(builtins.getFlake ("git+file:///etc/nixos")).outputs.nixosConfigurations.Lilim.options'';
}, };
-- TODO: Find a good general expression for this. # TODO: Find a good general expression for this.
-- home_manager = { # home_manager = {
-- expr = '(builtins.getFlake ("git+file://" + toString ./.)).homeConfigurations."ruixi@k-on".options', # expr =
-- }, # "'(builtins.getFlake (\"git+file://\" + toString ./.)).homeConfigurations.\"ruixi@k-on\".options'";
}, # };
}, };
}, };
}) };
'' };
}

View file

@ -5,15 +5,17 @@
... ...
}: }:
lib.optionalString (lib.elem "nvim::lsp::php" config.machine.pkgs) # lua lib.optionalAttrs (lib.elem "nvim::lsp::php" config.machine.pkgs) {
'' phpactor = {
lspconfig.phpactor.setup({ cmd = [
cmd = {"${pkgs.phpactor}/bin/phpactor", "language-server"}, "${pkgs.phpactor}/bin/phpactor"
"language-server"
];
init_options = { init_options = {
["symfony.enabled"] = true, "[\"symfony.enabled\"]" = true;
["language_server_phpstan.enabled"] = true, "[\"language_server_phpstan.enabled\"]" = true;
["language_server_phpstan.bin"] = "${pkgs.phpPackages.phpstan}/bin/phpstan", "[\"language_server_phpstan.bin\"]" = "${pkgs.phpPackages.phpstan}/bin/phpstan";
["language_server_phpstan.level"] = 5, "[\"language_server_phpstan.level\"]" = 5;
}, };
}) };
'' }

View file

@ -5,40 +5,50 @@
... ...
}: }:
lib.optionalString (lib.elem "nvim::lsp::python" config.machine.pkgs) # lua lib.optionalAttrs (lib.elem "nvim::lsp::python" config.machine.pkgs) {
'' pyright = {
lspconfig.pyright.setup({ cmd = [
cmd = {"${pkgs.pyright}/bin/pyright-langserver", "--stdio"}, "${pkgs.pyright}/bin/pyright-langserver"
"--stdio"
];
settings = { settings = {
pyright = { pyright = {
disableOrganizeImports = true, disableOrganizeImports = true;
}, };
python = { python = {
-- analysis = { # analysis = {
-- ignore = { '*' }, # ignore = { '*' },
-- }, # },
}, };
}, };
}) };
lspconfig.ruff.setup({ ruff = {
cmd = {"${pkgs.ruff}/bin/ruff", "server", "--preview"}, cmd = [
"${pkgs.ruff}/bin/ruff"
"server"
"--preview"
];
init_options = { init_options = {
settings = { settings = {
-- Modification to any of these settings has no effect. # Modification to any of these settings has no effect.
enable = true, enable = true;
ignoreStandardLibrary = true, ignoreStandardLibrary = true;
organizeImports = true, organizeImports = true;
fixAll = true, fixAll = true;
lineLength = 120;
lint = { lint = {
enable = true, enable = true;
run = 'onType', run = "onType";
}, };
}, };
}, };
on_attach = function(client, bufnr) on_attach =
_: # lua
''
function(client, bufnr)
if client.name == 'ruff' then if client.name == 'ruff' then
client.server_capabilities.hoverProvider = false; client.server_capabilities.hoverProvider = false;
end end
end, end'';
}) };
'' }

View file

@ -5,9 +5,13 @@
... ...
}: }:
lib.optionalString (lib.elem "nvim::lsp::rust" config.machine.pkgs) # lua lib.optionalAttrs (lib.elem "nvim::lsp::rust" config.machine.pkgs) {
'' rust_analyzer = {
lspconfig.rust_analyzer.setup({ cmd = [
cmd = {"${pkgs.rustup}/bin/rustup", "run", "nightly", "rust-analyzer"} "${pkgs.rustup}/bin/rustup"
}) "run"
'' "nightly"
"rust-analyzer"
];
};
}

View file

@ -5,9 +5,11 @@
... ...
}: }:
lib.optionalString (lib.elem "nvim::lsp::typescript" config.machine.pkgs) # lua lib.optionalAttrs (lib.elem "nvim::lsp::typescript" config.machine.pkgs) {
'' ts_ls = {
lspconfig.ts_ls.setup({ cmd = [
cmd = {"${pkgs.nodePackages.typescript-language-server}/bin/typescript-language-server", "--stdio"} "${pkgs.nodePackages.typescript-language-server}/bin/typescript-language-server"
}) "--stdio"
'' ];
};
}

View file

@ -5,20 +5,22 @@
... ...
}: }:
lib.optionalString (lib.elem "nvim::lsp::yaml" config.machine.pkgs) # lua lib.optionalAttrs (lib.elem "nvim::lsp::yaml" config.machine.pkgs) {
'' yamlls = {
lspconfig.yamlls.setup({ cmd = [
cmd = { "${pkgs.yaml-language-server}/bin/yaml-language-server", "--stdio" }, "${pkgs.yaml-language-server}/bin/yaml-language-server"
"--stdio"
];
settings = { settings = {
yaml = { yaml = {
schemaStore = { schemaStore = {
-- Disable to use Store from SchemaStore-nvim plugin # Disable to use Store from SchemaStore-nvim plugin
enable = false, enable = false;
-- Avoid TypeError: Cannot read properties of undefined (reading 'length') # Avoid TypeError: Cannot read properties of undefined (reading 'length')
url = "", url = "";
}, };
schemas = require('schemastore').yaml.schemas(), schemas = _: "require('schemastore').yaml.schemas()";
}, };
}, };
}) };
'' }