From a011eb6aa02783f6b393c26630365e4de8add6de Mon Sep 17 00:00:00 2001 From: Strahinja Val Markovic Date: Mon, 8 Jul 2013 15:56:54 -0700 Subject: [PATCH] Fix duplicate entries in filename completion We could just remove the "dup: 1" part in the completion dict, but that would leave the duplicate removal up to Vim which would be slow. Also, we might not end up returning the correct number of results then. --- .../completers/general/filename_completer.py | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/python/ycm/completers/general/filename_completer.py b/python/ycm/completers/general/filename_completer.py index 42ad6711..559968a1 100644 --- a/python/ycm/completers/general/filename_completer.py +++ b/python/ycm/completers/general/filename_completer.py @@ -125,10 +125,18 @@ def GetPathsStandardCase( path_dir ): def GenerateCandidatesForPaths( absolute_paths ): - def GenerateCandidateForPath( absolute_path ): - is_dir = os.path.isdir( absolute_path ) - return { 'word': os.path.basename( absolute_path ), - 'dup': 1, - 'menu': '[Dir]' if is_dir else '[File]' } + seen_basenames = set() + completion_dicts = [] - return [ GenerateCandidateForPath( path ) for path in absolute_paths ] + for absolute_path in absolute_paths: + basename = os.path.basename( absolute_path ) + if basename in seen_basenames: + continue + seen_basenames.add( basename ) + + is_dir = os.path.isdir( absolute_path ) + completion_dicts.append( { 'word': basename, + 'dup': 1, + 'menu': '[Dir]' if is_dir else '[File]' } ) + + return completion_dicts