nvim: Refactor automatic py venv call
This commit is contained in:
parent
1c8c5ca6d9
commit
1665dd6cf6
3 changed files with 9 additions and 5 deletions
|
@ -126,9 +126,10 @@ local lspconfig = require("lspconfig")
|
|||
|
||||
-- ensure python virtualenv is determined automatically on lsp start
|
||||
lspconfig.pyright.setup({
|
||||
on_attach = function(client, _)
|
||||
local python_path, msg = require("util.pyenv").get_path(client.config.root_dir)
|
||||
vim.notify(string.format("%s\n%s", msg, python_path))
|
||||
on_attach = function(client, bufnr)
|
||||
on_attach(client, bufnr)
|
||||
local python_path, msg = require("util").get_python_venv(client.config.root_dir)
|
||||
vim.notify_once(string.format("[PYTHON VENV]\n%s", python_path))
|
||||
client.config.settings.python.pythonPath = python_path
|
||||
end,
|
||||
})
|
||||
|
|
|
@ -9,4 +9,8 @@ function T.is_available(plugin)
|
|||
return lazy_config_avail and lazy_config.plugins[plugin] ~= nil
|
||||
end
|
||||
|
||||
function T.get_python_venv(workspace)
|
||||
return require("util.pyenv").get_path(workspace)
|
||||
end
|
||||
|
||||
return T
|
||||
|
|
|
@ -22,8 +22,7 @@ T.get_path = function(workspace)
|
|||
-- Find and use virtualenv in workspace directory.
|
||||
for _, pattern in ipairs({ "*", ".*" }) do
|
||||
local match = vim.fn.glob(path.join(workspace, pattern, "pyvenv.cfg"))
|
||||
local sep = path_sep()
|
||||
local py = "bin" .. sep .. "python"
|
||||
local py = "bin" .. path_sep() .. "python"
|
||||
if match ~= "" then
|
||||
match = string.gsub(match, "pyvenv.cfg", py)
|
||||
return match, string.format("venv base folder: %s", match)
|
||||
|
|
Loading…
Reference in a new issue