feat(lsp): replace jedi+pyright with pyrefly+ruff

This commit is contained in:
2025-05-21 06:44:46 +02:00
parent efe14244e0
commit 543e04b2bb
4 changed files with 46 additions and 191 deletions
-164
View File
@@ -1,164 +0,0 @@
local utils = require("ow.utils")
local ERROR = vim.diagnostic.severity.ERROR
local WARN = vim.diagnostic.severity.WARN
local INFO = vim.diagnostic.severity.INFO
local HINT = vim.diagnostic.severity.HINT
local SEVERITY_MAP = {
YTT = WARN,
ANN = WARN,
ASYNC = WARN,
B = WARN,
A = WARN,
COM = WARN,
C = WARN,
DTZ = WARN,
T = WARN,
FIX = WARN,
FA = WARN,
ISC = WARN,
PIE = WARN,
PYI = WARN,
PT = WARN,
RET = WARN,
SIM = WARN,
TC = WARN,
I = WARN,
E = ERROR,
W = WARN,
DOC = WARN,
D = INFO,
F = WARN,
PLC = WARN,
PLE = ERROR,
PLR = WARN,
PLW = WARN,
UP = WARN,
RUF = WARN,
}
---@type ServerConfig
return {
enable = true,
mason = { "jedi-language-server", dependencies = { "ruff" } },
linters = {
{
cmd = {
"ruff",
"check",
"--stdin-filename=%file%",
"--output-format=json",
"-q",
"-",
},
stdin = true,
stdout = true,
json = {
lnum = "location.row",
end_lnum = "end_location.row",
col = "location.column",
end_col = "end_location.column",
code = "code",
message = "message",
callback = function(diag)
if diag.severity or not diag.code then
return
end
diag.severity = SEVERITY_MAP[diag.code:match("^(%u+)")]
end,
},
source = "ruff",
tags = {
deprecated = {
"PYI057",
"PT020",
"UP005",
"UP019",
"UP021",
"UP023",
"UP026",
"UP035",
},
unnecessary = {
"ARG001",
"ARG002",
"ARG003",
"ARG004",
"ARG005",
"F401",
"F504",
"F522",
"F811",
"F841",
"F842",
"RUF029",
"RUF059",
"RUF100",
},
},
},
},
keymaps = {
{
mode = "n",
lhs = "<leader>lf",
rhs = function()
utils.format({
cmd = {
"ruff",
"format",
"--stdin-filename=%file%",
"--quiet",
"-",
},
output = "stdout",
})
utils.format({
cmd = {
"ruff",
"check",
"--stdin-filename=%file%",
"--select=I",
"--fix",
"--quiet",
"-",
},
output = "stdout",
})
end,
},
{
mode = "x",
lhs = "<leader>lf",
rhs = function()
utils.format({
cmd = {
"ruff",
"format",
"--stdin-filename=%file%",
"--quiet",
"--range=%row_start%:%col_start%-%row_end%:%col_end%",
"-",
},
output = "stdout",
})
end,
},
},
lspconfig = {
filetypes = {
"python",
},
cmd = { "jedi-language-server" },
single_file_support = true,
init_options = {
completion = {
disableSnippets = true,
},
diagnostics = {
enable = true,
},
},
},
}
+19
View File
@@ -0,0 +1,19 @@
local util = require("lspconfig.util")
---@type ServerConfig
return {
dependencies = { "pyrefly" },
lspconfig = {
cmd = { "pyrefly", "lsp" },
filetypes = { "python" },
root_dir = util.root_pattern(
"pyrefly.toml",
"pyproject.toml",
"setup.py",
"setup.cfg",
"requirements.txt",
"Pipfile",
".git"
),
},
}
-27
View File
@@ -1,27 +0,0 @@
---@type ServerConfig
return {
enable = true,
mason = { "pyright" },
lspconfig = {
filetypes = {
"python",
},
cmd = { "pyright-langserver", "--stdio" },
single_file_support = true,
-- https://microsoft.github.io/pyright/#/settings
settings = {
python = {
analysis = {
autoSearchPaths = true,
diagnosticMode = "openFilesOnly",
useLibraryCodeForTypes = true,
typeCheckingMode = "strict",
stubPath = "stubs",
},
},
pyright = {
disableLanguageServices = true,
},
},
},
}
+27
View File
@@ -0,0 +1,27 @@
local utils = require("ow.utils")
---@type ServerConfig
return {
mason = "ruff",
keymaps = {
{
mode = "n",
lhs = "<leader>lf",
rhs = function()
vim.lsp.buf.format()
utils.format({
cmd = {
"ruff",
"check",
"--stdin-filename=%file%",
"--select=I",
"--fix",
"--quiet",
"-",
},
output = "stdout",
})
end,
},
},
}