pappasam / jedi-language-server

A Python language server exclusively for Jedi. If Jedi supports it well, this language server should too.
MIT License
572 stars 44 forks source link

Add "environmentPath" init option, for Jedi "environment_path" #232

Closed gwerbin closed 1 year ago

gwerbin commented 1 year ago

This PR is intended to address the feature request in #199.

I'm not sure how to formally test this, but I have confirmed that it works as follows.

First, set up two venvs: one with this branch pip install-ed, and another with a nontrivial library dependency:

git clone https://gwerbin/jedi-language-server gwerbin_jedi-language-server
cd gwerbin_jedi-language-server

python -m venv ./jedi-env
./jedi-env/bin/pip install -e .

python -m venv ./work-env
./work-env/bin/pip install -U numpy

Then configure the following in Neovim LSP Config:

    lspconfig.jedi_language_server.setup({
      cmd = { '/path/to/jedi-env/bin/jedi-language-server' },
      on_new_config = function(new_config, root_dir)
        new_config.init_options = {
          workspace = {
            environmentPath = '/path/to/work-env/bin/python',
          },
        }
      end,
    }))

Finally, use Neovim to create a new Python file called nptest.py. You should be able to write import numpy as np at the top of the file and see Jedi completions for Numpy with np.<tab>, e.g. np.random.default_rng().

Confirm also that if you remove cmd = from the Neovim config above, that Numpy library completion no longer works when editing nptest.py.

pappasam commented 1 year ago

Thanks for the PR! To speed things up, I suggest running the tests locally and resolving any errors. make test will be helpful!

gwerbin commented 1 year ago

Thanks for merging this!

I'm relieved that it was such a quick fix. I strongly prefer Jedi LS compared to both PyLSP and the newcomer Anakin (although I figured out how to do it by reading the Anakin docs).

Now that this feature is merged, I'm eager to start using Jedi LS again.

Do you have a rough estimate for when this will land in PyPI? Wow, that was quick! https://pypi.org/project/jedi-language-server/0.38.0/