From a9bf27f1ec2ff4b53937ef6971f8395d3d9c5b2a Mon Sep 17 00:00:00 2001 From: Minijackson Date: Sat, 11 Mar 2023 16:29:57 +0100 Subject: development: additional tools --- dotfiles/vim/lua/vim-dev.lua | 32 ++++-- usecases/desktop/development.nix | 229 ++++++++++++++++++++++----------------- 2 files changed, 152 insertions(+), 109 deletions(-) diff --git a/dotfiles/vim/lua/vim-dev.lua b/dotfiles/vim/lua/vim-dev.lua index e1c38db..c8bcba7 100644 --- a/dotfiles/vim/lua/vim-dev.lua +++ b/dotfiles/vim/lua/vim-dev.lua @@ -31,7 +31,7 @@ local function on_attach(client, bufnr) -- Capability specific if client.server_capabilities.documentFormattingProvider then - vim.keymap.set("n", "sf", vim.lsp.buf.formatting, desc(opts, "Format buffer")) + vim.keymap.set("n", "sf", vim.lsp.buf.format, desc(opts, "Format buffer")) end -- Rust specific @@ -75,21 +75,31 @@ require("refactoring").setup {} -- Null LSP -require("null-ls").setup({ +local null_ls = require("null-ls") + +null_ls.setup({ sources = { - require("null-ls").builtins.code_actions.gitrebase, - require("null-ls").builtins.code_actions.gitsigns, - require("null-ls").builtins.code_actions.refactoring.with { + null_ls.builtins.code_actions.gitrebase, + null_ls.builtins.code_actions.gitsigns, + null_ls.builtins.code_actions.refactoring.with { filetypes = { "typescript", "javascript", "lua", "c", "cpp", "go", "python", "java", "php", "ruby" }, }, - require("null-ls").builtins.code_actions.shellcheck, - require("null-ls").builtins.code_actions.statix, - require("null-ls").builtins.diagnostics.deadnix, - require("null-ls").builtins.diagnostics.shellcheck, - require("null-ls").builtins.diagnostics.statix, - require("null-ls").builtins.diagnostics.vale.with { + null_ls.builtins.code_actions.shellcheck, + null_ls.builtins.code_actions.statix, + + null_ls.builtins.diagnostics.deadnix, + null_ls.builtins.diagnostics.ruff, + null_ls.builtins.diagnostics.shellcheck, + null_ls.builtins.diagnostics.statix, + null_ls.builtins.diagnostics.vale.with { filetypes = { "markdown", "pandoc", "tex", "asciidoc" }, }, + + null_ls.builtins.formatting.alejandra, + null_ls.builtins.formatting.black, + null_ls.builtins.formatting.isort, + null_ls.builtins.formatting.shfmt, + null_ls.builtins.formatting.taplo, }, on_attach = on_attach, }) diff --git a/usecases/desktop/development.nix b/usecases/desktop/development.nix index d15afec..bc936b8 100644 --- a/usecases/desktop/development.nix +++ b/usecases/desktop/development.nix @@ -1,9 +1,11 @@ -inputs: - -{ config, lib, pkgs, ... }: - -let - inherit (pkgs.unstable) +inputs: { + config, + lib, + pkgs, + ... +}: let + inherit + (pkgs.unstable) clang clang-tools elixir_ls @@ -11,67 +13,82 @@ let marksman rust-analyzer-unwrapped lua-language-server - - vimPlugins; - - inherit (pkgs.unstable.python3Packages) python-lsp-server; - - luaFormat = inputs.self.lib.generators.lua { }; - -in -{ + vimPlugins + ; + + pylsp = with pkgs.unstable.python3Packages; + python-lsp-server.overrideAttrs (old: { + propagatedBuildInputs = + old.propagatedBuildInputs + ++ python-lsp-server.passthru.optional-dependencies.all; + }); + + luaFormat = inputs.self.lib.generators.lua {}; +in { imports = [ (import ./development/latex.nix inputs) ]; - options = with lib; with luaFormat.lib; { + options = with lib; + with luaFormat.lib; { vim.lsp = mkOption { description = '' Configure Neovim to use these LSP servers; ''; - type = with types; attrsOf (submodule { - freeformType = luaFormat.type; - - options = { - capabilities = mkOption { - default = mkRaw "capabilities"; - }; - cmd = mkOption { - type = with types; listOf str; - }; - on_attach = mkOption { - default = mkRaw "on_attach"; + type = with types; + attrsOf (submodule { + freeformType = luaFormat.type; + + options = { + capabilities = mkOption { + default = mkRaw "capabilities"; + }; + cmd = mkOption { + type = with types; listOf str; + }; + on_attach = mkOption { + default = mkRaw "on_attach"; + }; }; - }; - }); - default = { }; + }); + default = {}; }; }; config = { # TODO: add cargo-info - users.extraUsers.minijackson.packages = with pkgs.unstable; [ - bintools - bacon - clang - clang-tools - diffoscopeMinimal - elixir - gcc - gdb - graphviz - man-pages - python3Packages.ipython - rr - rustup - watchexec - - # Python - black - python3Packages.isort - python3Packages.mypy - python3Packages.tox - ]; + users.extraUsers.minijackson.packages = with pkgs.unstable; + [ + bintools + bacon + clang + clang-tools + diffoscopeMinimal + elixir + gcc + gdb + graphviz + man-pages + python3Packages.ipython + rr + rustup + watchexec + + shfmt + taplo + + # Python + black + python3Packages.isort + python3Packages.mypy + python3Packages.tox + # TODO: how to install into pylsp's python env? + # python-lsp-black + # pyls-isort + # pylsp-mypy + + ruff + ]; vim = { extraPlugins = with vimPlugins; [ @@ -91,28 +108,45 @@ in }; lsp = { - elixirls.cmd = [ "${elixir_ls}/bin/elixir-ls" ]; - hls.cmd = [ "${haskell-language-server}/bin/haskell-language-server" "--lsp" ]; + elixirls.cmd = ["${elixir_ls}/bin/elixir-ls"]; + hls.cmd = ["${haskell-language-server}/bin/haskell-language-server" "--lsp"]; lua_ls = { - cmd = [ "${lua-language-server}/bin/lua-language-server" ]; - settings.Lua.completion.callSnippet = "Replace"; + cmd = ["${lua-language-server}/bin/lua-language-server"]; + settings.Lua = { + completion.callSnippet = "Replace"; + telemetry.enable = false; + }; + }; + marksman.cmd = ["${marksman}/bin/marksman"]; + pylsp = { + cmd = ["${pylsp}/bin/pylsp"]; + settings.pylsp.plugins = { + autopep8.enabled = false; + flake8.ignore = ["E501"]; + pycodestyle.ignore = ["E501"]; + yapf.enabled = false; + + # See TODO above + #black.enabled = true; + #isort.enabled = true; + #mypy.enabled = true; + }; }; - marksman.cmd = [ "${marksman}/bin/marksman" ]; - pylsp.cmd = [ "${python-lsp-server}/bin/pylsp" ]; }; luaConfig = with lib; let toLua = luaFormat.generate; lspconfigFor = name: settings: "lspconfig['${name}'].setup ${toLua settings}"; - lspconfig = concatStringsSep + lspconfig = + concatStringsSep "\n" (mapAttrsToList lspconfigFor config.vim.lsp); in - mkMerge [ - "require('vim-dev')" - "local lspconfig = require('lspconfig')" - lspconfig - ]; + mkMerge [ + "require('vim-dev')" + "local lspconfig = require('lspconfig')" + lspconfig + ]; }; programs.zsh.interactiveShellInit = '' @@ -128,47 +162,46 @@ in "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"; - - AlignAfterOpenBracket = "AlwaysBreak"; - 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"; - }; + 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"; + + AlignAfterOpenBracket = "AlwaysBreak"; + 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; + programs.direnv = { + enable = true; + enableBashIntegration = true; + enableZshIntegration = true; - nix-direnv.enable = true; - }; + nix-direnv.enable = true; }; + }; nixpkgs.overlays = [ (self: super: { inherit (self.unstable) nix-direnv direnv; }) ]; - }; } -- cgit v1.2.3