unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Adam Porter <adam@alphapapa.net>
To: "João Távora" <joaotavora@gmail.com>
Cc: emacs-devel <emacs-devel@gnu.org>, Joseph Turner <joseph@ushin.org>
Subject: Re: jsonrpc.el uses "Content-Length" headers which seem specific to LSP
Date: Wed, 22 Nov 2023 16:40:57 -0600	[thread overview]
Message-ID: <4d3cd934-01a8-41ac-b50b-61ff729c9a2c@alphapapa.net> (raw)
In-Reply-To: <87leby9n4m.fsf@gmail.com>


Hi João,

Thanks for this reply of yours from last month.  I hadn't had anything
to add until now, after we've had more development in our project.

On 10/19/23 19:02, João Távora wrote:

> After having looked at your code, I think you may be underestimating 
> the use of the Content-Length header.  It's not a spurious 
> decoration. Rather it helps processes make sense of incomplete or 
> multiple messages that may appear in the process buffer.  I'd say 
> it's only in toy examples or "lucky" cases in which you can safely 
> jsonrpc--json-read one single full JSON objects to completeness.

Agreed.  Our intention was to use the hack of trying to parse
potentially incomplete objects for only small responses, and only
because our RPC server doesn't support the Content-Length header.

We may be able to add support for that header to the RPC server, but
we've been discussing another potential solution: to use something like
the JSON Lines[0] (aka NDJSON[1]) format, which would mean that each
JSON object would be sent as a single line (with any internal newlines 
being escaped).  Then, in the process filter, we would look for 
unescaped newlines, and if we find any, we would parse the received data 
up to that newline.  This would allow us to know when a complete object 
has been received.

> It's true it uses some jsonrpc.el internals when it shouldn't but 
> it's quite OK to augment the jsonrpc.el API to export 
> jsonrpc--json-read and the few other internal helpers you're using. 
> That doesn't pose any backward-compatibility challenge and your code 
> is indeed quite simple.

Of course, this means that we would still need to make our own version
of the jsonrpc process filter function, similar to the code seen earlier
in this thread, but it should require only minor changes.

Given your experience with these things, does this seem like a
reasonable solution to you?  Or is there still strong reason to prefer
using a Content-Length header to detect the end of responses?

Thanks for your help!

--Adam

0: https://jsonlines.org/
1: https://ndjson.org/



  reply	other threads:[~2023-11-22 22:40 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-18 23:17 jsonrpc.el uses "Content-Length" headers which seem specific to LSP Adam Porter
2023-10-19  0:11 ` João Távora
2023-10-19 20:59   ` Adam Porter
2023-10-20  0:02     ` João Távora
2023-11-22 22:40       ` Adam Porter [this message]
2023-12-01  0:45         ` João Távora

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4d3cd934-01a8-41ac-b50b-61ff729c9a2c@alphapapa.net \
    --to=adam@alphapapa.net \
    --cc=emacs-devel@gnu.org \
    --cc=joaotavora@gmail.com \
    --cc=joseph@ushin.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).