-
-
Notifications
You must be signed in to change notification settings - Fork 579
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
Allow Functions for :test-dir #1671
Allow Functions for :test-dir #1671
Conversation
## 2.4.0 (2021-05-27) | ||
|
||
### New features | ||
|
||
* Add `projectile-update-project-type-function` for updating the properties of existing project types. | ||
* Add `projectile-update-project-type` function for updating the properties of existing project types. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just noticed this, sorry!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem.
8e8fe68
to
fbd1b2f
Compare
CHANGELOG.md
Outdated
@@ -2,11 +2,13 @@ | |||
|
|||
## master (unreleased) | |||
|
|||
* Allow the `:test-dir` option of a project to be set to a function for more flexible test switching. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has to go under "New features" or "Changes".
projectile.el
Outdated
@@ -3342,13 +3351,14 @@ test file." | |||
"No matching source file found for project type `%s'" | |||
(projectile-project-type)))) | |||
;; find the matching test file | |||
(let ((test-file (projectile-find-matching-test file-name))) | |||
(if test-file | |||
(if-let ((overriding-test-file (projectile--test-file-override file-name))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't it make more sense to incorporate this in the existing test lookup function instead of creating the potentially confusing test override concept? I definitely don't like how the code reads now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, in hindsight that makes more sense.
projectile.el
Outdated
@@ -3443,6 +3453,35 @@ Fallback to DEFAULT-VALUE for missing attributes." | |||
(or (string-equal prefix-name name) | |||
(string-equal suffix-name name)))))) | |||
|
|||
(defun projectile--complementary-file (file-path dir-fn filename-fn) | |||
"Return `(DIR-FN dir)/(FILENAME-FN name)' where FILE-PATH = dir/name. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You've quoted this a symbol reference, even though it's not.
projectile.el
Outdated
(defun projectile--impl-to-test-dir (impl-dir-path) | ||
"Return the directory path of a test whose impl file resides in IMPL-DIR-PATH. | ||
|
||
Occurrences of 'src-dir' are replaced with 'test-dir' to obtain the new directory." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The quoting references here a confusing, as those are not some references, but rather explanations of the implementation.
projectile.el
Outdated
(projectile-complementary-dir impl-dir-path impl-dir test-dir))) | ||
|
||
(defun projectile-complementary-dir (dir-path string replacement) | ||
"Return the 'complementary' directory of DIR-PATH by replacing STRING in DIR-PATH with REPLACEMENT." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
complementary
should be double-quoted here.
That'd be nice indeed, otherwise it'd be super weird why we have different setups for Overall the code looks good, but I'd like to try to simplify a bit the code - in particular it took me a while to understand the need for the overriding function. |
fbd1b2f
to
b733548
Compare
(error "No matching test file found for project type `%s'" | ||
(projectile-project-type))))))) | ||
(let* ((test-file (projectile-find-matching-test file-name)) | ||
(test-file-or-fallback (or test-file (projectile--test-file-fallback file-name))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
projectile--test-file-fallback
here does the same as projectile-create-test-file-for
did previously, minus the creation of the test file which has been moved to this function.
I'm undecided whether moving projectile--test-file-fallback
to projectile-find-matching-test
(as a final when-let
😄) or keeping it here would make more sense. What do you think?
Thanks, hopefully that should be straightforward once you're happy with this PR 👍
Thanks for feedback and fast response, hopefully I've simplified it a little now by integrating the precedence logic into |
Make changes to projectile-find-implementation-or-test to the effect that it will circumvent the previous call to projectile-find-matching-test if it is detected that :test-dir has been set to a function via projectile--test-file-override.
Adds tests for projectile-find-implementation-or-test, projectile--test-file-override, projectile--complementary-file and projectile--impl-to-test-dir.
State that :test-dir now accepts a function and add a note to the :related-files-fn doc explaining precedence. Also fix up some bad phrasing in related-files-fn doc. Add comparison of the :test-dir and :related-files-fn options.
b733548
to
5b13427
Compare
(if-let ((plist (projectile--related-files-plist-by-kind impl-file :test))) | ||
(projectile--related-files-from-plist plist) | ||
(if-let ((predicate (projectile--impl-to-test-predicate impl-file))) | ||
(if-let ((test-file-from-test-dir-fn |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is where the :test-dir
when set to a function takes precedence over :related-files-fn
. If it is not a function, the behaviour should be the same as before.
@bbatsov Do you have the time to take another look at this? I've added some comments + justifications to the PR so hopefully it should be easier to follow, thanks. |
Looks good! Thanks! |
Hi 👋, this PR is a proposed solution to #1650, achieved by allowing the
:test-dir
option to take a function which returns the test directory given the implementation directory.The behaviour for the project in #1650 with the config:
Is that calling
projectile-toggle-between-implementation-and-test
fromsrc/main/scala/bar/package.scala
sticks you insrc/main/scala/bar/packageSpec.scala
and calling fromsrc/test/scala/foo/package.scala
sticks you insrc/test/scala/foo/packageSpec.scala
(regardless of either test file existing).Calling
projectile-toggle-between-implementation-and-test
from either test file however will prompt a choice between the two existingpackage.scala
files. I can PR a similar change for allowing:src-dir
to take a function if you are happy with these changes.Setting the option to a function should override existing behaviour (for example
:related-files-fn
) , and if the option is not a function then the behaviour should be the same as before. I've added more detailed documentation in the README about the new behaviour, and also added a comparison of when I think you should use:test-dir
overrelated-files-fn
and vice versa.Apologies for the large PR 🙂, I'm not sure how it could be split up on top of omitting changes to
src-dir
.Thanks, let me know what you think!
Before submitting a PR make sure the following things have been done (and denote this
by checking the relevant checkboxes):
eldev test
)M-x checkdoc
warningsThanks!