Skip to content

Commit

Permalink
Replace pyright hook with a better one (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
linux-cultist committed Sep 6, 2023
1 parent 343058b commit a37ea94
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 18 deletions.
13 changes: 3 additions & 10 deletions lua/venv-selector/hooks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,9 @@ end
--- @type VenvChangedHook
function M.pyright_hook(_, venv_python)
M.execute_for_client("pyright", function(pyright)
local utils = require("venv-selector.utils")
local settings = vim.deepcopy(pyright.config.settings)
lspconfig.pyright.setup({
settings = settings,
before_init = function(_, c)
c.settings.python.pythonPath = venv_python
utils.dbg("Pyright settings:")
utils.dbg(c.settings)
end,
})
pyright.config.settings =
vim.tbl_deep_extend("force", pyright.config.settings, { python = { pythonPath = venv_python } })
pyright.notify("workspace/didChangeConfiguration", { settings = nil })
end)
end

Expand Down
15 changes: 7 additions & 8 deletions lua/venv-selector/venv.lua
Original file line number Diff line number Diff line change
Expand Up @@ -189,19 +189,18 @@ function M.set_pythonpath(python_path)
pattern = { "*.py" },
callback = function()
local active_clients = {}
for _, client in
ipairs(vim.lsp.get_active_clients({ name = "pyright", bufnr = vim.api.nvim_get_current_buf() }))
do
for _, client in ipairs(vim.lsp.get_active_clients({ name = "pyright", bufnr = vim.api.nvim_get_current_buf() })) do
table.insert(active_clients, client)
end
for _, client in
ipairs(vim.lsp.get_active_clients({ name = "pylance", bufnr = vim.api.nvim_get_current_buf() }))
do

for _, client in ipairs(vim.lsp.get_active_clients({ name = "pylance", bufnr = vim.api.nvim_get_current_buf() })) do
table.insert(active_clients, client)
end

for _, client in ipairs(active_clients) do
client.config.settings =
vim.tbl_deep_extend("force", client.config.settings, { python = { pythonPath = python_path } })
client.config.settings = vim.tbl_deep_extend("force", client.config.settings,
{ python = { pythonPath = python_path } })

client.notify("workspace/didChangeConfiguration", { settings = nil })
end
end,
Expand Down

0 comments on commit a37ea94

Please sign in to comment.