From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Adam Porter Newsgroups: gmane.emacs.devel Subject: Re: jsonrpc.el uses "Content-Length" headers which seem specific to LSP Date: Thu, 19 Oct 2023 15:59:59 -0500 Message-ID: References: <04f0ef0b-7fcf-4b09-a1c8-94960d8184cf@alphapapa.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------Zd0YnozEET705QKKb3OpEK6q" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="21164"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla Thunderbird Cc: emacs-devel , Joseph Turner To: =?UTF-8?B?Sm/Do28gVMOhdm9yYQ==?= Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu Oct 19 23:00:33 2023 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qta89-0005HZ-8A for ged-emacs-devel@m.gmane-mx.org; Thu, 19 Oct 2023 23:00:33 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qta7l-0004eR-Uw; Thu, 19 Oct 2023 17:00:09 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qta7j-0004P1-Ev for emacs-devel@gnu.org; Thu, 19 Oct 2023 17:00:07 -0400 Original-Received: from black.elm.relay.mailchannels.net ([23.83.212.19]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qta7h-0000kB-9B for emacs-devel@gnu.org; Thu, 19 Oct 2023 17:00:07 -0400 X-Sender-Id: dreamhost|x-authsender|adam@alphapapa.net Original-Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id DDA4690143D; Thu, 19 Oct 2023 21:00:01 +0000 (UTC) Original-Received: from pdx1-sub0-mail-a209.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 54A8390151C; Thu, 19 Oct 2023 21:00:01 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1697749201; a=rsa-sha256; cv=none; b=jX7dvwpr3qITjLMONlKURaQdNdE9+zzpCMD8EmX0jV/mPU2F34Fw7HZpRambYMWfjitVA+ nGojTTnypnirTF1HuvYYEXcYA+AXIepKCLo6KfquPPvDrVJViTa8V544YKdzl59IMrSBcA 8xhWAMKrI1YdFs9cVR21qGJoymLVHAfFLrys1lQ+Pd5K2HmQUjNVj0O950rPrQ9eJGZ7Qp h3abnojMbv3QJAqsb9bH9m2SScPPK8/m1HiwL2C/m9U98ww0hWlhUOmccvcDhwj4hbzfIE sMpMzDseQvnGTg2HpvqqsCUAaRvOLKCb+3Wn3GdmWmYcqgbZM5hYJwdhtWtYSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1697749201; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references:dkim-signature; bh=rzffavVR3s+FY2YlXsNJRsysyA0i3FXAbe2b7bGcsVk=; b=j1RYMBPXDa01rJterAqfwgxnCnkzZp3i5aB8RPmlxBpioDWBnpkA07zQccztiF+Q6SFGE1 XVhKBDM+NEattlx3gdwoRD51cA2SyulnxCJjCgdxkmmmukIvIkIBfht/dX7rUbIEb6I9Nd fs57AeWOcIPguECjgFee9O0UAtwyPFo1r5mw+7WEQ1UkhOmxm64RA+Atc6MLF723LDXOeI TAasKcDZFxWOGeOyiPyLeXxiU9q5CYwpqgSyzZHW2ySTad/c6zMPjMKtBQvEmU0qBEgHMl b3Cpa//YSEok2h9wW3tuO92Gqea6aeTl0K7cKu1q9YQjg9ceq0Ie2cuGBL60uQ== ARC-Authentication-Results: i=1; rspamd-846f4b758b-qn7hk; auth=pass smtp.auth=dreamhost smtp.mailfrom=adam@alphapapa.net X-Sender-Id: dreamhost|x-authsender|adam@alphapapa.net X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|adam@alphapapa.net X-MailChannels-Auth-Id: dreamhost X-Whimsical-Decisive: 421154e61380df02_1697749201617_1062335129 X-MC-Loop-Signature: 1697749201617:3957015097 X-MC-Ingress-Time: 1697749201617 Original-Received: from pdx1-sub0-mail-a209.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.113.192.164 (trex/6.9.2); Thu, 19 Oct 2023 21:00:01 +0000 Original-Received: from [10.45.0.250] (unknown [45.131.192.7]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: adam@alphapapa.net) by pdx1-sub0-mail-a209.dreamhost.com (Postfix) with ESMTPSA id 4SBKq45Ydrz9x; Thu, 19 Oct 2023 14:00:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alphapapa.net; s=dreamhost; t=1697749201; bh=rzffavVR3s+FY2YlXsNJRsysyA0i3FXAbe2b7bGcsVk=; h=Content-Type:Date:Subject:To:Cc:From; b=K38qzpy/C8U/UOLE3Q/1HRZlrvPmm3dK2IB3YjzG4axLm1t3sAB1zzSjZs+JvlTAf N/hFb348tVZDzhwULOPfmwbVjVQ7qzy5LG0irgsPd5bVK6hJYVCyjaT3Ho9MJnEpGw lpPOhMHlpIiw6sxzhvz4RT2CjI9SSr47arBFABpFXiXwDqChtsEgvpT43cCW81+nPV 9krI5ElyQHPFlUgbmOs2fUPrh63LfVuMLK3lJzg9hFfvfY2dbpSCmdT4o0dGgtqP7D OcjK8eYu3GurpsvmHZDPRA5ZkpV6VqMKAfaS3QX3umP1W1MFdmmIaO6hkDJOz0goGm J+6k/Kjwh3IPg== Content-Language: en-US In-Reply-To: Received-SPF: neutral client-ip=23.83.212.19; envelope-from=adam@alphapapa.net; helo=black.elm.relay.mailchannels.net X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_NEUTRAL=0.779 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:311606 Archived-At: This is a multi-part message in MIME format. --------------Zd0YnozEET705QKKb3OpEK6q Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Hi João, On 10/18/23 19:11, João Távora wrote: > Instead of jsonrpc.el, I think you mean jsonrpc-process-connection. It's > a subclass of jsonrpc-connection. If you want more genericity, you could > subclass jsonrpc-connection. Yes, thanks. > To give you an example, in a private project I subclassed > jsonrpc-connection to make a websocket-based JSONRPC transport. > It was really easy (I can show the code if you're interested). Sure, that could be helpful. > Presumably you're interested in using an Emacs pipe or network process > as the transport, so by doing that you'd find yourself reinventing lots of > stuff in the methods for jsonrpc-process-connection. Let's label this idea A. Yes, we're using a network process connecting to a local TCP server. Indeed, we didn't want to reinvent those things. > Now, the flaw I will concede about jsonrpc-process-connection is that it > describes itself as a "jsonrpc connection over an Emacs process", but it > would be more accurately described as "JSONRPC connection over HTTP-like > over Emacs process". Presumably, you want the first and the last part > but not the middle. Right, the code we wrote (shared below) basically removes those middle parts. > I guess we could express the existing > jsonrpc-process-connection as a mixin of HTTP-like behaviour and Emacs > process behaviour. If we did that, you could more elegantly do your > own hyperdrive-jsonrpc-connection by mixing in just the classes you wanted. > So this is idea B. > > Back to idea A, we could just bundle most of the functionality used by > the generics operating on jsonrpc-process-connection as free helper > functions. Then you could just easily build on top of jsonrpc-connection > the process-related stuff you want to do and the existing > jsonrpc-process-connection would also use these helpers. > > Nevertheless, I think idea B is cleaner. From reading your email, > you seem to agree with me. Right, we wanted to avoid the refactoring that would require. > But I have to see your code first. You seem to have already come up > with some kind of idea C. You say the code is "pleasantly simple", > yet you still think it could be easier, so I don't know. I haven't > seen your pleasantly-simple-but-not-quite-optimal code. Of course. Attaching that code below. :) > I do know subclassing and removing behaviour violates the "is a" > of inheritance and sometimes brings you into trouble > later on. Or maybe not. Yes, that is an ugly compromise. For the minor changes we had to make, it seemed reasonable within our project, but we'd be glad if it weren't necessary. > So, to summarize, changes to the transport implementor's API in > of jsonrpc.el are possible, so long as the current API isn't > broken and the new things, be it helpers of idea A or new classes of > idea B are documented in the manual. So show me your code and propose > some patch to jsonrpc.el showing how much it would simplify your > existing code. So, here's our code. As you can see, it just copies some forms from jsonrpc and removes the parts related to the HTTP-like headers. It seems to work so far, but I don't know if it's good or close to correct. :) Of course, one of the considerations is backward compatibility with existing users of jsonrpc. There don't appear to be very many yet, other than Eglot, so some kind of transition might be feasible, especially since jsonrpc.el is on GNU ELPA. Thanks for your work and your help with this. Adam --------------Zd0YnozEET705QKKb3OpEK6q Content-Type: text/x-emacs-lisp; charset=UTF-8; name="jsonrpc-hacks.el" Content-Disposition: attachment; filename="json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