From f91790e2ee5760cda3a520e45f4c64cb7455462b Mon Sep 17 00:00:00 2001 From: Strahinja Val Markovic Date: Mon, 28 Oct 2013 12:17:18 -0700 Subject: [PATCH] Only importing ycm_core in ycmd I'm not sure, but it seems that loading both ycm_client_support and ycm_core into the same process is causing random ycmd crashes. --- python/ycm/completers/completer.py | 16 ++++++++++------ python/ycm/utils.py | 8 ++++++++ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/python/ycm/completers/completer.py b/python/ycm/completers/completer.py index 63ccffa7..6dfa3339 100644 --- a/python/ycm/completers/completer.py +++ b/python/ycm/completers/completer.py @@ -18,8 +18,13 @@ # along with YouCompleteMe. If not, see . import abc -import ycm_client_support -from ycm.utils import ToUtf8IfNeeded, ForceSemanticCompletion +from ycm.utils import ToUtf8IfNeeded, ForceSemanticCompletion, RunningInsideVim + +if RunningInsideVim(): + from ycm_client_support import FilterAndSortCandidates +else: + from ycm_core import FilterAndSortCandidates + from ycm.completers.completer_utils import TriggersForFiletype NO_USER_COMMANDS = 'This completer does not define any commands.' @@ -206,10 +211,9 @@ class Completer( object ): elif 'insertion_text' in candidates[ 0 ]: sort_property = 'insertion_text' - matches = ycm_client_support.FilterAndSortCandidates( - candidates, - sort_property, - ToUtf8IfNeeded( query ) ) + matches = FilterAndSortCandidates( candidates, + sort_property, + ToUtf8IfNeeded( query ) ) return matches diff --git a/python/ycm/utils.py b/python/ycm/utils.py index 8d98bc66..15ad2727 100644 --- a/python/ycm/utils.py +++ b/python/ycm/utils.py @@ -62,6 +62,14 @@ def MakeFolderAccessibleToAll( path_to_folder ): os.chmod( path_to_folder, flags ) +def RunningInsideVim(): + try: + import vim # NOQA + return True + except ImportError: + return False + + def GetUnusedLocalhostPort(): sock = socket.socket() # This tells the OS to give us any free port in the range [1024 - 65535]