Skip to content
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

Variable configure file #4

Merged
merged 25 commits into from
Apr 15, 2018
Merged

Variable configure file #4

merged 25 commits into from
Apr 15, 2018

Conversation

zonuexe
Copy link
Member

@zonuexe zonuexe commented Apr 11, 2018

refs #2

@zonuexe zonuexe requested a review from Fuco1 April 11, 2018 16:11
@zonuexe
Copy link
Member Author

zonuexe commented Apr 11, 2018

Probably this change conflicts with #3.
This variable is not a customization variable, but it maybe works fine.

// Local Variables:
// phpstan-config-file: (root . "tests/phpstan.neon")
// phpstan-level: 7
// End:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is not automated, but we can check flycheck's behavior manually.

phpstan.el Outdated
"analyze"
"--no-progress"
"--errorFormat=raw"
:command ("php" (eval (phpstan-get-executable))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since phpstan is generally a PHP script (or Phar archive), this command works fine. Therefore, it is not possible to specify shell scripts that are not PHP or "real" executables.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a feature though? I run phpstan through docker so this would not work for me for example. And there are many people who do so as well: https://github.com/phpstan/docker-image

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. This problem was solved with the hack of phpstan-enabled-and-set-flycheck-variable. It is an evil side effect.

@zonuexe zonuexe mentioned this pull request Apr 11, 2018
phpstan.el Outdated

;;;###autoload
(progn
(defvar phpstan-config-file nil)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason of having these as variables instead of flycheck options? The flycheck macro expands to a defcustom so we can still change it manually just as a defvar but it probides good documentation and listing of options for users.

phpstan.el Outdated
#'(lambda (v) (or (null v)
(integerp v)
(and (stringp v)
(string-match-p "\\`[1-9][0-9]*\\'" v))))))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not match "0", why?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. It fixed.

phpstan.el Outdated

;;;###autoload
(progn
(defvar phpstan-executable nil)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flycheck defines a variable for this automatically. I guess the question is the same as for the variable above.

"Return path to phpstan configure file or `NIL'."
(if phpstan-config-file
(if (and (consp phpstan-config-file)
(eq 'root (car phpstan-config-file)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not clear what the structure of phpstan-config-file should be. I think user options should at least be defined as defcustoms with a type annotation.

phpstan.el Outdated
"analyze"
"--no-progress"
"--errorFormat=raw"
:command ("php" (eval (phpstan-get-executable))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a feature though? I run phpstan through docker so this would not work for me for example. And there are many people who do so as well: https://github.com/phpstan/docker-image

phpstan.el Outdated
:command ("php" (eval (phpstan-get-executable))
"analyze" "--errorFormat=raw" "--no-progress" "--no-interaction"
"-c" (eval (phpstan-get-config-file))
"-l" (eval (phpstan-get-level))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if these options eval to nil, then the flag has no value and it errors out. The (option ..) expansion flycheck uses takes care of that.

phpstan.el Outdated
source)
:working-directory (lambda (_) (php-project-get-root-dir))
:enabled (lambda () (locate-dominating-file "phpstan.neon" default-directory))
:enabled (lambda () (phpstan-get-config-file))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this still doesn't work if I don't use any configuration file at all.

phpstan.el Outdated

;;;###autoload
(progn
(defvar phpstan-config-file nil)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flycheck also provides the flycheck-def-config-file-var macro for this

@zonuexe
Copy link
Member Author

zonuexe commented Apr 13, 2018

@Fuco1
I'm sorry I almost passed through your reviews. But for your pointing out, I was able to take care of Docker and make it work.

First of all, since this package is phpstan.el instead of flycheck-phpstan.el, I did not want to depends on only Flycheck. Since Flymake has been improved in Emacs 26, I'd like to avoid dependency on Flycheck for a minimum Emacs environment.

#4 (comment)
What's the reason of having these as variables instead of flycheck options? The flycheck macro expands to a defcustom so we can still change it manually just as a defvar but it probides good documentation and listing of options for users.

#4 (comment)
It is not clear what the structure of phpstan-config-file should be. I think user options should at least be defined as defcustoms with a type annotation.

Your point is rational. However, I do not think that it is appropriate that project-specific settings depend on customization mechanisms. That is one reason why I did not depend on flycheck-def-config-file-var.

(root . "path/to/dir/phpstan-docker.neon")

This notation is not publicly specified, but I do not think that it is a remarkably esoteric notation by Emacs users. ......Uh, I know that my English sentences are not good.

@zonuexe zonuexe force-pushed the feature/variable-configure-file branch from bfaf09e to 0508372 Compare April 15, 2018 00:23
@zonuexe
Copy link
Member Author

zonuexe commented Apr 15, 2018

This code needs to be refactored, but once it is merged into master it will be the first release.

@zonuexe zonuexe merged commit 8a95d94 into master Apr 15, 2018
@zonuexe zonuexe deleted the feature/variable-configure-file branch April 15, 2018 00:26
source)
:working-directory (lambda (_) (php-project-get-root-dir))
:enabled (lambda () (locate-dominating-file "phpstan.neon" default-directory))
:command ("php" (eval (phpstan-get-command-args))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this work when this starts "php" but I set 'docker as executable? Then the arguments are going to be run --rm -v..., that won't work with php would it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Fuco1 This is an insane hack.

phpstan-enabled-and-set-flycheck-variable invoked as :enabled function sets flycheck-phpstan-executable as its side effect when flycheck-phpstan-executable is not set. Since it uses the fact that :enabled is called beforehand, there is a possibility that it will be destroyed in the future with low probability.

It was possible to explicitly write flycheck-phpstan-executable in the user setting, but it was handled within this function as it is somewhat complicated. I am looking for ways to solve this problem besides this hack.

@Fuco1
Copy link
Member

Fuco1 commented Apr 15, 2018

@zonuexe Thanks, I think your points are valid, if we want to support other mechanisms than flycheck then it makes sense to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants