diff --git a/flycheck-phpstan.el b/flycheck-phpstan.el index 707112a..82f62f4 100644 --- a/flycheck-phpstan.el +++ b/flycheck-phpstan.el @@ -45,6 +45,19 @@ (defvar flycheck-phpstan-executable) (defvar flycheck-phpstan--temp-buffer-name "*Flycheck PHPStan*") + +(defcustom flycheck-phpstan-ignore-metadata-list nil + "Set of metadata items to ignore in PHPStan messages for Flycheck." + :type '(set (const identifier) + (const tip)) + :group 'phpstan) + +(defcustom flycheck-phpstan-metadata-separator "\n" + "Separator of PHPStan message and metadata." + :type 'string + :safe #'stringp + :group 'phpstan) + (defun flycheck-phpstan--enabled-and-set-variable () "Return path to phpstan configure file, and set buffer execute in side effect." (let ((enabled (phpstan-enabled))) @@ -77,11 +90,21 @@ (let ((data (phpstan--parse-json json-buffer))) (cl-loop for (file . entry) in (flycheck-phpstan--plist-to-alist (plist-get data :files)) append (cl-loop for messages in (plist-get entry :messages) - for text = (let ((msg (plist-get messages :message)) - (tip (plist-get messages :tip))) - (if tip - (concat msg "\n" phpstan-tip-message-prefix tip) - msg)) + for text = (let* ((msg (plist-get messages :message)) + (ignorable (plist-get messages :ignorable)) + (identifier (unless (memq 'identifier flycheck-phpstan-ignore-metadata-list) + (plist-get messages :identifier))) + (tip (unless (memq 'tip flycheck-phpstan-ignore-metadata-list) + (plist-get messages :tip))) + (lines (list (when (and identifier ignorable) + (concat phpstan-identifier-prefix identifier)) + (when tip + (concat phpstan-tip-message-prefix tip)))) + (lines (cl-remove-if #'null lines))) + (if (null lines) + msg + (concat msg flycheck-phpstan-metadata-separator + (mapconcat #'identity lines "\n")))) collect (flycheck-error-new-at (plist-get messages :line) nil 'error text :filename file))))) diff --git a/phpstan.el b/phpstan.el index 0e42ef7..a66a7c6 100644 --- a/phpstan.el +++ b/phpstan.el @@ -129,6 +129,12 @@ :safe #'stringp :group 'phpstan) +(defcustom phpstan-identifier-prefix "🪪 " + "Prefix of PHPStan error identifier." + :type 'string + :safe #'stringp + :group 'phpstan) + (defcustom phpstan-enable-remote-experimental nil "Enable PHPStan analysis remotely by TRAMP. @@ -359,14 +365,14 @@ it returns the value of `SOURCE' as it is." (let ((file (phpstan--expand-file-name (or buffer-file-name (read-file-name "Choose a PHP script: "))))) (compile (mapconcat #'shell-quote-argument - (phpstan-get-command-args :include-executable t :args (list file)) " ")))) + (phpstan-get-command-args :include-executable t :args (list file) :verbose 1) " ")))) ;;;###autoload (defun phpstan-analyze-file (file) "Analyze a PHP script FILE using PHPStan." (interactive (list (phpstan--expand-file-name (read-file-name "Choose a PHP script: ")))) (compile (mapconcat #'shell-quote-argument - (phpstan-get-command-args :include-executable t :args (list file)) " "))) + (phpstan-get-command-args :include-executable t :args (list file) :verbose 1) " "))) ;;;###autoload (defun phpstan-analyze-project () @@ -440,7 +446,7 @@ it returns the value of `SOURCE' as it is." ((executable-find "phpstan") (list (executable-find "phpstan"))) (t (error "PHPStan executable not found"))))))) -(cl-defun phpstan-get-command-args (&key include-executable use-pro args format options config) +(cl-defun phpstan-get-command-args (&key include-executable use-pro args format options config verbose) "Return command line argument for PHPStan." (let ((executable-and-args (phpstan-get-executable-and-args)) (config (or config (phpstan-normalize-path (phpstan-get-config-file)))) @@ -457,6 +463,12 @@ it returns the value of `SOURCE' as it is." (and autoload (list "-a" autoload)) (and memory-limit (list "--memory-limit" memory-limit)) (and level (list "-l" level)) + (cond + ((null verbose) nil) + ((memq verbose '(1 t)) (list "-v")) + ((eq verbose 2) (list "-vv")) + ((eq verbose 3) (list "-vvv")) + (error ":verbose option should be 1, 2, 3 or `t'")) (cond (phpstan--use-xdebug-option (list phpstan--use-xdebug-option)) ((eq phpstan-use-xdebug-option 'auto)