From b56d703662ed0dfe772699808d9c60aea993e210 Mon Sep 17 00:00:00 2001 From: ray Date: Sun, 7 Dec 2025 23:48:11 +0000 Subject: [PATCH] fix ruff/Ruff duplication --- lua/keymaps.lua | 13 +++++++++++++ lua/plugins/lsp.lua | 10 ++++++++++ lua/plugins/mason-tool-installer.lua | 4 ++-- lua/plugins/none-ls.lua | 17 +++++++++++++---- lua/plugins/nvim-lint.lua | 14 ++++++++++++-- 5 files changed, 50 insertions(+), 8 deletions(-) diff --git a/lua/keymaps.lua b/lua/keymaps.lua index fbbbcc5..10db467 100644 --- a/lua/keymaps.lua +++ b/lua/keymaps.lua @@ -33,3 +33,16 @@ map('n', 'K', function() vim.cmd("normal! K") end end, { desc = 'Hover/Help (LSP or keywordprg fallback)', silent = true }) + +-- Diagnostic keymaps +map('n', 'xx', vim.diagnostic.setloclist, { desc = 'Show buffer diagnostics in location list', silent = true }) +map('n', 'xX', vim.diagnostic.setqflist, { desc = 'Show all diagnostics in quickfix', silent = true }) +map('n', 'xe', function() + vim.diagnostic.setloclist({ severity = vim.diagnostic.severity.ERROR }) +end, { desc = 'Show buffer errors in location list', silent = true }) +map('n', 'xE', function() + vim.diagnostic.setqflist({ severity = vim.diagnostic.severity.ERROR }) +end, { desc = 'Show all errors in quickfix', silent = true }) +map('n', '[d', vim.diagnostic.goto_prev, { desc = 'Go to previous diagnostic', silent = true }) +map('n', ']d', vim.diagnostic.goto_next, { desc = 'Go to next diagnostic', silent = true }) +map('n', 'xd', vim.diagnostic.open_float, { desc = 'Show diagnostic under cursor', silent = true }) diff --git a/lua/plugins/lsp.lua b/lua/plugins/lsp.lua index b9b8eac..eae03ed 100644 --- a/lua/plugins/lsp.lua +++ b/lua/plugins/lsp.lua @@ -7,6 +7,16 @@ return { config = function() local capabilities = require("cmp_nvim_lsp").default_capabilities() + -- Disable ruff LSP entirely (we use ruff via nvim-lint + none-ls instead) + vim.api.nvim_create_autocmd("LspAttach", { + callback = function(args) + local client = vim.lsp.get_client_by_id(args.data.client_id) + if client and client.name == "ruff" then + vim.lsp.stop_client(client.id) + end + end, + }) + -- Load project-local LSP settings from .nvim.lua local function load_project_lsp_settings(server_name, root_dir) if not root_dir then diff --git a/lua/plugins/mason-tool-installer.lua b/lua/plugins/mason-tool-installer.lua index 84ff1ef..b76028a 100644 --- a/lua/plugins/mason-tool-installer.lua +++ b/lua/plugins/mason-tool-installer.lua @@ -10,14 +10,14 @@ return { -- Formatters "prettier", -- JS, TS, CSS, JSON, Markdown, HTML "stylua", -- Lua - "black", -- Python + "ruff", -- Python (formatter + linter in one) -- Note: phpcbf already installed globally -- Linters "eslint_d", -- JS, TS (daemon version for speed) "markdownlint", -- Markdown - "ruff", -- Python (fast linter + import sorter) -- Note: phpcs already installed globally + -- Note: ruff also does linting (listed above) }, auto_update = false, run_on_start = true, diff --git a/lua/plugins/none-ls.lua b/lua/plugins/none-ls.lua index 0c14edc..ad7e73b 100644 --- a/lua/plugins/none-ls.lua +++ b/lua/plugins/none-ls.lua @@ -45,6 +45,17 @@ return { -- Note: Diagnostics (linters) moved to nvim-lint plugin + -- Custom ruff formatter (ruff format subcommand) + local ruff_format = { + method = null_ls.methods.FORMATTING, + filetypes = { "python" }, + generator = null_ls.formatter({ + command = find_executable({ "ruff" }) or "ruff", + args = { "format", "--stdin-filename", "$FILENAME", "-" }, + to_stdin = true, + }), + } + null_ls.setup({ sources = { -- Prettier (JS, TS, CSS, SCSS, JSON, Markdown, HTML) @@ -75,10 +86,8 @@ return { command = find_executable({ "stylua" }), }), - -- black (Python) - formatting.black.with({ - command = find_executable({ "black" }), - }), + -- ruff (Python formatter - custom since not in builtins) + ruff_format, }, -- Format on save diff --git a/lua/plugins/nvim-lint.lua b/lua/plugins/nvim-lint.lua index 073c46d..69af2fd 100644 --- a/lua/plugins/nvim-lint.lua +++ b/lua/plugins/nvim-lint.lua @@ -15,7 +15,7 @@ return { typescriptreact = { "eslint_d" }, markdown = { "markdownlint" }, php = { "phpcs" }, - python = { "ruff" }, + python = { "ruff" }, -- Code quality/style checks (pyright handles types) } -- Helper: Find project-local executable, fallback to global @@ -69,8 +69,18 @@ return { -- Configure markdownlint lint.linters.markdownlint.cmd = find_executable({ "markdownlint" }) or "markdownlint" - -- Configure ruff for Python + -- Configure ruff for Python linting (separate from formatting) lint.linters.ruff.cmd = find_executable({ "ruff" }) or "ruff" + lint.linters.ruff.args = { + "check", + "--select", "ALL", -- All rules + "--ignore", "E501,E999", -- Ignore line length (formatter handles) and syntax errors (pyright handles) + "--force-exclude", + "--quiet", + "--output-format", "json", + "--stdin-filename", function() return vim.api.nvim_buf_get_name(0) end, + "-", + } -- Auto-lint on these events local lint_augroup = vim.api.nvim_create_augroup("lint", { clear = true })