mirror of
https://gitlab.gnome.org/jwestman/blueprint-compiler.git
synced 2025-05-04 15:59:08 -04:00
lsp: Fix text encoding issue
Content-Length is the number of bytes in the message, but the JSONRPC code was interpreting it as a number of characters (when both reading and writing), which caused it to fail on multibyte UTF-8 characters.
This commit is contained in:
parent
08f7a4ebbd
commit
d23c06b8fd
1 changed files with 3 additions and 3 deletions
|
@ -103,12 +103,12 @@ class LanguageServer:
|
|||
line = ""
|
||||
content_len = -1
|
||||
while content_len == -1 or (line != "\n" and line != "\r\n"):
|
||||
line = sys.stdin.readline()
|
||||
line = sys.stdin.buffer.readline().decode()
|
||||
if line == "":
|
||||
return
|
||||
if line.startswith("Content-Length:"):
|
||||
content_len = int(line.split("Content-Length:")[1].strip())
|
||||
line = sys.stdin.read(content_len)
|
||||
line = sys.stdin.buffer.read(content_len).decode()
|
||||
self._log("input: " + line)
|
||||
|
||||
data = json.loads(line)
|
||||
|
@ -126,7 +126,7 @@ class LanguageServer:
|
|||
data["jsonrpc"] = "2.0"
|
||||
line = json.dumps(data, separators=(",", ":")) + "\r\n"
|
||||
self._log("output: " + line)
|
||||
sys.stdout.write(f"Content-Length: {len(line)}\r\nContent-Type: application/vscode-jsonrpc; charset=utf-8\r\n\r\n{line}")
|
||||
sys.stdout.write(f"Content-Length: {len(line.encode())}\r\nContent-Type: application/vscode-jsonrpc; charset=utf-8\r\n\r\n{line}")
|
||||
sys.stdout.flush()
|
||||
|
||||
def _log(self, msg):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue