Commit d9592fdb authored by Eliseo Martínez's avatar Eliseo Martínez Committed by Thiago de Arruda

Improve YCM contrib: Fix 'no newline at end of file' issue.

Problem:  YCM was reporting a much disturbing warning about a missing
          newline at the end of some files. This was odd, as the
          newlines were there and the warning only was shown for some
          files, not for all of them.
Cause:    After discussing this issue with @Valloric (see
, it
          turned out that not YCM, but libclang is responsible for it.
          This is, same compilation flags that produce no warnings with
          clang-the-binary on the command line, do produce them with
          libclang-the-library when used by YCM.
Solution: Add an extra flag (-Wno_newline_eof) to those extracted from
          configuration database before passing them to YCM.
parent 77e918bc
......@@ -26,6 +26,9 @@ def GetCompilationInfoForFile(filename):
if IsHeaderFile(filename):
basename = os.path.splitext(filename)[0]
c_file = basename + '.c'
# for pure headers (no c file), default to main.c
if not os.path.exists(c_file):
c_file = os.path.join(DirectoryOfThisScript(), 'main.c')
if os.path.exists(c_file):
compilation_info = database.GetCompilationInfoForFile(c_file)
if compilation_info.compiler_flags_:
......@@ -38,7 +41,14 @@ def FlagsForFile(filename):
compilation_info = GetCompilationInfoForFile(filename)
if not compilation_info:
return None
# Add flags not needed for clang-the-binary,
# but needed for libclang-the-library (YCM uses this last one).
flags = (list(compilation_info.compiler_flags_)
if compilation_info.compiler_flags_
else [])
extra_flags = ['-Wno-newline-eof']
final_flags = flags + extra_flags
return {
'flags': compilation_info.compiler_flags_,
'flags': final_flags,
'do_cache': True
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment