Function: php-ts-mode-flymake-php

php-ts-mode-flymake-php is a byte-compiled function defined in php-ts-mode.el.gz.

Signature

(php-ts-mode-flymake-php REPORT-FN &rest ARGS)

Documentation

PHP backend for Flymake.

Calls REPORT-FN directly.

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/php-ts-mode.el.gz
;; TODO: add phpmd and phpcs
(defun php-ts-mode-flymake-php (report-fn &rest _args)
  "PHP backend for Flymake.
Calls REPORT-FN directly."
  (when (process-live-p php-ts-mode--flymake-process)
    (kill-process php-ts-mode--flymake-process))
  (let ((source (current-buffer))
	(diagnostics-pattern (eval-when-compile
			       (rx bol (? "PHP ") ;; every diagnostic line start with PHP
				   (group (or "Fatal" "Parse")) ;; 1: type
				   " error:" (+ (syntax whitespace))
				   (group (+? nonl)) ;; 2: msg
				   " in " (group (+? nonl)) ;; 3: file
				   " on line " (group (+ num)) ;; 4: line
				   eol))))
    (save-restriction
      (widen)
      (setq php-ts-mode--flymake-process
	    (make-process
	     :name "php-ts-mode-flymake"
	     :noquery t
	     :connection-type 'pipe
	     :buffer (generate-new-buffer " *php-ts-mode-flymake*")
	     :command `(,(php-ts-mode--executable)
			"-l" "-d" "display_errors=0")
	     :sentinel
	     (lambda (proc _event)
	       (when (eq 'exit (process-status proc))
		 (unwind-protect
		     (if (with-current-buffer source
			   (eq proc php-ts-mode--flymake-process))
			 (with-current-buffer (process-buffer proc)
			   (goto-char (point-min))
			   (let (diags)
			     (while (search-forward-regexp
				     diagnostics-pattern
				     nil t)
			       (let* ((beg
				       (car (flymake-diag-region
					     source
					     (string-to-number (match-string 4)))))
				      (end
				       (cdr (flymake-diag-region
					     source
					     (string-to-number (match-string 4)))))
				      (msg (match-string 2))
				      (type :error))
				 (push (flymake-make-diagnostic
					source beg end type msg)
				       diags)))
			     (funcall report-fn diags)))
		       (flymake-log :warning "Canceling obsolete check %s" proc))
		   (kill-buffer (process-buffer proc)))))))
      (process-send-region php-ts-mode--flymake-process (point-min) (point-max))
      (process-send-eof php-ts-mode--flymake-process))))