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#72343: [PATCH] Fix eglot-server-programs for TeX modes Date: Tue, 6 Aug 2024 23:52:08 +0100 Message-ID: References: <87sevtz8xg.fsf@gmail.com> <86msm1z8c4.fsf@gnu.org> <87ttg8k9l6.fsf@gmail.com> <86frrszbep.fsf@gnu.org> <87o765k7ze.fsf@gmail.com> <87ed71fvy8.fsf@gmail.com> <87frrhxzbz.fsf@gmail.com> 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="33363"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Eli Zaretskii , 72343@debbugs.gnu.org To: Augusto Stoffel Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Aug 07 00:54:12 2024 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 1sbT4F-0008Tm-Qs for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 07 Aug 2024 00:54:12 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sbT42-0001jL-Ti; Tue, 06 Aug 2024 18:54: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 1sbT3i-0001iT-O8 for bug-gnu-emacs@gnu.org; Tue, 06 Aug 2024 18:53:40 -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 1sbT3h-00009M-Q0 for bug-gnu-emacs@gnu.org; Tue, 06 Aug 2024 18:53:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=Date:From:In-Reply-To:References:MIME-Version:To:Subject; bh=FxYxDeVmfNMeZGwEpXxID4QCWMxaOKnmPtgY7rGvIkw=; b=KYoqC66TCSWNX18ge6eEv744thymHovCxZClFGSYWmOihDv9onk4KbYsQ+29gzJxnMWA9nKWxGBQ5Im6sg0FqU0MeHvqaAJIPE9EIQ5qHaT6AIxQ22dhfkwVsaS6G0C5K5c9IT+zW3FP7uf08BwrFarlAtsV+xtsekZpawkZeR99l/mFTqAbTvfdHC9vAgDgx4tBUH84J+rB4BrWBtuvMgS1N4CBBGt8mm5PaGTP2LDst+tIrfE5CljC8N/Byc+ZkDkL/Fd3ilDzz++OnxavkHoHVwEEUL1lbmFEK2fMYWxO0cfcmq/c3IvyJT27Wej7sgY70VuoxZe0romjWI7EZQ==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sbT45-0004uS-RL for bug-gnu-emacs@gnu.org; Tue, 06 Aug 2024 18:54: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: Tue, 06 Aug 2024 22:54:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 72343 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 72343-submit@debbugs.gnu.org id=B72343.172298483318857 (code B ref 72343); Tue, 06 Aug 2024 22:54:01 +0000 Original-Received: (at 72343) by debbugs.gnu.org; 6 Aug 2024 22:53:53 +0000 Original-Received: from localhost ([127.0.0.1]:33164 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sbT3w-0004u5-NU for submit@debbugs.gnu.org; Tue, 06 Aug 2024 18:53:53 -0400 Original-Received: from mail-oa1-f51.google.com ([209.85.160.51]:55581) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sbT3t-0004tp-W0 for 72343@debbugs.gnu.org; Tue, 06 Aug 2024 18:53:51 -0400 Original-Received: by mail-oa1-f51.google.com with SMTP id 586e51a60fabf-264545214efso729657fac.3 for <72343@debbugs.gnu.org>; Tue, 06 Aug 2024 15:53:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722984740; x=1723589540; darn=debbugs.gnu.org; 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=FxYxDeVmfNMeZGwEpXxID4QCWMxaOKnmPtgY7rGvIkw=; b=m2WxZTJRqToNrLxSW9ey35xkNOS+eALuUxHqOFYHnM82esws4sevQl3tJ2Qk3srqyV Hbnz8ES39uIkAhSc4pF1rtDiTSsP9F4U858XjrU3j1btDfYmu6kgG3utKj9VAzezf4yI s8eQoWskfSoSHxSQ7Otqvn0WVbmzkDYwoOvCLC+R0DkFOsz2UigOzbPmrg+qHNOaC+QP iSHZp89Yt9/pIOoX3cRWbUeiLLb54LCtlopH0i342kFJXauQwO7/vRQFF9x6HrmdcXdf bsJkWebQbCBgylRyEMN7KgYQtC1QqCgvitFz/Ee369uLw1fzD7noeVWq/dU+GTXSP8/7 mKWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722984740; x=1723589540; 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=FxYxDeVmfNMeZGwEpXxID4QCWMxaOKnmPtgY7rGvIkw=; b=tiV4EpyqFFIUhyYkbUzo5gxqVmETXQv9aZnXreKB4rAeCMPaof5SozeImSKjaoyuWi r5KtnNJGpFU18vx0wGcdDtB5wCerUoYOnnVqljWj12AuaN3zYb7sBnYijtm56qwzFtNj rlfPHXm510kN4CYJSCXebEBG0UtLIFujJI4hec6aWgfZgYdXFwawi8DgOYk9I5NA7WQu 9KI8z9BEOhRq+C5ntOT0FsUChC8AYNBl4SFUVq04GY1VOWXUIj2cLbOeflNd3+V7mIr+ eRbHw6UW0V+ZSpDY3El0yydB5pBXPtaAi/DrAhzYXS9qpe52ETj/vuBYVwoQzM4/QGmB 9wAQ== X-Gm-Message-State: AOJu0Yw4GK2ptGcwhD8+4AfbWGqf43VlZ78BDJxCn5QgxaYKQyoEALn7 ogW/1Y1v1ZGwEb5dgApuuUioVl/RQBjoGY+ecib7SGCE3F+ibi6ps1Igng0sjK2mU9EWWshMV7/ nAXvQbmwtl4dPB1lNvpOJQ+8mCdY= X-Google-Smtp-Source: AGHT+IHC9qv9IjvagpdguyiOzQKiexlwcrQlFIzt70roc1b0MKw2rg6saYz4rGVIT2c819uxUntDgxpEqYvvmvxzqSU= X-Received: by 2002:a05:6870:961a:b0:25d:ff4c:bc64 with SMTP id 586e51a60fabf-26891a7f60fmr18208856fac.6.1722984739846; Tue, 06 Aug 2024 15:52:19 -0700 (PDT) In-Reply-To: <87frrhxzbz.fsf@gmail.com> 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:289861 Archived-At: On Tue, Aug 6, 2024 at 7:48PM Augusto Stoffel wrote: > I know about the list, but unfortunately "tex" as a language id makes no > sense. It's like saying a program is written in "lisp" without saying > which Lisp dialect. In that example, the "lisp" identifier is probably enough to derive that the file in question is a tree of Lisp forms, much like lisp-data-mode treats Lisp. > Again, every TeX program belongs to a specific dialect: plain TeX, LaTeX > and ConTeXt being the main ones. Accordingly, tex-mode is not a real > major mode; it's just an "abstract base mode" from which the actual TeX > modes derive (see the docstring for details). OK. That doesn't seem to necessitate that the tex-mode is a parent of latex-mode or plain-tex-mode. [Also, I see no need to write "again" for a point that you've just made once]. > except for the > caveat that ultimately the user might know better and it's useful to > rely on the user's choice of major mode / language id. How so a "caveat" if eglot-server-programs is a user-customizable variable where the user can explicitly set whatever languageId she wants?? > I didn't ask but I don't see what could go wrong, given that texlab is > for latex and bibtex only. It would be safer to ask. As far as I am concerned, currently we send "tex" to texlab and it likes it, or at least doesn't dislike it. For all we know, or at least, I know. "tex" is in the LSP spec, "plain-tex" is not. Then I suggest -- for this specific problem: 1. Asking for the spec to correct itself 2. Interpreting "tex" as really "plain-tex" in your server. You should probably be doing that anyway for old Eglot versions or any client who follows the spec. 3. Ignoring my advice and sending "plain-tex" from Eglot anyway (i.e. installing your patch without :language-id) For the _other_ orthogonal problem, I suggest: 1. Doing the simplification in eglot--lookup-mode, and then make the left-hand-side list be like (latex-mode (plain-tex-mode :language-id "tex") ; see previous problem also-derived-from-tex-mode tex-mode not-derived-from-tex-mode) Note that tex-mode is kept there, so this is compatible with any tex-mode derivations we don't know of. Some testing required, of course. I can perform some of it for C/C++ modes. This patch is after my sig. It also fixes a broken docstring. 2. Doing the ranking in eglot--languageID 3. fixing tex-mode's relation with its children modes Jo=C3=A3o diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el index 5845aff39b7..beff9b17a25 100644 --- a/lisp/progmodes/eglot.el +++ b/lisp/progmodes/eglot.el @@ -292,7 +292,7 @@ eglot-server-programs (scala-mode . ,(eglot-alternatives '("metals" "metals-emacs"))) (racket-mode . ("racket" "-l" "racket-langserver")) - ((tex-mode context-mode texinfo-mode bibtex-mode) + ((latex-mode (plain-tex-mode :language-id "tex") tex-mode context-mode texinfo-mode bibtex-mode) . ,(eglot-alternatives '("digestif" "texlab"))) (erlang-mode . ("erlang_ls" "--transport" "stdio")) ((yaml-ts-mode yaml-mode) . ("yaml-language-server" "--stdio")) @@ -1238,28 +1238,23 @@ eglot--lookup-mode "Lookup `eglot-server-programs' for MODE. Return (LANGUAGES . CONTACT-PROXY). -MANAGED-MODES is a list with MODE as its first element. -Subsequent elements are other major modes also potentially -managed by the server that is to manage MODE. - -LANGUAGE-IDS is a list of the same length as MANAGED-MODES. Each -elem is derived from the corresponding mode name, if not -specified in `eglot-server-programs' (which see). +LANGUAGES is a list ((MANAGED-MODE . LANGUAGE-ID) ...). MANAGED-MODE is +a major mode also potentially managed by the server that is to manage +MODE. LANGUAGE-ID is string identifying the language to the LSP server. +It's derived from the corresponding mode name, or explicitly specified +in `eglot-server-programs' (which see). CONTACT-PROXY is the value of the corresponding `eglot-server-programs' entry." - (cl-flet ((languages (main-mode-sym specs) - (let* ((res - (mapcar (jsonrpc-lambda (sym &key language-id &allow-other-keys) - (cons sym - (or language-id - (or (get sym 'eglot-language-id) - (replace-regexp-in-string - "\\(?:-ts\\)?-mode$" "" - (symbol-name sym)))))) - specs)) - (head (cl-find main-mode-sym res :key #'car))) - (cons head (delq head res))))) + (cl-flet ((languages (specs) + (mapcar (jsonrpc-lambda (sym &key language-id &allow-other-k= eys) + (cons sym + (or language-id + (or (get sym 'eglot-language-id) + (replace-regexp-in-string + "\\(?:-ts\\)?-mode$" "" + (symbol-name sym)))))) + specs))) (cl-loop for (modes . contact) in eglot-server-programs for specs =3D (mapcar #'eglot--ensure-list @@ -1268,7 +1263,7 @@ eglot--lookup-mode thereis (cl-some (lambda (spec) (cl-destructuring-bind (sym &key &allow-other-keys) spec (and (provided-mode-derived-p mode sym) - (cons (languages sym specs) contact)))) + (cons (languages specs) contact)))) specs)))) (defun eglot--guess-contact (&optional interactive)