Skip to content

Commit 497ac27

Browse files
committed
Add automatically --xdebug option support
1 parent cce2b02 commit 497ac27

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

phpstan.el

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
;; Version: 0.6.0
88
;; Keywords: tools, php
99
;; Homepage: https://github.com/emacs-php/phpstan.el
10-
;; Package-Requires: ((emacs "24.3") (php-mode "1.22.3"))
10+
;; Package-Requires: ((emacs "24.3") (php-mode "1.22.3") (php-runtime "0.2"))
1111
;; License: GPL-3.0-or-later
1212

1313
;; This program is free software; you can redistribute it and/or modify
@@ -55,6 +55,7 @@
5555
;;; Code:
5656
(require 'cl-lib)
5757
(require 'php-project)
58+
(require 'php-runtime)
5859

5960
(eval-when-compile
6061
(require 'php))
@@ -98,6 +99,15 @@
9899
:safe (lambda (v) (or (null v) (stringp v)))
99100
:group 'phpstan)
100101

102+
(defcustom phpstan-use-xdebug-option 'auto
103+
"Set --xdebug option."
104+
:type '(choice (const :tag "Set --xdebug option dynamically" 'auto)
105+
(const :tag "Add --xdebug option" t)
106+
(const :tag "No --xdebug option" nil))
107+
:group 'phpstan)
108+
109+
(defvar-local phpstan--use-xdebug-option nil)
110+
101111
;;;###autoload
102112
(progn
103113
(defvar phpstan-working-dir nil
@@ -361,6 +371,14 @@ it returns the value of `SOURCE' as it is."
361371
(and autoload (list "-a" autoload))
362372
(and memory-limit (list "--memory-limit" memory-limit))
363373
(and level (list "-l" level))
374+
(cond
375+
(phpstan--use-xdebug-option (list phpstan--use-xdebug-option))
376+
((eq phpstan-use-xdebug-option 'auto)
377+
(setq-local phpstan--use-xdebug-option
378+
(when (string= "1" (php-runtime-expr "extension_loaded('xdebug')"))
379+
"--xdebug"))
380+
(list phpstan--use-xdebug-option))
381+
(phpstan-use-xdebug-option (list "--xdebug")))
364382
(list "--")
365383
args)))
366384

0 commit comments

Comments
 (0)