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
|
-- ensure python virtualenv is determined automatically on lsp start
|
||||||
lspconfig.pyright.setup({
|
lspconfig.pyright.setup({
|
||||||
on_attach = function(client, _)
|
on_attach = function(client, bufnr)
|
||||||
local python_path, msg = require("util.pyenv").get_path(client.config.root_dir)
|
on_attach(client, bufnr)
|
||||||
vim.notify(string.format("%s\n%s", msg, python_path))
|
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
|
client.config.settings.python.pythonPath = python_path
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
|
@ -9,4 +9,8 @@ function T.is_available(plugin)
|
||||||
return lazy_config_avail and lazy_config.plugins[plugin] ~= nil
|
return lazy_config_avail and lazy_config.plugins[plugin] ~= nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function T.get_python_venv(workspace)
|
||||||
|
return require("util.pyenv").get_path(workspace)
|
||||||
|
end
|
||||||
|
|
||||||
return T
|
return T
|
||||||
|
|
|
@ -22,8 +22,7 @@ T.get_path = function(workspace)
|
||||||
-- Find and use virtualenv in workspace directory.
|
-- Find and use virtualenv in workspace directory.
|
||||||
for _, pattern in ipairs({ "*", ".*" }) do
|
for _, pattern in ipairs({ "*", ".*" }) do
|
||||||
local match = vim.fn.glob(path.join(workspace, pattern, "pyvenv.cfg"))
|
local match = vim.fn.glob(path.join(workspace, pattern, "pyvenv.cfg"))
|
||||||
local sep = path_sep()
|
local py = "bin" .. path_sep() .. "python"
|
||||||
local py = "bin" .. sep .. "python"
|
|
||||||
if match ~= "" then
|
if match ~= "" then
|
||||||
match = string.gsub(match, "pyvenv.cfg", py)
|
match = string.gsub(match, "pyvenv.cfg", py)
|
||||||
return match, string.format("venv base folder: %s", match)
|
return match, string.format("venv base folder: %s", match)
|
||||||
|
|
Loading…
Reference in a new issue