nvim: Remove reliance on lspconfig for python path

Localize the path joining function to the utility module.
This commit is contained in:
Marty Oehme 2023-12-26 09:48:57 +01:00
parent 49f6a0ef58
commit df10d40510
Signed by: Marty
GPG key ID: EDBF2ED917B2EF6A

View file

@ -1,27 +1,29 @@
local util = require("lspconfig.util")
local path = util.path
local T = {}
local exepath = vim.fn.exepath
local function path_join(...)
return table.concat(vim.tbl_flatten { ... }, '/')
end
-- from https://github.com/ray-x/navigator.lua/issues/247#issue-1465308677
T.get_path = function(workspace)
-- Use activated virtualenv.
if vim.env.VIRTUAL_ENV then
return path.join(vim.env.VIRTUAL_ENV, "bin", "python")
return path_join(vim.env.VIRTUAL_ENV, "bin", "python")
end
-- Find and use virtualenv in workspace directory.
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"))
if match ~= "" then
local py = path.join("bin", "python")
local py = path_join("bin", "python")
match = string.gsub(match, "pyvenv.cfg", py)
return match
end
match = vim.fn.glob(path.join(workspace, pattern, "poetry.lock"))
match = vim.fn.glob(path_join(workspace, pattern, "poetry.lock"))
if match ~= "" then
local venv_base_folder = vim.fn.trim(vim.fn.system("poetry env info -p"))
return path.join(venv_base_folder, "bin", "python")
return path_join(venv_base_folder, "bin", "python")
end
end