From 5fb1304dae629e428a4fd18a4df6f593ad9d08e7 Mon Sep 17 00:00:00 2001 From: Simon Bruder Date: Sun, 8 Nov 2020 12:17:22 +0100 Subject: [PATCH] home/neovim: Add pyls-black MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Black’s integrated vim plugin does some virtualenv wizardry that does not work on nixos. --- users/simon/modules/neovim.nix | 42 +++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/users/simon/modules/neovim.nix b/users/simon/modules/neovim.nix index e32fe58..5eb9aba 100644 --- a/users/simon/modules/neovim.nix +++ b/users/simon/modules/neovim.nix @@ -30,6 +30,41 @@ let sha256 = "1ss065b2psalli46bs3v13fhaplqydh13bg3jg3zr98wbdn70cws"; }; }; + pyls-black = pkgs.python3Packages.buildPythonPackage rec { + pname = "pyls-black"; + version = "0.4.6"; + + src = pkgs.python3Packages.fetchPypi { + inherit pname version; + sha256 = "0qsnjrpqhws7ajwg5y01fcpn1y6jc89ql61rpaknwqq5srg0ww1k"; + }; + + propagatedBuildInputs = with pkgs.python3Packages; [ + black + toml + ]; + + # circular dependency + doCheck = false; + postPatch = '' + sed -i 's/python-language-server; //' setup.cfg + ''; + }; + pyls = (pkgs.python3Packages.python-language-server.override { + providers = [ + # everything except autopep8 and yapf (conflicts with black) + "mccabe" + "pycodestyle" + "pydocstyle" + "pyflakes" + "pylint" + "rope" + ]; + }).overrideAttrs (oldAttrs: oldAttrs // { + propagatedBuildInputs = oldAttrs.propagatedBuildInputs ++ [ + pyls-black + ]; + }); in { programs.neovim = { @@ -119,7 +154,7 @@ in let g:LanguageClient_serverCommands = { \ 'rust': ['rustup', 'run', 'stable', 'rls'], \ 'go': ['${pkgs.gopls}/bin/gopls'], - \ 'python': ['${pkgs.python3Packages.python-language-server}/bin/pyls'], + \ 'python': ['${pyls}/bin/pyls'], \ 'typescript': ['${pkgs.nodePackages.javascript-typescript-langserver}/bin/javascript-typescript-stdio'], \ 'javascript': ['${pkgs.nodePackages.javascript-typescript-langserver}/bin/javascript-typescript-stdio'], \ 'haskell': ['${pkgs.haskellPackages.haskell-language-server}/bin/haskell-language-server', '--lsp'], @@ -134,7 +169,9 @@ in nnoremap K :call LanguageClient#textDocument_hover() nnoremap gd :call LanguageClient#textDocument_definition() nnoremap :call LanguageClient#textDocument_rename() - set formatexpr=LanguageClient#textDocument_rangeFormatting_sync() + nnoremap f :call LanguageClient#textDocument_formatting() + " disable since it breaks most code + "set formatexpr=LanguageClient#textDocument_rangeFormatting_sync() endif endfunction @@ -226,7 +263,6 @@ in rainbow_csv vim-openscad ]; - # TODO: add psf/black }; xdg.configFile = {