ycm-core / YouCompleteMe

A code-completion engine for Vim
http://ycm-core.github.io/YouCompleteMe/
GNU General Public License v3.0
25.44k stars 2.81k forks source link

Weird Dynamic Autocompletion #3049

Closed ikey4u closed 6 years ago

ikey4u commented 6 years ago

Reproduce the problem:

New a python3 file:

#! /usr/bin/env python3
#! -*- coding:utf-8 -*-

import multiprocessing as mp

Since python3's multiprocessing is based on python2's threading libs, the__init__.py for python3 multiprocessing has no function or class declaration. As a result, YCM cannot detect the completion. The completion result is showed as following:

image

After reading Jedi's documents, I find that Jedi has supplied us an API to dynamic get the completion as long as we feed it with locals(). Detail is in jedi.Interpreter class and showed here:https://jedi.readthedocs.io/en/latest/docs/api.html

I want to transfer locals() to Jedi but I failed. When I do the research, I change the code

def _GetResponse( self, handler, request_data = {} ): to

def _GetResponse( self, handler, request_data = {} ):
pass

in ~/.vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/completers/python/jedi_completer.py

Then something interesting(weird) happens, the expected and correct completion appears which is showed in the following figure image

So I have two problems:

  1. Do you have any opinions that could make Jedi knows the locals()?

  2. Why does the weird thing happen?

Any suggestions will be appreciated.

micbou commented 6 years ago

Do you have any opinions that could make Jedi knows the locals()?

There is no such thing as passing the locals to Jedi. Completions are missing from multiprocessing because of a Jedi limitation. See https://github.com/davidhalter/jedi/issues/1094.

Why does the weird thing happen?

The change you made to the jedi_completer.py file raises a syntax error (you should see the error in the output of :messages). Because of that error, YCM is unable to provide native completion for Python and falls back to Vim's omnifunc which is returning those suggestions. In that particular case, Vim's omnifunc does a better job than Jedi. You should revert the change you made and wait for issue https://github.com/davidhalter/jedi/issues/1094 to be resolved.

Closing the issue as a Jedi limitation.

ikey4u commented 6 years ago

@micbou Many thanks for your kind and quick reply.