From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?UTF-8?B?Sm/Do28gVMOhdm9yYQ==?= Newsgroups: gmane.emacs.devel Subject: Re: Eglot "inlay hints" landed Date: Thu, 23 Feb 2023 16:09:24 +0000 Message-ID: References: <83edqqaf8c.fsf@gnu.org> <2B284D77-97DF-4B3E-89FB-13F0CA93D240@gmail.com> <87356xv65z.fsf_-_@gmail.com> <83fsawriye.fsf@gnu.org> <835ybsr6aa.fsf@gnu.org> <83356wr224.fsf@gnu.org> <87bklktu89.fsf@gmail.com> <83y1oophd0.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="6474"; mail-complaints-to="usenet@ciao.gmane.io" Cc: dalal.chinmay.0101@gmail.com, emacs-devel@gnu.org, dimitri@belopopsky.com, luangruo@yahoo.com To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu Feb 23 17:10:22 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 1pVEAo-0001Ys-1v for ged-emacs-devel@m.gmane-mx.org; Thu, 23 Feb 2023 17:10:22 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pVEA9-0000xu-KR; Thu, 23 Feb 2023 11:09:41 -0500 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 1pVEA7-0000vR-G5 for emacs-devel@gnu.org; Thu, 23 Feb 2023 11:09:39 -0500 Original-Received: from mail-oi1-x22c.google.com ([2607:f8b0:4864:20::22c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pVEA5-0007IW-LC; Thu, 23 Feb 2023 11:09:39 -0500 Original-Received: by mail-oi1-x22c.google.com with SMTP id o12so6055561oik.6; Thu, 23 Feb 2023 08:09:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=WBoQ0HEYYHQmKJJ4lkxRq0hOvD6WfP4CDGHXu/NEqkM=; b=Pa8f259hXVFy7jOR1sLnT4yqrlnYFVOVv2iLjMtmHgKS0mFoSHDIeDDTMp4B4i4or5 +D7Ap5G9Sxyq4K7cok4+4+ctQYfjdexooFfLhAIIoN5o1jb+oxIpS89rkdMczdf5BzYX znT8P6sY2auyPky1s3jIgHMrWyocDO15MX5omb/iRkI4Tnlx0P8tt0dKQRMI2HB/eneZ NsVnbaAfCfoU0c3SQm2Env1VCMoeRDr1FPK0Y63kL/V8JKqKLvIy/FfMfmzcG5JXg7US A/2tD6tLuZixwwO4x50tda3IbWxYDvr5jj7BRN3miI7SWnJyqECN6/A5BZq8yi6QOTW/ kw7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=WBoQ0HEYYHQmKJJ4lkxRq0hOvD6WfP4CDGHXu/NEqkM=; b=VVPWh1jJx4UKIwpb/zR732eo8OxOvV/5h8pB2b1+dsPezgz8SW3qFVxJQRBHOiNLrT ZbBq2IfJqCAay35whX0JGErlyO6uAoS54D1/zJsDoOvgwkYYF4ulCY+0opAzNYefLCac cfnn1lrPRySt3gK0nF/b3Jo9Qq8Czb6k55/WcP1PZnQ4LjXTsV+fIU4nHqOfT1w8dFj6 5yBOcXjQ2/PSQHCRFSZ51gdH93A3ImGfjE+3+3Y3ZaEcxfQHt67cMl6ygVi0XubSPqJN Y+c8Zykw44aqJ6bPrrn7Qe/IeSeSgWogqIWJpvgoNp5Nn3hHM5Rq81CzOzf6M1EfnYtc Ja6g== X-Gm-Message-State: AO0yUKUQFd3VSkV0/WidmZ3J3VF4hksNn+CHMxnFQDqygZn1uHuLuP6t YWee81ngBJb98noUdDD/6ES18DjPs8G8TuRkQmVxpTlFBUE= X-Google-Smtp-Source: AK7set8MHxutambRV3VCD1VNQeSqFWpXKKKD9ptS0GFKfWLVFoDv1TbW2xgeUZmdSuheJBu8nybtGjVDdH+ufBMUGZE= X-Received: by 2002:a05:6808:13c9:b0:37f:84bc:b095 with SMTP id d9-20020a05680813c900b0037f84bcb095mr738033oiw.215.1677168575533; Thu, 23 Feb 2023 08:09:35 -0800 (PST) In-Reply-To: <83y1oophd0.fsf@gnu.org> Received-SPF: pass client-ip=2607:f8b0:4864:20::22c; envelope-from=joaotavora@gmail.com; helo=mail-oi1-x22c.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 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, FREEMAIL_FROM=0.001, FREEMAIL_REPLY=1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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:303710 Archived-At: On Thu, Feb 23, 2023 at 2:49 PM Eli Zaretskii wrote: > > > From: Jo=C3=A3o T=C3=A1vora > > Cc: dalal.chinmay.0101@gmail.com, emacs-devel@gnu.org, > > dimitri@belopopsky.com, luangruo@yahoo.com > > Date: Thu, 23 Feb 2023 12:57:26 +0000 > > > > Eli Zaretskii writes: > > > > > We don't need to make the overlays until the buffer is shown in some > > > window, right? > > > > Yes, but two buffers A and B might already be showing in some window. > > If you do the change in buffer A and it affects B, then in the current > > version, the parts of A being show in windows will be updated, but B th= e > > parts of B being shown in some other windows will not. > > If there's a change in A that affects B, jit-lock will call > fontification-functions in both A and B, each one when it's about to > display the corresponding window. Sure, but you're in charge of coding up the "affection" by asking the LSP server. In other words, only the LSP server knows that the change in A affects B. You must assume that it does and ask it "Hey LSP server, given that I've just changed document A, in your document B from 42 to 420 is are there any new or different inlay hints you'd like to give me?" jit-lock cannot foresee that upfront, it will only act on B's display if B's buffer is changed. Regardless of that separate issue, I started experimenting with jit-lock-register. It's promising, but has problems. Here's a small experiment. Use this foo.cpp file somewhere and have say, the clangd server handy. void foo(int bar){} int main() { foo(42); .... repeats about ~250 times .... foo(42); } If you start eglot and eglot-inlay-hints-mode in this buffer, you should see void foo(int bar){} int main() { foo(bar: 42); // 'bar: ' is the untangible hint overlay foo(bar: 42); foo(bar: 42); ... < end of window > I also traced the current eglot--update-hints-1 file which is a binary function of two buffer positions, just like the jit function. This is the function that contacts the LSP server via JSONRPC and some time in the future, after it returns, the 0-length overlays will be created. Here's how it is called after enabling eglot and scrolling 4 screenfuls forward (C-v) and 4 back (M-v). =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D 1 -> (eglot--update-hints-1 1 476) 1 <- eglot--update-hints-1: nil =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D 1 -> (eglot--update-hints-1 443 927) 1 <- eglot--update-hints-1: nil =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D 1 -> (eglot--update-hints-1 894 1378) 1 <- eglot--update-hints-1: nil =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D 1 -> (eglot--update-hints-1 1345 1829) 1 <- eglot--update-hints-1: nil =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D 1 -> (eglot--update-hints-1 1796 2280) 1 <- eglot--update-hints-1: nil =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D 1 -> (eglot--update-hints-1 1345 1829) 1 <- eglot--update-hints-1: nil =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D 1 -> (eglot--update-hints-1 894 1378) 1 <- eglot--update-hints-1: nil =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D 1 -> (eglot--update-hints-1 443 927) 1 <- eglot--update-hints-1: nil =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D 1 -> (eglot--update-hints-1 1 476) 1 <- eglot--update-hints-1: nil As you can see, it only requests inlay hints for the regions actually displayed in the window. It re-requests some stuff when going back, since it has no memory of what it already requested or if things were invalidated. Now if I put eglot--update-hints-1 in jit-lock-function and disable my window-scroll-functions, then do the same: =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D 1 -> (eglot--update-hints-1 1 1501) 1 <- eglot--update-hints-1: nil =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D 1 -> (eglot--update-hints-1 1501 2678) 1 <- eglot--update-hints-1: nil As you can see, it did much larger, heavier requests upfront, even before it knew I was going to scroll forward. But in general it worked and you can argue that doing only two requests for larger chunks of inlay hints is better than more requests for smaller chunks. Now, if I change the line void foo(int bar){} to void foo(int baz){} the point is to get updated hints in the window: int main() { foo(baz: 42); // 'bar: ' is the untangible hint overlay foo(baz: 42); foo(baz: 42); ... < end of window > The jit-lock implementation will do this: =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D 1 -> (eglot--update-hints-1 1 19) 1 <- eglot--update-hints-1: nil =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D 1 -> (eglot--update-hints-1 1 20) 1 <- eglot--update-hints-1: nil =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D 1 -> (eglot--update-hints-1 20 1520) 1 <- eglot--update-hints-1: nil The first two calls are useless and so is most of the third one. For the third one you can argue, as above, that it's a good thing to predict that the user is going to scroll down. But the first two, which also caused two LSP requests, are definitely useless. OT1H, I think I can make this work, by finding some means to coalesce those three calls into one. Suggestions welcome. Even after that complexity, it seems it will be a much neater implementation. OTOH it sort of negates my original intention of requesting only as many inlay hints as strictly necessary. THough that might have been premature optimization anyway. > > PS: On an unrelated note, I pushed this to emacs-29. If you wish me to > > revert the inlay hints implementation and do all this work in master, > > it's fine by me. > > emacs-29 is fine, thanks. OK! Jo=C3=A3o