Skip to content

Commit

Permalink
Fixing Windows issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Valloric committed Feb 11, 2016
1 parent 6acad6e commit 48aaf03
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 2 additions & 0 deletions ycmd/completers/typescript/typescript_completer.py
Expand Up @@ -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 ):
Expand All @@ -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()


Expand Down
17 changes: 16 additions & 1 deletion ycmd/utils.py
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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 )

Expand All @@ -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
Expand Down

0 comments on commit 48aaf03

Please sign in to comment.