cai*_*spb 4 vim plugins syntax-highlighting
我正在尝试配置vim插件"YouCompleteMe".我的C++项目由许多头文件组成,这些头文件遍布目录树.为了添加头目录,我必须将它们添加到".ycm_extra_conf.py"中.
摘抄:
'-I',
'./src/base/utils',
'-I',
'./src/base/modules',
Run Code Online (Sandbox Code Playgroud)
但这样的事情不起作用:
'-I',
'./src/base/*',
Run Code Online (Sandbox Code Playgroud)
有没有办法告诉YCM递归搜索头文件?
谢谢.
我遇到了同样的问题,所以我创建了一个函数来完成它。在标志列表之后将以下内容添加到“.ycm_extra_conf.py”中:
import glob
flagsRec=['/opt/e17/include/*']
def AddDirsRecursively( flagsRec ):
global flags
new_flags = []
for flag in flagsRec:
for d in glob.glob(flag) :
if os.path.isdir(d):
new_flags.append('-I')
new_flags.append(d)
flags += new_flags
AddDirsRecursively( flagsRec )
Run Code Online (Sandbox Code Playgroud)
其中“flagsRec”是要遍历并添加到“flags”的目录(正则表达式)列表
我添加了一个新语法-ISUB来包含所有子目录.
例如
"-ISUB./Pods/Headers/Public"
import os
import ycm_core
flags = [
#custom definition, include subfolders
'-ISUB./Pods/Headers/Public',
'-I./Pod/Classes',
]
def Subdirectories(directory):
res = []
for path, subdirs, files in os.walk(directory):
for name in subdirs:
item = os.path.join(path, name)
res.append(item)
return res
def IncludeFlagsOfSubdirectory( flags, working_directory ):
if not working_directory:
return list( flags )
new_flags = []
make_next_include_subdir = False
path_flags = [ '-ISUB']
for flag in flags:
# include the directory of flag as well
new_flag = [flag.replace('-ISUB', '-I')]
if make_next_include_subdir:
make_next_include_subdir = False
for subdir in Subdirectories(os.path.join(working_directory, flag)):
new_flag.append('-I')
new_flag.append(subdir)
for path_flag in path_flags:
if flag == path_flag:
make_next_include_subdir = True
break
if flag.startswith( path_flag ):
path = flag[ len( path_flag ): ]
for subdir in Subdirectories(os.path.join(working_directory, path)):
new_flag.append('-I' + subdir)
break
new_flags =new_flags + new_flag
return new_flags
Run Code Online (Sandbox Code Playgroud)