diff --git a/nix/neovim-overlay.nix b/nix/neovim-overlay.nix index 3e96063..9399e65 100644 --- a/nix/neovim-overlay.nix +++ b/nix/neovim-overlay.nix @@ -128,10 +128,16 @@ with final.pkgs.lib; let asm-lsp # Assembly language server clang-tools # C/C++ language server (callPackage ./cpptools.nix {}) # C/C++ debugger from VSCode | https://github.com/microsoft/vscode-cpptools + nil # nix LSP nodePackages.bash-language-server # Bash language server lua-language-server - nil # nix LSP - ]; + ] ++ [ (pkgs.python312.withPackages (python-pkgs: [ + python-pkgs.python-lsp-server + python-pkgs.python-lsp-ruff + python-pkgs.pylsp-mypy + python-pkgs.pylsp-rope + ]))]; + in { # This is the neovim derivation # returned by the overlay diff --git a/nvim/ftplugin/python.lua b/nvim/ftplugin/python.lua new file mode 100644 index 0000000..5d04524 --- /dev/null +++ b/nvim/ftplugin/python.lua @@ -0,0 +1,36 @@ +-- Exit if the language server isn't available +if vim.fn.executable('pylsp') ~= 1 then + return +end + +local root_files = { + 'pyproject.toml', + 'setup.py', + 'setup.cfg', + 'requirements.txt', + 'Pipfile', + 'pyrightconfig.json', + '.git', +} + +vim.lsp.start({ + name = 'python-lsp-server', + cmd = { "pylsp" }, + root_dir = vim.fs.dirname(vim.fs.find(root_files, { upward = true })[1]), + capabilities = require('user.lsp').make_client_capabilities(), + filetypes = { 'python' }, + on_attach = function(client, bufnr) + require("nvim-navic").attach(client, bufnr) + require("workspace-diagnostics").populate_workspace_diagnostics(client, bufnr) + end, + settings = { + pylsp = { + plugins = { + mypy = { enabled = true, }, + rope = { enabled = true, }, + ruff = { enabled = true, }, + }, + }, + }, + single_file_support = true +})