Repository navigation
Conversation
pylsp's Jedi used the Python that runs pylsp, so only packages of the plugin's own environment completed. Send plugins.jedi.environment with the project's interpreter (nbproject.python_path, Poetry, else a configured jedi.environment, else the default platform) when a server starts or restarts, when the project interpreter changes and when the LSP settings are saved. Missing interpreters and the default empty env_vars are not sent, because both break Jedi. Tests: PythonLspConfigurationTest, plus a real-pylsp integration test (-Dpython.lsp.test.executable). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #144: completion now uses the project's interpreter (its venv, Poetry environment or selected Python) instead of the plugin's own pylsp environment.
Cause
pylsp's Jedi plugins use
pylsp.plugins.jedi.environment. The plugin never sent it, so Jedi analysed code with the Python that runs pylsp (<userdir>/.pythonlsp/.venv). That's why only the standard library and packages installed in that environment completed.Change
New
PythonLspConfigurationsends the pylsp settings, withplugins.jedi.environmentset:PythonLspClient.startServerregisters the new server. Its settings are sent once NetBeans has initialized it (LSPBindingschange event). Previously they were sent only from the project-opened hook, so restarted servers and files outside projects got none. The hook still sends them too, for a server that kept running while its project was closed and reopened.The interpreter is, in order:
nbproject.python_path, or the Poetry environment (what Run uses).plugins.jedi.environmentthe user put in the settings JSON (kept as is).Two guards, both checked against pylsp 1.15 and Jedi 0.20:
.venv) is not sent. With such a path,jedi.create_environmentraises, which would break every Jedi request (completion, hover, go to definition), not just fall back.settings.jsonhas"env_vars": {}. While no environment is set, pylsp ignoresenv_vars. Once one is set, Jedi starts that interpreter with exactly these variables, so an empty map would mean an empty environment. That works on Linux, but CPython on Windows fails to start withoutSYSTEMROOT. An emptyenv_varsis therefore left out, so pylsp passes on its own environment (minusPYTHONPATH, as pylsp always does). A non-emptyenv_varsis sent unchanged.pom.xml: surefire setsnetbeans.usertotarget/test-userdir, becausePythonUtilityneeds it in tests.Tests
PythonLspConfigurationTest(12 tests, run in CI):env_varshandling and interpreter precedence;platforms.jsonfalls back to pylsp's own environment;It works on both RELEASE290 and RELEASE310; the private
LSPBindingsconstructor differs between them.PythonLspInterpreterIntegrationTestuses a real pylsp. It is skipped unless-Dpython.lsp.test.executable=/absolute/path/to/python-with-pylspis set. It creates a venv that has a module pylsp's environment lacks, and checks three things with the bundled default settings: completion misses the module without the interpreter (the issue), finds it with it, and loses it again after switching back.Built with
clean verifyon RELEASE290 and RELEASE310: 32 tests pass, including the real-pylsp test (pylsp 1.15.0, Jedi 0.20.1, Python 3.14).Also checked in a real NetBeans 31, with an isolated profile and the packaged NBM, through NetBeans' own LSP client. The project's
.venvcontains a module that pylsp's environment doesn't have:How to test by hand
.venv, install a package that the plugin's own environment lacks, e.g..venv/bin/pip install requests..venvas the project's Python in Project Properties.import requestsand thenrequests.in a file: completion listsget,post, and so on. On master it lists nothing.Not tested on Windows or macOS.
This change was written with AI assistance (Claude Opus) and reviewed and tested as described above.
🤖 Generated with Claude Code