No omnicompletion for python class members in vim?

I want to create tags (ctags 5.8) for my classes in python. For functions and class members defined outside the class definition, omnicompletion works fine. However, if I define a data element in the constructor (self.x = 2), I can not see the completion of ctags?

class A(object): def __init__(self): self.x = "whatever" # x will not seen in ctags/omnicompletion!!! 

Am I doing it wrong? Why is there no omnicompletion (the ctags file looks fine)?

+4
source share
1 answer

If I understand your problem correctly, you can always add attributes to the class definition:

 class A(object): x = None def __init__(self): self.x = whatever 

Thus, everyone who reads your code sees what attributes (you call them "class members") the class has.

UPDATE: using

 $ ctags --version Exuberant Ctags 5.9~svn20110310, Copyright (C) 1996-2009 Darren Hiebert Compiled: Mar 18 2011, 10:38:14 

The resulting tag file is as follows:

 !_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/ !_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted, 2=foldcase/ !_TAG_PROGRAM_AUTHOR Darren Hiebert / dhiebert@users.sourceforge.net / !_TAG_PROGRAM_NAME Exuberant Ctags // !_TAG_PROGRAM_URL http://ctags.sourceforge.net /official site/ !_TAG_PROGRAM_VERSION 5.9~svn20110310 // A aaa.py /^class A(object):$/;" c __init__ aaa.py /^ def __init__(self, x):$/;" m class:A x aaa.py /^ x = None$/;" v class:A 

As you can see, the attribute x has its own record.

It is also checked with Emacs by first creating a tag file compatible with emacs:

 ctags -e aaa.py # where aaa.py - file with code snippet above 

(created TAGS file)

Inside Emacs:

 M-. x (enter) ~/TAGS (enter) 

... and voila! The cursor is on the line x = None .

In addition, your original fragment does not work. Therefore, my advice on initializing an attribute in a class namespace is valid.

+1
source

Source: https://habr.com/ru/post/1392318/


All Articles