Added venv support for pyright
This commit is contained in:
@@ -13,6 +13,8 @@ return {
|
||||
local lspconfig = require("lspconfig")
|
||||
local tserrortranslator = require("ts-error-translator")
|
||||
local cmp_nvim_lsp = require("cmp_nvim_lsp")
|
||||
local util = require("lspconfig.util")
|
||||
local path = util.path
|
||||
|
||||
local on_attach = require("taken.utils.on_attach")
|
||||
local capabilities = cmp_nvim_lsp.default_capabilities()
|
||||
@@ -26,7 +28,6 @@ return {
|
||||
local defaultLsps = {
|
||||
"html",
|
||||
"cssls",
|
||||
"pyright",
|
||||
"jsonls",
|
||||
"rust_analyzer",
|
||||
"yamlls",
|
||||
@@ -66,6 +67,36 @@ return {
|
||||
},
|
||||
})
|
||||
|
||||
local function get_python_path(workspace)
|
||||
-- Use activated virtualenv.
|
||||
if vim.env.VIRTUAL_ENV then
|
||||
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"))
|
||||
if match ~= "" then
|
||||
return path.join(path.dirname(match), "bin", "python")
|
||||
end
|
||||
end
|
||||
|
||||
return nil
|
||||
end
|
||||
|
||||
-- python
|
||||
lspconfig["pyright"].setup({
|
||||
capabilities = capabilities,
|
||||
on_attach = on_attach,
|
||||
before_init = function(_, config)
|
||||
local python_path = get_python_path(config.root_dir)
|
||||
if python_path == nil then
|
||||
return
|
||||
end
|
||||
config.settings.python.pythonPath = get_python_path(config.root_dir)
|
||||
end,
|
||||
})
|
||||
|
||||
-- typescript
|
||||
lspconfig["ts_ls"].setup({
|
||||
capabilities = capabilities,
|
||||
|
||||
Reference in New Issue
Block a user