From: "João Távora" <joaotavora@gmail.com>
To: Filippo Argiolas <filippo.argiolas@gmail.com>
Cc: 65418@debbugs.gnu.org, Philip Kaludercic <philipk@posteo.net>,
Felician Nemeth <felician.nemeth@gmail.com>
Subject: bug#65418: 29.1; Eglot: support clangd inactiveRegions extension
Date: Fri, 25 Aug 2023 13:18:47 +0100 [thread overview]
Message-ID: <87zg2fnwm0.fsf@gmail.com> (raw)
In-Reply-To: <CAOdrLGLPzR_qCcSUNgBHxykjS+_yQBCysL_duUt9umouSn6E=w@mail.gmail.com> (Filippo Argiolas's message of "Tue, 22 Aug 2023 13:02:47 +0200")
Filippo Argiolas <filippo.argiolas@gmail.com> writes:
> On Tue, Aug 22, 2023 at 10:56 AM João Távora <joaotavora@gmail.com> 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/clangd-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; -*-
(require 'eglot)
(require 'cl-lib)
(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))
(defvar-local eglot-clangd-inactive-region-overlays '())
(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) = (eglot--range-region r)
for ov = (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ão
next prev parent reply other threads:[~2023-08-25 12:18 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-21 8:41 bug#65418: 29.1; Eglot: support clangd inactiveRegions extension Filippo Argiolas
2023-08-21 16:57 ` Philip Kaludercic
2023-08-21 19:04 ` Felician Nemeth
2023-08-22 7:09 ` Filippo Argiolas
2023-08-22 8:56 ` João Távora
2023-08-22 11:02 ` Filippo Argiolas
2023-08-25 12:18 ` João Távora [this message]
2023-08-27 10:52 ` Filippo Argiolas
2023-08-27 14:01 ` João Távora
2023-08-31 17:28 ` Filippo Argiolas
2023-09-04 1:05 ` João Távora
2023-09-04 1:08 ` João Távora
2023-09-04 3:59 ` Filippo Argiolas
2023-09-04 4:09 ` Filippo Argiolas
2023-09-04 10:51 ` João Távora
2023-09-04 12:44 ` Eli Zaretskii
2023-09-04 12:49 ` João Távora
2023-09-04 16:17 ` Eli Zaretskii
2023-09-04 20:37 ` João Távora
2023-09-04 11:41 ` Eli Zaretskii
2023-09-02 8:14 ` Filippo Argiolas
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=87zg2fnwm0.fsf@gmail.com \
--to=joaotavora@gmail.com \
--cc=65418@debbugs.gnu.org \
--cc=felician.nemeth@gmail.com \
--cc=filippo.argiolas@gmail.com \
--cc=philipk@posteo.net \
/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).