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#50244: 28.0.50; Support project-wide diagnostics reports in flymake.el Date: Tue, 14 Sep 2021 12:34:42 +0100 Message-ID: <87ee9r2xwt.fsf@gmail.com> References: <87bl5hm5qj.fsf@gmail.com> <87y283536t.fsf@gmail.com> <41cd4854-d162-bc6c-900e-96a4245e2c59@yandex.ru> <87o88w4al4.fsf@gmail.com> <87ilz444zy.fsf@gmail.com> <87k0jj35iz.fsf@gmail.com> <46AA4768-F628-49C5-A933-8ED43814CAC9@thornhill.no> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="6287"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: 50244-done@debbugs.gnu.org, Philipp Stephani , Dmitry Gutov To: Theodor Thornhill Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Sep 14 13:35:22 2021 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 1mQ6if-0001Ns-D9 for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 14 Sep 2021 13:35:21 +0200 Original-Received: from localhost ([::1]:53640 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mQ6id-0001pq-Uh for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 14 Sep 2021 07:35:19 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:39446) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mQ6iM-0001mq-Sk for bug-gnu-emacs@gnu.org; Tue, 14 Sep 2021 07:35:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:36187) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mQ6iM-0002ps-L3 for bug-gnu-emacs@gnu.org; Tue, 14 Sep 2021 07:35:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mQ6iM-0002CL-8f for bug-gnu-emacs@gnu.org; Tue, 14 Sep 2021 07:35:02 -0400 Resent-From: =?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?= Original-Sender: "Debbugs-submit" Resent-To: bug-gnu-emacs@gnu.org Resent-Date: Tue, 14 Sep 2021 11:35:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: cc-closed 50244 X-GNU-PR-Package: emacs Mail-Followup-To: 50244@debbugs.gnu.org, joaotavora@gmail.com, joaotavora@gmail.com Original-Received: via spool by 50244-done@debbugs.gnu.org id=D50244.16316192968430 (code D ref 50244); Tue, 14 Sep 2021 11:35:02 +0000 Original-Received: (at 50244-done) by debbugs.gnu.org; 14 Sep 2021 11:34:56 +0000 Original-Received: from localhost ([127.0.0.1]:47731 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mQ6iG-0002Bt-2h for submit@debbugs.gnu.org; Tue, 14 Sep 2021 07:34:56 -0400 Original-Received: from mail-wr1-f53.google.com ([209.85.221.53]:34624) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mQ6i9-0002BX-U2 for 50244-done@debbugs.gnu.org; Tue, 14 Sep 2021 07:34:55 -0400 Original-Received: by mail-wr1-f53.google.com with SMTP id m9so19693132wrb.1 for <50244-done@debbugs.gnu.org>; Tue, 14 Sep 2021 04:34:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=Qm8LEx0xyKowqlS06XtbneP3IRcxcPdZG/LvWlvOmVA=; b=gC2zmGW/9sKS2aHf1ZlaRqyFxIsxw8Ms+Z5gLNwvbtKU/iYpoIe7CFEwRIF8DAnsV7 /4xQdEZtxE6inMgmGwRMSXzwsYgqz/3NXvLj46NUYPzWMvAfGtjJjVEQOt8SCIvowD6G oX+eYEOlAYEEaOAF7BjGs2wPdK0fOIMi4jUdt4KPZrIcGjdjptIR6i7IYzdLIDMivCmj b/CNHLRQVVr5m7PEajS/4n5E9axw99qhekUZhA7omg26wp1Vo8UHt3DteiGNzV/H5rLX 6lUYxrfzSZ2E1kV/Xg61WkgJWKyPnTre0bQ+d+s8Q0dceAkhLk2zBt3qRvJWtMqaH7Mf /oDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=Qm8LEx0xyKowqlS06XtbneP3IRcxcPdZG/LvWlvOmVA=; b=rxrh9XFvzmpavKZHICs8zwiqvK62zUG0guG9aOXjshKUd73yjFWTrTRPnAtBw8UrNn AauOWRpp9jP/smZUAB7w/UJgcY7jqpECVVKwvPt7mvGeJnt6s3W3XaxVRk8bJBBIg+Kh dz51h6KJsVuomDBmM3WKwlwXhnrag93/mhu/CAP/h4ciGTQ3uyqarLihJ7/GmuN7Wgc+ tg3FE3ovENRcc3BRoL1bHRnRDogtRti7Lz6O2tDZ5t9Qnc67HtJEMyOZJ9f3V2I//cM3 7M2qAUR+IXc+gXQJbIRElfh+YunZvwNtzG8eoVGAX6H7XCZRFl796nIHYWyaQ/dYxHnS 6mrQ== X-Gm-Message-State: AOAM530ySKeYk6rECYiGk95yF7V5L27xLu3t0fYXjpU3a8lmLVFiGTpM Rr/kWNPIBDICuwCoSUGX74A= X-Google-Smtp-Source: ABdhPJzwfIrlV3r6SZRG5EIj7mxctyDnpCtothniVJVcQw4hdS8B/v+Q5Re4e8EOsjzZHwpWA/bJqg== X-Received: by 2002:a5d:650b:: with SMTP id x11mr18089038wru.350.1631619284013; Tue, 14 Sep 2021 04:34:44 -0700 (PDT) Original-Received: from nadja (a83-132-177-247.cpe.netcabo.pt. [83.132.177.247]) by smtp.gmail.com with ESMTPSA id m3sm13278827wrg.45.2021.09.14.04.34.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Sep 2021 04:34:43 -0700 (PDT) In-Reply-To: <46AA4768-F628-49C5-A933-8ED43814CAC9@thornhill.no> (Theodor Thornhill's message of "Tue, 14 Sep 2021 11:21:36 +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" Xref: news.gmane.io gmane.emacs.bugs:214298 Archived-At: Hi Theodor, I've now pushed this to master, so I'm marking the bug done. But we can keep discussing the Eglot patch here (or in another bug, or in Eglot's tracker, as you prefer...) Theodor Thornhill writes: >>Thanks. I think I'll try rust-analyzer as I've been meaning to anyway. >>Perhaps make it the default Rust server for Eglot. > Absolutely, the community seems to have moved on. Actually I did still try with `rls` since that was most handy and it also provides diagnostics for other files on startup. So I tested it with rls and got decent results (see Eglot patch). > By the way- these list only diagnostics do in fact happen on each > keystroke in the mentioned servers. Not just on the first load. > Would this mean the foreign variant is more correct to use? Yes, it would, indeed. I don't know if _every_ server operates like that, though. But doesn't matter. Are you saying that in your server, making a modification to any file always brings in diagnostics for all other files, too? Anyway, I've tested a bit with Eglot and flymake-list-only-diagnostics and it seems to do the right thing (mostly). I attach the Eglot patch which you can use as starting point. diff --git a/eglot.el b/eglot.el index 7ebc422..d036a75 100644 --- a/eglot.el +++ b/eglot.el @@ -1386,6 +1386,11 @@ Doubles as an indicator of snippet support." (font-lock-ensure) (string-trim (filter-buffer-substring (point-min) (point-max)))))) +(defun eglot--diag-type (severity) + (cond ((<= severity 1) 'eglot-error) + ((= severity 2) 'eglot-warning) + (t 'eglot-note))) + (define-obsolete-variable-alias 'eglot-ignored-server-capabilites 'eglot-ignored-server-capabilities "1.8") @@ -1788,8 +1793,7 @@ COMMAND is a symbol naming the command." diag-spec (setq message (concat source ": " message)) (pcase-let - ((sev severity) - (`(,beg . ,end) (eglot--range-region range))) + ((`(,beg . ,end) (eglot--range-region range))) ;; Fallback to `flymake-diag-region' if server ;; botched the range (when (= beg end) @@ -1808,16 +1812,26 @@ COMMAND is a symbol naming the command." (point-at-eol (1+ (plist-get (plist-get range :end) :line))))))) (eglot--make-diag (current-buffer) beg end - (cond ((<= sev 1) 'eglot-error) - ((= sev 2) 'eglot-warning) - (t 'eglot-note)) + (eglot--diag-type severity) message `((eglot-lsp-diag . ,diag-spec))))) into diags finally (cond (eglot--current-flymake-report-fn (eglot--report-to-flymake diags)) (t (setq eglot--unreported-diagnostics (cons t diags)))))) - (jsonrpc--debug server "Diagnostics received for unvisited %s" uri))) + (cl-loop + with path = (expand-file-name (eglot--uri-to-path uri)) + for diag-spec across diagnostics + collect (eglot--dbind ((Diagnostic) message severity source) diag-spec + (setq message (concat source ": " message)) + (eglot--make-diag path (cons 1 1) nil ; cons 1 1 bcs lazy... + (eglot--diag-type severity) + message)) + into diags + finally + (setq flymake-list-only-diagnostics + (assoc-delete-all path flymake-list-only-diagnostics #'string=)) + (push (cons path diags) flymake-list-only-diagnostics)))) (cl-defun eglot--register-unregister (server things how) "Helper for `registerCapability'.