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

Cannot get completion to work with Python #1909

Closed robertsawko closed 8 years ago

robertsawko commented 8 years ago

Hi,

I am reading about Jedi integration with YCM for completion and for everyone this seems to be working out of the box. Alas, not for me!

I can confirm that set filetype? results in python. My configuration is pretty minimal

"YCM config
"let g:ycm_filetype_whitelist = { 'cpp' : 1, 'python' : 1 }
"let g:ycm_filetype_blacklist = { 'vim' : 1, 'text' : 1 }
"let g:ycm_filetype_specific_completion_to_disable = { 'python': 1  }
"let g:ycm_confirm_extra_conf = 0
let g:ycm_autoclose_preview_window_after_completion=1
nnoremap <leader>g :YcmCompleter GoToDefinitionElseDeclaration<CR>

I normally work with other let lines uncommented. Finally, the :YcmCompleter command ends up with:

ValueError: Supported commands are:                                                                
GoToDefinition                                                                                     
GoToDeclaration                                                                                    
GoTo

and I can confirm that the go-tos work fine, but not the completion. The minimal example with which I am working is:

from numpy import arange                                                                       
x = arange(10)  
x.sha... # Hitting <Ctrl+N> to force YCM

where I am expecting shape to appear.

How can I check that Jedi has been selected? Should I be worried about this ValueError? Is there anything specific I need to configure to get good Python completion, ideally for function parameter names too.

micbou commented 8 years ago

How can I check that Jedi has been selected?

If :YcmCompleter returns a list of commands, it means YCM is using Jedi. You can also type the :YcmDebugInfo command and check if the JediHTTP server is running.

Should I be worried about this ValueError?

No, this is proper behavior when no parameter is given to :YcmCompleter.

Concerning your example, Jedi has some issue to complete Numpy functions. YCM cannot do anything about it. However, you may also experience some timeout issue. If you often get the following message in the status line:

HTTPConnectionPool(host='127.0.0.1', port=44642): Read timed out. (read timeout=0.5)

you can increase the value of TIMEOUT_SECONDS in python/ycm/client/completion_request.py.

robertsawko commented 8 years ago

Thanks, yes, now I see that my problem may be numpy related. For instance I get completion on

x = [1, 2, 3]
x.app # Don't even have to press anything

where append pops up as expected. Yay. But that's really a shame as numpy and scipy completions are the ones for which I yearn most.

Ah, yes, I forgot that :YcmCompleter is really a prefix to other commands. It's YcmDebugInfo I was after. The output is

Printing YouCompleteMe debug information...                                                        
-- Server has Clang support compiled in: True                                                      
-- Clang version: clang version 3.7.0 (tags/RELEASE_370/final)                                     
--                                                                                                 
-- Server running at: http://127.0.0.1:54261                                                       
-- Server process ID: 6350                                                                         
-- Server logfiles:                                                                                
--   /tmp/ycm_temp/server_54261_stdout.log                                                         
--   /tmp/ycm_temp/server_54261_stderr.log

So there's clang but no Jedi!

Increasing TIMEOUT_SECONDS didn't change anything.

micbou commented 8 years ago

Did you update YCM to the latest version? JediHTTP informations in :YcmDebugInfo will only appear in recent versions.

Increasing TIMEOUT_SECONDS didn't change anything.

This is useful only if you get timeouts from YCM. It will not help for completing Numpy functions.

robertsawko commented 8 years ago

You're right, I just updated everything and I am getting

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:60591                                                                                                             
--   stdout log: /tmp/ycm_temp/jedihttp_60591_stdout.log                                                                                           
--   stderr log: /tmp/ycm_temp/jedihttp_60591_stderr.log                                                                                           
-- Server running at: http://127.0.0.1:37356                                                                                                       
-- Server process ID: 10213                                                                                                                        
-- Server logfiles:                                                                                                                                
--   /tmp/ycm_temp/server_37356_stdout.log                                                                                                         
--   /tmp/ycm_temp/server_37356_stderr.log 

And the numpy example still doesn't complete. Now, I think, we're confident that Jedi is working. Does this close the issue on YCM side?

micbou commented 8 years ago

I think so. Let us know if you have other issues.