From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Yuan Fu Newsgroups: gmane.emacs.devel Subject: Re: Explain a bit more on how to configure language server in Eglot's manual Date: Wed, 8 Mar 2023 15:19:02 -0800 Message-ID: <6866252E-DA6D-4399-B4CD-06C0E44B3A03@gmail.com> References: <86sfeisu49.fsf@stephe-leake.org> <87356gvkkb.fsf@gmail.com> <87r0tz8jag.fsf_-_@gmail.com> <87lek78eyq.fsf@gmail.com> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.400.51.1.1\)) Content-Type: multipart/mixed; boundary="Apple-Mail=_C8A324A5-373F-4559-A5E9-5D0716B0F2D7" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="20996"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Augusto Stoffel , Stephen Leake , Emacs developers To: =?utf-8?B?Sm/Do28gVMOhdm9yYQ==?= Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu Mar 09 00:19:59 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 1pa34h-0005In-47 for ged-emacs-devel@m.gmane-mx.org; Thu, 09 Mar 2023 00:19:59 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pa342-0007yU-QO; Wed, 08 Mar 2023 18:19:18 -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 1pa341-0007yI-T2 for emacs-devel@gnu.org; Wed, 08 Mar 2023 18:19:17 -0500 Original-Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pa340-0007lg-2i for emacs-devel@gnu.org; Wed, 08 Mar 2023 18:19:17 -0500 Original-Received: by mail-pl1-x630.google.com with SMTP id i3so146344plg.6 for ; Wed, 08 Mar 2023 15:19:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678317554; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:from:to:cc:subject:date:message-id:reply-to; bh=6kwtaVItFfuZRC6/+a6rKbAiW45JgHl4nYvYATO3R1A=; b=andWJlSjM+M8pvrz4jwu2ymaZu2TzD53iSChjF5WfnDTM6sUxJABSiSSXiV5aaj/vC a9GadOm4fFRC+tfqDY1f/5VxKP1wSoQf801F0V05qd0LakpZaqgqSS4YbVoweAEeaUIu rPkGG+n8v5QfsE0MeePVFQaCD7Tsen9c6oqzO85bYdx8MS+FFtRe0POgZEnt1RjJdNpl Mii8tKylqY3W9SHoaIDrDoMo06KK3yIlTEIGk4cHb82e1PdLSxPfuOAez6mmd7D3I0lk hTFWJuJUipx9HZbi9osHMR/mwB0QENlSpOD9rhhNr9fQ0hMSXnk7CT30AgcW7Gq75R9C YQzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678317554; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=6kwtaVItFfuZRC6/+a6rKbAiW45JgHl4nYvYATO3R1A=; b=6GZCG94iWjbhesFkDt7jRrxt67RcsvKLWp29gHjuB+/JQ6e0hXOtC+b2SDFCAh3bnQ mGsKggFXONrEhDnIMPcKsmsbXqMcXEzfB8qJcOOaJ1MgJQqNAoTW4exaBVr6SvnMa2pw jYXOvPyeM7Q9DH8hLelv/HVXiLy3E6RbFQASGpjypLd77wWOFYryvbGe+MpCxvS5efhf Th2Kn2/zdU/FkJCbYsASZP1F9t707Yuwjs4Eao/9gslOeiFUvCohpIBMoykHlyCkha6T jG3U0RLh2shIQkEPFLkNF+W8ezyfYfMi6KfGGb6e7+kKmu5l3yGqAmmWc1EA8W9VLoxg L0SA== X-Gm-Message-State: AO0yUKXbyOga+z9RZkuC/lZaYa/1pjnahSyYUdiGk2rk5Ne1gZBvWsQ5 6dZN/kPs3Lf6jk0PgiJNZ5o= X-Google-Smtp-Source: AK7set+K2d5/atJRNM3PSEwNZ3X9QjqDKL/x0LSKzuPaAtB0UbIpvWIYESa//oA6yCqzeGn7ffV1Iw== X-Received: by 2002:a05:6a20:2446:b0:b5:a231:107f with SMTP id t6-20020a056a20244600b000b5a231107fmr21080872pzc.12.1678317554415; Wed, 08 Mar 2023 15:19:14 -0800 (PST) Original-Received: from smtpclient.apple (cpe-172-117-161-177.socal.res.rr.com. [172.117.161.177]) by smtp.gmail.com with ESMTPSA id p21-20020aa78615000000b005a8c16fcb78sm9887222pfn.56.2023.03.08.15.19.13 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Mar 2023 15:19:13 -0800 (PST) In-Reply-To: X-Mailer: Apple Mail (2.3731.400.51.1.1) Received-SPF: pass client-ip=2607:f8b0:4864:20::630; envelope-from=casouri@gmail.com; helo=mail-pl1-x630.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.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, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham 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:304156 Archived-At: --Apple-Mail=_C8A324A5-373F-4559-A5E9-5D0716B0F2D7 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On Mar 8, 2023, at 11:43 AM, Jo=C3=A3o T=C3=A1vora = wrote: >=20 > On Wed, Mar 8, 2023 at 3:01=E2=80=AFPM Augusto Stoffel = wrote: >=20 >>> I don't understand: didn't you state you _like_ dotted notation? >>=20 >> Yes, as a quick fix. But you and the circumstances showed that it = isn't >> nearly good enough. >=20 > OK. Then we'll hold that idea back. AFAICT, Yuan also is also a fan > of that notation, so maybe he can chime in. >=20 >>> A special plist editing mode for a single Eglot variable falls into >>> that category, IMNSHO. >>=20 >> By the way, my suggestion is to edit a JSON value, which is what the >> server receives, you can copy and paste from other places, and = doesn't >> require you to know jsonrpc.el internals such as :json-false and the >> translation of nil. >=20 > They are not internals. They are the external, published and = documented > way to create JSON for jsonrpc.el contexts. The documentation isn't > great, I know. This is precisely what this thread is originally about > and I'm working on it. >=20 >>> and I don't see any other good place to put a single utility = function >>> that facilitates it but in Eglot. >>=20 >> The utility function belongs to map.el. It is called `assoc-in` in >> Clojure. >=20 > Yuri presented some pretty good arguments about how that would > be a bad idea. Also, not a Clojure expert, but AFAIK that > function doesn't take dotted notation strings as input. >=20 >> Speaking of bloat, and I know I shouldn't insist, but a basic version = of >> the savable eglot-show-workspace-configuration barely adds 30 LOC. >=20 > Your code has at least two big problems: >=20 > * it takes the current value from one place and > potentially saves it in another place. This is asking > for trouble. I know you favour the 'nil' method exclusively > for setting e-w-configuration, but it's not the only supported > methods and there are configurations out in the wild that > we can't break. Also note the that per-file or per-sub-hierarchy > workspace configurations _are_supported by LSP (the scopeUri > argument to the workspace/configuration server request). >=20 > * it doesn't take into account dir-local-set-class-variables >=20 > These are exactly the type of edge cases that I don't want > to handle in Eglot. In other words, Emacs has many variable > setting methods and making an Eglot function to oversimplify > them, even if it happens to work for an estimated majority of > cases, is a bad idea, simply because it will break a minority. >=20 > That said, your code has great ergonomics and you seem to be > a very able Elisper. So I'll restate: if a generic, safe > version of this hits Emacs libraries, Eglot will be happy to > use it and I at least will be very grateful for that contribution. >=20 > A better dir-local editing facility would account for (at least) > those two cases. Even if that accounting is, at first, just bailing > out and warning the user if it detects them. That's perfectly fine > in my book. It'll mean the code will work fine for the 90% of users > and not confuse the other 10% to death. >=20 > That new dir-local editing facility could even allow you to > use JSON notation to edit a variable's plist, and eglot.el could > hint on that preference by setting 'serializer' and 'deserializer' > properties on e-w-configuration (though a more lispy name would > be 'write' and 'read' perhaps). >=20 > Additionally, in eglot.el, a variable watcher could be added to > e-w-c to take care of LSP signalling automatically if changes to > the value are detected. >=20 > So I urge you to generalize your code and propose it here > in a new :core ELPA package. Orthogonal to Augusto=E2=80=99s function, but I think something like = this would be nice: a function that pops up a buffer and enters = recursive edit for arbitrary input and edit, and when you hit C-c C-c, = it returns the buffer content, kind of like Magit=E2=80=99s commit = buffer. Plus buffer content validator (eg, validate JSON), and arbitrary = major modes in the buffer, etc. Load the file, and try (json-parse-string (read-complex-value (lambda () (js-json-mode) (read-complex-value-insert-prompt "Type C-c C-c to finish, C-c C-k to = abort:\n\n")) (lambda () (condition-case nil (progn (json-parse-buffer) t) ((or end-of-file json-parse-error) (message "Invalid JSON") nil)))) :object-type =E2=80=98plist) It should pop a buffer in js-json-mode, and validates your JSON value. = Typing C-c C-c returns the JSON as a plist. Yuan --Apple-Mail=_C8A324A5-373F-4559-A5E9-5D0716B0F2D7 Content-Disposition: attachment; filename=read-complex-value.el Content-Type: application/octet-stream; x-unix-mode=0644; name="read-complex-value.el" Content-Transfer-Encoding: quoted-printable ;;;=20read-complex-value.el=20---=20Read=20complex=20value=20with=20= recursive=20edit=20=20-*-=20lexical-binding:=20t;=20-*-=0A=0A;;=20= Author:=20Yuan=20Fu=20=0A=0A;;;=20This=20file=20is=20= NOT=20part=20of=20GNU=20Emacs=0A=0A;;;=20Commentary:=0A;;=0A;;=20This=20= package=20provides=20a=20function=20=E2=80=98read-complex-value=E2=80=99=20= that=20pops=20up=0A;;=20a=20buffer=20and=20goes=20into=20recursive=20= edit=20for=20user=20to=20enter=20and=20edit=0A;;=20text.=20When=20the=20= user=20is=20done=20and=20hit=20C-c=20C-c,=20the=20buffer=20content=20is=0A= ;;=20returned.=0A=0A;;;=20Code:=0A=0A(defface=20= read-complex-value-prompt-face=0A=20=20'((t=20.=20(:inherit=20shadow)))=0A= =20=20"Face=20used=20for=20the=20prompt=20text=20in=20= =E2=80=98read-complex-value=E2=80=99=20buffer.")=0A=0A(defvar-local=20= read-complex-value--validator=20nil=0A=20=20"The=20function=20used=20to=20= validate=20buffer=E2=80=99s=20content.=0ASee=20documentation=20of=20= =E2=80=98read-complex-value-raw=E2=80=99=20for=20more.")=0A=0A= (defvar-local=20read-complex-value--mode=20nil=0A=20=20"Whether=20this=20= buffer=20is=20a=20=E2=80=98read-complex-value=E2=80=99=20buffer.")=0A=0A= (defvar=20read-complex-value-map=0A=20=20(let=20((map=20= (make-sparse-keymap)))=0A=20=20=20=20(keymap-set=20map=20"C-c=20C-c"=20= #'read-complex-value--done)=0A=20=20=20=20(keymap-set=20map=20"C-c=20= C-k"=20#'read-complex-value--abort)=0A=20=20=20=20map)=0A=20=20"Keymap=20= used=20in=20=E2=80=98read-complex-value=E2=80=99=20buffer.")=0A=0A(defun=20= read-complex-value-insert-prompt=20(&rest=20texts)=0A=20=20"Insert=20= each=20string=20in=20TEXTS=20into=20buffer=20as=20prompt=20text."=0A=20=20= (dolist=20(text=20texts)=0A=20=20=20=20(insert=20(propertize=20text=0A=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= 'read-complex-value-setup=20t=0A=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20'rear-nonsticky=20t=0A=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20'read-only=20t=0A=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= 'font-lock-face=20'read-complex-value-prompt-face=0A=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20'face=20= 'read-complex-value-prompt-face))))=0A=0A(defun=20read-complex-value=0A=20= =20=20=20(&optional=20setup=20validator=20history=0A=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20display-action=20return-buffer=20signal)=0A=20=20= "Pop=20up=20a=20buffer=20and=20enter=20recursive=20edit,=20then=20return=20= buffer=20content.=0A=0AReturns=20the=20buffer=20content=20or=20nil=20= when=20user=20types=20C-c=20C-c=20or=20C-c=0AC-k,=20respectively.=0A=0A= SETUP=20can=20be=20either=20a=20string,=20which=20is=20inserted=20at=20= the=20beginning=0Aof=20the=20buffer=20as=20prompt,=20or=20a=20function=20= that=20takes=20no=20arguments=0Athat=E2=80=99s=20run=20in=20the=20buffer=20= for=20arbitrary=20setup.=0A=0AAny=20prompt=20are=20removed=20in=20the=20= returned=20text.=20To=20insert=20prompt=0Atext=20in=20the=20SETUP=20= function,=20use=0A=E2=80=98read-complex-value-insert-prompt=E2=80=99.=0A=0A= VALIDATOR=20should=20be=20a=20function=20that=20takes=20no=20argument,=20= and=0Areturns=20either=20t=20if=20the=20buffer=20content=20is=20valid,=20= or=20nil=20if=20not.=0AIt=20runs=20in=20the=20buffer=20and=20should=20= display=20messages=20to=20help=20the=20user=0Ato=20understand=20why,=20= when=20buffer=20content=20is=20invalid.=0A=0AHISTORY=20is=20currently=20= unused.=0A=0ADISPLAY-ACTION=20controls=20how=20to=20display=20the=20= buffer,=20it=20is=20the=20same=0Aas=20in=20the=20ACTION=20parameter=20in=20= =E2=80=98display-buffer=E2=80=99.=0A=0AIf=20RETURN-BUFFER=20is=20= non-nil,=20return=20the=20buffer=20rather=20than=20a=20string.=0A=0AIf=20= SIGNAL=20is=20non-nil,=20signal=20=E2=80=98read-complex-value-aborted=E2=80= =99=20when=0Auser=20types=20C-c=20C-k,=20otherwise=20C-c=20C-k=20causes=20= this=20function=20to=0Areturn=20nil."=0A=20=20(let=20((buf=20= (generate-new-buffer=20"=20*read-complex-value*"))=0A=20=20=20=20=20=20=20= =20(window-config=20(current-window-configuration))=0A=20=20=20=20=20=20=20= =20(aborted=20nil))=0A=20=20=20=20(select-window=20(display-buffer=20buf=20= display-action))=0A=20=20=20=20(cond=20((stringp=20setup)=0A=20=20=20=20=20= =20=20=20=20=20=20(read-complex-value-insert-prompt=20setup))=0A=20=20=20= =20=20=20=20=20=20=20((functionp=20setup)=20(funcall=20setup))=0A=20=20=20= =20=20=20=20=20=20=20(t=20(signal=20'wrong-type-argument=0A=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20`((or=20stringp=20= functionp)=20.=20,setup))))=0A=0A=20=20=20=20(setq-local=20= read-complex-value--validator=20validator=0A=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20read-complex-value--aborted=20nil=0A=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20read-complex-value--mode=20t=0A=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20minor-mode-map-alist=0A=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20(cons=20(cons=20'read-complex-value--mode=0A= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20read-complex-value-map)=0A=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20minor-mode-map-alist))=0A=0A=20=20=20=20= (unwind-protect=0A=20=20=20=20=20=20=20=20(progn=0A=20=20=20=20=20=20=20=20= =20=20(condition-case=20data=0A=20=20=20=20=20=20=20=20=20=20=20=20=20=20= (recursive-edit)=0A=20=20=20=20=20=20=20=20=20=20=20=20(quit=0A=20=20=20=20= =20=20=20=20=20=20=20=20=20(message=20"%s"=20data)=0A=20=20=20=20=20=20=20= =20=20=20=20=20=20(if=20signal=0A=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20(signal=20'read-complex-value-aborted=20data)=0A=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20(setq=20aborted=20t))))=0A=0A=20=20=20=20=20=20= =20=20=20=20(unless=20aborted=0A=20=20=20=20=20=20=20=20=20=20=20=20= (read-complex-value--prune-buffer)=0A=20=20=20=20=20=20=20=20=20=20=20=20= (if=20return-buffer=0A=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= (current-buffer)=0A=20=20=20=20=20=20=20=20=20=20=20=20=20=20= (buffer-string))))=0A=0A=20=20=20=20=20=20(kill-buffer)=0A=20=20=20=20=20= =20(set-window-configuration=20window-config))))=0A=0A(defun=20= read-complex-value--prune-buffer=20()=0A=20=20"Remove=20prompt=20text=20= from=20the=20current=20buffer."=0A=20=20(goto-char=20(point-min))=0A=20=20= (let=20((inhibit-read-only=20t)=0A=20=20=20=20=20=20=20=20prop)=0A=20=20=20= =20(while=20(setq=20prop=20(text-property-search-forward=0A=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= 'read-complex-value-setup))=0A=20=20=20=20=20=20(delete-region=20= (prop-match-beginning=20prop)=0A=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20(prop-match-end=20prop)))))=0A=0A(defun=20= read-complex-value--done=20()=0A=20=20"Validate=20buffer=20content=20and=20= exit=20recursive=20edit."=0A=20=20(interactive)=0A=20=20(cond=20((null=20= read-complex-value--validator)=0A=20=20=20=20=20=20=20=20=20= (exit-recursive-edit))=0A=0A=20=20=20=20=20=20=20=20((functionp=20= read-complex-value--validator)=0A=20=20=20=20=20=20=20=20=20(let=20((buf=20= (current-buffer))=0A=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= (validator=20read-complex-value--validator))=0A=20=20=20=20=20=20=20=20=20= =20=20(if=20(with-temp-buffer=0A=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20(insert-buffer-substring=20buf)=0A=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20(read-complex-value--prune-buffer)=0A=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20(goto-char=20(point-min))=0A=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20(funcall=20validator))=0A=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20(exit-recursive-edit)))))=0A=0A=20= =20(when=20(or=20(null=20read-complex-value--validator)=0A=20=20=20=20=20= =20=20=20=20=20=20=20(funcall=20read-complex-value--validator))=0A=20=20=20= =20(exit-recursive-edit)))=0A=0A(defun=20read-complex-value--abort=20()=0A= =20=20"Abort=20the=20recursive=20edit."=0A=20=20(interactive)=0A=20=20= (abort-recursive-edit))=0A=0A(provide=20'read-complex-value)=0A=0A;;;=20= read-complex-value.el=20ends=20here=0A= --Apple-Mail=_C8A324A5-373F-4559-A5E9-5D0716B0F2D7--