Skip to content

Do not use Editor Mode if the buffer is not being edited #58

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions flycheck-phpstan.el
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,6 @@ passed to `flycheck-finish-checker-process'."
(string-match-p flycheck-phpstan--nofiles-message output))
(funcall next checker exit-status files output callback cwd)))

(defcustom flycheck-phpstan-fallback-to-original-analysis-if-editor-mode-unavailable t
"If non-NIL, analyze the original file when PHPStan editor mode is unavailable."
:type 'boolean
:safe #'booleanp)

(defun flycheck-phpstan--enabled-and-set-variable ()
"Return path to phpstan configure file, and set buffer execute in side effect."
(let ((enabled (phpstan-enabled)))
Expand Down Expand Up @@ -145,10 +140,8 @@ passed to `flycheck-finish-checker-process'."
:filename file))))

(defun flycheck-phpstan-analyze-original (original)
"Return non-NIL if ORIGINAL is NIL, fallback is enabled, and buffer is modified."
(and (null original)
flycheck-phpstan-fallback-to-original-analysis-if-editor-mode-unavailable
(buffer-modified-p)))
"Return non-NIL if ORIGINAL is non-NIL and buffer is not modified."
(and original (not (buffer-modified-p))))

(flycheck-define-checker phpstan
"PHP static analyzer based on PHPStan."
Expand Down
11 changes: 2 additions & 9 deletions flymake-phpstan.el
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,6 @@
:type 'boolean
:group 'flymake-phpstan)

(defcustom flycheck-phpstan-fallback-to-original-analysis-if-editor-mode-unavailable t
"If non-NIL, analyze the original file when PHPStan editor mode is unavailable."
:type 'boolean
:safe #'booleanp)

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

(defun flymake-phpstan-make-process (root command-args report-fn source)
Expand Down Expand Up @@ -94,10 +89,8 @@
(code (user-error "PHPStan error (exit status: %s)" code)))))))

(defun flymake-phpstan-analyze-original (original)
"Return non-NIL if ORIGINAL is NIL, fallback is enabled, and buffer is modified."
(and (null original)
flymake-phpstan-fallback-to-original-analysis-if-editor-mode-unavailable
(buffer-modified-p)))
"Return non-NIL if ORIGINAL is non-NIL and buffer is not modified."
(and original (not (buffer-modified-p))))

(defun flymake-phpstan--create-temp-file ()
"Create temp file and return the path."
Expand Down
15 changes: 8 additions & 7 deletions phpstan.el
Original file line number Diff line number Diff line change
Expand Up @@ -521,13 +521,14 @@ it returns the value of `SOURCE' as it is."
(phpstan-use-xdebug-option (list "--xdebug")))
(when editor
(let ((original-file (plist-get editor :original-file)))
(if (phpstan-editor-mode-available-p (car (phpstan-get-executable-and-args)))
(list "--tmp-file" (funcall (plist-get editor :temp-file))
"--instead-of" original-file
"--" original-file)
(if (funcall (plist-get editor :analyze-original) original-file)
(list "--" original-file)
(list "--" (funcall (plist-get editor :inplace)))))))
(cond
((funcall (plist-get editor :analyze-original) original-file)
(list "--" original-file))
((phpstan-editor-mode-available-p (car (phpstan-get-executable-and-args)))
(list "--tmp-file" (funcall (plist-get editor :temp-file))
"--instead-of" original-file
"--" original-file))
((list "--" (funcall (plist-get editor :inplace)))))))
options
(and args (cons "--" args)))))

Expand Down