From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Theodor Thornhill via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#50244: 28.0.50; Support project-wide diagnostics reports in flymake.el Date: Sat, 23 Oct 2021 21:22:08 +0200 Message-ID: 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> <87ee9r2xwt.fsf@gmail.com> Reply-To: Theodor Thornhill 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="25719"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 50244-done@debbugs.gnu.org, Philipp Stephani , Dmitry Gutov To: =?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?= Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Oct 23 21:23:30 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 1meMc4-0006W1-L0 for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 23 Oct 2021 21:23:30 +0200 Original-Received: from localhost ([::1]:43312 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1meMc2-0004K1-M5 for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 23 Oct 2021 15:23:26 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:39938) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1meMbe-0003u0-HC for bug-gnu-emacs@gnu.org; Sat, 23 Oct 2021 15:23:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:54017) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1meMbe-00016H-8m for bug-gnu-emacs@gnu.org; Sat, 23 Oct 2021 15:23:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1meMbe-0003QU-5L for bug-gnu-emacs@gnu.org; Sat, 23 Oct 2021 15:23:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Theodor Thornhill Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 23 Oct 2021 19:23:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 50244 X-GNU-PR-Package: emacs Original-Received: via spool by 50244-done@debbugs.gnu.org id=D50244.163501693913087 (code D ref 50244); Sat, 23 Oct 2021 19:23:02 +0000 Original-Received: (at 50244-done) by debbugs.gnu.org; 23 Oct 2021 19:22:19 +0000 Original-Received: from localhost ([127.0.0.1]:37325 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1meMaw-0003P1-Uk for submit@debbugs.gnu.org; Sat, 23 Oct 2021 15:22:19 -0400 Original-Received: from out0.migadu.com ([94.23.1.103]:48031) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1meMar-0003Oq-UC for 50244-done@debbugs.gnu.org; Sat, 23 Oct 2021 15:22:17 -0400 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thornhill.no; s=key1; t=1635016932; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Fdvs/vOw+0jXm5B241OPbQxGfCAzfUlAsqC+w1VntLs=; b=uegVPQY8gpLsF8b/2t6E7FXkRDGfvRINHkG1SOhtQm8AnksfqiKHAVQc4wVIztf+iSC4Rr 1OkT4lC8XCK+ie8+plF/oRnuFm33WwNY+O3uFBG2/58S5axQq8uenkQWEqDCaO6nyBQ9Mb F+2yoAkCwklqJh+g7wvy5h3qznbdGOSIC92HqAj1p7HIz3/jpGnyjC9b7bdR6WzdcDqcGT akalz7LAcXT3DPWzGA568sufxwp68AQ253v+wrWFBF4Lk5F3HX+8EdtLgX3FhYV48iLexS GM+iAI0R75pzG/xNrDRVkffMOwOuStd9Hhn7CCMDXWt22sSdHjuGPlnoM9S2VQ== In-Reply-To: <87ee9r2xwt.fsf@gmail.com> X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: theo@thornhill.no 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:218038 Archived-At: Hi Jo=C3=A3o! (sent this mail some days ago, but the bug was archived, so not sure if it worked. Trying again. If this is only noise, then I'm sorry, but hopefully ok considering i found a typo in the old patch :)) I finally did get to test this out a little, and I seem to have hit some small snags I can't really understand. I'd love some pointers as to how to continue! (the patch I currently use is attached at the bottom) Ok, so what happens is: - There is no backend set on the list-only-diagnostics as for now, and I cannot for the life of me see how to set them, as it doesn't look like eglot itself sets it. Is there some reflection going on here that I have missed? - The function in question is riddled with fallbacks and failure checking. Are we sure we need all that? I see most of the commits relating to the range checking is from 2018, so they may not be relevant anymore? - The diff as supplied appends the list-only-diagnostics just fine to the flymake buffer, but I believe since the backend isn't set, eglot doesn't report the proper diagnostics when I visit the file. I have to make a bogus edit to trigger the eglot-flymake-backend function. (This could just as well be some unrelated eglot/elmls issue...) - What would be the best way to get the proper line and column? Now I simply use the range, but considering there's a lot of error handling there I guess that is a little risky? I did have a version earlier using with-temp-buffer and finding the correct positions, but that seemed more complicated than needed. I'd love to get your thoughts on this :) Theodor diff --git a/eglot.el b/eglot.el index bf9cf25..47c7b74 100644 --- a/eglot.el +++ b/eglot.el @@ -1776,9 +1776,14 @@ COMMAND is a symbol naming the command." (_server (_method (eql telemetry/event)) &rest _any) "Handle notification telemetry/event") ;; noop, use events buffer =20 +(defun eglot--diag-type (severity) + (cond ((<=3D severity 1) 'eglot-error) + ((=3D severity 2) 'eglot-warning) + (t 'eglot-note))) + (cl-defmethod eglot-handle-notification (server (_method (eql textDocument/publishDiagnostics)) &key uri diagnos= tics - &allow-other-keys) ; FIXME: doesn't respect `eglot-strict-mode' + &allow-other-keys) ; FIXME: doesn't respect `eglot-strict= -mode' "Handle notification publishDiagnostics" (if-let ((buffer (find-buffer-visiting (eglot--uri-to-path uri)))) (with-current-buffer buffer @@ -1787,9 +1792,7 @@ COMMAND is a symbol naming the command." collect (eglot--dbind ((Diagnostic) range message severity source) diag-spec (setq message (concat source ": " message)) - (pcase-let - ((sev severity) - (`(,beg . ,end) (eglot--range-region range))) + (pcase-let ((`(,beg . ,end) (eglot--range-region range)= )) ;; Fallback to `flymake-diag-region' if server ;; botched the range (when (=3D beg end) @@ -1807,17 +1810,29 @@ COMMAND is a symbol naming the command." (setq end (point-at-eol (1+ (plist-get (plist-get range :end) :li= ne))))))) - (eglot--make-diag (current-buffer) beg end - (cond ((<=3D sev 1) 'eglot-error) - ((=3D sev 2) 'eglot-warning) - (t 'eglot-note)) - message `((eglot-lsp-diag . ,diag-s= pec))))) + (eglot--make-diag + (current-buffer) beg end + (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 =3D (expand-file-name (eglot--uri-to-path uri)) + for diag-spec across diagnostics + collect (eglot--dbind ((Diagnostic) range message severity source) di= ag-spec + (setq message (concat source ": " message)) + (let* ((start (plist-get range :start)) + (line (1+ (plist-get start :line))) + (char (1+ (plist-get start :character)))) + (eglot--make-diag path (cons line char) nil (eglot--diag-= type severity) message))) + into diags + finally + (setq flymake-list-only-diagnostics + (assoc-delete-all path flymake-list-only-diagnostics #'string= =3D)) + (push (cons path diags) flymake-list-only-diagnostics)))) =20 (cl-defun eglot--register-unregister (server things how) "Helper for `registerCapability'.