Skip to content

Commit

Permalink
Merge pull request #767 from borodean/ts-server-cr-lf-fix
Browse files Browse the repository at this point in the history
Bypass the TSServer CRLF bug
  • Loading branch information
Orta Therox authored Feb 9, 2021
2 parents a607ddf + 85a6565 commit 27c0c0c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions typescript/libs/global_vars.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 9 additions & 0 deletions typescript/libs/node_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 27c0c0c

Please sign in to comment.