From 48aaf033b20bdfa70cebf91f4179d456484201c3 Mon Sep 17 00:00:00 2001 From: Val Markovic Date: Tue, 9 Feb 2016 15:33:12 -0800 Subject: [PATCH] Fixing Windows issues --- .../typescript/typescript_completer.py | 2 ++ ycmd/utils.py | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/ycmd/completers/typescript/typescript_completer.py b/ycmd/completers/typescript/typescript_completer.py index 0a7424f531..2459965d79 100755 --- a/ycmd/completers/typescript/typescript_completer.py +++ b/ycmd/completers/typescript/typescript_completer.py @@ -219,6 +219,7 @@ def _SendCommand( self, command, arguments = None ): with self._writelock: self._tsserver_handle.stdin.write( json.dumps( request ) ) self._tsserver_handle.stdin.write( "\n" ) + self._tsserver_handle.stdin.flush() def _SendRequest( self, command, arguments = None ): @@ -235,6 +236,7 @@ def _SendRequest( self, command, arguments = None ): with self._writelock: self._tsserver_handle.stdin.write( json.dumps( request ) ) self._tsserver_handle.stdin.write( "\n" ) + self._tsserver_handle.stdin.flush() return deferred.result() diff --git a/ycmd/utils.py b/ycmd/utils.py index 7a0e32d500..a273ccd66f 100644 --- a/ycmd/utils.py +++ b/ycmd/utils.py @@ -31,7 +31,7 @@ import stat import subprocess -from future.utils import PY2 +from future.utils import PY2, iteritems, native # Creation flag to disable creating a console window on Windows. See # https://msdn.microsoft.com/en-us/library/windows/desktop/ms684863.aspx @@ -273,6 +273,15 @@ def ForceSemanticCompletion( request_data ): # A wrapper for subprocess.Popen that fixes quirks on Windows. def SafePopen( args, **kwargs ): + def ToNativeStringDict( dict_obj ): + new_dict = dict() + for k, v in iteritems( dict_obj ): + if PY2: + new_dict[ native( ToBytes( k ) ) ] = native( ToBytes( v ) ) + else: + new_dict[ ToUnicode( k ) ] = ToUnicode( v ) + return new_dict + if OnWindows(): # We need this to start the server otherwise bad things happen. # See issue #637. @@ -287,6 +296,11 @@ def SafePopen( args, **kwargs ): # short ones to obtain paths with only ascii characters. args = ConvertArgsToShortPath( args ) + if 'env' in kwargs: + # Popen requires that on Windows, the environment has only native strings + # on py2 and py3. + kwargs[ 'env' ] = ToNativeStringDict( kwargs[ 'env' ] ) + kwargs.pop( 'stdin_windows', None ) return subprocess.Popen( args, **kwargs ) @@ -306,6 +320,7 @@ def ConvertIfPath( arg ): # Get the Windows short path name. # Based on http://stackoverflow.com/a/23598461/200291 def GetShortPathName( path ): + path = native( ToBytes( path ) ) from ctypes import windll, wintypes, create_unicode_buffer # Set the GetShortPathNameW prototype