diff --git a/python/ycm/tests/test_utils.py b/python/ycm/tests/test_utils.py index b1bcb53b..d1733dbd 100644 --- a/python/ycm/tests/test_utils.py +++ b/python/ycm/tests/test_utils.py @@ -33,7 +33,7 @@ import os import re import sys -from ycmd.utils import ToUnicode +from ycmd.utils import GetCurrentDirectory, ToUnicode BUFNR_REGEX = re.compile( '^bufnr\(\'(?P.+)\', ([01])\)$' ) @@ -56,7 +56,7 @@ VIM_MOCK = MagicMock() @contextlib.contextmanager def CurrentWorkingDirectory( path ): - old_cwd = os.getcwd() + old_cwd = GetCurrentDirectory() os.chdir( path ) try: yield diff --git a/python/ycm/vimsupport.py b/python/ycm/vimsupport.py index c50641e0..4c8564d3 100644 --- a/python/ycm/vimsupport.py +++ b/python/ycm/vimsupport.py @@ -1,4 +1,5 @@ -# Copyright (C) 2011, 2012 Google Inc. +# Copyright (C) 2011-2012 Google Inc. +# 2016 YouCompleteMe contributors # # This file is part of YouCompleteMe. # @@ -26,11 +27,11 @@ from builtins import * # noqa from future.utils import iterkeys import vim import os -import tempfile import json import re from collections import defaultdict -from ycmd.utils import ToUnicode, ToBytes, JoinLinesAsUnicode +from ycmd.utils import ( GetCurrentDirectory, JoinLinesAsUnicode, ToBytes, + ToUnicode ) from ycmd import user_options_store BUFFER_COMMAND_MAP = { 'same-buffer' : 'edit', @@ -156,13 +157,8 @@ def GetBufferFilepath( buffer_object ): if buffer_object.name: return buffer_object.name # Buffers that have just been created by a command like :enew don't have any - # buffer name so we use the buffer number for that. Also, os.getcwd() throws - # an exception when the CWD has been deleted so we handle that. - try: - folder_path = os.getcwd() - except OSError: - folder_path = tempfile.gettempdir() - return os.path.join( folder_path, str( buffer_object.number ) ) + # buffer name so we use the buffer number for that. + return os.path.join( GetCurrentDirectory(), str( buffer_object.number ) ) def UnplaceSignInBuffer( buffer_number, sign_id ): diff --git a/python/ycm/youcompleteme.py b/python/ycm/youcompleteme.py index 461fcb3a..6acfe520 100644 --- a/python/ycm/youcompleteme.py +++ b/python/ycm/youcompleteme.py @@ -1,4 +1,5 @@ -# Copyright (C) 2011, 2012 Google Inc. +# Copyright (C) 2011-2012 Google Inc. +# 2016 YouCompleteMe contributors # # This file is part of YouCompleteMe. # @@ -225,7 +226,7 @@ class YouCompleteMe( object ): self._omnicomp, wrapped_request_data ) return self._latest_completion_request - request_data[ 'working_dir' ] = os.getcwd() + request_data[ 'working_dir' ] = utils.GetCurrentDirectory() self._AddExtraConfDataIfNeeded( request_data ) if force_semantic: @@ -677,12 +678,8 @@ class YouCompleteMe( object ): def _AddTagsFilesIfNeeded( self, extra_data ): def GetTagFiles(): tag_files = vim.eval( 'tagfiles()' ) - # getcwd() throws an exception when the CWD has been deleted. - try: - current_working_directory = os.getcwd() - except OSError: - return [] - return [ os.path.join( current_working_directory, x ) for x in tag_files ] + return [ os.path.join( utils.GetCurrentDirectory(), tag_file ) + for tag_file in tag_files ] if not self._user_options[ 'collect_identifiers_from_tags_files' ]: return diff --git a/third_party/ycmd b/third_party/ycmd index f3232ce5..63c3d992 160000 --- a/third_party/ycmd +++ b/third_party/ycmd @@ -1 +1 @@ -Subproject commit f3232ce5180753822d839c80e9b9ea4e33e89d4c +Subproject commit 63c3d992a2db8d189cd78a25a70c87348726fc52