diff --git a/autoload/youcompleteme.vim b/autoload/youcompleteme.vim index 05c0b199..642fbbf9 100644 --- a/autoload/youcompleteme.vim +++ b/autoload/youcompleteme.vim @@ -42,16 +42,17 @@ function! youcompleteme#Enable() exe 'python sys.path.insert( 0, "' . s:script_folder_path . '/../python" )' py from ycm import extra_conf_store py extra_conf_store.CallExtraConfYcmCorePreloadIfExists() - py import ycm + py from ycm import base - if !pyeval( 'ycm.CompatibleWithYcmCore()') + if !pyeval( 'base.CompatibleWithYcmCore()') echohl WarningMsg | \ echomsg "YouCompleteMe unavailable: ycm_core too old, PLEASE RECOMPILE ycm_core" | \ echohl None return endif - py ycm_state = ycm.YouCompleteMe() + py from ycm.youcompleteme import YouCompleteMe + py ycm_state = YouCompleteMe() augroup youcompleteme autocmd! @@ -386,7 +387,7 @@ endfunction function! s:IdentifierFinishedOperations() - if !pyeval( 'ycm.CurrentIdentifierFinished()' ) + if !pyeval( 'base.CurrentIdentifierFinished()' ) return endif py ycm_state.OnCurrentIdentifierFinished() @@ -511,7 +512,7 @@ function! youcompleteme#Complete( findstart, base ) " TODO: make this a function-local variable instead of a script-local one - let s:completion_start_column = pyeval( 'ycm.CompletionStartColumn()' ) + let s:completion_start_column = pyeval( 'base.CompletionStartColumn()' ) let s:should_use_filetype_completion = \ pyeval( 'ycm_state.ShouldUseFiletypeCompleter(' . \ s:completion_start_column . ')' ) @@ -534,7 +535,7 @@ endfunction function! youcompleteme#OmniComplete( findstart, base ) if a:findstart let s:omnifunc_mode = 1 - let s:completion_start_column = pyeval( 'ycm.CompletionStartColumn()' ) + let s:completion_start_column = pyeval( 'base.CompletionStartColumn()' ) return s:completion_start_column else return s:CompletionsForQuery( a:base, 1, s:completion_start_column ) diff --git a/python/ycm/__init__.py b/python/ycm/__init__.py index 6dbc7fcd..e69de29b 100644 --- a/python/ycm/__init__.py +++ b/python/ycm/__init__.py @@ -1,33 +0,0 @@ -#!/usr/bin/env python -# -# Copyright (C) 2011, 2012 Strahinja Val Markovic -# -# This file is part of YouCompleteMe. -# -# YouCompleteMe is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# YouCompleteMe is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with YouCompleteMe. If not, see . - -from youcompleteme import ( - YouCompleteMe, CompatibleWithYcmCore, CurrentIdentifierFinished, - CompletionStartColumn ) - -# We don't really need to do this, but if we don't, pyflakes complains that we -# have unused imports. Pyflakes should ignore unused imports in __init__.py -# files, but doesn't. See this bug report: -# https://bugs.launchpad.net/pyflakes/+bug/1178905 -__all__ = [ - YouCompleteMe.__name__, - CompatibleWithYcmCore.__name__, - CurrentIdentifierFinished.__name__, - CompletionStartColumn.__name__ -] diff --git a/python/ycm/base.py b/python/ycm/base.py new file mode 100644 index 00000000..fe9189c1 --- /dev/null +++ b/python/ycm/base.py @@ -0,0 +1,83 @@ +#!/usr/bin/env python +# +# Copyright (C) 2011, 2012 Strahinja Val Markovic +# +# This file is part of YouCompleteMe. +# +# YouCompleteMe is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# YouCompleteMe is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with YouCompleteMe. If not, see . + +import os +import vim +from ycm import vimsupport +from ycm import utils + +try: + import ycm_core +except ImportError as e: + vimsupport.PostVimMessage( + 'Error importing ycm_core. Are you sure you have placed a version 3.2+ ' + 'libclang.[so|dll|dylib] in folder "{0}"? See the Installation Guide in ' + 'the docs. Full error: {1}'.format( + os.path.dirname( os.path.abspath( __file__ ) ), str( e ) ) ) + + +def CompletionStartColumn(): + """Returns the 0-based index where the completion string should start. So if + the user enters: + foo.bar^ + with the cursor being at the location of the caret, then the starting column + would be the index of the letter 'b'. + """ + + line = vim.current.line + start_column = vimsupport.CurrentColumn() + + while start_column > 0 and utils.IsIdentifierChar( line[ start_column - 1 ] ): + start_column -= 1 + return start_column + + +def CurrentIdentifierFinished(): + current_column = vimsupport.CurrentColumn() + previous_char_index = current_column - 1 + if previous_char_index < 0: + return True + line = vim.current.line + try: + previous_char = line[ previous_char_index ] + except IndexError: + return False + + if utils.IsIdentifierChar( previous_char ): + return False + + if ( not utils.IsIdentifierChar( previous_char ) and + previous_char_index > 0 and + utils.IsIdentifierChar( line[ previous_char_index - 1 ] ) ): + return True + else: + return line[ : current_column ].isspace() + + +COMPATIBLE_WITH_CORE_VERSION = 3 + +def CompatibleWithYcmCore(): + try: + current_core_version = ycm_core.YcmCoreVersion() + except AttributeError: + return False + + return current_core_version == COMPATIBLE_WITH_CORE_VERSION + + diff --git a/python/ycm/completers/cpp/tests/flags_test.py b/python/ycm/completers/cpp/tests/flags_test.py index b283b3a1..90654152 100644 --- a/python/ycm/completers/cpp/tests/flags_test.py +++ b/python/ycm/completers/cpp/tests/flags_test.py @@ -18,7 +18,7 @@ # along with YouCompleteMe. If not, see . from nose.tools import eq_ -from ycm_test_utils import MockVimModule +from ycm.test_utils import MockVimModule vim_mock = MockVimModule() from .. import flags diff --git a/python/ycm/youcompleteme.py b/python/ycm/youcompleteme.py index e95e9b80..35ef7bef 100644 --- a/python/ycm/youcompleteme.py +++ b/python/ycm/youcompleteme.py @@ -20,22 +20,12 @@ import imp import os import vim +import ycm_core from ycm import vimsupport -from ycm import utils - -try: - import ycm_core -except ImportError as e: - vimsupport.PostVimMessage( - 'Error importing ycm_core. Are you sure you have placed a version 3.2+ ' - 'libclang.[so|dll|dylib] in folder "{0}"? See the Installation Guide in ' - 'the docs. Full error: {1}'.format( - os.path.dirname( os.path.abspath( __file__ ) ), str( e ) ) ) - - from ycm.completers.all.omni_completer import OmniCompleter from ycm.completers.general.general_completer_store import GeneralCompleterStore + FILETYPE_SPECIFIC_COMPLETION_TO_DISABLE = vim.eval( 'g:ycm_filetype_specific_completion_to_disable' ) @@ -220,51 +210,3 @@ def _PathToFiletypeCompleterPluginLoader( filetype ): return os.path.join( _PathToCompletersFolder(), filetype, 'hook.py' ) -def CompletionStartColumn(): - """Returns the 0-based index where the completion string should start. So if - the user enters: - foo.bar^ - with the cursor being at the location of the caret, then the starting column - would be the index of the letter 'b'. - """ - - line = vim.current.line - start_column = vimsupport.CurrentColumn() - - while start_column > 0 and utils.IsIdentifierChar( line[ start_column - 1 ] ): - start_column -= 1 - return start_column - - -def CurrentIdentifierFinished(): - current_column = vimsupport.CurrentColumn() - previous_char_index = current_column - 1 - if previous_char_index < 0: - return True - line = vim.current.line - try: - previous_char = line[ previous_char_index ] - except IndexError: - return False - - if utils.IsIdentifierChar( previous_char ): - return False - - if ( not utils.IsIdentifierChar( previous_char ) and - previous_char_index > 0 and - utils.IsIdentifierChar( line[ previous_char_index - 1 ] ) ): - return True - else: - return line[ : current_column ].isspace() - - -COMPATIBLE_WITH_CORE_VERSION = 3 - -def CompatibleWithYcmCore(): - try: - current_core_version = ycm_core.YcmCoreVersion() - except AttributeError: - return False - - return current_core_version == COMPATIBLE_WITH_CORE_VERSION -