Skip to content

Commit cebd96e

Browse files
authored
feat(python-lsp)!: replace the old pylsp with zuban and ruff (#1528)
1 parent f23229b commit cebd96e

File tree

4 files changed

+32
-111
lines changed

4 files changed

+32
-111
lines changed

lua/core/settings.lua

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ settings["formatter_block_list"] = {
4040
settings["server_formatting_block_list"] = {
4141
clangd = true,
4242
lua_ls = true,
43+
ruff = false, -- set to false to enable ruff formatting, see discussion #1485
4344
ts_ls = true,
4445
}
4546

@@ -116,11 +117,12 @@ settings["lsp_inlayhints"] = false
116117
settings["lsp_deps"] = {
117118
"bashls",
118119
"clangd",
120+
"gopls",
119121
"html",
120122
"jsonls",
121123
"lua_ls",
122-
"pylsp",
123-
"gopls",
124+
"ruff",
125+
"zuban",
124126
}
125127

126128
-- General-purpose sources for none-ls to install during bootstrap.

lua/modules/configs/completion/mason-lspconfig.lua

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
local M = {}
22

33
M.setup = function()
4-
local is_windows = require("core.global").is_windows
5-
64
local lsp_deps = require("core.settings").lsp_deps
75
local mason_registry = require("mason-registry")
86
local mason_lspconfig = require("mason-lspconfig")
@@ -118,67 +116,6 @@ please REMOVE your LSP configuration (rust_analyzer.lua) from the `servers` dire
118116
for _, pkg in ipairs(mason_registry.get_installed_package_names()) do
119117
setup_lsp_for_package(pkg)
120118
end
121-
122-
-- Hook into Mason's package install event to install extra plugins for pylsp (black, ruff, rope),
123-
-- then configure the installed package's LSP using setup_lsp_for_package.
124-
mason_registry:on(
125-
"package:install:success",
126-
vim.schedule_wrap(function(pkg)
127-
if pkg.name == "python-lsp-server" then
128-
local venv = vim.fn.stdpath("data") .. "/mason/packages/python-lsp-server/venv"
129-
local python = is_windows and venv .. "/Scripts/python.exe" or venv .. "/bin/python"
130-
local black = is_windows and venv .. "/Scripts/black.exe" or venv .. "/bin/black"
131-
local ruff = is_windows and venv .. "/Scripts/ruff.exe" or venv .. "/bin/ruff"
132-
133-
require("plenary.job")
134-
:new({
135-
command = python,
136-
args = {
137-
"-m",
138-
"pip",
139-
"install",
140-
"-U",
141-
"--disable-pip-version-check",
142-
"python-lsp-black",
143-
"python-lsp-ruff",
144-
"pylsp-rope",
145-
},
146-
cwd = venv,
147-
env = { VIRTUAL_ENV = venv },
148-
on_exit = function()
149-
if vim.fn.executable(black) == 1 and vim.fn.executable(ruff) == 1 then
150-
vim.notify(
151-
"Finished installing pylsp plugins",
152-
vim.log.levels.INFO,
153-
{ title = "[lsp] Install Status" }
154-
)
155-
else
156-
vim.notify(
157-
"Failed to install pylsp plugins. [Executable not found]",
158-
vim.log.levels.ERROR,
159-
{ title = "[lsp] Install Failure" }
160-
)
161-
end
162-
end,
163-
on_start = function()
164-
vim.notify(
165-
"Now installing pylsp plugins...",
166-
vim.log.levels.INFO,
167-
{ title = "[lsp] Install Status", timeout = 6000 }
168-
)
169-
end,
170-
on_stderr = function(_, msg_stream)
171-
if msg_stream then
172-
vim.notify(msg_stream, vim.log.levels.ERROR, { title = "[lsp] Install Failure" })
173-
end
174-
end,
175-
})
176-
:start()
177-
end
178-
179-
setup_lsp_for_package(pkg)
180-
end)
181-
)
182119
end
183120

184121
return M

lua/modules/configs/completion/servers/pylsp.lua

Lines changed: 0 additions & 46 deletions
This file was deleted.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
-- https://github.com/neovim/nvim-lspconfig/blob/master/lsp/ruff.lua
2+
return {
3+
cmd = { "ruff", "server" },
4+
filetypes = { "python" },
5+
root_markers = { "pyproject.toml", "ruff.toml", ".ruff.toml", ".git" },
6+
7+
-- the following are added by nvimdots
8+
settings = {
9+
init_options = {
10+
settings = {
11+
lint = {
12+
select = {
13+
-- enable: pycodestyle
14+
"E",
15+
-- enable: pyflakes
16+
"F",
17+
},
18+
extendSelect = {
19+
-- enable: isort
20+
"I",
21+
},
22+
-- the same line length as black
23+
lineLength = 88,
24+
},
25+
},
26+
},
27+
},
28+
}

0 commit comments

Comments
 (0)