diff options
author | Minijackson <minijackson@riseup.net> | 2021-06-16 16:29:56 +0200 |
---|---|---|
committer | Minijackson <minijackson@riseup.net> | 2021-06-16 16:31:51 +0200 |
commit | 28edc231da9976f2127c9624c468b8a52abfc334 (patch) | |
tree | f5870f21400127a17c01c698fb465ca087a22768 | |
parent | 527a4d67f5957c1cc5a8e501a577819fcc52d919 (diff) | |
download | nixos-config-reborn-28edc231da9976f2127c9624c468b8a52abfc334.tar.gz nixos-config-reborn-28edc231da9976f2127c9624c468b8a52abfc334.zip |
vim-dev: better LSP configuration
-rw-r--r-- | dotfiles/vim-dev.lua | 16 | ||||
-rw-r--r-- | usecases/desktop/development.nix | 162 |
2 files changed, 97 insertions, 81 deletions
diff --git a/dotfiles/vim-dev.lua b/dotfiles/vim-dev.lua index 0422b2f..5c971e3 100644 --- a/dotfiles/vim-dev.lua +++ b/dotfiles/vim-dev.lua | |||
@@ -46,22 +46,6 @@ capabilities.textDocument.completion.completionItem.resolveSupport = { | |||
46 | } | 46 | } |
47 | } | 47 | } |
48 | 48 | ||
49 | function setup_lsp_with(servers) | ||
50 | for _, server in ipairs(servers) do | ||
51 | lspconfig[server].setup { | ||
52 | capabilities = capabilities, | ||
53 | cmd = vim.g[server .. "_cmd"], | ||
54 | on_attach = on_attach, | ||
55 | } | ||
56 | end | ||
57 | end | ||
58 | |||
59 | setup_lsp_with { | ||
60 | "clangd", | ||
61 | "elixirls", | ||
62 | "pyls", | ||
63 | } | ||
64 | |||
65 | require("rust-tools").setup { | 49 | require("rust-tools").setup { |
66 | server = { | 50 | server = { |
67 | cmd = { vim.g.rust_analyzer_path }, | 51 | cmd = { vim.g.rust_analyzer_path }, |
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 @@ | |||
1 | inputs: | 1 | inputs: |
2 | 2 | ||
3 | { config, pkgs, ... }: | 3 | { config, lib, pkgs, ... }: |
4 | 4 | ||
5 | let | 5 | let |
6 | inherit (pkgs.unstable) | 6 | inherit (pkgs.unstable) |
@@ -15,78 +15,110 @@ let | |||
15 | 15 | ||
16 | in | 16 | in |
17 | { | 17 | { |
18 | users.extraUsers.minijackson.packages = with pkgs; [ | 18 | options = with lib; { |
19 | clang | 19 | vim.lsp = mkOption { |
20 | clang-tools | 20 | description = '' |
21 | elixir | 21 | Configure Neovim to use these LSP servers; |
22 | gcc | 22 | ''; |
23 | gdb | 23 | # TODO: change that to submodule with cmd, settings, capabilities, etc. |
24 | man-pages | 24 | type = with types; attrsOf (listOf str); |
25 | rr | 25 | default = { }; |
26 | rtags | ||
27 | ]; | ||
28 | |||
29 | vim = { | ||
30 | extraPlugins = with vimPlugins; [ | ||
31 | nvim-lspconfig | ||
32 | rust-tools-nvim | ||
33 | vim-grammarous | ||
34 | ]; | ||
35 | luaConfig = builtins.readFile ../../dotfiles/vim-dev.lua; | ||
36 | |||
37 | # TODO: make this a NixOS module | ||
38 | variables = { | ||
39 | clangd_cmd = "{ '${clang-tools}/bin/clangd', '--resource-dir=${clang}/resource-root' }"; | ||
40 | elixirls_cmd = "{ '${elixir_ls}/bin/elixir-ls' }"; | ||
41 | pyls_cmd = "{ '${python-language-server}/bin/pyls' }"; | ||
42 | rust_analyzer_cmd = "{ '${rust-analyzer-unwrapped}/bin/rust-analyzer' }"; | ||
43 | }; | 26 | }; |
44 | }; | 27 | }; |
45 | 28 | ||
46 | programs.zsh.interactiveShellInit = '' | 29 | config = { |
47 | (( $+commands[rustc] )) && fpath+="$(rustc --print sysroot)/share/zsh/site-functions" | 30 | users.extraUsers.minijackson.packages = with pkgs; [ |
48 | ''; | 31 | clang |
49 | 32 | clang-tools | |
50 | documentation.dev.enable = true; | 33 | elixir |
34 | gcc | ||
35 | gdb | ||
36 | man-pages | ||
37 | rr | ||
38 | rtags | ||
39 | ]; | ||
51 | 40 | ||
52 | boot.kernel.sysctl = { | 41 | vim = { |
53 | # For RR | 42 | extraPlugins = with vimPlugins; [ |
54 | "kernel.perf_event_paranoid" = 1; | 43 | nvim-lspconfig |
55 | }; | 44 | rust-tools-nvim |
45 | vim-grammarous | ||
46 | ]; | ||
56 | 47 | ||
57 | home-manager.users.minijackson = { config, ... }: | 48 | variables = { |
58 | { | 49 | rust_analyzer_path = "'${rust-analyzer-unwrapped}/bin/rust-analyzer'"; |
59 | home.file.".clang-format".source = (pkgs.formats.yaml { }).generate | 50 | }; |
60 | "clang-format.yml" | ||
61 | { | ||
62 | BasedOnStyle = "Mozilla"; | ||
63 | ColumnLimit = 100; | ||
64 | TabWidth = 4; | ||
65 | IndentWidth = 4; | ||
66 | UseTab = "ForIndentation"; | ||
67 | |||
68 | AccessModifierOffset = -4; | ||
69 | AlwaysBreakAfterDefinitionReturnType = "None"; | ||
70 | AlwaysBreakAfterReturnType = "None"; | ||
71 | AlwaysBreakTemplateDeclarations = true; | ||
72 | BinPackArguments = false; | ||
73 | BinPackParameters = false; | ||
74 | BreakConstructorInitializers = "BeforeComma"; | ||
75 | Cpp11BracedListStyle = true; | ||
76 | DerivePointerAlignment = false; | ||
77 | NamespaceIndentation = "Inner"; | ||
78 | PenaltyBreakBeforeFirstCallParameter = 2; | ||
79 | PointerAlignment = "Left"; | ||
80 | Standard = "Latest"; | ||
81 | }; | ||
82 | 51 | ||
83 | programs.direnv = { | 52 | lsp = { |
84 | enable = true; | 53 | clangd = [ "${clang-tools}/bin/clangd" "--resource-dir=${clang}/resource-root" ]; |
85 | enableBashIntegration = true; | 54 | elixirls = [ "${elixir_ls}/bin/elixir-ls" ]; |
86 | enableZshIntegration = true; | 55 | pyls = [ "${python-language-server}/bin/pyls" ]; |
87 | }; | 56 | }; |
88 | 57 | ||
58 | luaConfig = with lib; let | ||
59 | toLua = list: "{ ${concatMapStringsSep ", " (elem: "'${escape [ "'" ] elem}'") list} }"; | ||
60 | lspconfigFor = name: cmd: '' | ||
61 | lspconfig["${name}"].setup { | ||
62 | capabilities = capabilities, | ||
63 | cmd = ${toLua cmd}, | ||
64 | on_attach = on_attach, | ||
65 | } | ||
66 | ''; | ||
67 | lspconfig = concatStringsSep | ||
68 | "\n" | ||
69 | (mapAttrsToList lspconfigFor config.vim.lsp); | ||
70 | in | ||
71 | mkMerge [ | ||
72 | (readFile ../../dotfiles/vim-dev.lua) | ||
73 | lspconfig | ||
74 | ]; | ||
89 | }; | 75 | }; |
90 | 76 | ||
91 | services.lorri.enable = true; | 77 | programs.zsh.interactiveShellInit = '' |
78 | (( $+commands[rustc] )) && fpath+="$(rustc --print sysroot)/share/zsh/site-functions" | ||
79 | ''; | ||
80 | |||
81 | documentation.dev.enable = true; | ||
82 | |||
83 | boot.kernel.sysctl = { | ||
84 | # For RR | ||
85 | "kernel.perf_event_paranoid" = 1; | ||
86 | }; | ||
87 | |||
88 | home-manager.users.minijackson = { config, ... }: | ||
89 | { | ||
90 | home.file.".clang-format".source = (pkgs.formats.yaml { }).generate | ||
91 | "clang-format.yml" | ||
92 | { | ||
93 | BasedOnStyle = "Mozilla"; | ||
94 | ColumnLimit = 100; | ||
95 | TabWidth = 4; | ||
96 | IndentWidth = 4; | ||
97 | UseTab = "ForIndentation"; | ||
98 | |||
99 | AccessModifierOffset = -4; | ||
100 | AlwaysBreakAfterDefinitionReturnType = "None"; | ||
101 | AlwaysBreakAfterReturnType = "None"; | ||
102 | AlwaysBreakTemplateDeclarations = true; | ||
103 | BinPackArguments = false; | ||
104 | BinPackParameters = false; | ||
105 | BreakConstructorInitializers = "BeforeComma"; | ||
106 | Cpp11BracedListStyle = true; | ||
107 | DerivePointerAlignment = false; | ||
108 | NamespaceIndentation = "Inner"; | ||
109 | PenaltyBreakBeforeFirstCallParameter = 2; | ||
110 | PointerAlignment = "Left"; | ||
111 | Standard = "Latest"; | ||
112 | }; | ||
113 | |||
114 | programs.direnv = { | ||
115 | enable = true; | ||
116 | enableBashIntegration = true; | ||
117 | enableZshIntegration = true; | ||
118 | }; | ||
119 | |||
120 | }; | ||
121 | |||
122 | services.lorri.enable = true; | ||
123 | }; | ||
92 | } | 124 | } |