Merge branch 'globlist' of github.com:kljohann/YouCompleteMe into kljohann-globlist

Conflicts:
	python/completers/cpp/flags.py
This commit is contained in:
Strahinja Val Markovic 2013-02-28 09:51:38 -08:00
commit aafcd4264d
3 changed files with 64 additions and 12 deletions

View File

@ -320,11 +320,10 @@ or in any directory above it in the hierarchy (recursively); when the file is
found, it is loaded (only once!) as a Python module. YCM calls a `FlagsForFile` found, it is loaded (only once!) as a Python module. YCM calls a `FlagsForFile`
method in that module which should provide it with the information necessary to method in that module which should provide it with the information necessary to
compile the current file. (You can also provide a path to a global compile the current file. (You can also provide a path to a global
`.ycm_extra_conf.py` file, which will be used as a fallback. See the Options `.ycm_extra_conf.py` file, which will be used as a fallback.)
section for more details.) To prevent the execution of malicious code from a file you didn't write YCM
To prevent the execution of malicious code from a file you didn't write will ask once per module if it is safe to be loaded. This can be disabled and
YCM will ask once per module if it is safe to be loaded. you can white-/blacklist files. See the Options section for more details.
(This can be disabled. See the Options section.)
This system was designed this way so that the user can perform any arbitrary This system was designed this way so that the user can perform any arbitrary
@ -680,6 +679,38 @@ Default: `1`
let g:ycm_confirm_extra_conf = 1 let g:ycm_confirm_extra_conf = 1
### The `g:ycm_extra_conf_globlist` option
This option is a list that may contain several globbing patterns. If a pattern
starts with a `!` all `.ycm_extra_conf.py` files matching that pattern will be
blacklisted, that is they won't be loaded and no confirmation dialog will be
shown. If a pattern does not start with a `!` all files matching that pattern
will be whitelisted. Note that this option is not used when confirmation is
disabled using `g:ycm_confirm_extra_conf` and that items earlier in the list
will take precedence over the later ones.
Rules:
* `*` matches everything
* `?` matches any single character
* `[seq]` matches any character in seq
* `[!seq]` matches any char not in seq
Example:
let g:ycm_extra_conf_globlist = ['~/dev/*','!~/*']
* The first rule will match everything contained in the `~/dev` directory so
`.ycm_extra_conf.py` files from there will be loaded.
* The second rule will match everything in the home directory so a
`.ycm_extra_conf.py` file from there won't be loaded.
* As the first rule takes precedence everything in the home directory excluding
the `~/dev` directory will be blacklisted.
Default: `[]`
let g:ycm_extra_conf_globlist = []
### The `g:ycm_semantic_triggers` option ### The `g:ycm_semantic_triggers` option
This option controls the character-based triggers for the various semantic This option controls the character-based triggers for the various semantic

View File

@ -104,6 +104,9 @@ let g:ycm_global_ycm_extra_conf =
let g:ycm_confirm_extra_conf = let g:ycm_confirm_extra_conf =
\ get( g:, 'ycm_confirm_extra_conf', 1 ) \ get( g:, 'ycm_confirm_extra_conf', 1 )
let g:ycm_extra_conf_globlist =
\ get( g:, 'ycm_extra_conf_globlist', [] )
let g:ycm_semantic_triggers = let g:ycm_semantic_triggers =
\ get( g:, 'ycm_semantic_triggers', { \ get( g:, 'ycm_semantic_triggers', {
\ 'c' : ['->', '.'], \ 'c' : ['->', '.'],

View File

@ -24,6 +24,7 @@ import random
import string import string
import sys import sys
import vimsupport import vimsupport
from fnmatch import fnmatch
YCM_EXTRA_CONF_FILENAME = '.ycm_extra_conf.py' YCM_EXTRA_CONF_FILENAME = '.ycm_extra_conf.py'
NO_EXTRA_CONF_FILENAME_MESSAGE = ('No {0} file detected, so no compile flags ' NO_EXTRA_CONF_FILENAME_MESSAGE = ('No {0} file detected, so no compile flags '
@ -110,16 +111,24 @@ class FlagsModules( object ):
@staticmethod @staticmethod
def ShouldLoad( module_file ): def ShouldLoad( module_file ):
"""Checks if a module is safe to be loaded. """Checks if a module is safe to be loaded. By default this will try to
By default this will ask the user for confirmation.""" decide using a white-/blacklist and ask the user for confirmation as a
fallback."""
if module_file == GLOBAL_YCM_EXTRA_CONF_FILE: if ( module_file == GLOBAL_YCM_EXTRA_CONF_FILE or
not vimsupport.GetBoolValue( 'g:ycm_confirm_extra_conf' ) ):
return True return True
if ( vimsupport.GetBoolValue( 'g:ycm_confirm_extra_conf' ) and
not vimsupport.Confirm( globlist = vimsupport.GetVariableValue( 'g:ycm_extra_conf_globlist' )
CONFIRM_CONF_FILE_MESSAGE.format( module_file ) ) ): for glob in globlist:
is_blacklisted = glob[0] == '!'
if MatchesGlobPattern( module_file, glob.lstrip('!') ):
return not is_blacklisted
if vimsupport.Confirm( CONFIRM_CONF_FILE_MESSAGE.format( module_file ) ):
return True
else:
return False return False
return True
def Load( self, module_file, force = False ): def Load( self, module_file, force = False ):
"""Load and return the module contained in a file. """Load and return the module contained in a file.
@ -218,3 +227,12 @@ def _SpecialClangIncludes():
def _DirectoryOfThisScript(): def _DirectoryOfThisScript():
return os.path.dirname( os.path.abspath( __file__ ) ) return os.path.dirname( os.path.abspath( __file__ ) )
def MatchesGlobPattern( filename, glob ):
"""Returns true if a filename matches a given pattern. A '~' in glob will be
expanded to the home directory and checking will be performed using absolute
paths. See the documentation of fnmatch for the supported patterns."""
abspath = os.path.abspath( filename )
return fnmatch( abspath, os.path.abspath( os.path.expanduser( glob ) ) )