From 8d20637295ede470afa4bb01fc4663fc994c11ef Mon Sep 17 00:00:00 2001 From: Strahinja Val Markovic Date: Mon, 22 Apr 2013 21:44:18 -0700 Subject: [PATCH] User can now pick the root for relative paths --- README.md | 16 ++++++++++++++++ plugin/youcompleteme.vim | 3 +++ python/completers/general/filename_completer.py | 7 +++++++ 3 files changed, 26 insertions(+) diff --git a/README.md b/README.md index c554ad49..85f9a4f1 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,10 @@ YCM also provides semantic go-to-definition/declaration commands for C-family languages. Expect more IDE features powered by the various YCM semantic engines in the future. +You'll also find that YCM has filepath completers (try typing `./` in a file) +and a completer that integrates with [UltiSnips][]. + + Mac OS X super-quick installation --------------------------------- @@ -861,6 +865,17 @@ Default: `[]` let g:ycm_extra_conf_globlist = [] +### The `g:ycm_filepath_completion_use_working_dir` option + +By default, YCM's filepath completion will interpret relative paths like `../` +as being relative to the folder of the file of the currently active buffer. +Setting this option will force YCM to always interpret relative paths as being +relative to Vim's current working directory. + +Default: `0` + + let g:ycm_filepath_completion_use_working_dir = 0 + ### The `g:ycm_semantic_triggers` option This option controls the character-based triggers for the various semantic @@ -1140,3 +1155,4 @@ This software is licensed under the [GPL v3 license][gpl]. [win-wiki]: https://github.com/Valloric/YouCompleteMe/wiki/Windows-Installation-Guide [eclim]: http://eclim.org/ [jedi]: https://github.com/davidhalter/jedi +[ultisnips]: https://github.com/SirVer/ultisnips/blob/master/doc/UltiSnips.txt diff --git a/plugin/youcompleteme.vim b/plugin/youcompleteme.vim index b846aefc..006e8dd3 100644 --- a/plugin/youcompleteme.vim +++ b/plugin/youcompleteme.vim @@ -121,6 +121,9 @@ let g:ycm_confirm_extra_conf = let g:ycm_extra_conf_globlist = \ get( g:, 'ycm_extra_conf_globlist', [] ) +let g:ycm_filepath_completion_use_working_dir = + \ get( g:, 'ycm_filepath_completion_use_working_dir', 0 ) + let g:ycm_semantic_triggers = \ get( g:, 'ycm_semantic_triggers', { \ 'c' : ['->', '.'], diff --git a/python/completers/general/filename_completer.py b/python/completers/general/filename_completer.py index d3e5534b..e2c524e9 100644 --- a/python/completers/general/filename_completer.py +++ b/python/completers/general/filename_completer.py @@ -18,9 +18,12 @@ from completers.completer import GeneralCompleter import vim +import vimsupport import os import re +USE_WORKING_DIR = vimsupport.GetBoolValue( + 'g:ycm_filepath_completion_use_working_dir' ) class FilenameCompleter( GeneralCompleter ): """ @@ -74,6 +77,10 @@ class FilenameCompleter( GeneralCompleter ): match = self._path_regex.search( line ) path_dir = os.path.expanduser( match.group() ) if match else '' + if not USE_WORKING_DIR and not path_dir.startswith( '/' ): + path_dir = os.path.join( os.path.dirname( vim.current.buffer.name ), + path_dir ) + try: paths = os.listdir( path_dir ) except: