From 543e04b2bb5be2fc0234ee6f766cbbbf172c803d Mon Sep 17 00:00:00 2001 From: Oscar Wallberg Date: Wed, 21 May 2025 06:44:46 +0200 Subject: [PATCH] feat(lsp): replace jedi+pyright with pyrefly+ruff --- lua/ow/lsp/config/jedi_language_server.lua | 164 --------------------- lua/ow/lsp/config/pyrefly.lua | 19 +++ lua/ow/lsp/config/pyright.lua | 27 ---- lua/ow/lsp/config/ruff.lua | 27 ++++ 4 files changed, 46 insertions(+), 191 deletions(-) delete mode 100644 lua/ow/lsp/config/jedi_language_server.lua create mode 100644 lua/ow/lsp/config/pyrefly.lua delete mode 100644 lua/ow/lsp/config/pyright.lua create mode 100644 lua/ow/lsp/config/ruff.lua diff --git a/lua/ow/lsp/config/jedi_language_server.lua b/lua/ow/lsp/config/jedi_language_server.lua deleted file mode 100644 index 9277175..0000000 --- a/lua/ow/lsp/config/jedi_language_server.lua +++ /dev/null @@ -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 = "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 = "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, - }, - }, - }, -} diff --git a/lua/ow/lsp/config/pyrefly.lua b/lua/ow/lsp/config/pyrefly.lua new file mode 100644 index 0000000..a07967d --- /dev/null +++ b/lua/ow/lsp/config/pyrefly.lua @@ -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" + ), + }, +} diff --git a/lua/ow/lsp/config/pyright.lua b/lua/ow/lsp/config/pyright.lua deleted file mode 100644 index d33bab6..0000000 --- a/lua/ow/lsp/config/pyright.lua +++ /dev/null @@ -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, - }, - }, - }, -} diff --git a/lua/ow/lsp/config/ruff.lua b/lua/ow/lsp/config/ruff.lua new file mode 100644 index 0000000..3d19e1e --- /dev/null +++ b/lua/ow/lsp/config/ruff.lua @@ -0,0 +1,27 @@ +local utils = require("ow.utils") + +---@type ServerConfig +return { + mason = "ruff", + keymaps = { + { + mode = "n", + lhs = "lf", + rhs = function() + vim.lsp.buf.format() + utils.format({ + cmd = { + "ruff", + "check", + "--stdin-filename=%file%", + "--select=I", + "--fix", + "--quiet", + "-", + }, + output = "stdout", + }) + end, + }, + }, +}