Skip to content

Commit 1d70b68

Browse files
authored
Merge pull request #46 from emacs-php/feature/remote-experimental-support
Experimental support TRAMP
2 parents 525bdba + eb82849 commit 1d70b68

File tree

2 files changed

+38
-15
lines changed

2 files changed

+38
-15
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
All notable changes of the `phpstan.el` are documented in this file using the [Keep a Changelog](https://keepachangelog.com/) principles.
44

5+
## Unreleased
6+
7+
### Added
8+
9+
* Add `phpstan-enable-remote-experimental` custom variable for activate PHPStan on TRAMP.
10+
511
## [0.7.0]
612

713
### Added

phpstan.el

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,16 @@
129129
:safe #'stringp
130130
:group 'phpstan)
131131

132+
(defcustom phpstan-enable-remote-experimental nil
133+
"Enable PHPStan analysis remotely by TRAMP.
134+
135+
When non-nil, PHPStan will be executed on a remote server for code analysis.
136+
This feature is experimental and should be used with caution as it may
137+
have unexpected behaviors or performance implications."
138+
:type 'boolean
139+
:safe #'booleanp
140+
:group 'phpstan)
141+
132142
(defvar-local phpstan--use-xdebug-option nil)
133143

134144
;;;###autoload
@@ -257,11 +267,12 @@ NIL
257267

258268
(defun phpstan-enabled ()
259269
"Return non-NIL if PHPStan configured or Composer detected."
260-
(and (not (file-remote-p default-directory)) ;; Not support remote filesystem
261-
(or (phpstan-get-config-file)
262-
(phpstan-get-autoload-file)
263-
(and phpstan-enable-on-no-config-file
264-
(php-project-get-root-dir)))))
270+
(unless (and (not phpstan-enable-remote-experimental)
271+
(file-remote-p default-directory)) ;; Not support remote filesystem by default
272+
(or (phpstan-get-config-file)
273+
(phpstan-get-autoload-file)
274+
(and phpstan-enable-on-no-config-file
275+
(php-project-get-root-dir)))))
265276

266277
(defun phpstan-get-config-file ()
267278
"Return path to phpstan configure file or NIL."
@@ -334,21 +345,26 @@ it returns the value of `SOURCE' as it is."
334345
(let ((json-object-type 'plist) (json-array-type 'list))
335346
(json-read-object)))))
336347

348+
(defun phpstan--expand-file-name (name)
349+
"Expand file name by NAME."
350+
(let ((file (expand-file-name name)))
351+
(if (file-remote-p name)
352+
(tramp-file-name-localname (tramp-dissect-file-name name))
353+
(expand-file-name file))))
354+
337355
;;;###autoload
338356
(defun phpstan-analyze-this-file ()
339357
"Analyze current buffer-file using PHPStan."
340358
(interactive)
341-
(let ((file (phpstan-normalize-path
342-
(expand-file-name (or buffer-file-name
343-
(read-file-name "Choose a PHP script: "))))))
359+
(let ((file (phpstan--expand-file-name (or buffer-file-name
360+
(read-file-name "Choose a PHP script: ")))))
344361
(compile (mapconcat #'shell-quote-argument
345362
(phpstan-get-command-args :include-executable t :args (list file)) " "))))
346363

347364
;;;###autoload
348365
(defun phpstan-analyze-file (file)
349366
"Analyze a PHP script FILE using PHPStan."
350-
(interactive (list (phpstan-normalize-path
351-
(expand-file-name (read-file-name "Choose a PHP script: ")))))
367+
(interactive (list (phpstan--expand-file-name (read-file-name "Choose a PHP script: "))))
352368
(compile (mapconcat #'shell-quote-argument
353369
(phpstan-get-command-args :include-executable t :args (list file)) " ")))
354370

@@ -413,13 +429,14 @@ it returns the value of `SOURCE' as it is."
413429
(listp (cdr phpstan-executable)))
414430
(cdr phpstan-executable))
415431
((null phpstan-executable)
416-
(let ((vendor-phpstan (expand-file-name "vendor/bin/phpstan"
417-
(php-project-get-root-dir))))
432+
(let* ((vendor-phpstan (expand-file-name "vendor/bin/phpstan"
433+
(php-project-get-root-dir)))
434+
(expanded-vendor-phpstan (phpstan--expand-file-name vendor-phpstan)))
418435
(cond
419436
((file-exists-p vendor-phpstan)
420437
(if (file-executable-p vendor-phpstan)
421-
(list vendor-phpstan)
422-
(list php-executable vendor-phpstan)))
438+
(list expanded-vendor-phpstan)
439+
(list php-executable expanded-vendor-phpstan)))
423440
((executable-find "phpstan") (list (executable-find "phpstan")))
424441
(t (error "PHPStan executable not found")))))))
425442

@@ -436,7 +453,7 @@ it returns the value of `SOURCE' as it is."
436453
(format "--error-format=%s" (or format "raw"))
437454
"--no-progress" "--no-interaction")
438455
(and use-pro (list "--pro" "--no-ansi"))
439-
(and config (list "-c" config))
456+
(and config (list "-c" (phpstan--expand-file-name config)))
440457
(and autoload (list "-a" autoload))
441458
(and memory-limit (list "--memory-limit" memory-limit))
442459
(and level (list "-l" level))

0 commit comments

Comments
 (0)