Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/361.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python YCM找不到我的标题?_Python_C_Vim_Header Files_Vim Plugin - Fatal编程技术网

Python YCM找不到我的标题?

Python YCM找不到我的标题?,python,c,vim,header-files,vim-plugin,Python,C,Vim,Header Files,Vim Plugin,我有以下文件夹结构: . ├── include │   └── ctset │   ├── hashtable.h │   └── set.h └── src └── hashtable └── hashtable.c 在hashtable.c中的include#include“ctset/hashtable.h”, 但YCM一直告诉我,它不知道我在头文件中定义的类型和在源文件中使用的类型 My.ycm\u extra\u conf.py几乎是默认配置

我有以下文件夹结构:

.
├── include
│   └── ctset
│       ├── hashtable.h
│       └── set.h
└── src
    └── hashtable
        └── hashtable.c
hashtable.c
中的include
#include“ctset/hashtable.h”
, 但YCM一直告诉我,它不知道我在头文件中定义的类型和在源文件中使用的类型

My
.ycm\u extra\u conf.py
几乎是默认配置,但有一些调整:

# This file is NOT licensed under the GPLv3, which is the license for the rest
# of YouCompleteMe.
#
# Here's the license text for this file:
#
# This is free and unencumbered software released into the public domain.
#
# Anyone is free to copy, modify, publish, use, compile, sell, or
# distribute this software, either in source code form or as a compiled
# binary, for any purpose, commercial or non-commercial, and by any
# means.
#
# In jurisdictions that recognize copyright laws, the author or authors
# of this software dedicate any and all copyright interest in the
# software to the public domain. We make this dedication for the benefit
# of the public at large and to the detriment of our heirs and
# successors. We intend this dedication to be an overt act of
# relinquishment in perpetuity of all present and future rights to this
# software under copyright law.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
#
# For more information, please refer to <http://unlicense.org/>

import os
import ycm_core

# These are the compilation flags that will be used in case there's no
# compilation database set (by default, one is not set).
# CHANGE THIS LIST OF FLAGS. YES, THIS IS THE DROID YOU HAVE BEEN LOOKING FOR.
flags = [
'-Wall',
'-Wextra',
'-Werror',
'-Wno-long-long',
'-Wno-variadic-macros',
'-DNDEBUG',

# THIS IS IMPORTANT! Without a "-std=<something>" flag, clang won't know which
# language to use when compiling headers. So it will guess. Badly. So C++
# headers will be compiled as C headers. You don't want that so ALWAYS specify
# a "-std=<something>".
# For a C project, you would set this to something like 'c99' instead of
# 'c++11'.
'-std=c99',

# ...and the same thing goes for the magic -x option which specifies the
# language that the files to be compiled are written in. This is mostly
# relevant for c++ headers.
# For a C project, you would set this to 'c' instead of 'c++'.
'-x', 'c',

'-I', '.',

'-I', './src/',

'-I', './include/',

'-I', './ClangCompleter',

'-isystem', '../llvm/include',

'-isystem', '../llvm/tools/clang/include',

'-isystem', './tests/gmock/gtest',

'-isystem', './tests/gmock/gtest/include',

'-isystem', './tests/gmock',

'-isystem', './tests/gmock/include',

'-isystem', '/usr/include',

'-isystem', '/usr/local/include',

]

# Set this to the absolute path to the folder (NOT the file!) containing the
# compile_commands.json file to use that instead of 'flags'. See here for
# more details: http://clang.llvm.org/docs/JSONCompilationDatabase.html
#
# Most projects will NOT need to set this to anything; you can just change the
# 'flags' list of compilation flags. Notice that YCM itself uses that approach.
compilation_database_folder = ''

if os.path.exists( compilation_database_folder ):
  database = ycm_core.CompilationDatabase( compilation_database_folder )
else:
  database = None

SOURCE_EXTENSIONS = [ '.cpp', '.cxx', '.cc', '.c', '.m', '.mm' ]

def DirectoryOfThisScript():
  return os.path.dirname( os.path.abspath( __file__ ) )


def MakeRelativePathsInFlagsAbsolute( flags, working_directory ):
  if not working_directory:
    return list( flags )
  new_flags = []
  make_next_absolute = False
  path_flags = [ '-isystem', '-I', '-iquote', '--sysroot=' ]
  for flag in flags:
    new_flag = flag

    if make_next_absolute:
      make_next_absolute = False
      if not flag.startswith( '/' ):
        new_flag = os.path.join( working_directory, flag )

    for path_flag in path_flags:
      if flag == path_flag:
        make_next_absolute = True
        break

    if flag.startswith( path_flag ):
        path = flag[ len( path_flag ): ]
        new_flag = path_flag + os.path.join( working_directory, path )
        break

    if new_flag:
      new_flags.append( new_flag )
  return new_flags


def IsHeaderFile( filename ):
  extension = os.path.splitext( filename )[ 1 ]
  return extension in [ '.h', '.hxx', '.hpp', '.hh' ]


def GetCompilationInfoForFile( filename ):
    # The compilation_commands.json file generated by CMake does not have entries
    # for header files. So we do our best by asking the db for flags for a
    # corresponding source file, if any. If one exists, the flags for that file
    # should be good enough.
    if IsHeaderFile( filename ):
        basename = os.path.splitext( filename )[ 0 ]
        for extension in SOURCE_EXTENSIONS:
            replacement_file = basename + extension
            if os.path.exists( replacement_file ):
                compilation_info = database.GetCompilationInfoForFile( replacement_file )
                if compilation_info.compiler_flags_:
                    return compilation_info
        return None
    return database.GetCompilationInfoForFile( filename )


def FlagsForFile( filename, **kwargs ):
  if database:
    # Bear in mind that compilation_info.compiler_flags_ does NOT return a
    # python list, but a "list-like" StringVec object
    compilation_info = GetCompilationInfoForFile( filename )
    if not compilation_info:
      return None

    final_flags = MakeRelativePathsInFlagsAbsolute(
      compilation_info.compiler_flags_,
      compilation_info.compiler_working_dir_ )

    # NOTE: This is just for YouCompleteMe; it's highly likely that your project
    # does NOT need to remove the stdlib flag. DO NOT USE THIS IN YOUR
    # ycm_extra_conf IF YOU'RE NOT 100% SURE YOU NEED IT.
    try:
      final_flags.remove( '-stdlib=libc++' )
    except ValueError:
      pass
  else:
    relative_to = DirectoryOfThisScript()
    final_flags = MakeRelativePathsInFlagsAbsolute( flags, relative_to )

  return {
    'flags': final_flags,
    'do_cache': True
  }
#此文件未在GPLv3下获得许可,GPLv3是其余文件的许可证
#你的全部。
#
#以下是此文件的许可证文本:
#
#这是一款免费且无障碍的软件,发布到公共领域。
#
#任何人都可以自由复制、修改、发布、使用、编译、销售或
#以源代码形式或编译后的格式分发此软件
#二进制,出于任何目的,商业或非商业,以及
#意味着。
#
#在承认版权法的司法管辖区,作者
#本软件的任何和所有版权权益
#将软件转移到公共领域。我们做出这一奉献是为了利益
#公众的利益,损害我们的继承人和
#继任者。我们希望这一奉献是一种公开的行动
#永久放弃本协议的所有现有和未来权利
#版权法下的软件。
#
#软件按“原样”提供,无任何形式的担保,
#明示或暗示,包括但不限于
#适销性、特定用途适用性和非侵权性。
#在任何情况下,提交人均不对任何索赔、损害或赔偿负责
#其他责任,无论是合同诉讼、侵权诉讼还是其他诉讼,
#由本软件或其使用引起的、由本软件引起的或与本软件或其使用有关的;或
#软件中的其他交易。
#
#有关更多信息,请参阅
导入操作系统
导入ycm_核心
#这些是编译标志,在没有
#编译数据库集(默认情况下,未设置一个)。
#更改此标志列表。是的,这就是你一直在寻找的机器人。
标志=[
“-墙”,
“-Wextra”,
“-沃罗”,
“-Wno long”,
“-Wno可变宏”,
“-DNDEBUG”,
#这很重要!没有“-std=”标志,clang将不知道是哪个
编译头文件时要用到的语言。所以它会猜错。C++。
#标题将被编译为C标题。您不希望这样,所以请始终指定
#a“-std=”。
#对于C项目,您可以将其设置为类似于“c99”的值,而不是
#“c++11”。
“-std=c99”,
#…同样的事情也发生在magic-x选项中,它指定了
#要编译的文件所用的语言。这主要是
与C++头相关。
#对于C项目,可以将其设置为“C”,而不是“C++”。
“-x”,“c”,
“-I”,”,
“-I',”./src/”,
'-I','./包括/',
“-I',”./ClangCompleter',
“-isystem',”../llvm/include',
'-isystem','../llvm/tools/clang/include',
“-isystem',”./tests/gmock/gtest',
“-isystem',”./tests/gmock/gtest/include',
“-isystem',”./tests/gmock',
“-isystem',”./tests/gmock/include',
“-isystem”,“/usr/include”,
“-isystem”,“/usr/local/include”,
]
#将其设置为包含文件的文件夹(而不是文件!)的绝对路径
#编译_commands.json文件以使用该文件而不是“标志”。请看这里
#更多详情:http://clang.llvm.org/docs/JSONCompilationDatabase.html
#
#大多数项目都不需要将此设置为任何值;你只需要换个颜色就行了
#编译标志的“标志”列表。请注意,YCM本身使用这种方法。
编译\数据库\文件夹=“”
如果os.path.存在(编译\数据库\文件夹):
database=ycm\u core.CompilationDatabase(compilation\u database\u文件夹)
其他:
数据库=无
SOURCE_扩展=['.cpp'、'.cxx'、'.cc'、'.c'、'.m'、'.mm']
def directoryofthiscript():
返回os.path.dirname(os.path.abspath(_文件__))
def MakeRelativePathsInFlagsAbsolute(标志,工作目录):
如果未在目录中工作:
返回列表(标志)
新的_标志=[]
使_next_绝对=False
路径_标志=['-isystem','-I','-iNote','-sysroot=']
对于旗帜中的旗帜:
新标志=标志
如果将下一个设置为绝对:
使_next_绝对=False
如果不使用(“/”)标记.startswith:
new_flag=os.path.join(工作目录,标志)
对于路径标志中的路径标志:
如果标志==路径\标志:
使_next_绝对=真
打破
if flag.startswith(路径_标志):
路径=标志[len(路径\标志):]
new_flag=path_flag+os.path.join(工作目录,路径)
打破
如果是新的_标志:
新_标志。追加(新_标志)
返回新的\u标志
def IsHeaderFile(文件名):
扩展名=os.path.splitext(文件名)[1]
['.h'、'.hxx'、'.hpp'、'.hh'中的返回扩展名
def GetCompliationInfoForFile(文件名):
#CMake生成的compilation_commands.json文件没有条目
#用于头文件。因此,我们尽最大努力要求db提供一个
#相应的源文件(如果有)。如果存在,则显示该文件的标志
#应该足够好了。
如果是IsHeaderFile(文件名):
basename=os.path.splitext(文件名)[0]
对于源扩展中的扩展:
替换文件=基本名称+扩展名
如果os.path.存在(替换文件):
compilation\u info=database.GetCompilationInfoForFile(替换\u文件)
如果编译\u info.compiler\u标志\u:
返回编译信息
一无所获
return database.GetCompilationInfoForFile(文件名)
def标志文件(文件名,**kwargs):
如果数据库:
#请记住,compilation_info.compiler_flags不会返回
#python列表,但它是一个“类似列表”的StringVec对象
compilation\u info=GetCompilationInfoForFile(文件名)
如果不是编译信息:
一无所获
final_flags=使相对性标记为溶质(
编译\u info.compiler\u标志\u,
编译\u info.compiler\u working\u dir\u
#注意:这只适用于YouCompleteMe;很可能你的项目
#不需要删除stdlib标志。不要用这个
for path_flag in path_flags:
  if flag == path_flag:
    make_next_absolute = True
    break

if flag.startswith( path_flag ):
    path = flag[ len( path_flag ): ]
    new_flag = path_flag + os.path.join( working_directory, path )
    break
for path_flag in path_flags:
  if flag == path_flag:
    make_next_absolute = True
    break

  if flag.startswith( path_flag ):
    path = flag[ len( path_flag ): ]
    new_flag = path_flag + os.path.join( working_directory, path )
    break
# This file is NOT licensed under the GPLv3, which is the license for the rest
# of YouCompleteMe.
#
# Here's the license text for this file:
#
# This is free and unencumbered software released into the public domain.
#
# Anyone is free to copy, modify, publish, use, compile, sell, or
# distribute this software, either in source code form or as a compiled
# binary, for any purpose, commercial or non-commercial, and by any
# means.
#
# In jurisdictions that recognize copyright laws, the author or authors
# of this software dedicate any and all copyright interest in the
# software to the public domain. We make this dedication for the benefit
# of the public at large and to the detriment of our heirs and
# successors. We intend this dedication to be an overt act of
# relinquishment in perpetuity of all present and future rights to this
# software under copyright law.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
#
# For more information, please refer to <http://unlicense.org/>

import os
import ycm_core

# These are the compilation flags that will be used in case there's no
# compilation database set (by default, one is not set).
# CHANGE THIS LIST OF FLAGS. YES, THIS IS THE DROID YOU HAVE BEEN LOOKING FOR.
flags = [
'-Wall',
'-Wextra',
'-Werror',
'-Wno-long-long',
'-Wno-variadic-macros',
'-DNDEBUG',

# THIS IS IMPORTANT! Without a "-std=<something>" flag, clang won't know which
# language to use when compiling headers. So it will guess. Badly. So C++
# headers will be compiled as C headers. You don't want that so ALWAYS specify
# a "-std=<something>".
# For a C project, you would set this to something like 'c99' instead of
# 'c++11'.
'-std=c99',

# ...and the same thing goes for the magic -x option which specifies the
# language that the files to be compiled are written in. This is mostly
# relevant for c++ headers.
# For a C project, you would set this to 'c' instead of 'c++'.
'-x', 'c',

'-I', '.',

'-I', './src/',

'-I', './include/',

'-I', './ClangCompleter',

'-isystem', '../llvm/include',

'-isystem', '../llvm/tools/clang/include',

'-isystem', './tests/gmock/gtest',

'-isystem', './tests/gmock/gtest/include',

'-isystem', './tests/gmock',

'-isystem', './tests/gmock/include',

'-isystem', '/usr/include',

'-isystem', '/usr/local/include',

]

# Set this to the absolute path to the folder (NOT the file!) containing the
# compile_commands.json file to use that instead of 'flags'. See here for
# more details: http://clang.llvm.org/docs/JSONCompilationDatabase.html
#
# Most projects will NOT need to set this to anything; you can just change the
# 'flags' list of compilation flags. Notice that YCM itself uses that approach.
compilation_database_folder = ''

if os.path.exists( compilation_database_folder ):
  database = ycm_core.CompilationDatabase( compilation_database_folder )
else:
  database = None

SOURCE_EXTENSIONS = [ '.cpp', '.cxx', '.cc', '.c', '.m', '.mm' ]

def DirectoryOfThisScript():
  return os.path.dirname( os.path.abspath( __file__ ) )


def MakeRelativePathsInFlagsAbsolute( flags, working_directory ):
  if not working_directory:
    return list( flags )
  new_flags = []
  make_next_absolute = False
  path_flags = [ '-isystem', '-I', '-iquote', '--sysroot=' ]
  for flag in flags:
    new_flag = flag

    if make_next_absolute:
      make_next_absolute = False
      if not flag.startswith( '/' ):
        new_flag = os.path.join( working_directory, flag )

    for path_flag in path_flags:
      if flag == path_flag:
        make_next_absolute = True
        break

      if flag.startswith( path_flag ):
        path = flag[ len( path_flag ): ]
        new_flag = path_flag + os.path.join( working_directory, path )
        break

    if new_flag:
      new_flags.append( new_flag )
  return new_flags


def IsHeaderFile( filename ):
  extension = os.path.splitext( filename )[ 1 ]
  return extension in [ '.h', '.hxx', '.hpp', '.hh' ]


def GetCompilationInfoForFile( filename ):
    # The compilation_commands.json file generated by CMake does not have entries
    # for header files. So we do our best by asking the db for flags for a
    # corresponding source file, if any. If one exists, the flags for that file
    # should be good enough.
    if IsHeaderFile( filename ):
        basename = os.path.splitext( filename )[ 0 ]
        for extension in SOURCE_EXTENSIONS:
            replacement_file = basename + extension
            if os.path.exists( replacement_file ):
                compilation_info = database.GetCompilationInfoForFile( replacement_file )
                if compilation_info.compiler_flags_:
                    return compilation_info
        return None
    return database.GetCompilationInfoForFile( filename )


def FlagsForFile( filename, **kwargs ):
  if database:
    # Bear in mind that compilation_info.compiler_flags_ does NOT return a
    # python list, but a "list-like" StringVec object
    compilation_info = GetCompilationInfoForFile( filename )
    if not compilation_info:
      return None

    final_flags = MakeRelativePathsInFlagsAbsolute(
      compilation_info.compiler_flags_,
      compilation_info.compiler_working_dir_ )

    # NOTE: This is just for YouCompleteMe; it's highly likely that your project
    # does NOT need to remove the stdlib flag. DO NOT USE THIS IN YOUR
    # ycm_extra_conf IF YOU'RE NOT 100% SURE YOU NEED IT.
    try:
      final_flags.remove( '-stdlib=libc++' )
    except ValueError:
      pass
  else:
    relative_to = DirectoryOfThisScript()
    final_flags = MakeRelativePathsInFlagsAbsolute( flags, relative_to )

  return {
    'flags': final_flags,
    'do_cache': True
  }