linux-cultist / venv-selector.nvim

Allows selection of python virtual environment from within neovim
MIT License
378 stars 40 forks source link

Error in VenvSelectLog #141

Closed abhinavnatarajan closed 3 weeks ago

abhinavnatarajan commented 3 weeks ago

The file https://github.com/linux-cultist/venv-selector.nvim/blob/203c9046e1c0787ec00edfd456b30e4381afbfd1/lua/venv-selector/user_commands.lua is missing an import. The following line https://github.com/linux-cultist/venv-selector.nvim/blob/203c9046e1c0787ec00edfd456b30e4381afbfd1/lua/venv-selector/user_commands.lua#L15 contains a reference to log, but there is no log = require('venv-selector.logger').

linux-cultist commented 3 weeks ago

Its because log is a global variable from init.lua, so we dont have to include it in every lua file:

log = require 'venv-selector.logger'

Since init.lua always runs first, you shouldnt get any import errors. Did you just notice it in the code or do you have some error?

linux-cultist commented 3 weeks ago

Actually its not a good idea either way to have it global. Could be causing conflicts and bugs.

I switched to having it as a local variable, included in every file. Thank you.

Update the plugin and you will get the change. :)

abhinavnatarajan commented 3 weeks ago

Updated - now I get the error "Please set debug to true in options to use the logger". I have set this to true, here is my config:

cache = {
    file = "~/.cache/venv-selector/venvs2.json",
},
options = {
    on_venv_activate_callback = nil,             -- callback function for after a venv activates
    enable_default_searches = true,              -- switches all default searches on/off
    enable_cached_venvs = true,                  -- use cached venvs that are activated automatically when a python file is registered with the LSP.
    cached_venv_automatic_activation = true,     -- if set to false, the VenvSelectCached command becomes available to manually activate them.
    activate_venv_in_terminal = true,            -- activate the selected python interpreter in terminal windows opened from neovim
    set_environment_variables = true,            -- sets VIRTUAL_ENV or CONDA_PREFIX environment variables
    notify_user_on_venv_activation = false,      -- notifies user on activation of the virtual env
    search_timeout = 5,                          -- if a search takes longer than this many seconds, stop it and alert the user
    debug = true,                               -- enables you to run the VenvSelectLog command to view debug logs
    -- fd_binary_name = M.find_fd_command_name(),   -- plugin looks for `fd` or `fdfind` but you can set something else here

    -- telescope viewer options
    on_telescope_result_callback = nil,   -- callback function for modifying telescope results
    show_telescope_search_type = true,    -- Shows which of the searches found which venv in telescope
    telescope_filter_type =
    "substring"                           -- When you type something in telescope, filter by "substring" or "character"     },
},
search = {
    mambaforge_envs = {
        command = "$FD '/bin/python$' ~/mambaforge/envs --full-path --color never -E /proc -a -L",
        type = "anaconda"
    },
},
abhinavnatarajan commented 3 weeks ago

As it turns out I had to wrap all the options into a field called settings, which I forgot to do. All sorted!

linux-cultist commented 3 weeks ago

You need to have a settings lua table at the top, and all your config goes under that one. You probably forgot that one and that's why your settings are not registering. :)

See the Readme for examples.

Edit: You figured it out. :) You don't need to set all these settings in the config, just in case you don't know. Only the ones you want to change from the their default setting.