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 19:26:10 +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> <83k008pah3.fsf@gnu.org> <83edqgp8fl.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="20780"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Stefan Monnier , 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 20:27:24 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 1pVHFR-0005BV-JP for ged-emacs-devel@m.gmane-mx.org; Thu, 23 Feb 2023 20:27:21 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pVHEY-000452-Vl; Thu, 23 Feb 2023 14:26:27 -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 1pVHEX-00044l-B8 for emacs-devel@gnu.org; Thu, 23 Feb 2023 14:26:25 -0500 Original-Received: from mail-oa1-x30.google.com ([2001:4860:4864:20::30]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pVHEV-0003xq-GB; Thu, 23 Feb 2023 14:26:25 -0500 Original-Received: by mail-oa1-x30.google.com with SMTP id 586e51a60fabf-172334d5c8aso13071249fac.8; Thu, 23 Feb 2023 11:26:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1677180381; 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=nmTzB4BvM3kzS3zsdBq96BpUvRdeG6FwytYerU9bco4=; b=Ul564+/Doc2xtox4xnovpBbfLtwkz9GwgAaDi/pQHqkmGIoUHkN54CLTC3G7E5fQpW cQZ02jCME+ATfgCT+gz+QR92JMASs8Qpp2Ujem8G/1EOjLqhg2CCdYP5nLp5xu5ZMGbz ljlwogD/9+oDwivcac4qoDa5XNlRNOBEzuRXJ0Qgc3W05h3+b1pwtQum1cFHwD2Rb6LY p+APM0LiyzMpMDQB3sM3T/O3Gti2aBnKV1vR5qdDOs08dYlPQZFQum9/vN3BntJIKRBo Q4gzf3IP7Bu0VfVzz5eJzJA6bPehJZKlPgCZkIgmaNlxRDo61O7s4efY9hyNmII/II2y Vodw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677180381; 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=nmTzB4BvM3kzS3zsdBq96BpUvRdeG6FwytYerU9bco4=; b=Qg6gk1J6x/Amu2/vqmS1Bq7E6zZR/iEHfmW8yG1/+U1WWm135KUPLFiRqlCoV6SRFl PCpm5EjjkB+Jk6YRh/0GhmLIvqJtSoGqpr1mqyerMME2tA6F5ihgHOJt790/KjMROvc2 YoPnuUi6mQiJy+PP59uC/nUf5H8qORDEVud+0D24jT82kWYJnrrzVcepf+tUFXJrRgR/ Su13ga37tr0NRaz/xPjfmGo5yhZNmTalztOalBkrlCV9sWMaLqkeyV535WieP7xJoB7Q 2AFLsP+IevEF2nwtlKZ902pnK/yj0/IhsxNPwbNt7D74T5Jutl45VRoaQTxdKvdiKx03 VhGA== X-Gm-Message-State: AO0yUKVDNKb0ZwWjhjiEQk81AroRb3QTPB7KblVVbqvO1F/wnWhYcGUW cS7fh1lOLokrjbllbC+AgSLmS9wqdxHY8e9OG454BZ60urM= X-Google-Smtp-Source: AK7set8PLEgtVR+GD78jBb8RMeeR25oftMjwGXB0DEIBa9OqSSA4aI5///5OykteO6swoF+cg/sh93oRpSDPaV+wyxo= X-Received: by 2002:a05:6870:3a01:b0:171:8f59:3437 with SMTP id du1-20020a0568703a0100b001718f593437mr306596oab.8.1677180381705; Thu, 23 Feb 2023 11:26:21 -0800 (PST) In-Reply-To: <83edqgp8fl.fsf@gnu.org> Received-SPF: pass client-ip=2001:4860:4864:20::30; envelope-from=joaotavora@gmail.com; helo=mail-oa1-x30.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:303714 Archived-At: On Thu, Feb 23, 2023 at 6:01 PM Eli Zaretskii wrote: > > > From: Jo=C3=A3o T=C3=A1vora > > Date: Thu, 23 Feb 2023 17:46:08 +0000 > > Cc: dalal.chinmay.0101@gmail.com, emacs-devel@gnu.org, dimitri@belopops= ky.com, > > luangruo@yahoo.com > > > > > That's no for jit-lock to do. And I don't see how it could be > > > relevant to the issue we are discussing. How do you do this now? > > > > I don't. I was just pointing out that jit-lock by itself doesn't > > solve this A -> B dependency, which you seemed to suggest it does when > > you wrote: > > > > > > 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 t= o > > > > display the corresponding window. > > That was written under the assumption that the overlays in B are > already updated. Then redisplay will know it must redraw B. > > > > window-scroll-functions cannot promise that, since > > > they are only called "when the window is scrolled", and there's more > > > to that condition than meets the eye, believe me. > > > > I believe you. But as far as I can tell so far, it's the least > > imperfect of the methods, and I haven't seen demonstrations of > > problems so far, only your speculation of hypothetical problems. > > I actually gave you a recipe for demonstrating the problems I have in > mind: scroll the window under pixel-scroll-precision-mode. AFAIK, we > don't call window-scroll-functions in that case. I don't have a pixel-scroll-enabled Emacs to test. Can you scroll large portions of the window like that and w-s-functions will never get called? I'd say that's a bug we should fix. > Another situation where we don't call window-scroll-functions is when > the user types into the buffer. That is handled by Eglot's after-change-functions already so it isn't a problem. > Yet another situation is when you type "C-x 1" to delete all the other > windows on the frame, leaving the current window that now shows more > stuff than before. Reproduced. Easy enough to fix with window-configuration-change-functions. I pushed a fix. > > I'd love to switch over to the jit-lock implementation as it has > > potential to be much neater. But I can't seem to get it to not > > over-request stuff. I attach the patch I've been trying, and it's > > clearly got some thinkos when you test it. It doesn't help that > > `window-start` and `window-end` aren't -- apparently -- reliable > > when called from a jit-lock function. > > Sorry, I don't have time for that ATM, but maybe Stefan will want to > comment. I'll keep trying. I think what I'd want is for the "contextual" call with the big chunk about to be jit-refontified remember the smaller adjacent chunks and make a request for the big chunk + the smaller chunks. Here's the latest version of the patch using a timer to achieve that. It's pretty gross, but I hope it expresses the idea. diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el index eea8be6d1aa..251f6f11090 100644 --- a/lisp/progmodes/eglot.el +++ b/lisp/progmodes/eglot.el @@ -3507,14 +3507,47 @@ eglot-lazy-inlay-hints (defun eglot--inlay-hints-fully () (eglot--widening (eglot--update-hints-1 (point-min) (point-max)))) -(cl-defun eglot--inlay-hints-lazily (&optional (buffer (current-buffer))) - (eglot--when-live-buffer buffer - (when eglot--managed-mode - (dolist (window (get-buffer-window-list nil nil 'visible)) - (eglot--update-hints-1 (window-start window) (window-end window)))= ))) +(defvar-local eglot--inlay-hints-outstanding nil + "List of regions") + +(defvar-local eglot--inlay-hints-outstanding-timer nil + "Timer") + +(defun eglot--update-hints (from to) + "Jit-lock function for Eglot inlay hints." + (if eglot--inlay-hints-outstanding-timer + (cancel-timer eglot--inlay-hints-outstanding-timer)) + (push (cons from to) eglot--inlay-hints-outstanding) + (setq eglot--inlay-hints-outstanding-timer + (run-with-timer + ;; FIXME: Gross + (+ 0.1 (max eglot-lazy-inlay-hints jit-lock-context-time)) + nil (lambda () + (trace-values eglot--inlay-hints-outstanding) + (cl-loop with region< =3D (lambda (r1 r2) + (if (=3D (car r1) (car r2)) + (< (cdr r1) (cdr r2)) + (< (car r1) (car r2)))) + with sorted =3D (cl-sort eglot--inlay-hints-outstanding region<) + with coalesced =3D (cl-reduce (lambda (acc x) + (cond ((and acc (>=3D (cdr (car acc)) + (car x))) + (setcdr (car acc) (cdr x)) + acc) + (t + (push x acc) + acc))) + sorted + :initial-value nil) + for r in coalesced + do (eglot--update-hints-1 (max (car r) (point-min)= ) + (min (cdr r) (point-max)= )) + finally + (setq eglot--inlay-hints-outstanding nil + eglot--inlay-hints-outstanding-timer nil))))= )) (defun eglot--update-hints-1 (from to) - "Request LSP inlay hints and annotate current buffer from FROM to TO." + "Do actual work for `eglot--update-hints', including LSP request." (let* ((buf (current-buffer)) (paint-hint (eglot--lambda ((InlayHint) position kind label paddingLeft paddingRight) @@ -3545,36 +3578,6 @@ eglot--update-hints-1 (mapc paint-hint hints)))) :deferred 'eglot--update-hints-1))) -(defun eglot--inlay-hints-after-scroll (window display-start) - (cl-macrolet ((wsetq (sym val) `(set-window-parameter window ',sym ,val)= ) - (wgetq (sym) `(window-parameter window ',sym))) - (let ((buf (window-buffer window)) - (timer (wgetq eglot--inlay-hints-timer)) - (last-display-start (wgetq eglot--last-inlay-hint-display-start)= )) - (when (and eglot-lazy-inlay-hints - ;; FIXME: If `window' is _not_ the selected window, - ;; then for some unknown reason probably related to - ;; the overlays added later to the buffer, the scroll - ;; function will be called indefinitely. Not sure if - ;; an Emacs bug, but prevent useless duplicate calls - ;; by saving and examining `display-start' fixes it. - (not (eql last-display-start display-start))) - (when timer (cancel-timer timer)) - (wsetq eglot--last-inlay-hint-display-start - display-start) - (wsetq eglot--inlay-hints-timer - (run-at-time - eglot-lazy-inlay-hints - nil (lambda () - (eglot--when-live-buffer buf - (when (eq buf (window-buffer window)) - (eglot--update-hints-1 (window-start window) - (window-end window)) - (wsetq eglot--inlay-hints-timer nil)))))))))) - -(defun eglot--inlay-hints-after-window-config-change () - (eglot--update-hints-1 (window-start) (window-end))) - (define-minor-mode eglot-inlay-hints-mode "Minor mode for annotating buffers with LSP server's inlay hints." :global nil @@ -3584,28 +3587,15 @@ eglot-inlay-hints-mode (eglot--warn "No :inlayHintProvider support. Inlay hints will not work.")) (eglot-lazy-inlay-hints - (add-hook 'eglot--document-changed-hook - #'eglot--inlay-hints-lazily t t) - (add-hook 'window-scroll-functions - #'eglot--inlay-hints-after-scroll nil t) - (add-hook 'window-configuration-change-hook - #'eglot--inlay-hints-after-window-config-change nil t= ) - ;; Maybe there isn't a window yet for current buffer, - ;; so `run-at-time' ensures this runs after redisplay. - (run-at-time 0 nil #'eglot--inlay-hints-lazily)) + (jit-lock-register #'eglot--update-hints)) (t (add-hook 'eglot--document-changed-hook #'eglot--inlay-hints-fully nil t) (eglot--inlay-hints-fully)))) (t - (remove-hook 'window-configuration-change-hook - #'eglot--inlay-hints-after-window-config-change) - (remove-hook 'eglot--document-changed-hook - #'eglot--inlay-hints-lazily t) + (jit-lock-unregister #'eglot--update-hints) (remove-hook 'eglot--document-changed-hook #'eglot--inlay-hints-fully t) - (remove-hook 'window-scroll-functions - #'eglot--inlay-hints-after-scroll t) (remove-overlays nil nil 'eglot--inlay-hint t))))