Open mochouaaaaa opened 2 weeks ago
Hi,
Im not sure i understand. What do you mean with The cache modal produces the venvs2.json record file
?
Do you mean this file:
cache = {
file = "~/.cache/venv-selector/venvs2.json",
},
This is an internal file for venvselect that keeps track of cached virtual environments for a working directory. Do you mean that you can see that your venv appears in the file?
Also noticed that you are setting a variable called pyenv_path
and sending it into the plugin config for some reason. Its not a variable that the plugin expects or will use. And you seem to set it to $PYENV_ROOT/versions
, and later not use it.
I cant really debug this without seeing any paths or results that you are getting. If you enable the debug mode, you can open the log viewer with :VenvSelectLog
and share some information about what the plugin is saying and doing. :)
Maybe its a misunderstanding here in what you write:
but opening the directory again does not activate the virtual environment
The plugin will only activate the virtual environment when you open a python file in the same directory as before. Without a python file opened, the LSP server is not running, and the plugin cant activate anything with the LSP server.
So what you should do is:
And you should see in the VenvSelectLog
how it activates:
2024-06-20 07:29:52 [DEBUG]: Activating venv from cache
2024-06-20 07:29:52 [DEBUG]: $CONDA_PREFIX has been unset.
2024-06-20 07:29:52 [DEBUG]: $VIRTUAL_ENV set to /home/cado/.pyenv/versions/venv-31012
2024-06-20 07:29:52 [DEBUG]: Setting dap python interpreter to '/home/cado/.pyenv/versions/venv-31012/bin/python'
2024-06-20 07:29:52 [DEBUG]: Setting require("venv-selector").python() to '/home/cado/.pyenv/versions/venv-31012/bin/python'
2024-06-20 07:29:52 [DEBUG]: Setting require("venv-selector").venv() to '/home/cado/.pyenv/versions/venv-31012'
Maybe its a misunderstanding here in what you write:
but opening the directory again does not activate the virtual environment
The plugin will only activate the virtual environment when you open a python file in the same directory as before. Without a python file opened, the LSP server is not running, and the plugin cant activate anything with the LSP server.
So what you should do is:
- Open neovim in the same working directory you were before when you activated a venv.
- Open a python file located in that directory.
And you should see in the
VenvSelectLog
how it activates:2024-06-20 07:29:52 [DEBUG]: Activating venv from cache 2024-06-20 07:29:52 [DEBUG]: $CONDA_PREFIX has been unset. 2024-06-20 07:29:52 [DEBUG]: $VIRTUAL_ENV set to /home/cado/.pyenv/versions/venv-31012 2024-06-20 07:29:52 [DEBUG]: Setting dap python interpreter to '/home/cado/.pyenv/versions/venv-31012/bin/python' 2024-06-20 07:29:52 [DEBUG]: Setting require("venv-selector").python() to '/home/cado/.pyenv/versions/venv-31012/bin/python' 2024-06-20 07:29:52 [DEBUG]: Setting require("venv-selector").venv() to '/home/cado/.pyenv/versions/venv-31012'
The image is a bit too big to upload to issues! Usage Process
Do I need to do anything else?
I saw the image, thank you. Can you open the VenvSelectLog also and see what it says when you are opening a python file and previously has activated a venv in that directory? I only tried this myself with pyright
lsp server, so it would be interesting to see how it acts when you have many of them installed.
Set the debug
option to true and you should get lots of info in there.
2024-06-21 18:52:22 [DEBUG]: Starting 'pipx': 'fd '/bin/python$' ~/.local/share/pipx/venvs ~/.local/pipx/venvs --full-path --color never -E /proc'
2024-06-21 18:52:22 [DEBUG]: Starting 'cwd': 'fd '/bin/python$' /Volumes/Code/Projects/python/django_ninjia --full-path --color never -HI -a -L -E /proc -E .git/ -E .wine/ -E .steam/ -E Steam/ -E site-packages/'
2024-06-21 18:52:22 [DEBUG]: Starting 'anaconda_base': 'fd '/python$' /opt/anaconda/bin --full-path --color never -E /proc'
2024-06-21 18:52:22 [DEBUG]: Starting 'anaconda_envs': 'fd 'bin/python$' ~/.conda/envs --full-path --color never -E /proc'
2024-06-21 18:52:22 [DEBUG]: Starting 'pyenv': 'fd python$ /Users/mochou/.config/env/pyenv/versions --max-depth 3 --full-path -a -L'
2024-06-21 18:52:22 [DEBUG]: Starting 'poetry': 'fd '/bin/python$' ~/Library/Caches/pypoetry/virtualenvs --full-path'
2024-06-21 18:52:22 [DEBUG]: Starting 'hatch': 'fd 'python$' ~/Library/Application/Support/hatch/env/virtual --color never -E '*-build*' -E /proc'
2024-06-21 18:52:22 [DEBUG]: Starting 'virtualenvs': 'fd 'python$' ~/.virtualenvs --color never -E /proc'
2024-06-21 18:52:22 [DEBUG]: Workspace folders:
2024-06-21 18:52:22 [DEBUG]: 1: /Volumes/Code/Projects/python/django_ninjia
2024-06-21 18:52:22 [DEBUG]: Starting 'workspace': 'fd '/bin/python$' /Volumes/Code/Projects/python/django_ninjia --full-path --color never -E /proc -HI -a -L'
2024-06-21 18:52:22 [DEBUG]: [fd error]: Search path '/Users/mochou/.local/share/pipx/venvs' is not a directory.
2024-06-21 18:52:22 [DEBUG]: [fd error]: Search path '/Users/mochou/.local/pipx/venvs' is not a directory.
2024-06-21 18:52:22 [DEBUG]: [fd error]: No valid search paths given.
2024-06-21 18:52:22 [DEBUG]: [fd error]: Search path '/opt/anaconda/bin' is not a directory.
2024-06-21 18:52:22 [DEBUG]: [fd error]: No valid search paths given.
2024-06-21 18:52:22 [DEBUG]: [fd error]: Search path '/Users/mochou/.conda/envs' is not a directory.
2024-06-21 18:52:22 [DEBUG]: [fd error]: No valid search paths given.
2024-06-21 18:52:22 [DEBUG]: [fd error]: Search path '/Users/mochou/Library/Caches/pypoetry/virtualenvs' is not a directory.
2024-06-21 18:52:22 [DEBUG]: [fd error]: No valid search paths given.
2024-06-21 18:52:22 [DEBUG]: Result:
2024-06-21 18:52:22 [DEBUG]: path: /Users/mochou/.config/env/pyenv/versions/3.12.3/bin/python
2024-06-21 18:52:22 [DEBUG]: icon:
2024-06-21 18:52:22 [DEBUG]: source: pyenv
2024-06-21 18:52:22 [DEBUG]: name: /Users/mochou/.config/env/pyenv/versions/3.12.3/bin/python
2024-06-21 18:52:22 [DEBUG]: type: venv
2024-06-21 18:52:22 [DEBUG]: Result:
2024-06-21 18:52:22 [DEBUG]: path: /Users/mochou/.config/env/pyenv/versions/async_django/bin/python
2024-06-21 18:52:22 [DEBUG]: icon:
2024-06-21 18:52:22 [DEBUG]: source: pyenv
2024-06-21 18:52:22 [DEBUG]: name: /Users/mochou/.config/env/pyenv/versions/async_django/bin/python
2024-06-21 18:52:22 [DEBUG]: type: venv
2024-06-21 18:52:22 [DEBUG]: Result:
2024-06-21 18:52:22 [DEBUG]: path: /Users/mochou/.config/env/pyenv/versions/django-ninjia/bin/python
2024-06-21 18:52:22 [DEBUG]: icon:
2024-06-21 18:52:22 [DEBUG]: source: pyenv
2024-06-21 18:52:22 [DEBUG]: name: /Users/mochou/.config/env/pyenv/versions/django-ninjia/bin/python
2024-06-21 18:52:22 [DEBUG]: type: venv
2024-06-21 18:52:22 [DEBUG]: Result:
2024-06-21 18:52:22 [DEBUG]: path: /Users/mochou/.config/env/pyenv/versions/global/bin/python
2024-06-21 18:52:22 [DEBUG]: icon:
2024-06-21 18:52:22 [DEBUG]: source: pyenv
2024-06-21 18:52:22 [DEBUG]: name: /Users/mochou/.config/env/pyenv/versions/global/bin/python
2024-06-21 18:52:22 [DEBUG]: type: venv
2024-06-21 18:52:22 [DEBUG]: [fd error]: Search path '/Users/mochou/Library/Application/Support/hatch/env/virtual' is not a directory.
2024-06-21 18:52:22 [DEBUG]: [fd error]: No valid search paths given.
2024-06-21 18:52:22 [DEBUG]: [fd error]: Search path '/Users/mochou/.virtualenvs' is not a directory.
2024-06-21 18:52:22 [DEBUG]: [fd error]: No valid search paths given.
2024-06-21 18:52:22 [INFO]: Searching finished.
2024-06-21 18:52:22 [DEBUG]: Calculating path similarity based on: '/Volumes/Code/Projects/python/django_ninjia'
2024-06-21 18:52:22 [DEBUG]: Sorting telescope results on path similarity.
2024-06-21 18:52:23 [DEBUG]: Telescope entry selected by user:
2024-06-21 18:52:23 [DEBUG]: index: 2
2024-06-21 18:52:23 [DEBUG]: icon:
2024-06-21 18:52:23 [DEBUG]: source: pyenv
2024-06-21 18:52:23 [DEBUG]: display: function: 0x010f55a2f8
2024-06-21 18:52:23 [DEBUG]: ordinal: /Users/mochou/.config/env/pyenv/versions/django-ninjia/bin/python
2024-06-21 18:52:23 [DEBUG]: path: /Users/mochou/.config/env/pyenv/versions/django-ninjia/bin/python
2024-06-21 18:52:23 [DEBUG]: value: /Users/mochou/.config/env/pyenv/versions/django-ninjia/bin/python
2024-06-21 18:52:23 [DEBUG]: name: /Users/mochou/.config/env/pyenv/versions/django-ninjia/bin/python
2024-06-21 18:52:23 [DEBUG]: type: venv
2024-06-21 18:52:23 [DEBUG]: Below message sent to user since this message was not notified about before.
2024-06-21 18:52:23 [INFO]: Registered '/Users/mochou/.config/env/pyenv/versions/django-ninjia/bin/python' with basedpyright LSP.
2024-06-21 18:52:23 [DEBUG]: Cache content:
2024-06-21 18:52:23 [DEBUG]: {"/Volumes/Code/Projects/python/django_ninjia": {"source": "pyenv", "type": "venv", "value": "/Users/mochou/.config/env/pyenv/versions/django-ninjia/bin/python"}}
2024-06-21 18:52:23 [DEBUG]: Wrote cache content to /Users/mochou/.cache/venv-selector/venvs2.json
2024-06-21 18:52:23 [DEBUG]: Setting new terminal path : ...
2024-06-21 18:52:23 [DEBUG]: Setting dap python interpreter to '/Users/mochou/.config/env/pyenv/versions/django-ninjia/bin/python'
2024-06-21 18:52:23 [DEBUG]: Setting require("venv-selector").python() to '/Users/mochou/.config/env/pyenv/versions/django-ninjia/bin/python'
2024-06-21 18:52:23 [DEBUG]: Setting require("venv-selector").venv() to '/Users/mochou/.config/env/pyenv/versions/django-ninjia'
2024-06-21 18:52:23 [DEBUG]: $CONDA_PREFIX has been unset.
2024-06-21 18:52:23 [DEBUG]: $VIRTUAL_ENV set to /Users/mochou/.config/env/pyenv/versions/django-ninjia
I didn't get any other useful information, and based on the logs I couldn't pinpoint the reason for the lack of automatic activation
Its a bit strange that I dont see any attempt to activate the venv from cache in your log there.
vim.api.nvim_create_autocmd("LspAttach", {
pattern = "*.py",
callback = on_lsp_attach,
})
local function on_lsp_attach()
local cache = require("venv-selector.cached_venv")
if config.user_settings.options.cached_venv_automatic_activation == true then
cache.retrieve()
end
end
This is from the plugin code, and just to explain a bit, it creates an autocommand called LspAttach
that will call the lsp_attach()
function whenever you open a python file.
And unless you have set the option cached_venv_automatic_activation
to false, it should retrieve the venv from cache.
I see in your debug info that its writing the venv to the cache, but no attempts at reading it from cache. It should also write your settings at the top of the debug info, but I guess you removed that?
I've probably pinpointed the problem, when lazy=false
, lsp servers fail to start, currently checking the logs for that.
When lazy
is not set, it defaults to true
, which prevents the environment from being activated automatically.
venv-selector set lazy=false
[START][2024-06-24 02:09:30] LSP logging initiated
[INFO][2024-06-24 02:09:30] .../vim/lsp/rpc.lua:731 "Starting RPC client" { cmd = { "/Users/mochou/.local/share/nvim/mason/bin/ruff", "server", "--preview" }, extra = { cwd = "/Volumes/Code/Projects/python/django_ninjia" }}
[INFO][2024-06-24 02:09:30] .../vim/lsp/rpc.lua:731 "Starting RPC client" { cmd = { "/Users/mochou/.local/share/nvim/mason/bin/ruff-lsp" }, extra = { cwd = "/Volumes/Code/Projects/python/django_ninjia" }}
[INFO][2024-06-24 02:09:30] ...m/lsp/client.lua:618 "LSP[ruff]" "server_capabilities" { server_capabilities = { codeActionProvider = { codeActionKinds = { "quickfix", "source.fixAll.ruff", "source.organizeImports.ruff", "notebook.source.fixAll.ruff", "notebook.source.organizeImports.ruff" }, resolveProvider = true, workDoneProgress = true }, diagnosticProvider = { identifier = "Ruff", interFileDependencies = false, workDoneProgress = true, workspaceDiagnostics = false }, documentFormattingProvider = true, documentRangeFormattingProvider = true, executeCommandProvider = { commands = { "ruff.applyFormat", "ruff.applyAutofix", "ruff.applyOrganizeImports", "ruff.printDebugInformation" }, workDoneProgress = false }, hoverProvider = true, notebookDocumentSync = { notebookSelector = { { cells = { { language = "python" } } } }, save = false }, positionEncoding = "utf-16", textDocumentSync = { change = 2, openClose = true, willSave = false, willSaveWaitUntil = false }, workspace = { workspaceFolders = { changeNotifications = true, supported = true } } }}
[INFO][2024-06-24 02:09:31] ...lsp/handlers.lua:627 'Workspace settings: {\n "args": {\n "filetypes": [\n "python"\n ]\n }\n}'
[INFO][2024-06-24 02:09:31] ...lsp/handlers.lua:627 "Global settings: {}"
[INFO][2024-06-24 02:09:31] ...m/lsp/client.lua:618 "LSP[ruff_lsp]" "server_capabilities" { server_capabilities = { codeActionProvider = { codeActionKinds = { "quickfix", "source.fixAll", "source.organizeImports", "source.fixAll.ruff", "source.organizeImports.ruff", "notebook.source.fixAll", "notebook.source.organizeImports", "notebook.source.fixAll.ruff", "notebook.source.organizeImports.ruff" }, resolveProvider = true }, documentFormattingProvider = true, documentRangeFormattingProvider = { documentSelector = { { language = "python", scheme = "file" }, { language = "python", scheme = "untitled" } }, rangesSupport = false, workDoneProgress = false }, executeCommandProvider = { commands = { "ruff.applyAutofix", "ruff.applyOrganizeImports", "ruff.applyFormat" } }, hoverProvider = false, positionEncoding = "utf-16", textDocumentSync = { change = 2, openClose = true, save = true, willSave = false, willSaveWaitUntil = false }, workspace = { fileOperations = vim.empty_dict(), workspaceFolders = { changeNotifications = true, supported = true } } }}
[INFO][2024-06-24 02:09:31] ...lsp/handlers.lua:627 "Using interpreter executable: /Users/mochou/.local/share/nvim/mason/packages/ruff-lsp/venv/bin/ruff"
[INFO][2024-06-24 02:09:31] ...lsp/handlers.lua:627 "Inferred version 0.4.8 for: /Users/mochou/.local/share/nvim/mason/packages/ruff-lsp/venv/bin/ruff"
[INFO][2024-06-24 02:09:31] ...lsp/handlers.lua:627 "Found ruff 0.4.8 at /Users/mochou/.local/share/nvim/mason/packages/ruff-lsp/venv/bin/ruff"
[INFO][2024-06-24 02:09:31] ...lsp/handlers.lua:627 "Running Ruff with: /Users/mochou/.local/share/nvim/mason/packages/ruff-lsp/venv/bin/ruff ['check', '--force-exclude', '--no-cache', '--no-fix', '--quiet', '--output-format', 'json', '-', 'filetypes', '--stdin-filename', '/Volumes/Code/Projects/python/django_ninjia/manage.py']"
No lazy
parameter
[INFO][2024-06-24 02:10:25] .../lua/vim/lsp.lua:793 "exit_handler" { { _log_prefix = "LSP[ruff]", _on_attach_cbs = { <function 1> }, _on_exit_cbs = { <function 2>, <function 3> }, _on_init_cbs = { <function 4> }, _root_dir = "/Volumes/Code/Projects/python/django_ninjia", _trace = "off", attached_buffers = { [3] = true }, cancel_request = <function 5>, capabilities = <1>{ general = <2>{ positionEncodings = { "utf-16" } }, textDocument = { callHierarchy = <3>{ dynamicRegistration = false }, codeAction = <4>{ codeActionLiteralSupport = { codeActionKind = { valueSet = { "", "quickfix", "refactor", "refactor.extract", "refactor.inline", "refactor.rewrite", "source", "source.organizeImports" } } }, dataSupport = true, dynamicRegistration = true, isPreferredSupport = true, resolveSupport = { properties = { "edit" } } }, completion = { completionItem = { commitCharactersSupport = true, deprecatedSupport = true, documentationFormat = <5>{ "markdown", "plaintext" }, insertReplaceSupport = true, insertTextModeSupport = { valueSet = { 1, 2 } }, labelDetailsSupport = true, preselectSupport = true, resolveSupport = { properties = { "documentation", "detail", "additionalTextEdits", "sortText", "filterText", "insertText", "textEdit", "insertTextFormat", "insertTextMode" } }, snippetSupport = true, tagSupport = { valueSet = { 1 } } }, completionItemKind = <6>{ valueSet = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 } }, completionList = { itemDefaults = { "commitCharacters", "editRange", "insertTextFormat", "insertTextMode", "data" } }, contextSupport = true, dynamicRegistration = false, insertTextMode = 1 }, declaration = <7>{ linkSupport = true }, definition = <8>{ dynamicRegistration = true, linkSupport = true }, diagnostic = <9>{ dynamicRegistration = false }, documentHighlight = <10>{ dynamicRegistration = false }, documentSymbol = <11>{ dynamicRegistration = false, hierarchicalDocumentSymbolSupport = true, symbolKind = { valueSet = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26 } } }, formatting = <12>{ dynamicRegistration = true }, hover = <13>{ contentFormat = { "markdown", "plaintext" }, dynamicRegistration = true }, implementation = <14>{ linkSupport = true }, inlayHint = <15>{ dynamicRegistration = true, resolveSupport = { properties = { "textEdits", "tooltip", "location", "command" } } }, publishDiagnostics = <16>{ dataSupport = true, relatedInformation = true, tagSupport = { valueSet = { 1, 2 } } }, rangeFormatting = <17>{ dynamicRegistration = true }, references = <18>{ dynamicRegistration = false }, rename = <19>{ dynamicRegistration = true, prepareSupport = true }, semanticTokens = <20>{ augmentsSyntaxTokens = true, dynamicRegistration = false, formats = { "relative" }, multilineTokenSupport = false, overlappingTokenSupport = true, requests = { full = { delta = true }, range = false }, serverCancelSupport = false, tokenModifiers = { "declaration", "definition", "readonly", "static", "deprecated", "abstract", "async", "modification", "documentation", "defaultLibrary" }, tokenTypes = { "namespace", "type", "class", "enum", "interface", "struct", "typeParameter", "parameter", "variable", "property", "enumMember", "event", "function", "method", "macro", "keyword", "modifier", "comment", "string", "number", "regexp", "operator", "decorator" } }, signatureHelp = <21>{ dynamicRegistration = false, signatureInformation = { activeParameterSupport = true, documentationFormat = { "markdown", "plaintext" }, parameterInformation = { labelOffsetSupport = true } } }, synchronization = <22>{ didSave = true, dynamicRegistration = false, willSave = true, willSaveWaitUntil = true }, typeDefinition = <23>{ linkSupport = true } }, window = <24>{ showDocument = { support = true }, showMessage = { messageActionItem = { additionalPropertiesSupport = false } }, workDoneProgress = true }, workspace = { applyEdit = true, configuration = true, didChangeConfiguration = <25>{ dynamicRegistration = false }, didChangeWatchedFiles = <26>{ dynamicRegistration = true, relativePatternSupport = true }, inlayHint = <27>{ refreshSupport = true }, semanticTokens = <28>{ refreshSupport = true }, symbol = <29>{ dynamicRegistration = false, symbolKind = { valueSet = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26 } } }, workspaceEdit = <30>{ resourceOperations = { "rename", "create", "delete" } }, workspaceFolders = true } }, commands = {}, config = { _on_attach = <function 6>, autostart = true, capabilities = <table 1>, cmd = { "/Users/mochou/.local/share/nvim/mason/bin/ruff", "server", "--preview" }, cmd_cwd = "/Volumes/Code/Projects/python/django_ninjia", filetypes = { "python" }, handlers = <31>{}, init_options = vim.empty_dict(), log_level = 2, message_level = 2, name = "ruff", on_attach = <function 1>, on_exit = <function 2>, on_init = <function 4>, root_dir = "/Volumes/Code/Projects/python/django_ninjia", settings = <32>{}, single_file_support = true, workspace_folders = <33>{ { name = "/Volumes/Code/Projects/python/django_ninjia", uri = "file:///Volumes/Code/Projects/python/django_ninjia" } }, <metatable> = <34>{ __tostring = <function 7> } }, dynamic_capabilities = { capabilities = { ["workspace/didChangeWatchedFiles"] = { { id = "ruff-server-watch", method = "workspace/didChangeWatchedFiles", registerOptions = { watchers = { { globPattern = "**/.ruff.toml" }, { globPattern = "**/ruff.toml" }, { globPattern = "**/pyproject.toml" } } } } } }, client_id = 1, <metatable> = { __index = <35>{ get = <function 8>, match = <function 9>, new = <function 10>, register = <function 11>, supports = <function 12>, supports_registration = <function 13>, unregister = <function 14> } } }, flags = {}, get_language_id = <function 15>, handlers = <table 31>, id = 1, initialized = true, is_stopped = <function 16>, messages = { messages = {}, name = "ruff", progress = {}, status = {} }, name = "ruff", notify = <function 17>, offset_encoding = "utf-16", on_attach = <function 18>, progress = { _idx_read = 0, _idx_write = 0, _items = {}, _size = 51, pending = {}, <metatable> = { __call = <function 19>, __index = <36>{ clear = <function 20>, peek = <function 21>, pop = <function 22>, push = <function 23> } } }, request = <function 24>, request_sync = <function 25>, requests = {}, root_dir = "/Volumes/Code/Projects/python/django_ninjia", rpc = { is_closing = <function 26>, notify = <function 27>, request = <function 28>, terminate = <function 29> }, server_capabilities = { codeActionProvider = { codeActionKinds = { "quickfix", "source.fixAll.ruff", "source.organizeImports.ruff", "notebook.source.fixAll.ruff", "notebook.source.organizeImports.ruff" }, resolveProvider = true, workDoneProgress = true }, diagnosticProvider = { identifier = "Ruff", interFileDependencies = false, workDoneProgress = true, workspaceDiagnostics = false }, documentFormattingProvider = true, documentRangeFormattingProvider = true, executeCommandProvider = { commands = { "ruff.applyFormat", "ruff.applyAutofix", "ruff.applyOrganizeImports", "ruff.printDebugInformation" }, workDoneProgress = false }, hoverProvider = true, notebookDocumentSync = { notebookSelector = { { cells = { { language = "python" } } } }, save = false }, positionEncoding = "utf-16", textDocumentSync = { change = 2, openClose = true, willSave = false, willSaveWaitUntil = false }, workspace = { workspaceFolders = { changeNotifications = true, supported = true } } }, settings = <table 32>, stop = <function 30>, supports_method = <function 31>, workspace_did_change_configuration = <function 32>, workspace_folders = <table 33>, <metatable> = <37>{ __index = <table 37>, _add_workspace_folder = <function 33>, _cancel_request = <function 34>, _exec_cmd = <function 35>, _is_stopped = <function 36>, _notification = <function 37>, _notify = <function 38>, _on_attach = <function 39>, _on_error = <function 40>, _on_exit = <function 41>, _remove_workspace_folder = <function 42>, _request = <function 43>, _request_sync = <function 44>, _resolve_handler = <function 45>, _run_callbacks = <function 46>, _server_request = <function 47>, _stop = <function 48>, _supports_method = <function 49>, _text_document_did_open_handler = <function 50>, create = <function 51>, initialize = <function 52>, write_error = <function 53> } }, { _log_prefix = "LSP[ruff_lsp]", _on_attach_cbs = { <function 54> }, _on_exit_cbs = { <function 55>, <function 3> }, _on_init_cbs = { <function 56> }, _root_dir = "/Volumes/Code/Projects/python/django_ninjia", _trace = "off", attached_buffers = { [3] = true }, cancel_request = <function 57>, capabilities = <38>{ general = <table 2>, textDocument = { callHierarchy = <table 3>, codeAction = <table 4>, completion = { completionItem = { commitCharactersSupport = true, deprecatedSupport = true, documentationFormat = <table 5>, insertReplaceSupport = true, insertTextModeSupport = { valueSet = { 1, 2 } }, labelDetailsSupport = true, preselectSupport = true, resolveSupport = { properties = { "documentation", "detail", "additionalTextEdits", "sortText", "filterText", "insertText", "textEdit", "insertTextFormat", "insertTextMode" } }, snippetSupport = true, tagSupport = { valueSet = { 1 } } }, completionItemKind = <table 6>, completionList = { itemDefaults = { "commitCharacters", "editRange", "insertTextFormat", "insertTextMode", "data" } }, contextSupport = true, dynamicRegistration = false, insertTextMode = 1 }, declaration = <table 7>, definition = <table 8>, diagnostic = <table 9>, documentHighlight = <table 10>, documentSymbol = <table 11>, formatting = <table 12>, hover = <table 13>, implementation = <table 14>, inlayHint = <table 15>, publishDiagnostics = <table 16>, rangeFormatting = <table 17>, references = <table 18>, rename = <table 19>, semanticTokens = <table 20>, signatureHelp = <table 21>, synchronization = <table 22>, typeDefinition = <table 23> }, window = <table 24>, workspace = { applyEdit = true, configuration = true, didChangeConfiguration = <table 25>, didChangeWatchedFiles = <table 26>, inlayHint = <table 27>, semanticTokens = <table 28>, symbol = <table 29>, workspaceEdit = <table 30>, workspaceFolders = true } }, commands = {}, config = { _on_attach = <function 58>, autostart = true, capabilities = <table 38>, cmd = { "/Users/mochou/.local/share/nvim/mason/bin/ruff-lsp" }, cmd_cwd = "/Volumes/Code/Projects/python/django_ninjia", filetypes = { "python" }, handlers = <table 31>, init_options = { settings = { args = { filetypes = { "python" } } } }, log_level = 2, message_level = 2, name = "ruff_lsp", on_attach = <function 54>, on_exit = <function 55>, on_init = <function 56>, root_dir = "/Volumes/Code/Projects/python/django_ninjia", settings = <39>{}, single_file_support = true, workspace_folders = <40>{ { name = "/Volumes/Code/Projects/python/django_ninjia", uri = "file:///Volumes/Code/Projects/python/django_ninjia" } }, <metatable> = <table 34> }, dynamic_capabilities = { capabilities = {}, client_id = 2, <metatable> = { __index = <table 35> } }, flags = {}, get_language_id = <function 15>, handlers = <table 31>, id = 2, initialized = true, is_stopped = <function 59>, messages = { messages = {}, name = "ruff_lsp", progress = {}, status = {} }, name = "ruff_lsp", notify = <function 60>, offset_encoding = "utf-16", on_attach = <function 61>, progress = { _idx_read = 0, _idx_write = 0, _items = {}, _size = 51, pending = {}, <metatable> = { __call = <function 62>, __index = <table 36> } }, request = <function 63>, request_sync = <function 64>, requests = {}, root_dir = "/Volumes/Code/Projects/python/django_ninjia", rpc = { is_closing = <function 65>, notify = <function 66>, request = <function 67>, terminate = <function 68> }, server_capabilities = { codeActionProvider = { codeActionKinds = { "quickfix", "source.fixAll", "source.organizeImports", "source.fixAll.ruff", "source.organizeImports.ruff", "notebook.source.fixAll", "notebook.source.organizeImports", "notebook.source.fixAll.ruff", "notebook.source.organizeImports.ruff" }, resolveProvider = true }, documentFormattingProvider = true, documentRangeFormattingProvider = { documentSelector = { { language = "python", scheme = "file" }, { language = "python", scheme = "untitled" } }, rangesSupport = false, workDoneProgress = false }, executeCommandProvider = { commands = { "ruff.applyAutofix", "ruff.applyOrganizeImports", "ruff.applyFormat" } }, hoverProvider = false, positionEncoding = "utf-16", textDocumentSync = { change = 2, openClose = true, save = true, willSave = false, willSaveWaitUntil = false }, workspace = { fileOperations = vim.empty_dict(), workspaceFolders = { changeNotifications = true, supported = true } } }, settings = <table 39>, stop = <function 69>, supports_method = <function 70>, workspace_did_change_configuration = <function 71>, workspace_folders = <table 40>, <metatable> = <table 37> } }
[START][2024-06-24 02:10:27] LSP logging initiated
[INFO][2024-06-24 02:10:27] .../vim/lsp/rpc.lua:731 "Starting RPC client" { cmd = { "/Users/mochou/.local/share/nvim/mason/bin/ruff", "server", "--preview" }, extra = { cwd = "/Volumes/Code/Projects/python/django_ninjia" }}
[INFO][2024-06-24 02:10:27] .../vim/lsp/rpc.lua:731 "Starting RPC client" { cmd = { "/Users/mochou/.local/share/nvim/mason/bin/ruff-lsp" }, extra = { cwd = "/Volumes/Code/Projects/python/django_ninjia" }}
[INFO][2024-06-24 02:10:27] .../vim/lsp/rpc.lua:731 "Starting RPC client" { cmd = { "/Users/mochou/.local/share/nvim/mason/bin/basedpyright-langserver", "--stdio" }, extra = { cwd = "/Volumes/Code/Projects/python/django_ninjia" }}
[INFO][2024-06-24 02:10:27] ...m/lsp/client.lua:618 "LSP[ruff]" "server_capabilities" { server_capabilities = { codeActionProvider = { codeActionKinds = { "quickfix", "source.fixAll.ruff", "source.organizeImports.ruff", "notebook.source.fixAll.ruff", "notebook.source.organizeImports.ruff" }, resolveProvider = true, workDoneProgress = true }, diagnosticProvider = { identifier = "Ruff", interFileDependencies = false, workDoneProgress = true, workspaceDiagnostics = false }, documentFormattingProvider = true, documentRangeFormattingProvider = true, executeCommandProvider = { commands = { "ruff.applyFormat", "ruff.applyAutofix", "ruff.applyOrganizeImports", "ruff.printDebugInformation" }, workDoneProgress = false }, hoverProvider = true, notebookDocumentSync = { notebookSelector = { { cells = { { language = "python" } } } }, save = false }, positionEncoding = "utf-16", textDocumentSync = { change = 2, openClose = true, willSave = false, willSaveWaitUntil = false }, workspace = { workspaceFolders = { changeNotifications = true, supported = true } } }}
[INFO][2024-06-24 02:10:27] ...lsp/handlers.lua:627 "basedpyright language server 1.1.368 starting"
[INFO][2024-06-24 02:10:27] ...lsp/handlers.lua:627 "Server root directory: file:///Users/mochou/.local/share/nvim/mason/packages/basedpyright/venv/lib/python3.12/site-packages/basedpyright/dist"
[INFO][2024-06-24 02:10:27] ...lsp/handlers.lua:627 'Starting service instance "/Volumes/Code/Projects/python/django_ninjia"'
[INFO][2024-06-24 02:10:27] ...m/lsp/client.lua:618 "LSP[basedpyright]" "server_capabilities" { server_capabilities = { callHierarchyProvider = true, codeActionProvider = { codeActionKinds = { "quickfix", "source.organizeImports" }, workDoneProgress = true }, completionProvider = { completionItem = { labelDetailsSupport = true }, resolveProvider = true, triggerCharacters = { ".", "[", '"', "'" }, workDoneProgress = true }, declarationProvider = { workDoneProgress = true }, definitionProvider = { workDoneProgress = true }, documentHighlightProvider = { workDoneProgress = true }, documentSymbolProvider = { workDoneProgress = true }, executeCommandProvider = { commands = {}, workDoneProgress = true }, hoverProvider = { workDoneProgress = true }, inlayHintProvider = true, referencesProvider = { workDoneProgress = true }, renameProvider = { prepareProvider = true, workDoneProgress = true }, semanticTokensProvider = { full = true, legend = { tokenModifiers = { "definition", "declaration", "async", "readonly", "defaultLibrary", "builtin" }, tokenTypes = { "class", "parameter", "typeParameter", "function", "method", "decorator", "property", "namespace", "variable", "type", "keyword" } } }, signatureHelpProvider = { triggerCharacters = { "(", ",", ")" }, workDoneProgress = true }, textDocumentSync = { change = 2, openClose = true, save = { includeText = false }, willSave = false, willSaveWaitUntil = false }, typeDefinitionProvider = { workDoneProgress = true }, workspace = { workspaceFolders = { changeNotifications = true, supported = true } }, workspaceSymbolProvider = { workDoneProgress = true } }}
[INFO][2024-06-24 02:10:28] ...lsp/handlers.lua:627 'Workspace settings: {\n "args": {\n "filetypes": [\n "python"\n ]\n }\n}'
[INFO][2024-06-24 02:10:28] ...lsp/handlers.lua:627 "Global settings: {}"
[INFO][2024-06-24 02:10:28] ...m/lsp/client.lua:618 "LSP[ruff_lsp]" "server_capabilities" { server_capabilities = { codeActionProvider = { codeActionKinds = { "quickfix", "source.fixAll", "source.organizeImports", "source.fixAll.ruff", "source.organizeImports.ruff", "notebook.source.fixAll", "notebook.source.organizeImports", "notebook.source.fixAll.ruff", "notebook.source.organizeImports.ruff" }, resolveProvider = true }, documentFormattingProvider = true, documentRangeFormattingProvider = { documentSelector = { { language = "python", scheme = "file" }, { language = "python", scheme = "untitled" } }, rangesSupport = false, workDoneProgress = false }, executeCommandProvider = { commands = { "ruff.applyAutofix", "ruff.applyOrganizeImports", "ruff.applyFormat" } }, hoverProvider = false, positionEncoding = "utf-16", textDocumentSync = { change = 2, openClose = true, save = true, willSave = false, willSaveWaitUntil = false }, workspace = { fileOperations = vim.empty_dict(), workspaceFolders = { changeNotifications = true, supported = true } } }}
[INFO][2024-06-24 02:10:28] ...lsp/handlers.lua:627 "Using interpreter executable: /Users/mochou/.local/share/nvim/mason/packages/ruff-lsp/venv/bin/ruff"
[INFO][2024-06-24 02:10:28] ...lsp/handlers.lua:627 "Inferred version 0.4.8 for: /Users/mochou/.local/share/nvim/mason/packages/ruff-lsp/venv/bin/ruff"
[INFO][2024-06-24 02:10:28] ...lsp/handlers.lua:627 "Found ruff 0.4.8 at /Users/mochou/.local/share/nvim/mason/packages/ruff-lsp/venv/bin/ruff"
[INFO][2024-06-24 02:10:28] ...lsp/handlers.lua:627 "Running Ruff with: /Users/mochou/.local/share/nvim/mason/packages/ruff-lsp/venv/bin/ruff ['check', '--force-exclude', '--no-cache', '--no-fix', '--quiet', '--output-format', 'json', '-', 'filetypes', '--stdin-filename', '/Volumes/Code/Projects/python/django_ninjia/manage.py']"
[INFO][2024-06-24 02:10:28] ...lsp/handlers.lua:627 "Loading pyproject.toml file at /Volumes/Code/Projects/python/django_ninjia/pyproject.toml"
[INFO][2024-06-24 02:10:28] ...lsp/handlers.lua:627 "Assuming Python version 3.12.3.final.0"
[INFO][2024-06-24 02:10:28] ...lsp/handlers.lua:627 "No include entries specified; assuming /Volumes/Code/Projects/python/django_ninjia"
[INFO][2024-06-24 02:10:28] ...lsp/handlers.lua:627 "Auto-excluding **/node_modules"
[INFO][2024-06-24 02:10:28] ...lsp/handlers.lua:627 "Auto-excluding **/__pycache__"
[INFO][2024-06-24 02:10:28] ...lsp/handlers.lua:627 "Auto-excluding **/.*"
[ERROR][2024-06-24 02:10:28] ...lsp/handlers.lua:623 "unknown config option: disableLanguageServices"
[WARN][2024-06-24 02:10:28] ...lsp/handlers.lua:625 "The useLibraryCodeForTypes has been specified in both the config file and the client settings. The value in the config file (true) will take precedence"
[INFO][2024-06-24 02:10:28] ...lsp/handlers.lua:627 "Found 25 source files"
Good find!
I just tested at my machine and the plugin doesnt work properly with lazy = true
. With that setting i get no cached venvs to activate and I dont even get VenvSelectLog to show anything.
I never tested lazy loading the plugin actually. Clearly it doesnt currently work properly, thank you for finding that. :)
Im going on vacation for two weeks to Italy tomorrow, so I wont be able to fix that until I get back. But its very good to know that its causing problems. If you want to write a PR to fix lazy loading, you are very welcome. :)
Its a bit strange that I dont see any attempt to activate the venv from cache in your log there.
vim.api.nvim_create_autocmd("LspAttach", { pattern = "*.py", callback = on_lsp_attach, }) local function on_lsp_attach() local cache = require("venv-selector.cached_venv") if config.user_settings.options.cached_venv_automatic_activation == true then cache.retrieve() end end
This is from the plugin code, and just to explain a bit, it creates an autocommand called
LspAttach
that will call thelsp_attach()
function whenever you open a python file.And unless you have set the option
cached_venv_automatic_activation
to false, it should retrieve the venv from cache.I see in your debug info that its writing the venv to the cache, but no attempts at reading it from cache. It should also write your settings at the top of the debug info, but I guess you removed that?
local function on_lsp_attach(client, bufnr)
print(client.name)
local cache = require 'venv-selector.cached_venv'
if config.default_settings.options.cached_venv_automatic_activation == true then
cache.retrieve()
end
end
vim.api.nvim_create_autocmd('LspAttach', {
group = vim.api.nvim_create_augroup('lsp_acttach_python_venv', { clear = true }),
pattern = '*.py',
callback = function(args)
local client = vim.lsp.get_client_by_id(args.data.client_id)
local bufnr = args.buf
if client and bufnr then
on_lsp_attach(client, bufnr)
end
end,
})
local M = {
"linux-cultist/venv-selector.nvim",
dependencies = {
"neovim/nvim-lspconfig",
},
branch = "regexp", -- This is the regexp branch, use this for the new version
-- lazy = false,
event = { "LspAttach" },
}
Modifying the above will automatically activate the environment, but there are still errors.
When I set lazy=false
it causes LSP Server to fail to start, I haven't found the reason for this yet.
Still, on my environment I have the following problem, which is something that might be needed for the program
LspAttach
based listener plugin is launched, there are no parameters in user_settings
, so it is recommended to use the table
function to override default_settings
directly with the parameters passed in by the user.hooks
can be made based on the LSP Server
selected by the userpyenv
, they must have set the PYENV_ROOT
environment variable, because that's a precondition inside the pyenv
documentation, and venv-selector
can be used without using the hard-codedI'll try to fix the main current problem with the above
Ok I read this and understand the pull request a bit more, but I think I need to look at the code a bit to see what is causing the problem. Also to understand what you have found. But since I'm on vacation, it will have to wait a few weeks. Bad timing. :)
nvim config
The cache modal produces the venvs2.json record file, but opening the directory again does not activate the virtual environment
Whether you use nvim . or nvim file you end up not being able to activate it automatically. use commint: d946b1e86212f38ff9c42e3b622a8178bbc93461
I have 2 questions.