Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the new Jedi API #1025

Merged
merged 22 commits into from
Dec 26, 2020
Merged

Use the new Jedi API #1025

merged 22 commits into from
Dec 26, 2020

Conversation

davidhalter
Copy link
Owner

  • Removed all usages of deprecated functions in Jedi
  • Reworked environment support. We are using jedi.Project now to manage environment paths (This might make parts of [WIP/RFC] Improve selection of environments #836 not necessary)
  • Added :JediChooseEnvironment (which displays a list of environments that a user can choose)
  • Added a for now undocumented :JediLoadProject, which might need some changes to Jedi to properly work like I want it to.

Still thinking about implementing refactorings.

Would be interested in @blueyed's thoughts about these changes.

@davidhalter davidhalter requested a review from blueyed August 1, 2020 12:27
It should mostly still work (except for :Pyimport), but it won't pass all the tests anymore.
Since I'm dropping Python 2 in Jedi anyways, it makes sense to also remove it here.
@davidhalter
Copy link
Owner Author

davidhalter commented Aug 4, 2020

The CI is finally passing now.

I removed Python 2 support in the CI. I'm going to release the next Jedi version very soon which drops Python 2. So I guess it's fine to remove support here. It still works with Python 2 though, that's why I did not remove the jedi#force_py_version = 2.

@davidhalter
Copy link
Owner Author

@blueyed I would like to merge this, because I would like to make it compatible with Jedi 0.18.0, which should be released soon.

I can understand if you don't have a lot of time to spare. Should I just merge without review regardless?

@hjwp
Copy link

hjwp commented Oct 13, 2020

Hi @davidhalter I was trying out your branch in the context of my search for #1029 . I'm seeing the following traceback when trying to do a go-to-definition:

Traceback (most recent call last):
  File "/home/harry/.vim/bundle/jedi-vim/pythonx/jedi_vim.py", line 194, in wrapper
    return func(*args, **kwargs)
  File "/home/harry/.vim/bundle/jedi-vim/pythonx/jedi_vim.py", line 395, in goto
    names = script.goto(*pos, follow_imports=True)
  File "/home/harry/.vim/bundle/jedi-vim/pythonx/jedi/jedi/api/helpers.py", line 487, in wrapper
    return func(self, line, column, *args, **kwargs)
  File "/home/harry/.vim/bundle/jedi-vim/pythonx/jedi/jedi/api/__init__.py", line 371, in goto
    return self._goto(line, column, **kwargs)
  File "/home/harry/.vim/bundle/jedi-vim/pythonx/jedi/jedi/api/__init__.py", line 396, in _goto
    names = list(name.goto())
  File "/home/harry/.vim/bundle/jedi-vim/pythonx/jedi/jedi/inference/names.py", line 155, in goto
    module_names = goto_import(context, name)
  File "/home/harry/.vim/bundle/jedi-vim/pythonx/jedi/jedi/inference/cache.py", line 44, in wrapper
    rv = function(obj, *args, **kwargs)
  File "/home/harry/.vim/bundle/jedi-vim/pythonx/jedi/jedi/inference/imports.py", line 77, in goto_import
    _prepare_infer_import(module_context, tree_name)
  File "/home/harry/.vim/bundle/jedi-vim/pythonx/jedi/jedi/inference/imports.py", line 115, in _prepare_infer_import
    importer = Importer(module_context.inference_state, tuple(import_path),
  File "/home/harry/.vim/bundle/jedi-vim/pythonx/jedi/jedi/inference/imports.py", line 169, in __init__
    debug.speed('import %s %s' % (import_path, module_context))
  File "/home/harry/.vim/bundle/jedi-vim/pythonx/jedi/jedi/inference/context.py", line 216, in __repr__
    return '%s(%s)' % (self.__class__.__name__, self._value)
  File "/home/harry/.vim/bundle/jedi-vim/pythonx/jedi/jedi/inference/value/module.py", line 228, in __repr__
    self.is_stub()
  File "/home/harry/.vim/bundle/jedi-vim/pythonx/jedi/jedi/inference/value/module.py", line 159, in is_stub
    if self._path is not None and self._path.endswith('.pyi'):
AttributeError: 'PosixPath' object has no attribute 'endswith'

fwiw i hacked a quick fix into the jedi submodule like this

diff --git a/jedi/inference/value/module.py b/jedi/inference/value/module.py
index 12d2bfcf..f7987447 100644
--- a/jedi/inference/value/module.py
+++ b/jedi/inference/value/module.py
@@ -156,7 +156,7 @@ class ModuleValue(ModuleMixin, TreeValue):
         self._is_package = is_package
 
     def is_stub(self):
-        if self._path is not None and self._path.endswith('.pyi'):
+        if self._path is not None and str(self._path).endswith('.pyi'):
             # Currently this is the way how we identify stubs when e.g. goto is
             # used in them. This could be changed if stubs would be identified
             # sooner and used as StubModuleValue.

@hjwp
Copy link

hjwp commented Oct 13, 2020

I found a few similar errors coming from various places, eg

  File "/home/harry/.vim/bundle/jedi-vim/pythonx/jedi/jedi/inference/references.py", line 210, in recurse_find_python_folders_and_files
    if path.endswith('.py') or path.endswith('.pyi'):
AttributeError: 'PosixPath' object has no attribute 'endswith'

I see that one's coming from a call to folder_io.walk() -- something yielding PosixPath objects instead of strings?

@hjwp hjwp mentioned this pull request Oct 14, 2020
@davidhalter
Copy link
Owner Author

@hjwp This branch is probably not working well with the old jedi/parso versions. So please just try to upgrade those submodules to latest master and it should work.

I pushed one more fix as well.

@hjwp
Copy link

hjwp commented Oct 26, 2020

seems to be working well! thanks david :-)

i'll close my pr...

@hjwp
Copy link

hjwp commented Oct 26, 2020

why not update the submodules on this branch?

@davidhalter
Copy link
Owner Author

Will do that when I'm done with the 0.18.0 release for Jedi. Otherwise I just have to update again and again.

@hjwp
Copy link

hjwp commented Oct 26, 2020

Hey I just wanted to say thanks for all your work on this David! People are always asking me how the heck I get so much IDE-like functionality out vim. It's all thanks to you <3

@hjwp
Copy link

hjwp commented Oct 26, 2020

not forgetting @blueyed and all the other contributors too. thanks for all that you do!

@davidhalter
Copy link
Owner Author

@hjwp

You're very welcome!

Just as a head's up: Jedi-vim is more like a side-project that I use for testing Jedi. If you ever get annoyed by some of its idiosyncrasies, feel free to check out stuff like https://github.com/pappasam/jedi-language-server or all the other Jedi based language servers (there's quite a few of them). Some of these language servers have more Jedi features implemented than jedi-vim.

@anthraxx
Copy link

Our distro is currently trying to get python 3.9 shippen, but this is one of our issues right now which i believe would tackle our issues. No pressure here and all your work is very much appreciated, but is there any kind of ETC? 🐱

@davidhalter davidhalter force-pushed the jedi-api branch 4 times, most recently from 23c6455 to 092f8c8 Compare December 26, 2020 22:35
@davidhalter
Copy link
Owner Author

Since there wasn't any feedback anymore and the latest Jedi does not work anymore with current jedi-vim, I decided to merge.

Includes the switch from Travis CI to GitHub Actions and the submodule upgrades from Jedi 0.17.2 to 0.18.0 as well as the Parso 0.8 upgrade.

This makes the removal of Python 2 from the code base final.

@davidhalter davidhalter merged commit 57757bd into master Dec 26, 2020
@davidhalter davidhalter deleted the jedi-api branch December 26, 2020 22:48
@davidhalter
Copy link
Owner Author

@anthraxx Sorry for not giving you an estimate earlier, but there's really none. It all depends on my mood. Jedi is in general way higher in priority than jedi-vim and now that I'm rewriting stuff in Rust, that is even higher priority, while none of them is my job. So yeah, it's just going to arrive when it does :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants