pydiction是一个比较老的python补全插件,相比于youcompleteme来说确实落后了不少,但是安装更加简单快捷,没有很复杂的配置,就想拿来代替youcompleteme,查看了一下代码,发现只支持python2(插件太老了,python3之后就没有什么更新)
这个插件不是读取python3的包,而是读取一个文件complete-dict,这个文件可以手工编辑,需要的函数添加进去,在vim当中使用tab键就能自动提示和补齐,自定义的元素更多,原作者当时写了一个.py的脚本用于手工添加,但是只支持python2的语法
插件的安装网上其他开发者的教程很全,这里就不赘述了,我修改了这个脚本里面python2的写法,让他兼容python3源码如下
#!/usr/bin/env python
"""
pydiction.py 1.2.3 by Ryan Kulla (rkulla AT gmail DOT com).
License: BSD.
Description: Creates a Vim dictionary of Python module attributes for Vim's
completion feature. The created dictionary file is used by
the Vim ftplugin "python_pydiction.vim".
Usage: pydiction.py <module> [<module> ...] [-v]
Example: The following will append all the "time" and "math" modules'
attributes to a file, in the current directory, called "pydiction",
with and without the "time." and "math." prefix:
$ python pydiction.py time math
To output only to stdout and not append to file, use -v:
$ python pydiction.py -v time math
"""
__author__ = "Ryan Kulla (rkulla AT gmail DOT com)"
__version__ = "1.2.3"
__copyright__ = "Copyright (c) 2003-2014 Ryan Kulla"
import os
import sys
import types
import shutil
# Path/filename of the vim dictionary file to write to:
PYDICTION_DICT = r'complete-dict'
# Path/filename of the vim dictionary backup file:
PYDICTION_DICT_BACKUP = r'complete-dict.last'
# Sentintal to test if we should only output to stdout:
STDOUT_ONLY = False
def get_submodules(module_name, submodules):
"""Build a list of all the submodules of modules."""
# Try to import a given module, so we can dir() it:
try:
imported_module = my_import(module_name)
except ImportError:
return submodules
mod_attrs = dir(imported_module)
for mod_attr in mod_attrs:
try:
if isinstance(getattr(imported_module, mod_attr), types.ModuleType):
submodules.append(module_name + '.' + mod_attr)
except AttributeError as e:
print (e)
return submodules
def get_format(imported_m