AckslD / swenv.nvim

Tiny plugin to quickly switch python virtual environments from within neovim without restarting.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

LspRestart not triggered/working

sebhahn opened this issue · comments

Using post_set_venv = vim.cmd.LspRestart, doesn't seem to trigger a restart of the Lsp. Am I missing something?

Hmm, just to rule out the possibilities, how do you know it's not triggered? Could it be that it's triggered to early or some other reason?

because I have multiple environments and only one of them has e.g. matplotlib, after switching to this environment the import of matplotlib is still marked as unknown, if I type LspRestart into the cmd it finds it...

Just to try, could you set the variable to eg

post_set_venv = function()
  print('before LspRestart')
  vim.cmd.LspRestart()
  print('after LspRestart')
end

and see if the messages come up?

no message is printed

Hmm, this works for me, how are you configuring this?

return {
  "AckslD/swenv.nvim",
  dependencies = {
    "nvim-lua/plenary.nvim",
  },
  config = function()

    local swenv = require("swenv")
    local swenv_api = require('swenv.api')

    swenv.setup({
        -- Should return a list of tables with a `name` and a `path` entry each.
        -- Gets the argument `venvs_path` set below.
        -- By default just lists the entries in `venvs_path`.
        get_venvs = function(venvs_path)
          return swenv_api.get_venvs(venvs_path)
        end,
        -- Path passed to `get_venvs`.
        venvs_path = vim.fn.expand('~/.pyenv/versions'),
        -- Something to do after setting an environment, for example call vim.cmd.LspRestart
        -- post_set_venv = vim.cmd.LspRestart,
        post_set_venv = function()
          print('before LspRestart')
          vim.cmd.LspRestart()
          print('after LspRestart')
        end
    })

  end,
}

And does the following work?

:lua require('swenv.config').settings.post_set_venv()

this works

Hmm, sorry, I think I'm out of ideas, not sure why it's not working for you

can I somehow debug this on my end?

ok I found the problem, it should be

        get_venvs = function(venvs_path)
          return require('swenv.api').get_venvs(venvs_path)
        end,

Now the LspRestart is triggered correctly, but each Python environment is listed twice in the setenv menu. Is this normal?

ok setting the path to

venvs_path = vim.fn.expand('~/venvs'),

fixes the duplicated entries, but I'm confused why it shouldn't be set to the pyenv/versions folder?

Hey @sebhahn, I am curious! What is the reason for you to restart the lsp?

@b0lle I have multipe projects, each with its own conda environment/dependencies. Hence, a restart of lsp is required to initialize the lsp with the right (currently active) environment

oh I am in the same situation and wondered why sometimes dependencies are not recognized by the lsp, even though the venv was activated successfully. Thanks for the tip! I will adopt this setting :)