Correct format for JSONRPC for Clangd

Correct format for JSONRPC for Clangd
typescript
Ethan Jackson

I am attempting to send JSON to Clangd on my desktop using Python. I see in the terminal window that Clangd says:

I[15:52:46.580] Warning: Missing Content-Length header, or zero-length message. "Content-Length": 53 { "jsonrpc": "2.0", "id": 1, "method": "exit" }

But that is not the case. Python code:

import argparse import sys if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument("-p", "--process_num", type=int, help="Clangd process number", required=True) parser.add_argument("-d", "--dry_run", action="store_true", help="Dry run") args = parser.parse_args() filepath = f"/proc/{args.process_num}/fd/0" my_content = """\ "Content-Length": 53 { "jsonrpc": "2.0", "id": 1, "method": "exit" }""" if args.dry_run: print(my_content.encode("utf-8")) sys.exit(0) with open(filepath, 'wb') as f: f.write(my_content.encode("utf-8"))

Is there something in the formatting I am missing?

Answer

You're not supposed to quote the "Content-Length" , just send Content-Length: 53

Make sure you're using \r\n for the newlines too in the header part, as shown in the Language Server Protocol . Make sure your Content-Length is right as well, the json you posted here isn't 53 bytes,

Related Articles