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

Python autocomplete does not work with "semantic completer exception" #1924

Closed revothuang closed 8 years ago

revothuang commented 8 years ago

Thanks for the great work of YCM, it really improves my productivity writing c++.

Now i am trying to try this plugin while writing python code, but i got exception message in the server log file as following:

387 2016-01-19 21:57:39,575 - INFO - Received event notification 388 2016-01-19 21:57:39,575 - INFO - Adding ONE buffer identifier for file: /home/rhuang/test_ycm/test.py 389 2016-01-19 21:57:39,578 - INFO - Received completion request 390 2016-01-19 21:57:39,581 - INFO - Starting new HTTP connection (1): 127.0.0.1 391 2016-01-19 21:57:39,583 - ERROR - Exception from semantic completer (using general): Traceback (most recent call last): 392 File "/home/rhuang/.vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/../ycmd/handlers.py", line 104, in GetCompletions 393 .ComputeCandidates( request_data ) ) 394 File "/home/rhuang/.vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/../ycmd/completers/completer.py", line 168, in ComputeCandidates 395 candidates = self._GetCandidatesFromSubclass( request_data ) 396 File "/home/rhuang/.vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/../ycmd/completers/completer.py", line 184, in _GetCandidatesFromSubclass 397 raw_completions = self.ComputeCandidatesInner( request_data ) 398 File "/home/rhuang/.vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/../ycmd/completers/python/jedi_completer.py", line 217, in ComputeCandidatesI nner 399 for completion in self._JediCompletions( request_data ) ] 400 File "/home/rhuang/.vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/../ycmd/completers/python/jedi_completer.py", line 221, in _JediCompletions 401 return self._GetResponse( '/completions', request_data )[ 'completions' ] 402 File "/home/rhuang/.vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/../ycmd/completers/python/jedi_completer.py", line 167, in _GetResponse 403 auth = HmacAuth( self._hmac_secret ) ) 404 File "/home/rhuang/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/requests/requests/api.py", line 109, in post 405 return request('post', url, data=data, json=json, _kwargs) 406 File "/home/rhuang/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/requests/requests/api.py", line 50, in request 407 response = session.request(method=method, url=url, _kwargs) 408 File "/home/rhuang/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/requests/requests/sessions.py", line 468, in request 409 resp = self.send(prep, _send_kwargs) 410 File "/home/rhuang/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/requests/requests/sessions.py", line 576, in send 411 r = adapter.send(request, _kwargs) 412 File "/home/rhuang/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/requests/requests/adapters.py", line 423, in send 413 raise ConnectionError(e, request=request)

414 ConnectionError: HTTPConnectionPool(host='127.0.0.1', port=50246): Max retries exceeded with url: /completions (Caused by NewConnectionError('<req uests.packages.urllib3.connection.HTTPConnection object at 0x7f556c0293d0>: Failed to establish a new connection: [Errno 111] Connection refused', ))

Any idea what's going wrong?

Thx.

micbou commented 8 years ago

What is the output of :YcmDebugInfo in a Python file?

vheon commented 8 years ago

A reproducible test case would be great :+1:

revothuang commented 8 years ago

Thx for the reply. While editing my test.py file, the YcmDebugInfo gives:

====================================================
Printing YouCompleteMe debug information...
-- Server has Clang support compiled in: True
-- Clang version: clang version 3.3 (tags/RELEASE_33/final)
-- Server running at: http://127.0.0.1:53991
-- Server process ID: 3469
-- Server logfiles:
--   /tmp/ycm_temp/server_53991_stdout.log
--   /tmp/ycm_temp/server_53991_stderr.log
================================================

stdout.log is empty. stderr.log shows:

================================================
2016-01-20 10:18:43,241 - INFO - Received event notification
2016-01-20 10:18:43,242 - INFO - Received event notification
2016-01-20 10:18:43,280 - INFO - Adding buffer identifiers for file: /home/rhuang/test_ycm/test.py
2016-01-20 10:18:43,446 - INFO - Starting JediHTTP server
2016-01-20 10:18:43,446 - INFO - using port 44670
2016-01-20 10:18:43,624 - INFO - Received health request
2016-01-20 10:18:43,632 - INFO - Received filetype completion available request
2016-01-20 10:18:47,967 - INFO - Received debug info request
2016-01-20 10:18:47,979 - INFO - Starting new HTTP connection (1): 127.0.0.1
================================================

Then if i want to trigger the autocomplete menu by typing "sys.", the stderr.log then shows the call stack in my first post. (just port number changed)

I am not sure what test case you need. My test.py file is extreamly simple.

================================================
import sys;
print(sys.version);
class MyClass:
    i = 123456;
    def f():
        return "hello";

sys.
================================================

It seems not due to the python file i am editing, it's more like some network setting issue. I am using this on my office Redhat linux server, maybe the IT guys set up firewall or something that could break the connection.

Thx.

vheon commented 8 years ago

There is something strange here:

====================================================
Printing YouCompleteMe debug information...
-- Server has Clang support compiled in: True
-- Clang version: clang version 3.3 (tags/RELEASE_33/final)
-- Server running at: http://127.0.0.1:53991
-- Server process ID: 3469
-- Server logfiles:
--   /tmp/ycm_temp/server_53991_stdout.log
--   /tmp/ycm_temp/server_53991_stderr.log
================================================

There should've been information about JediHTTP, for example here's mine:

Printing YouCompleteMe debug information...
-- Server has Clang support compiled in: True
-- Clang version: clang version 3.7.0 (tags/RELEASE_370/final)
-- JediHTTP running at 127.0.0.1:51240
--   stdout log: /var/folders/fv/h6qjtq2n4k9dmhgf4r_k__0r0000gn/T/ycm_temp/jedihttp_51240_stdout.log
--   stderr log: /var/folders/fv/h6qjtq2n4k9dmhgf4r_k__0r0000gn/T/ycm_temp/jedihttp_51240_stderr.log
-- Server running at: http://127.0.0.1:51233
-- Server process ID: 55909
-- Server logfiles:
--   /var/folders/fv/h6qjtq2n4k9dmhgf4r_k__0r0000gn/T/ycm_temp/server_51233_stdout.log
--   /var/folders/fv/h6qjtq2n4k9dmhgf4r_k__0r0000gn/T/ycm_temp/server_51233_stderr.log
vheon commented 8 years ago

why there are semicolons in your example?? Anyway I just tried on my machine and I can get completion just fine. If I were you I would try a plain install: delete the YouCompleteMe directory and start from scratch.

krak3n commented 8 years ago

I have the same issue where JediHTTP dosn't appear to be starting.

krak3n commented 8 years ago

I tried to start the Jedi Server locally myself just by calling python third_party/ycmd/third_party/JediHTTP/jedihttp.py - it threw this exception:

Traceback (most recent call last):
  File "./jedihttp.py", line 22, in <module>
    from jedihttp import handlers
  File "/Users/chrisreeves/.vim/plugged/YouCompleteMe/third_party/ycmd/third_party/JediHTTP/jedihttp/handlers.py", line 115, in <module>
    @app.error( httplib.INTERNAL_SERVER_ERROR )
AttributeError: 'module' object has no attribute 'INTERNAL_SERVER_ERROR'

Which I narrowed to this import: https://github.com/vheon/JediHTTP/blob/master/jedihttp/handlers.py#L25

Removing that try except and simply just importing httplib fixes the issue and the jedi server can start and auto complete once again works.

I guess this was added for Python 3 compatibility since httplib was moved to http.client in python 3 but my python 2 install does have an http.client module which doesn't mirror httplib, it looks like this (/Library/Python/2.7/site-packages/http):

from __future__ import absolute_import

from httplib import *

I would suggest the the import check should be the other way round:

try:
    import httplib
except ImportError:
    from http import client as httplib
vheon commented 8 years ago

Thanks for investigating this through! I've pushed a new commit to JediHTTP, so as soon as it lands we can update ycmd and YCM

revothuang commented 8 years ago

Thank to krak3n, i also figure out my problem. By invoking the jedihttp.py direction, there's an import excpetion saying it finds no argparse module. Once I download the package to copy the argparse.py file to the JediHttp folder, everything works perfectly.

Well, yes, my Redhat linux is still using very old python version, which is 2.6.6. Anyway, thx a lot. My problem solved.

vheon commented 8 years ago

@revothuang How did you install YCM? I assume not using the install.py script because that script uses argparse too :confused: In the test suite for JediHTTP I use the Travis linux machine and for python 2.6 it install 2.6.9 :disappointed:

micbou commented 8 years ago

@vheon But argparse is bundled in ycmd. This is not the case for JediHTTP.

vheon commented 8 years ago

@micbou I was confident that we used the one in the standard library since my tests were passing on Travis. At this point I think I should import it as a submodule in JediHTTP too :cry:

micbou commented 8 years ago

argparse is only available since python 2.7. Your tests pass because one of the packages from test_requirements.txt (or the unittest2 and ordereddict packages) depends on argparse. I couldn't find which one however.

Valloric commented 8 years ago

@vheon What's the state of this in JediHTTP? Is argparse now bundled there?

vheon commented 8 years ago

Yes it is, I've create a PR in ycmd to update the submodule