l3nkz / ycmconf Goto Github PK
View Code? Open in Web Editor NEWA YouCompleteMe Extra Conf for all your projects
License: MIT License
A YouCompleteMe Extra Conf for all your projects
License: MIT License
The def FlagsForFile(file_name, **kwargs):
is not used anymore and the new function is called def Settings(filename, **kwargs):
. See ycm-core/YouCompleteMe#3512 . The following patch is needed:
$ git diff
diff --git a/ycm_extra_conf.py b/ycm_extra_conf.py
index 1b4fdb0..e1203e7 100644
--- a/ycm_extra_conf.py
+++ b/ycm_extra_conf.py
@@ -697,30 +697,30 @@ def parse_default_flags(file_name):
# Entry point for the YouCompleteMe plugin
####
-def FlagsForFile(file_name, **kwargs):
+def Settings(filename, **kwargs):
"""
This method is the entry point for the YCM plugin. It is called by the
plugin to get the all necessary compiler flags to parse a specific file
given as argument.
- :param file_name: The path to the file for which YouCompleteMe likes to do
+ :param filename: The path to the file for which YouCompleteMe likes to do
auto completion.
- :type file_name: str
+ :type filename: str
:param kwargs: Additional key word arguments.
:type kwargs: dict[str,str]
:rtype: dict[str,object]
:return: The compilation flags for the file in the format wanted by YCM.
"""
# First check for a compile_commands.json file.
- search_base = dirname(file_name)
+ search_base = dirname(filename)
if file_exists("compile_commands.json", search_base):
# There exists a compile_commands.json file. Try to use this one.
- return parse_compile_commands(file_name, search_base)
+ return parse_compile_commands(filename, search_base)
elif file_exists(".clang_complete", search_base):
# There exists a .clang_complete file. Try to use this one.
- return parse_clang_complete(file_name, search_base)
+ return parse_clang_complete(filename, search_base)
else:
# No files exists. Use the default flags.
- return parse_default_flags(file_name)
+ return parse_default_flags(filename)
As a side note I needed to add a "compiler flags" to projects I use with compiler_commands.json
cause they are the defaults from compiler and I default to C header:
diff --git a/ycm_extra_conf.py b/../../.ycm_extra_conf.py
index e1203e7..38f772b 100644
--- a/ycm_extra_conf.py
+++ b/../../.ycm_extra_conf.py
@@ -1,7 +1,8 @@
+#!/usr/bin/false python3
import ycm_core
from os import getcwd
from os.path import abspath, join, isabs, normpath, exists, splitext, \
- dirname
+ dirname, realpath
####
# Global lists for the flags and file detection
@@ -15,6 +16,12 @@ default_flags = [
"-Wextra",
]
+##
+# This is a list of always added flags
+##
+compiler_flags = [
+ # add here the output of:
+ # compiler-gcc -dM -E -x c /dev/null | sed '/^#define \([^ ]*\) *\(.*\)/!d;s//\1=\2/;s/"/\\"/g;s/\([^=]*\)=\(.*\)/"-D","\1=\2",/;'
+]
+
##
# C header extensions
##
@@ -34,18 +41,15 @@ c_source_extensions = [
##
c_additional_flags = [
# Tell clang that this is a C file.
- "-x",
- "c",
-
+ "-x","c",
# Use the latest standard if possible.
- "-std=c11",
+ "-std=gnu11",
]
##
# CPP header extensions
##
cpp_header_extensions = [
- ".h",
".hh",
".H",
".hp",
@@ -73,11 +77,9 @@ cpp_source_extensions = [
##
cpp_additional_flags = [
# Tell clang that this file is a CPP file.
- "-x",
- "c++",
-
+ "-x","c++",
# Use the latest standard if possible.
- "-std=c++11",
+ "-std=gnu++17",
]
@@ -384,12 +386,11 @@ def make_final_flags(file_name, flags, base_dir = getcwd()):
stripped = strip_flags(flags)
absolute = make_absolute_flags(stripped, base_dir)
+ final = absolute
+ if is_c_file(file_name):
+ final = save_add_flags(absolute, c_additional_flags)
if is_cpp_file(file_name):
final = save_add_flags(absolute, cpp_additional_flags)
- elif is_c_file(file_name):
- final = save_add_flags(absolute, c_additional_flags)
- else:
- final = absolute
return create_result(final)
@@ -601,6 +602,12 @@ def create_result(flags, do_cache = True, **kwargs):
return dict(ret, **kwargs)
+def merge_lists(l1, l2):
+ tmp = l1
+ for i in l2:
+ tmp.append(i)
+ return tmp
+
##
# Methods to parse the different formats supported by this script
##
@@ -641,7 +648,8 @@ def parse_compile_commands(file_name, search_base = getcwd()):
# In the database we found flags for the alternative name
if (compilation_info.compiler_flags_):
- return make_final_flags(file_name, compilation_info.compiler_flags_,
+ tmp = merge_lists(compilation_info.compiler_flags_, compiler_flags)
+ return make_final_flags(file_name, tmp,
compilation_info.compiler_working_dir_)
elif is_source(file_name):
@@ -649,7 +657,8 @@ def parse_compile_commands(file_name, search_base = getcwd()):
# We found flags for the file in the database
if (compilation_info.compiler_flags_):
- return make_final_flags(file_name, compilation_info.compiler_flags_,
+ tmp = merge_lists(compilation_info.compiler_flags_, compiler_flags)
+ return make_final_flags(file_name, tmp,
compilation_info.compiler_working_dir_)
# We either don't have a proper file ending or did not find any information in the
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.