feat(nvim): various lsps

This commit is contained in:
u2515h
2024-01-25 20:22:20 +01:00
parent d7e30ca465
commit 499892baac
3 changed files with 123 additions and 65 deletions

View File

@@ -109,3 +109,12 @@ lspconfig.clangd.setup({cmd = {(deps["clang-tools_path"] .. "/bin/clangd")}})
lspconfig.bashls.setup({ lspconfig.bashls.setup({
cmd = {(deps["bash-language-server_path"] .. "/bin/bash-language-server")} cmd = {(deps["bash-language-server_path"] .. "/bin/bash-language-server")}
}) })
lspconfig.pylsp.setup({
cmd = { (deps["python-lsp-server_path"] .. "/bin/pylsp") },
})
lspconfig.lua_ls.setup({
cmd = { (deps["lua-lsp_path"] .. "/bin/lua-lsp") },
})
lspconfig.yamlls.setup({
cmd = { (deps["yaml-language-server_path"] .. "/bin/yaml-language-server"), "--stdio" },
})

View File

@@ -1,6 +1,17 @@
{ config, pkgs, lib, ... }: with lib; let {
rust-analyzer = if (pkgs ? rust-analyzer-nightly && config.class ? dev) then pkgs.rust-analyzer-nightly else pkgs.rust-analyzer; config,
rust-sdk = with pkgs; if config.class ? dev then pkgs,
lib,
...
}:
with lib; let
rust-analyzer =
if (pkgs ? rust-analyzer-nightly && config.class ? dev)
then pkgs.rust-analyzer-nightly
else pkgs.rust-analyzer;
rust-sdk = with pkgs;
if config.class ? dev
then
symlinkJoin symlinkJoin
{ {
name = "nvim-fenix"; name = "nvim-fenix";
@@ -15,10 +26,13 @@
]) ])
cargo-watch cargo-watch
]; ];
} else symlinkJoin { name = "nvim-rust"; paths = [ rustc cargo rustfmt clippy cargo-watch ]; }; }
in else
{ symlinkJoin {
name = "nvim-rust";
paths = [rustc cargo rustfmt clippy cargo-watch];
};
in {
programs.neovim = { programs.neovim = {
# https://github.com/nix-community/home-manager/blob/master/modules/programs/neovim.nix # https://github.com/nix-community/home-manager/blob/master/modules/programs/neovim.nix
enable = true; enable = true;
@@ -58,7 +72,11 @@ in
cmp-calc cmp-calc
cmp-cmdline cmp-cmdline
rustaceanvim rustaceanvim
(if config.programs.neovim.package.version == "0.10.0" then throw "lsp-inlayhints-nvim may be removed" else lsp-inlayhints-nvim) # https://github.com/mrcjkb/rustaceanvim/discussions/46#discussioncomment-7620822 (
if config.programs.neovim.package.version == "0.10.0"
then throw "lsp-inlayhints-nvim may be removed"
else lsp-inlayhints-nvim
) # https://github.com/mrcjkb/rustaceanvim/discussions/46#discussioncomment-7620822
plenary-nvim plenary-nvim
crates-nvim crates-nvim
nvim-lspconfig nvim-lspconfig
@@ -66,23 +84,45 @@ in
telescope-undo-nvim telescope-undo-nvim
oil-nvim oil-nvim
]; ];
extraLuaConfig = extraLuaConfig = let
let
# tries to compute a package set required to make package resolution in lua # tries to compute a package set required to make package resolution in lua
# via deps["pkg"] work # via deps["pkg"] work
packages = file: inherit (builtins) head tail hasAttr getAttr;
let pkg = parts: pkgs: let
rem = tail parts;
subset =
if hasAttr (head parts) pkgs
then getAttr (head parts) pkgs
else throw "no attr ${name}";
in
if rem == []
then subset
else builtins.addErrorContext "${concatStringsSep "." parts}" (pkg rem subset);
getPkg = name: let parts = builtins.split "\\." name; in pkg parts pkgs;
packages = file: let
out = builtins.readFile (pkgs.runCommandLocal "extract-deps" out = builtins.readFile (pkgs.runCommandLocal "extract-deps"
{ nativeBuildInputs = [ pkgs.gnused ]; __contentAddressed = true; } '' {
nativeBuildInputs = [pkgs.gnused];
__contentAddressed = true;
} ''
sed -nr 's/.*(deps\["(.*)_path"\]).*/\2/p' ${file} | uniq > $out sed -nr 's/.*(deps\["(.*)_path"\]).*/\2/p' ${file} | uniq > $out
''); '');
names = lib.splitString "\n" out; names = lib.splitString "\n" out;
in in
filter (name: name != "") names; filter (name: name != "") names;
paths = (listToAttrs (map (name: { inherit name; value = builtins.getAttr name pkgs; }) (packages "${confDir}/*.lua"))) // { paths =
(listToAttrs (map
(name: {
inherit name;
value = getPkg name;
})
(packages "${confDir}/*.lua")))
// {
lldb = pkgs.lldb; lldb = pkgs.lldb;
rust_analyzer = rust-analyzer; rust_analyzer = rust-analyzer;
typst_lsp = pkgs.typst-lsp; typst_lsp = pkgs.typst-lsp;
inherit (pkgs.python3Packages) python-lsp-server;
inherit (pkgs.luajitPackages) lua-lsp;
inherit (pkgs.nodePackages) typescript-language-server bash-language-server; inherit (pkgs.nodePackages) typescript-language-server bash-language-server;
}; };
pathsLua = pkgs.writeTextFile { pathsLua = pkgs.writeTextFile {
@@ -102,16 +142,22 @@ in
''; '';
}; };
programs.git.ignores = [".nvim_session"]; programs.git.ignores = [".nvim_session"];
xdg.configFile."nvim/coc-settings.json".text = xdg.configFile."nvim/coc-settings.json".text = let
let preferProjectEnv = binName: alternate:
preferProjectEnv = binName: alternate: pkgs.writeShellScript "${binName}-switcher" '' pkgs.writeShellScript "${binName}-switcher" ''
if command -v ${binName}; then if command -v ${binName}; then
${binName} ''${@} ${binName} ''${@}
else else
${alternate} ''${@} ${alternate} ''${@}
fi fi
''; '';
addSDK = { name, lsp, sdk }: with pkgs; runCommandLocal name addSDK = {
name,
lsp,
sdk,
}:
with pkgs;
runCommandLocal name
{ {
nativeBuildInputs = [makeWrapper]; nativeBuildInputs = [makeWrapper];
} '' } ''
@@ -150,7 +196,6 @@ in
body = ''format!($${receiver})''; body = ''format!($${receiver})'';
description = "use receiver as format string"; description = "use receiver as format string";
scope = "expr"; scope = "expr";
}; };
"wrap { .. }" = { "wrap { .. }" = {
postfix = ["brace" "wrap"]; postfix = ["brace" "wrap"];
@@ -196,7 +241,10 @@ in
}; };
}; };
}; };
procMacro = { enable = true; attributes.enable = true; }; procMacro = {
enable = true;
attributes.enable = true;
};
serverPath = addSDK { serverPath = addSDK {
name = "rust-env"; name = "rust-env";
lsp = "${rust-analyzer}/bin/rust-analyzer"; lsp = "${rust-analyzer}/bin/rust-analyzer";

View File

@@ -239,3 +239,4 @@ lspconfig.nil_ls.setup {
require("lsp-inlayhints").setup() require("lsp-inlayhints").setup()
require("completion") require("completion")
require("rust")