jedi-vim omni completion with not standard library
Asked Answered
B

2

8

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?

Bellman answered 3/3, 2013 at 19:39 Comment(2)
Please post set omnifunc and :messagesRomy
perhaps relevant : #2085375 . In short, check what :py print(sys.path) shows.Landers
P
2

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.

Pattypatulous answered 11/11, 2013 at 1:27 Comment(0)
H
1

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.

Hypogeous answered 17/12, 2018 at 19:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.