Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/vim/5.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
C 和你一起完成我_C_Vim_Neovim_Youcompleteme - Fatal编程技术网

C 和你一起完成我

C 和你一起完成我,c,vim,neovim,youcompleteme,C,Vim,Neovim,Youcompleteme,我已经编写了一段时间,当我最需要的只是ctag和代码完成时,从一个IDE移动到另一个IDE是一件非常痛苦的事情。我最终决定去维姆,在这个例子中是neovim,但这不是重点 我有CTAG在工作,并且一直在跟踪 但我似乎无法让YCM为我工作 我遵循以下步骤: cd ~/.nvim/bundle git clone https://github.com/Valloric/YouCompleteMe.git cd YouCompleteMe git submodule update --init --r

我已经编写了一段时间,当我最需要的只是ctag和代码完成时,从一个IDE移动到另一个IDE是一件非常痛苦的事情。我最终决定去维姆,在这个例子中是neovim,但这不是重点

我有CTAG在工作,并且一直在跟踪

但我似乎无法让YCM为我工作

我遵循以下步骤:

cd ~/.nvim/bundle
git clone https://github.com/Valloric/YouCompleteMe.git
cd YouCompleteMe
git submodule update --init --recursive
./install.sh --clang-completer --system-libclang
这经历了下载、编译、安装等过程

然后我在“~/.nvim/.ycm\u extra\u conf.py”创建了
.ycm\u extra\u conf.py文件

并添加:let
g:ycm\u global\u ycm\u extra\u conf=“~/.nvm/.ycm\u extra\u conf.py”

到我的
~/.nvimrc文件的顶部

这是我添加到.ycm_extra_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',
'-fexceptions',
'-DNDEBUG',
'-ftrapv',
'-finstrument’-functions',
'-Wfloat’-equal',
'-Wundef',
'-Wshadow',
'-Wpointer-arith',
'-Wcast’-align',
'-Wstrict-prototypes',
'-Wstrict-overflow=5',
'-Wwrite-strings',
'-Waggregate-return',
'-Wcast-qual',
'-Wswitch-default',
'-Wswitch-enum',
'-Wconversion',
'-Wunreachable-code',
# You 100% do NOT need -DUSE_CLANG_COMPLETER in your flags; only the YCM
# source code needs it.

'-DUSE_CLANG_COMPLETER',

# 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
# 'c99'.
'-std=c+99',
# ...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.
'-x',
'c',
'-isystem',
'../BoostParts',
'-isystem',
# This path will only work on OS X, but extra paths that don't exist are not  harmful
'/System/Library/Frameworks/Python.framework/Headers',
'-isystem',
'../llvm/include',
'-isystem',
'../llvm/tools/clang/include',
'-I',
'.',
'-I',
'./ClangCompleter',
'-isystem',
'./tests/gmock/gtest',
'-isystem',
'./tests/gmock/gtest/include',
'-isystem',
'./tests/gmock',
'-isystem',
'./tests/gmock/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
#
# You can get CMake to generate this file for you by adding:
#   set( CMAKE_EXPORT_COMPILE_COMMANDS 1 )
# to your CMakeLists.txt file.
#
# 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_ )

  else:
    relative_to = DirectoryOfThisScript()
    final_flags = MakeRelativePathsInFlagsAbsolute( flags, relative_to )

  return {
    'flags': final_flags,
    'do_cache': True
  }
#此文件未在GPLv3下获得许可,GPLv3是其余文件的许可证
#你的全部。
#
#以下是此文件的许可证文本:
#
#这是一款免费且无障碍的软件,发布到公共领域。
#
#任何人都可以自由复制、修改、发布、使用、编译、销售或
#以源代码形式或编译后的格式分发此软件
#二进制,出于任何目的,商业或非商业,以及
#意味着。
#
#在承认版权法的司法管辖区,作者
#本软件的任何和所有版权权益
#将软件转移到公共领域。我们做出这一奉献是为了利益
#公众的利益,损害我们的继承人和
#继任者。我们希望这一奉献是一种公开的行动
#永久放弃本协议的所有现有和未来权利
#版权法下的软件。
#
#软件按“原样”提供,无任何形式的担保,
#明示或暗示,包括但不限于
#适销性、特定用途适用性和非侵权性。
#在任何情况下,提交人均不对任何索赔、损害或赔偿负责
#其他责任,无论是合同诉讼、侵权诉讼还是其他诉讼,
#由本软件或其使用引起的、由本软件引起的或与本软件或其使用有关的;或
#软件中的其他交易。
#
#有关更多信息,请参阅
导入操作系统
导入ycm_核心
#这些是编译标志,在没有
#编译数据库集(默认情况下,未设置一个)。
#更改此标志列表。是的,这就是你一直在寻找的机器人。
标志=[
“-墙”,
“-Wextra”,
“-沃罗”,
“-Wno long”,
“-Wno可变宏”,
“-feexceptions”,
“-DNDEBUG”,
“-ftrapv”,
“-finstrument”-函数”,
'-Wfloat'-equal'-,
“-Wundef”,
“-Wshadow”,
“-Wpointer arith”,
'-Wcast'-align'-,
“-Wstrict原型”,
'-Wstrict溢出=5',
“-Wwrite strings”,
“-Waggregate返回”,
“-Wcast qual”,
“-Wswitch default”,
“-Wswitch enum”,
“-Wconversion”,
“-Wunreachable代码”,
#您100%不需要-DUSE_clangg_COMPLETER在您的旗帜;只有YCM
#源代码需要它。
“-DUSE_CLANG_COMPLETER”,
#这很重要!没有“-std=”标志,clang将不知道是哪个
编译头文件时要用到的语言。所以它会猜错。C++。
#标头将被编译为C标头。您不希望这样,因此请始终指定
#a“-std=”。
#对于C项目,您可以将其设置为类似于“c99”的值,而不是
#“c99”。
'-std=c+99',
#…同样的事情也发生在magic-x选项中,它指定了
#要编译的文件所用的语言。这主要是
#与c标题相关。
“-x”,
"c",,
“-isystem”,
“../BoostParts”,
“-isystem”,
#此路径仅在OSX上有效,但不存在的额外路径不会造成危害
“/System/Library/Frameworks/Python.framework/Headers”,
“-isystem”,
“../llvm/include”,
“-isystem”,
“../llvm/tools/clang/include”,
“-我”,
'.',
“-我”,
“./ClangCompleter”,
“-isystem”,
“/测试/gmock/gtest”,
“-isystem”,
“/测试/gmock/gtest/include”,
“-isystem”,
“./测试/gmock”,
“-isystem”,
“./测试/gmock/include”,
]
#将其设置为包含文件的文件夹(而不是文件!)的绝对路径
#编译_commands.json文件以使用该文件而不是“标志”。请看这里
#更多详情:http://clang.llvm.org/docs/JSONCompilationDatabase.html
#
#您可以通过添加以下内容让CMake为您生成此文件:
#设置(CMAKE\u导出\u编译\u命令1)
#到您的CMakeLists.txt文件。
#
#大多数项目都不需要将此设置为任何值;你只需要换个颜色就行了
#编译标志的“标志”列表。请注意,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]
延期
-- Server crashed, no debug info from server
-- Server running at: http://127.0.0.1:64594
-- Server process ID: 47040
-- Server logfiles:
--   /var/folders/64/d3t4_pcs06943d651dfgp3m00000gn/T/ycm_temp/server_64594_stdout.log
--   /var/folders/64/d3t4_pcs06943d651dfgp3m00000gn/T/ycm_temp/server_64594_stderr.log
Brother:.vim blubee$ python
Python 2.7.6 (default, Sep  9 2014, 15:04:36) 
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> with open(".ycm_extra_conf.py") as fp:
...  for i, line in enumerate(fp):
...   if "\xe2" in line:
...    print i, repr(line)
... 
45 "'-finstrument\xe2\x80\x99-functions',\n"
46 "'-Wfloat\xe2\x80\x99-equal',\n"
50 "'-Wcast\xe2\x80\x99-align',\n"
'-finstrument’-functions',
'-Wfloat’-equal',
'-Wundef',
'-Wshadow',
'-Wpointer-arith',
'-Wcast’-align',
'-finstrument-functions',  #removed quote after finstrument
'-Wfloat-equal',           #removed quote after Wfloat
'-Wundef',
'-Wshadow',
'-Wpointer-arith',
'-Wcast-align',            #removed quote after Wcast