From 41934d3000427393c4a253abf25947c705eee843 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Mon, 25 Sep 2023 19:38:57 +0200 Subject: [PATCH] nvim: Attach ruff client to active python environment --- nvim/.config/nvim/lua/plugins/config/lsp.lua | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/nvim/.config/nvim/lua/plugins/config/lsp.lua b/nvim/.config/nvim/lua/plugins/config/lsp.lua index 25ae1cb..d3b6704 100644 --- a/nvim/.config/nvim/lua/plugins/config/lsp.lua +++ b/nvim/.config/nvim/lua/plugins/config/lsp.lua @@ -126,15 +126,29 @@ lsp.setup({ local lspconfig = require("lspconfig") +local python_path -- ensure python virtualenv is determined automatically on lsp start lspconfig.pyright.setup({ on_attach = function(client, bufnr) - on_attach(client, bufnr) - local python_path, _ = require("util").get_python_venv(client.config.root_dir) - vim.notify_once(string.format("[PYTHON VENV]\n%s", python_path)) + if python_path == nil then + python_path, _ = require("util").get_python_venv(client.config.root_dir) + end + print(string.format("[PYTHON VENV]: %s", vim.inspect(python_path))) client.config.settings.python.pythonPath = python_path + on_attach(client, bufnr) end, }) +lspconfig.ruff_lsp.setup({ + on_attach = function(client, bufnr) + if python_path == nil then + python_path, _ = require("util").get_python_venv(client.config.root_dir) + end + print(string.format("[PYTHON VENV]: %s", vim.inspect(python_path))) + client.config.settings.python.pythonPath = python_path + on_attach(client, bufnr) + end, +}) + -- set up arduino with the help of arduino.nvim plugin if require("util").is_available("arduino") then lspconfig.arduino_language_server.setup({