Use helper function to get current directory

Fix tests.
This commit is contained in:
micbou 2016-10-12 04:40:25 +02:00
parent 3109c9d8a4
commit 234658f30b
No known key found for this signature in database
GPG Key ID: C7E8FD1F3BDA1E05
4 changed files with 14 additions and 21 deletions

View File

@ -33,7 +33,7 @@ import os
import re import re
import sys import sys
from ycmd.utils import ToUnicode from ycmd.utils import GetCurrentDirectory, ToUnicode
BUFNR_REGEX = re.compile( '^bufnr\(\'(?P<buffer_filename>.+)\', ([01])\)$' ) BUFNR_REGEX = re.compile( '^bufnr\(\'(?P<buffer_filename>.+)\', ([01])\)$' )
@ -56,7 +56,7 @@ VIM_MOCK = MagicMock()
@contextlib.contextmanager @contextlib.contextmanager
def CurrentWorkingDirectory( path ): def CurrentWorkingDirectory( path ):
old_cwd = os.getcwd() old_cwd = GetCurrentDirectory()
os.chdir( path ) os.chdir( path )
try: try:
yield yield

View File

@ -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. # This file is part of YouCompleteMe.
# #
@ -26,11 +27,11 @@ from builtins import * # noqa
from future.utils import iterkeys from future.utils import iterkeys
import vim import vim
import os import os
import tempfile
import json import json
import re import re
from collections import defaultdict 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 from ycmd import user_options_store
BUFFER_COMMAND_MAP = { 'same-buffer' : 'edit', BUFFER_COMMAND_MAP = { 'same-buffer' : 'edit',
@ -156,13 +157,8 @@ def GetBufferFilepath( buffer_object ):
if buffer_object.name: if buffer_object.name:
return buffer_object.name return buffer_object.name
# Buffers that have just been created by a command like :enew don't have any # 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 # buffer name so we use the buffer number for that.
# an exception when the CWD has been deleted so we handle that. return os.path.join( GetCurrentDirectory(), str( buffer_object.number ) )
try:
folder_path = os.getcwd()
except OSError:
folder_path = tempfile.gettempdir()
return os.path.join( folder_path, str( buffer_object.number ) )
def UnplaceSignInBuffer( buffer_number, sign_id ): def UnplaceSignInBuffer( buffer_number, sign_id ):

View File

@ -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. # This file is part of YouCompleteMe.
# #
@ -225,7 +226,7 @@ class YouCompleteMe( object ):
self._omnicomp, wrapped_request_data ) self._omnicomp, wrapped_request_data )
return self._latest_completion_request return self._latest_completion_request
request_data[ 'working_dir' ] = os.getcwd() request_data[ 'working_dir' ] = utils.GetCurrentDirectory()
self._AddExtraConfDataIfNeeded( request_data ) self._AddExtraConfDataIfNeeded( request_data )
if force_semantic: if force_semantic:
@ -677,12 +678,8 @@ class YouCompleteMe( object ):
def _AddTagsFilesIfNeeded( self, extra_data ): def _AddTagsFilesIfNeeded( self, extra_data ):
def GetTagFiles(): def GetTagFiles():
tag_files = vim.eval( 'tagfiles()' ) tag_files = vim.eval( 'tagfiles()' )
# getcwd() throws an exception when the CWD has been deleted. return [ os.path.join( utils.GetCurrentDirectory(), tag_file )
try: for tag_file in tag_files ]
current_working_directory = os.getcwd()
except OSError:
return []
return [ os.path.join( current_working_directory, x ) for x in tag_files ]
if not self._user_options[ 'collect_identifiers_from_tags_files' ]: if not self._user_options[ 'collect_identifiers_from_tags_files' ]:
return return

2
third_party/ycmd vendored

@ -1 +1 @@
Subproject commit f3232ce5180753822d839c80e9b9ea4e33e89d4c Subproject commit 63c3d992a2db8d189cd78a25a70c87348726fc52