diff --git a/lua/core/settings.lua b/lua/core/settings.lua index e89b76d90..9e55f14c4 100644 --- a/lua/core/settings.lua +++ b/lua/core/settings.lua @@ -40,6 +40,7 @@ settings["formatter_block_list"] = { settings["server_formatting_block_list"] = { clangd = true, lua_ls = true, + ruff = false, -- set to false to enable ruff formatting, see discussion #1485 ts_ls = true, } @@ -116,11 +117,12 @@ settings["lsp_inlayhints"] = false settings["lsp_deps"] = { "bashls", "clangd", + "gopls", "html", "jsonls", "lua_ls", - "pylsp", - "gopls", + "ruff", + "zuban", } -- General-purpose sources for none-ls to install during bootstrap. diff --git a/lua/modules/configs/completion/mason-lspconfig.lua b/lua/modules/configs/completion/mason-lspconfig.lua index 8ed2d1cd5..6995831d0 100644 --- a/lua/modules/configs/completion/mason-lspconfig.lua +++ b/lua/modules/configs/completion/mason-lspconfig.lua @@ -1,8 +1,6 @@ local M = {} M.setup = function() - local is_windows = require("core.global").is_windows - local lsp_deps = require("core.settings").lsp_deps local mason_registry = require("mason-registry") local mason_lspconfig = require("mason-lspconfig") @@ -118,67 +116,6 @@ please REMOVE your LSP configuration (rust_analyzer.lua) from the `servers` dire for _, pkg in ipairs(mason_registry.get_installed_package_names()) do setup_lsp_for_package(pkg) end - - -- Hook into Mason's package install event to install extra plugins for pylsp (black, ruff, rope), - -- then configure the installed package's LSP using setup_lsp_for_package. - mason_registry:on( - "package:install:success", - vim.schedule_wrap(function(pkg) - if pkg.name == "python-lsp-server" then - local venv = vim.fn.stdpath("data") .. "/mason/packages/python-lsp-server/venv" - local python = is_windows and venv .. "/Scripts/python.exe" or venv .. "/bin/python" - local black = is_windows and venv .. "/Scripts/black.exe" or venv .. "/bin/black" - local ruff = is_windows and venv .. "/Scripts/ruff.exe" or venv .. "/bin/ruff" - - require("plenary.job") - :new({ - command = python, - args = { - "-m", - "pip", - "install", - "-U", - "--disable-pip-version-check", - "python-lsp-black", - "python-lsp-ruff", - "pylsp-rope", - }, - cwd = venv, - env = { VIRTUAL_ENV = venv }, - on_exit = function() - if vim.fn.executable(black) == 1 and vim.fn.executable(ruff) == 1 then - vim.notify( - "Finished installing pylsp plugins", - vim.log.levels.INFO, - { title = "[lsp] Install Status" } - ) - else - vim.notify( - "Failed to install pylsp plugins. [Executable not found]", - vim.log.levels.ERROR, - { title = "[lsp] Install Failure" } - ) - end - end, - on_start = function() - vim.notify( - "Now installing pylsp plugins...", - vim.log.levels.INFO, - { title = "[lsp] Install Status", timeout = 6000 } - ) - end, - on_stderr = function(_, msg_stream) - if msg_stream then - vim.notify(msg_stream, vim.log.levels.ERROR, { title = "[lsp] Install Failure" }) - end - end, - }) - :start() - end - - setup_lsp_for_package(pkg) - end) - ) end return M diff --git a/lua/modules/configs/completion/servers/pylsp.lua b/lua/modules/configs/completion/servers/pylsp.lua deleted file mode 100644 index 0c98c37cb..000000000 --- a/lua/modules/configs/completion/servers/pylsp.lua +++ /dev/null @@ -1,46 +0,0 @@ --- https://github.com/neovim/nvim-lspconfig/blob/master/lua/lspconfig/configs/pylsp.lua -return { - cmd = { "pylsp" }, - filetypes = { "python" }, - settings = { - pylsp = { - plugins = { - -- Lint - ruff = { - enabled = true, - select = { - -- enable pycodestyle - "E", - -- enable pyflakes - "F", - }, - ignore = { - -- ignore E501 (line too long) - -- "E501", - -- ignore F401 (imported but unused) - -- "F401", - }, - extendSelect = { "I" }, - severities = { - -- Hint, Information, Warning, Error - F401 = "I", - E501 = "I", - }, - }, - flake8 = { enabled = false }, - pyflakes = { enabled = false }, - pycodestyle = { enabled = false }, - mccabe = { enabled = false }, - - -- Code refactor - rope = { enabled = true }, - - -- Formatting - black = { enabled = true }, - pyls_isort = { enabled = false }, - autopep8 = { enabled = false }, - yapf = { enabled = false }, - }, - }, - }, -} diff --git a/lua/modules/configs/completion/servers/ruff.lua b/lua/modules/configs/completion/servers/ruff.lua new file mode 100644 index 000000000..a4d08d594 --- /dev/null +++ b/lua/modules/configs/completion/servers/ruff.lua @@ -0,0 +1,28 @@ +-- https://github.com/neovim/nvim-lspconfig/blob/master/lsp/ruff.lua +return { + cmd = { "ruff", "server" }, + filetypes = { "python" }, + root_markers = { "pyproject.toml", "ruff.toml", ".ruff.toml", ".git" }, + + -- the following are added by nvimdots + settings = { + init_options = { + settings = { + lint = { + select = { + -- enable: pycodestyle + "E", + -- enable: pyflakes + "F", + }, + extendSelect = { + -- enable: isort + "I", + }, + -- the same line length as black + lineLength = 88, + }, + }, + }, + }, +}