pythoncjedigobject-introspectionjedi-vim

autocompletion for own gobject derived library in python using jedi-vim using gobject introspection


I'm trying to create a shared C library that uses the gobject library as foundation. So my object inherits in GObject speak from GObject. GObject allows bindings to all different scripting languages such as Python via GObject introspection. Then from python one can import the library from the gi.repository.

import gi
gi.require_versions({'Edf': '0.0', 'GLib': '2.0'})
from gi.repository import Edf

Vim offers autocompletion via jedi-vim. This works out of the box for other libraries making use of the GObject introspections, such as GLib and GTK. I would like use pytest to run some unit tests of the libraries. I would like very much to edit my files using vim with autocompletion for my own library. So if I import a library as Above, I do get autocompletion for GLib, but not for my Edf module.

I've tried to getting autocompletion to work via setting the GI_TYPELIB_PATH environmental variable to the directory containing my Edf.typelib file. Also I've created a debian package and intstalled the library to /usr/lib/x86_64-linux-gnu/ and the typelib to /usr/lib/x86_64-linux-gnu/girepository-1.0/, both these methods are enough to get autocompletion in REPL's such as bpython3, ipython3 and even the python REPL, however I'm unable to get completion using jedi-vim inside vim.

I would be very happy to see it working. Has anyone any tips to get it to work?

Best regards and thank you for your attention.


Solution

  • It's been a while since I posted this question, however, today I saw the light. What I noticed was, all libraries already installed on the system, had automatic completions out of the box. The problem was, I was working on a library that is currently only in my build directories. In order for a program to start I usually had to specify

    export GI_TYPELIB_PATH="/path/to/my/typelib/folder"
    export LD_LIBRARY_PATH="/path/to/my/gobject/based/library"
    

    The funny thing is, autocompletion with vim in program using my gobject library using gir-introspection relies on exactly the environment. Hence jedi-vim, you-complete-me also needs to know where the typelib and the library are located, hence specify/export those variables before opening vim.

    So this question and answer is perhaps relevant for people who use vim with python and perhaps other languages for which GObject bindings exists.