Skip to content

Bypass the TSServer CRLF bug #767

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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