Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jedi-vim omni completion with not standard library

I read the README of the jedi-vim. https://github.com/davidhalter/jedi

There are screenshots of omni completing with a non-standard library (Django).

I installed django by pip and tried exact same code to test omni completion of Django, but it doesn't work.

Omni completion (^O^N^P) Pattern not found.

Standard library's omni completion is working perfect.

I'm usually using some non-standard library so I want to use omni completion with those libraries.

Should I do some configuration to use omni completion with non-standard libraries?

like image 789
supermomonga Avatar asked Mar 03 '13 19:03

supermomonga


2 Answers

Most third libraries should work out of the box, Django isn't so nice with autocompletion, you need to have in your environment the variable DJANGO_SETTINGS set, otherwise most imports will raise an improperly configured exception and the autocompletion will not work.

You can set this variable in you virtualenv, or with a alias in your shell, or using something like this in your .vimrc:

function FindDjangoSettings()
  if strlen($VIRTUAL_ENV) && has('python')
    let output  = system("find $VIRTUAL_ENV \\( -wholename '*/lib/*' -or -wholename '*/install/' \\) -or \\( -name 'settings.py' -print0 \\) | tr '\n' ' '")
    let outarray= split(output, '[\/]\+')
    let module  = outarray[-2] . '.' . 'settings'
    let syspath = system("python -c 'import sys; print sys.path' | tr '\n' ' ' ")
    " let curpath = '/' . join(outarray[:-2], '/')

    execute 'python import sys, os'
    " execute 'python sys.path.append("' . curpath . '")'
    " execute 'python sys.path.append("' . syspath . '")'
    execute 'python sys.path = ' . syspath
    execute 'python os.environ.setdefault("DJANGO_SETTINGS_MODULE", "' . module . '")'
  endif
endfunction
autocmd FileType python call FindDjangoSettings()

This assumes that you are using virtualenv for your projects, and might bother you if you are using a virtualenv for something that is not django.

I also recommend you to have a look in you complete me plugin, its an awesome complete plugin, it is not a replacement for jedi, in fact, it has jedi as a dependency for python completion.

like image 162
Augusto Hack Avatar answered Sep 16 '22 18:09

Augusto Hack


You can try this: sys.path.append(/path/to/lib)

I use SUMO/TraCI as a non-standard lib.

In python code I have added sys.path.append("/path/to/SUMO/tools/") before using traci methods and then completion in Vim works perfectly.

like image 38
roman1e2f5p8s Avatar answered Sep 18 '22 18:09

roman1e2f5p8s