Because pythoncomplete executes the code in the original file and prompts the code by executing the exec statement, all the objects used must be imported. Therefore, if you define a class in the current original file, there is no prompt to create an instance. For example:
Class Foo (object ):
Name = 'lucifer'
F = Foo ()
F. This will fail.
The solution is very simple: manually import this class. For example, if our original file is named TT. py, add this sentence: from TT import Foo, and the code prompts will work properly. Therefore, the patch is also very simple. Open the pythoncomplete. Vim file under autoload, and add
Import Vim
Import OS, re
Then add the following two sentences to the class completer (object): Get the file name of the current file.
Filename = OS. Path. basename (Vim. buffers [0]. Name)
Filename = filename [0:-3]
Then add the following to the namespace added last time in function def evalsource (self, text, line = 0 ):
If not namespace:
For item in SRC. Split ('/N '):
If item. startswith ('from') or item. startswith ('import '):
Namespace. append (item)
# Get the class name defined in the current file
If item. startswith ('class') and item. endswith (':'):
RegEx = Re. Compile (R' ^ class/S + (? P <Name>. + ?) /(. +? /): $ ')
Matchs = RegEx. findall (item)
If Len (matchs ):
Name = matchs [0]
From_import = 'from % s import % s' % (filename, name)
Namespace. append (from_import)