github.com/igggame/nebulas-go@v2.1.0+incompatible/nbre/.ycm_extra_conf.py (about)

     1  # Copyright (C) 2014 Google Inc.
     2  #
     3  # This file is part of ycmd.
     4  #
     5  # ycmd is free software: you can redistribute it and/or modify
     6  # it under the terms of the GNU General Public License as published by
     7  # the Free Software Foundation, either version 3 of the License, or
     8  # (at your option) any later version.
     9  #
    10  # ycmd is distributed in the hope that it will be useful,
    11  # but WITHOUT ANY WARRANTY; without even the implied warranty of
    12  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    13  # GNU General Public License for more details.
    14  #
    15  # You should have received a copy of the GNU General Public License
    16  # along with ycmd.  If not, see <http://www.gnu.org/licenses/>.
    17  
    18  import os
    19  import ycm_core
    20  cur_dir = os.path.basename(os.path.abspath(__file__))
    21  
    22  # These are the compilation flags that will be used in case there's no
    23  # compilation database set (by default, one is not set).
    24  # CHANGE THIS LIST OF FLAGS. YES, THIS IS THE DROID YOU HAVE BEEN LOOKING FOR.
    25  flags = [
    26  '-Wall',
    27  '-Wextra',
    28  '-Werror',
    29  '-fexceptions',
    30  '-DNDEBUG',
    31  '-DPROTO_BUF_SUPPORT',
    32  # THIS IS IMPORTANT! Without a "-std=<something>" flag, clang won't know which
    33  # language to use when compiling headers. So it will guess. Badly. So C++
    34  # headers will be compiled as C headers. You don't want that so ALWAYS specify
    35  # a "-std=<something>".
    36  # For a C project, you would set this to something like 'c99' instead of
    37  # 'c++11'.
    38  '-std=c++14',
    39  
    40  # ...and the same thing goes for the magic -x option which specifies the
    41  # language that the files to be compiled are written in. This is mostly
    42  # relevant for c++ headers.
    43  # For a C project, you would set this to 'c' instead of 'c++'.
    44  '-x',
    45  'c++',
    46  '-I./',
    47  '-I./lib/include',
    48  '-isystem',
    49  '/usr/include',
    50  '-isystem',
    51  '/usr/local/include',
    52  '-isystem',
    53  '-isystem',
    54  ]
    55  
    56  
    57  # Set this to the absolute path to the folder (NOT the file!) containing the
    58  # compile_commands.json file to use that instead of 'flags'. See here for
    59  # more details: http://clang.llvm.org/docs/JSONCompilationDatabase.html
    60  #
    61  # Most projects will NOT need to set this to anything; you can just change the
    62  # 'flags' list of compilation flags.
    63  compilation_database_folder = ''
    64  
    65  if os.path.exists( compilation_database_folder ):
    66    database = ycm_core.CompilationDatabase( compilation_database_folder )
    67  else:
    68    database = None
    69  
    70  SOURCE_EXTENSIONS = [ '.cpp', '.cxx', '.cc', '.c', '.m', '.mm' ]
    71  
    72  def DirectoryOfThisScript():
    73    return os.path.dirname( os.path.abspath( __file__ ) )
    74  
    75  
    76  def MakeRelativePathsInFlagsAbsolute( flags, working_directory ):
    77    if not working_directory:
    78      return list( flags )
    79    new_flags = []
    80    make_next_absolute = False
    81    path_flags = [ '-isystem', '-I', '-iquote', '--sysroot=' ]
    82    for flag in flags:
    83      new_flag = flag
    84  
    85      if make_next_absolute:
    86        make_next_absolute = False
    87        if not flag.startswith( '/' ):
    88          new_flag = os.path.join( working_directory, flag )
    89  
    90      for path_flag in path_flags:
    91        if flag == path_flag:
    92          make_next_absolute = True
    93          break
    94  
    95        if flag.startswith( path_flag ):
    96          path = flag[ len( path_flag ): ]
    97          new_flag = path_flag + os.path.join( working_directory, path )
    98          break
    99  
   100      if new_flag:
   101        new_flags.append( new_flag )
   102    return new_flags
   103  
   104  
   105  def IsHeaderFile( filename ):
   106    extension = os.path.splitext( filename )[ 1 ]
   107    return extension in [ '.h', '.hxx', '.hpp', '.hh' ]
   108  
   109  
   110  def GetCompilationInfoForFile( filename ):
   111    # The compilation_commands.json file generated by CMake does not have entries
   112    # for header files. So we do our best by asking the db for flags for a
   113    # corresponding source file, if any. If one exists, the flags for that file
   114    # should be good enough.
   115    if IsHeaderFile( filename ):
   116      basename = os.path.splitext( filename )[ 0 ]
   117      for extension in SOURCE_EXTENSIONS:
   118        replacement_file = basename + extension
   119        if os.path.exists( replacement_file ):
   120          compilation_info = database.GetCompilationInfoForFile(
   121            replacement_file )
   122          if compilation_info.compiler_flags_:
   123            return compilation_info
   124      return None
   125    return database.GetCompilationInfoForFile( filename )
   126  
   127  
   128  # This is the entry point; this function is called by ycmd to produce flags for
   129  # a file.
   130  def FlagsForFile( filename, **kwargs ):
   131    if database:
   132      # Bear in mind that compilation_info.compiler_flags_ does NOT return a
   133      # python list, but a "list-like" StringVec object
   134      compilation_info = GetCompilationInfoForFile( filename )
   135      if not compilation_info:
   136        return None
   137  
   138      final_flags = MakeRelativePathsInFlagsAbsolute(
   139        compilation_info.compiler_flags_,
   140        compilation_info.compiler_working_dir_ )
   141    else:
   142      relative_to = DirectoryOfThisScript()
   143      final_flags = MakeRelativePathsInFlagsAbsolute( flags, relative_to )
   144  
   145    return { 'flags': final_flags }