From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?= Newsgroups: gmane.emacs.bugs Subject: bug#65418: 29.1; Eglot: support clangd inactiveRegions extension Date: Fri, 25 Aug 2023 13:18:47 +0100 Message-ID: <87zg2fnwm0.fsf@gmail.com> References: <87edjw6wtz.fsf@betli.tmit.bme.hu> 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="27743"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 65418@debbugs.gnu.org, Philip Kaludercic , Felician Nemeth To: Filippo Argiolas Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Aug 25 14:17:26 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1qZVkj-0006sc-3M for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 25 Aug 2023 14:17:25 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qZVkK-0000xR-5t; Fri, 25 Aug 2023 08:17:00 -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 1qZVkH-0000ww-Sq for bug-gnu-emacs@gnu.org; Fri, 25 Aug 2023 08:16:57 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qZVkH-0003l3-KH for bug-gnu-emacs@gnu.org; Fri, 25 Aug 2023 08:16:57 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qZVkL-0001az-Sr for bug-gnu-emacs@gnu.org; Fri, 25 Aug 2023 08:17:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: =?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 25 Aug 2023 12:17:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 65418 X-GNU-PR-Package: emacs Original-Received: via spool by 65418-submit@debbugs.gnu.org id=B65418.16929657806067 (code B ref 65418); Fri, 25 Aug 2023 12:17:01 +0000 Original-Received: (at 65418) by debbugs.gnu.org; 25 Aug 2023 12:16:20 +0000 Original-Received: from localhost ([127.0.0.1]:39496 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qZVjf-0001Zn-Vo for submit@debbugs.gnu.org; Fri, 25 Aug 2023 08:16:20 -0400 Original-Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]:62678) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qZVjb-0001ZX-UF for 65418@debbugs.gnu.org; Fri, 25 Aug 2023 08:16:18 -0400 Original-Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-3ff5ddb4329so12152515e9.0 for <65418@debbugs.gnu.org>; Fri, 25 Aug 2023 05:16:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692965765; x=1693570565; h=content-transfer-encoding:mime-version:user-agent:message-id:date :references:in-reply-to:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Y0Z9tCtmp6lZ6/yCEjOb3/W5h+3QQIp9AQ8cKvD8els=; b=BVUUdbW8ewsYo5XNo7jHt437CXP2WOTREG4SZnSUPMjr2GvHYpxd+IKq6huxSzYEpf /IWeJEaocLb3mfldRYOzb4TSoZI8CumQmrzWsbefPzWUsEqmI7625TZ/IUsMuPegZ/93 Bdg0nfg2Ha4/Y1lVpAHib06lq0cLhAt5KRi0kGJ0oyeZQLt3AsjjYdd98AIeh61lTCuk ep+4uoRC4H61RKbLhrogL1PWz7up2S9zuIgI1XHCUsoTf8LoAP3qGeqdtGMSzF4TQ1Mk cea5lpXzNTJN4n057EP28G9TGUPVP8NqhqWHC+HkA+jJ8lvWO23nfdJV45OInN2i+XmL 5r4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692965765; x=1693570565; h=content-transfer-encoding:mime-version:user-agent:message-id:date :references:in-reply-to:subject:cc:to:from:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=Y0Z9tCtmp6lZ6/yCEjOb3/W5h+3QQIp9AQ8cKvD8els=; b=dkLoX6JQmMr+SPuRrGVwy/BQ3VW7hBv7fe+/LqLqELSbyQ8AoTfssUaptso1wHTvrO XAaUZqfVKwixAVHVuLudgFYACjeU2Oz6GCkIcG03TNHzEniuwwSB7E9dRJMiggbU56RG QJ//srxQjnEcsqAd8B+FSQXlT3/vRgr2+91EFI/ZmPvsWXaOenXVjfveZyf1x/tsqH1H NWZHt8wHgLMMyPODm96QY6Fa51s8qIlcFLPiNhmkj8hSsWQH6VgIz9FKqMskOoXa8uUu u0w9L2KZTg1DPRIieMBONAa/LP/ZcOO8GGUUj/zuG+dx1shth6qr4xBNsX0BZEy9F/7k Pj5g== X-Gm-Message-State: AOJu0YznjD8GtgmDLFd3JtS7lTLRp/aGnx85iVQSqRcJG+Cv0YW63YYS otPAxeS6np6pQj7yfkpRS0s= X-Google-Smtp-Source: AGHT+IHLJ/5hoMzOM5/kVUwaQqn23fcgrX6nusqU9LTSJmxDGdsk/LOBHixQHYVTwr038PYs+9T5Tg== X-Received: by 2002:a5d:58cf:0:b0:315:acbc:cab6 with SMTP id o15-20020a5d58cf000000b00315acbccab6mr15904182wrf.16.1692965764942; Fri, 25 Aug 2023 05:16:04 -0700 (PDT) Original-Received: from krug ([87.196.73.154]) by smtp.gmail.com with ESMTPSA id n10-20020a5d51ca000000b0031c5dda3aedsm2045260wrv.95.2023.08.25.05.16.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Aug 2023 05:16:04 -0700 (PDT) In-Reply-To: (Filippo Argiolas's message of "Tue, 22 Aug 2023 13:02:47 +0200") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:268429 Archived-At: Filippo Argiolas writes: > On Tue, Aug 22, 2023 at 10:56=E2=80=AFAM Jo=C3=A3o T=C3=A1vora wrote: >> I'm more worried that this isn't even out yet. Afaik Filippo you >> compiled a Clangd 17 with a patch, right? I have done that in the >> past, but it's not very practical every time, so either we wait for >> this to stabilize or you have to tell me where to grab the patched >> Clangd and llvm toolchain somewhere. > > It's much easier than that! They release unstable git snapshots in > github. You can find them at https://github.com/clangd/clangd/releases > Clangd is released as a static binary you can just copy in your path > (e.g. in ~/.local/bin). From what I can tell you don't need to upgrade > the whole toolchain, the binary runs fine on its own. Latest one for > linux is at > https://github.com/clangd/clangd/releases/download/snapshot_20230820/clan= gd-linux-snapshot_20230820.zip > > It would be great if you could test it and see if you can get server > notifications for inactiveRegions. OK, after fetching that git snapshot today, I've done this: ;;; eglot-clangd-inactive-region.el -*- lexical-binding: t; -*- =20=20=20=20 (require 'eglot) (require 'cl-lib) =20=20=20=20 (cl-defmethod eglot-client-capabilities :around (server) (let ((base (cl-call-next-method))) (when (cl-find "clangd" (process-command (jsonrpc--process server)) :test #'string-match) (setf (cl-getf (cl-getf base :textDocument) :inactiveRegionsCapabilities) '(:inactiveRegions t))) base)) =20=20=20=20 (defvar-local eglot-clangd-inactive-region-overlays '()) =20=20=20=20 (cl-defmethod eglot-handle-notification (_server (_method (eql textDocument/inactiveRegions)) &key regions textDocument &allow-other-keys) (if-let* ((path (expand-file-name (eglot--uri-to-path (cl-getf textDocument :uri)))) (buffer (find-buffer-visiting path))) (with-current-buffer buffer (mapc #'delete-overlay eglot-clangd-inactive-region-overlays) (cl-loop for r across regions for (beg . end) =3D (eglot--range-region r) for ov =3D (make-overlay beg end) do (overlay-put ov 'face 'shadow) (push ov eglot-clangd-inactive-region-overlays))))) Be sure to evaluate with lexical-binding (easiest if you save it to a file first). It's bare-bone but it works, because the method for communicating "inactive regions" is very basic (and similar to unsolicited diagnostics). Only minimally tested, so YMMV. This serves as a good example of how to support unofficial LSP extensions using Eglot as an API. Could well be in the manual. The method for providing a client-side capability based on a server is crude. Servers do identify themselves properly via LSP, but only after being initialized, so it's too late and I had to use an heuritic based on the command. We could also use a proper subclass for clangd servers, but that's too verbose and overkill IMHO. The usage of some '--' symbols like 'eglot--uri-to-path' and 'eglot--range-region' points out that these symbols should probably be promoted to be part of the Eglot API. Patches welcome for that. Jo=C3=A3o