unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: sir@hacktivista.com
To: 40351@debbugs.gnu.org
Subject: bug#40351: Flymake error count
Date: Tue, 31 Mar 2020 07:21:54 -0300	[thread overview]
Message-ID: <2ICKUTXGCUO0W.3GVX8GSQ0BRIC@handheld.hackware.cl> (raw)

[-- Attachment #1: Type: text/plain, Size: 847 bytes --]

I've created a flymake backend based on the flymake docs: https://www.gnu.org/software/emacs/manual/html_node/flymake/An-annotated-example-backend.html#An-annotated-example-backend

It works, but I'm also using Eglot, and noticed that on the error count displayed on the status line of emacs it doesn't count properly for my backend. It displays a number 1 for each error it discovers, but Eglot errors are able to increase the number of its backend. This is what displays my status line:

(PHP//l company Flymake[1 1 1 3 0] ...)

It should display ... Flymake [3 3 0] ...

The attached image will explain it better. I'm attaching the backend also, if you need to see the code (though it's actually pretty much the same as the example in docs).

How could I make my backend increase the error count instead of creating other counter?


[-- Attachment #2: eglot-flymake.png --]
[-- Type: image/png, Size: 121324 bytes --]

[-- Attachment #3: flymake-phpcs.el --]
[-- Type: text/plain, Size: 4569 bytes --]

;;; flymake-phpcs.el --- PHP Code Sniffer Flymake backend  -*- lexical-binding: t; -*-

(defcustom flymake-phpcs-standard "PSR12"
  "Setting the Coding Standard for PHP CodeSniffer."
  :type 'string
  :group 'flymake-phpcs)

(defcustom flymake-phpcs-command (executable-find "phpcs")
  "The name of the phpcs executable."
  :type 'string
  :group 'flymake-phpcs)

(defcustom flymake-phpcbf-command (executable-find "phpcbf")
  "The name of the phpcbf executable."
  :type 'string
  :group 'flymake-phpcs)

(defvar-local phpcs--flymake-proc nil)

(defun phpcs-flymake (report-fn &rest _args)
  (unless (executable-find flymake-phpcs-command)
    (error "Cannot find phpcs executable"))

  ;; If a live process launched in an earlier check was found, that
  ;; process is killed.  When that process's sentinel eventually runs,
  ;; it will notice its obsoletion, since it have since reset
  ;; `phpcs-flymake-proc' to a different value
  ;;
  (when (process-live-p phpcs--flymake-proc)
    (kill-process phpcs--flymake-proc))

  ;; Save the current buffer, the narrowing restriction, remove any
  ;; narrowing restriction.
  ;;
  (let ((source (current-buffer)))
    (save-restriction
      (widen)
      ;; Reset the `phpcs--flymake-proc' process to a new process
      ;; calling the phpcs tool.
      ;;
      (setq
       phpcs--flymake-proc
       (make-process
        :name "phpcs-flymake" :noquery t :connection-type 'pipe
        ;; Make output go to a temporary buffer.
        ;;
        :buffer (generate-new-buffer " *phpcs-flymake*")
        :command `(,flymake-phpcs-command "--report=emacs" ,(concat "--standard=" flymake-phpcs-standard))
        :sentinel
        (lambda (proc _event)
          ;; Check that the process has indeed exited, as it might
          ;; be simply suspended.
          ;;
          (when (eq 'exit (process-status proc))
            (unwind-protect
                ;; Only proceed if `proc' is the same as
                ;; `phpcs--flymake-proc', which indicates that
                ;; `proc' is not an obsolete process.
                ;;
                (if (with-current-buffer source (eq proc phpcs--flymake-proc))
                    (with-current-buffer (process-buffer proc)
                      (goto-char (point-min))
                      ;; Parse the output buffer for diagnostic's
                      ;; messages and locations, collect them in a list
                      ;; of objects, and call `report-fn'.
                      ;;
                      (cl-loop
                       while (search-forward-regexp
                              "^STDIN:\\([[:digit:]]+\\):\\([[:digit:]]+\\): \\([[:alpha:]]+\\) - \\(.*\\)$"
                              nil t)
                       for lnum = (string-to-number (match-string 1))
                       ;; for (beg . end) = (flymake-diag-region source lnum (string-to-number (match-string 2)))
                       for (beg . end) = (flymake-diag-region source lnum)
                       for type = (make-symbol (match-string 3))
                       for msg = (match-string 4)
                       collect (flymake-make-diagnostic source
                                                        beg
                                                        end
                                                        type
                                                        msg)
                       into diags
                       finally (funcall report-fn diags)))
                  (flymake-log :warning "Canceling obsolete check %s"
                               proc))
              ;; Cleanup the temporary buffer used to hold the
              ;; check's output.
              ;;
              (kill-buffer (process-buffer proc)))))))
      ;; Send the buffer contents to the process's stdin, followed by
      ;; an EOF.
      ;;
      (process-send-region phpcs--flymake-proc (point-min) (point-max))
      (process-send-eof phpcs--flymake-proc))))

(defun flymake-phpcs-load ()
  "Configure flymake mode to check the current buffer's PHP syntax."
  (interactive)
  (add-hook 'flymake-diagnostic-functions 'phpcs-flymake nil t))

(defun phpcbf ()
  "Run phpcbf on current file (saved-files only)."
  (interactive)
  (shell-command (combine-and-quote-strings (list flymake-phpcbf-command (concat "--standard=" flymake-phpcs-standard) (buffer-file-name))))
  (revert-buffer :ignore-auto :noconfirm))

(provide 'flymake-phpcs)

             reply	other threads:[~2020-03-31 10:21 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-31 10:21 sir [this message]
2020-05-12 18:30 ` bug#40351: Flymake error count João Távora
2022-12-12  8:50   ` Stefan Kangas

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=2ICKUTXGCUO0W.3GVX8GSQ0BRIC@handheld.hackware.cl \
    --to=sir@hacktivista.com \
    --cc=40351@debbugs.gnu.org \
    /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).