Skip to content

Commit 27c0c0c

Browse files
author
Orta Therox
authored
Merge pull request #767 from borodean/ts-server-cr-lf-fix
Bypass the TSServer CRLF bug
2 parents a607ddf + 85a6565 commit 27c0c0c

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

typescript/libs/global_vars.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import sublime
55
from os.path import dirname
66

7+
IS_WINDOWS = sublime.platform() == "windows"
8+
79
# determine if the host is sublime text 2
810
IS_ST2 = int(sublime.version()) < 3000
911

typescript/libs/node_client.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,15 @@ def read_msg(stream, msgq, asyncReq, proc, asyncEventHandlers):
185185
if body_length > 0:
186186
data = stream.read(body_length)
187187
log.debug('Read body of length: {0}'.format(body_length))
188+
189+
# TypeScript adds a newline at the end of the response message and counts
190+
# it as one character (LF) towards the content length. However, newlines
191+
# are two characters on Windows (CR LF), so we need to take care of that.
192+
# See issue: https://github.com/Microsoft/TypeScript/issues/3403
193+
# The fix is based on: https://github.com/ycm-core/ycmd/pull/503
194+
if global_vars.IS_WINDOWS and data.endswith(b'\r'):
195+
data += stream.read(1)
196+
188197
data_json = data.decode("utf-8")
189198

190199
data_dict = json_helpers.decode(data_json)

0 commit comments

Comments
 (0)