davidhalter / jedi-vim

Using the jedi autocompletion library for VIM.
MIT License
5.27k stars 370 forks source link

Use the new Jedi API #1025

Closed davidhalter closed 3 years ago

davidhalter commented 4 years ago

Still thinking about implementing refactorings.

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

davidhalter commented 4 years ago

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 commented 4 years ago

@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 commented 3 years ago

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 commented 3 years ago

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?

davidhalter commented 3 years ago

@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 commented 3 years ago

seems to be working well! thanks david :-)

i'll close my pr...

hjwp commented 3 years ago

why not update the submodules on this branch?

davidhalter commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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

davidhalter commented 3 years ago

@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 commented 3 years ago

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? :cat:

davidhalter commented 3 years ago

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 commented 3 years ago

@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 :)