From 1581d48eeb2acd4b1471575aefe2b098e20ee6b3 Mon Sep 17 00:00:00 2001 From: Boris Staletic Date: Mon, 3 Jul 2017 16:11:48 +0200 Subject: [PATCH] Windows style flags --- ycmd/completers/cpp/flags.py | 12 ++++++++++-- ycmd/tests/clang/flags_test.py | 11 +++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/ycmd/completers/cpp/flags.py b/ycmd/completers/cpp/flags.py index e85e6093fb..79465dfb46 100644 --- a/ycmd/completers/cpp/flags.py +++ b/ycmd/completers/cpp/flags.py @@ -391,6 +391,11 @@ def _RemoveUnusedFlags( flags, filename ): previous_flag_is_include = False previous_flag_starts_with_dash = False current_flag_starts_with_dash = False + enable_windows_style_flags = False + + for flag in flags: + if flag.startswith( '--driver-mode' ): + enable_windows_style_flags = ( flag == '--driver-mode=cl' ) for flag in flags: previous_flag_starts_with_dash = current_flag_starts_with_dash @@ -417,12 +422,15 @@ def _RemoveUnusedFlags( flags, filename ): # flags for headers. The returned flags include "foo.cpp" and we need to # remove that. if ( not current_flag_starts_with_dash and - ( not previous_flag_starts_with_dash or - ( not previous_flag_is_include and '/' in flag ) ) ): + ( not previous_flag_starts_with_dash or + ( not previous_flag_is_include and '/' in flag ) ) and + ( not enable_windows_style_flags or + ( enable_windows_style_flags and os.path.exists( flag ) ) ) ): continue new_flags.append( flag ) previous_flag_is_include = flag in INCLUDE_FLAGS + return new_flags diff --git a/ycmd/tests/clang/flags_test.py b/ycmd/tests/clang/flags_test.py index f72c0a0073..1b51d7cdca 100644 --- a/ycmd/tests/clang/flags_test.py +++ b/ycmd/tests/clang/flags_test.py @@ -215,6 +215,17 @@ def RemoveUnusedFlags_RemoveFlagWithoutPrecedingDashFlag_test(): eq_( expected, flags._RemoveUnusedFlags( expected[ :1 ] + to_remove + expected[ 1: ], filename ) ) + expected = [ 'g++', '-foo', '--driver-mode=cl', '-xc++', '-bar', + 'include_dir', '/foo' ] + to_remove = [ '..' ] + filename = 'file' + + eq_( expected, + flags._RemoveUnusedFlags( expected + to_remove, filename ) ) + + eq_( expected, + flags._RemoveUnusedFlags( expected[ :1 ] + to_remove + expected[ 1: ], + filename ) ) def RemoveUnusedFlags_Depfiles_test():