unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#40351: Flymake error count
@ 2020-03-31 10:21 sir
  2020-05-12 18:30 ` João Távora
  0 siblings, 1 reply; 3+ messages in thread
From: sir @ 2020-03-31 10:21 UTC (permalink / raw)
  To: 40351

[-- 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)

^ permalink raw reply	[flat|nested] 3+ messages in thread

* bug#40351: Flymake error count
  2020-03-31 10:21 bug#40351: Flymake error count sir
@ 2020-05-12 18:30 ` João Távora
  2022-12-12  8:50   ` Stefan Kangas
  0 siblings, 1 reply; 3+ messages in thread
From: João Távora @ 2020-05-12 18:30 UTC (permalink / raw)
  To: sir; +Cc: 40351

Hello, sir@hacktivista.com:

I'm sorry for the very long delay in answering this.  Next time you
report a bug for flymake, make sure you also forward me the message that
the bug reporting system sends back to you.  (yes I know you had written
me separately).

Anyway, to your problem:


>                        for (beg . end) = (flymake-diag-region source lnum)
>                        for type = (make-symbol (match-string 3))
                                     ^^^^^^^^^^^

I think the problem you experience is found here.  TYPE cannot be a
different symbol for each error you find, otherwise Flymake will think
that each error has its unique type.  If `(match-string 3)` is indeed
often enough the same string, you can try `intern` instead.

Let's say (match-string 3) can only return "oops", "warn" or "info" I would write
that line like

    for type = (intern (format "flymake-phpcs--%s" (match-string 3)))

Then separately I would write in a top-level-form

    (put 'flymake-phpcs--oops 'flymake-category 'flymake-error)
    (put 'flymake-phpcs--warn 'flymake-category 'flymake-warning)
    (put 'flymake-phpcs--info 'flymake-category 'flymake-note)

Then the errors would be merged with the errors from Eglot, I think.

See the manual section 2.1 Customizing Flymake error types

I see the the docstring for `flymake-make-diagnostic` could see some
improvement.  In particular, the phrase "TYPE is a key to symbol"
doesnt' make much sense.

João








^ permalink raw reply	[flat|nested] 3+ messages in thread

* bug#40351: Flymake error count
  2020-05-12 18:30 ` João Távora
@ 2022-12-12  8:50   ` Stefan Kangas
  0 siblings, 0 replies; 3+ messages in thread
From: Stefan Kangas @ 2022-12-12  8:50 UTC (permalink / raw)
  To: João Távora; +Cc: sir, 40351-done

João Távora <joaotavora@gmail.com> writes:

> Hello, sir@hacktivista.com:
>
> I'm sorry for the very long delay in answering this.  Next time you
> report a bug for flymake, make sure you also forward me the message that
> the bug reporting system sends back to you.  (yes I know you had written
> me separately).
>
> Anyway, to your problem:
>
>
>>                        for (beg . end) = (flymake-diag-region source lnum)
>>                        for type = (make-symbol (match-string 3))
>                                      ^^^^^^^^^^^
>
> I think the problem you experience is found here.  TYPE cannot be a
> different symbol for each error you find, otherwise Flymake will think
> that each error has its unique type.  If `(match-string 3)` is indeed
> often enough the same string, you can try `intern` instead.
>
> Let's say (match-string 3) can only return "oops", "warn" or "info" I would write
> that line like
>
>     for type = (intern (format "flymake-phpcs--%s" (match-string 3)))
>
> Then separately I would write in a top-level-form
>
>     (put 'flymake-phpcs--oops 'flymake-category 'flymake-error)
>     (put 'flymake-phpcs--warn 'flymake-category 'flymake-warning)
>     (put 'flymake-phpcs--info 'flymake-category 'flymake-note)
>
> Then the errors would be merged with the errors from Eglot, I think.
>
> See the manual section 2.1 Customizing Flymake error types
>
> I see the the docstring for `flymake-make-diagnostic` could see some
> improvement.  In particular, the phrase "TYPE is a key to symbol"
> doesnt' make much sense.

There have been no further replies here within 2.5 years, so I'm going
to assume the above was enough to resolve this issue.  I'm therefore
closing this bug report.

If this conclusion is incorrect and this is still an issue, please reply
to this email (use "Reply to all" in your email client) and we can
reopen the bug report.





^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-12-12  8:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-31 10:21 bug#40351: Flymake error count sir
2020-05-12 18:30 ` João Távora
2022-12-12  8:50   ` Stefan Kangas

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).