From 28edc231da9976f2127c9624c468b8a52abfc334 Mon Sep 17 00:00:00 2001 From: Minijackson Date: Wed, 16 Jun 2021 16:29:56 +0200 Subject: vim-dev: better LSP configuration --- usecases/desktop/development.nix | 162 +++++++++++++++++++++++---------------- 1 file changed, 97 insertions(+), 65 deletions(-) (limited to 'usecases/desktop') diff --git a/usecases/desktop/development.nix b/usecases/desktop/development.nix index a50ddb6..5d9697f 100644 --- a/usecases/desktop/development.nix +++ b/usecases/desktop/development.nix @@ -1,6 +1,6 @@ inputs: -{ config, pkgs, ... }: +{ config, lib, pkgs, ... }: let inherit (pkgs.unstable) @@ -15,78 +15,110 @@ let in { - users.extraUsers.minijackson.packages = with pkgs; [ - clang - clang-tools - elixir - gcc - gdb - man-pages - rr - rtags - ]; - - vim = { - extraPlugins = with vimPlugins; [ - nvim-lspconfig - rust-tools-nvim - vim-grammarous - ]; - luaConfig = builtins.readFile ../../dotfiles/vim-dev.lua; - - # TODO: make this a NixOS module - variables = { - clangd_cmd = "{ '${clang-tools}/bin/clangd', '--resource-dir=${clang}/resource-root' }"; - elixirls_cmd = "{ '${elixir_ls}/bin/elixir-ls' }"; - pyls_cmd = "{ '${python-language-server}/bin/pyls' }"; - rust_analyzer_cmd = "{ '${rust-analyzer-unwrapped}/bin/rust-analyzer' }"; + options = with lib; { + vim.lsp = mkOption { + description = '' + Configure Neovim to use these LSP servers; + ''; + # TODO: change that to submodule with cmd, settings, capabilities, etc. + type = with types; attrsOf (listOf str); + default = { }; }; }; - programs.zsh.interactiveShellInit = '' - (( $+commands[rustc] )) && fpath+="$(rustc --print sysroot)/share/zsh/site-functions" - ''; - - documentation.dev.enable = true; + config = { + users.extraUsers.minijackson.packages = with pkgs; [ + clang + clang-tools + elixir + gcc + gdb + man-pages + rr + rtags + ]; - boot.kernel.sysctl = { - # For RR - "kernel.perf_event_paranoid" = 1; - }; + vim = { + extraPlugins = with vimPlugins; [ + nvim-lspconfig + rust-tools-nvim + vim-grammarous + ]; - home-manager.users.minijackson = { config, ... }: - { - home.file.".clang-format".source = (pkgs.formats.yaml { }).generate - "clang-format.yml" - { - BasedOnStyle = "Mozilla"; - ColumnLimit = 100; - TabWidth = 4; - IndentWidth = 4; - UseTab = "ForIndentation"; - - AccessModifierOffset = -4; - AlwaysBreakAfterDefinitionReturnType = "None"; - AlwaysBreakAfterReturnType = "None"; - AlwaysBreakTemplateDeclarations = true; - BinPackArguments = false; - BinPackParameters = false; - BreakConstructorInitializers = "BeforeComma"; - Cpp11BracedListStyle = true; - DerivePointerAlignment = false; - NamespaceIndentation = "Inner"; - PenaltyBreakBeforeFirstCallParameter = 2; - PointerAlignment = "Left"; - Standard = "Latest"; - }; + variables = { + rust_analyzer_path = "'${rust-analyzer-unwrapped}/bin/rust-analyzer'"; + }; - programs.direnv = { - enable = true; - enableBashIntegration = true; - enableZshIntegration = true; + lsp = { + clangd = [ "${clang-tools}/bin/clangd" "--resource-dir=${clang}/resource-root" ]; + elixirls = [ "${elixir_ls}/bin/elixir-ls" ]; + pyls = [ "${python-language-server}/bin/pyls" ]; }; + luaConfig = with lib; let + toLua = list: "{ ${concatMapStringsSep ", " (elem: "'${escape [ "'" ] elem}'") list} }"; + lspconfigFor = name: cmd: '' + lspconfig["${name}"].setup { + capabilities = capabilities, + cmd = ${toLua cmd}, + on_attach = on_attach, + } + ''; + lspconfig = concatStringsSep + "\n" + (mapAttrsToList lspconfigFor config.vim.lsp); + in + mkMerge [ + (readFile ../../dotfiles/vim-dev.lua) + lspconfig + ]; }; - services.lorri.enable = true; + programs.zsh.interactiveShellInit = '' + (( $+commands[rustc] )) && fpath+="$(rustc --print sysroot)/share/zsh/site-functions" + ''; + + documentation.dev.enable = true; + + boot.kernel.sysctl = { + # For RR + "kernel.perf_event_paranoid" = 1; + }; + + home-manager.users.minijackson = { config, ... }: + { + home.file.".clang-format".source = (pkgs.formats.yaml { }).generate + "clang-format.yml" + { + BasedOnStyle = "Mozilla"; + ColumnLimit = 100; + TabWidth = 4; + IndentWidth = 4; + UseTab = "ForIndentation"; + + AccessModifierOffset = -4; + AlwaysBreakAfterDefinitionReturnType = "None"; + AlwaysBreakAfterReturnType = "None"; + AlwaysBreakTemplateDeclarations = true; + BinPackArguments = false; + BinPackParameters = false; + BreakConstructorInitializers = "BeforeComma"; + Cpp11BracedListStyle = true; + DerivePointerAlignment = false; + NamespaceIndentation = "Inner"; + PenaltyBreakBeforeFirstCallParameter = 2; + PointerAlignment = "Left"; + Standard = "Latest"; + }; + + programs.direnv = { + enable = true; + enableBashIntegration = true; + enableZshIntegration = true; + }; + + }; + + services.lorri.enable = true; + }; } -- cgit v1.2.3