From 85a6565a5cd3d624bad7fee95a0cde219c94cad8 Mon Sep 17 00:00:00 2001 From: Vadym Borodin Date: Sat, 23 Jan 2021 04:52:09 +0200 Subject: [PATCH] Bypass the TSServer CRLF bug --- typescript/libs/global_vars.py | 2 ++ typescript/libs/node_client.py | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/typescript/libs/global_vars.py b/typescript/libs/global_vars.py index 84e45f2b..b958f525 100644 --- a/typescript/libs/global_vars.py +++ b/typescript/libs/global_vars.py @@ -4,6 +4,8 @@ import sublime from os.path import dirname +IS_WINDOWS = sublime.platform() == "windows" + # determine if the host is sublime text 2 IS_ST2 = int(sublime.version()) < 3000 diff --git a/typescript/libs/node_client.py b/typescript/libs/node_client.py index 82e7148b..76259b01 100644 --- a/typescript/libs/node_client.py +++ b/typescript/libs/node_client.py @@ -185,6 +185,15 @@ def read_msg(stream, msgq, asyncReq, proc, asyncEventHandlers): if body_length > 0: data = stream.read(body_length) log.debug('Read body of length: {0}'.format(body_length)) + + # TypeScript adds a newline at the end of the response message and counts + # it as one character (LF) towards the content length. However, newlines + # are two characters on Windows (CR LF), so we need to take care of that. + # See issue: https://github.com/Microsoft/TypeScript/issues/3403 + # The fix is based on: https://github.com/ycm-core/ycmd/pull/503 + if global_vars.IS_WINDOWS and data.endswith(b'\r'): + data += stream.read(1) + data_json = data.decode("utf-8") data_dict = json_helpers.decode(data_json)