-
-
Notifications
You must be signed in to change notification settings - Fork 577
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 Function for :src-dir #1679
Allow Function for :src-dir #1679
Conversation
Make changes to projectile--find-matching file to the effect that it will circumvent any existing logic if it is detected that the src-dir property of the current project has been set to a function, in which case, that function is called instead with the path of the test file.
Add tests for projectile--test-name-for-impl-name, projectile--impl-file-from-src-dir-fn and add test for projectile--find-matching-file to check precedence logic is as expected.
Document usage and behaviour of the src-dir option allowing a function as a value.
|
||
| :test | ||
| A command to test the project. | ||
|
||
| :test-dir | ||
| A path, relative to the project root, where the test code lives. A function may also be specified which takes one parameter - the directory of a file, and it should return the directory in which the test file should reside. | ||
| A path, relative to the project root, where the test code lives. A function may also be specified which takes one parameter - the directory of a file, and it should return the directory in which the test file should reside. This option is only used for implementation/test toggling. |
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.
From looking at the source, please correct me if this is wrong.
7133f61
to
70ff939
Compare
src-dir | ||
#'projectile--impl-name-for-test-name))) | ||
(when (file-exists-p impl-file) | ||
(file-relative-name impl-file (projectile-project-root))))))) |
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.
Pretty much projectile--test-file-from-test-dir-fn
but with the lookup reversed and it's also checked that the implementation file exists.
test-file (cl-remove-if-not predicate (projectile-current-project-files)))))) | ||
(if-let ((impl-file-from-src-dir-fn | ||
(projectile--impl-file-from-src-dir-fn test-file))) | ||
(list impl-file-from-src-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.
Where :src-dir
takes precendence if it's set to a function.
Great work! |
Awesome! Thanks for you ⚡ response |
Should this PR be resolved since it was merged? Also, does it resolve #1650 as well? |
I've just pinged the creator of that issue to ask if he's happy that it's resolved. |
Hi! This PR is a follow up to #1671, it allows the
:src-dir
property of projects to be set to a function like:test-dir
was in the previous PR.Similar to to
:test-dir
, whenprojectile-toggle-between-implementation-and-test
is called and the user is in a test file, and it's determined a project type has it's:src-dir
property set to a function, this function will be called to obtain the directory in which the implementation file of the corresponding test file resides.The result is that from the project in #1650 with the config:
Is that calling
projectile-toggle-between-implementation-and-test
from:src/main/scala/bar/package.scala
sticks you insrc/test/scala/bar/packageSpec.scala
(regardless of the test file existing)src/main/scala/foo/package.scala
sticks you insrc/test/scala/foo/packageSpec.scala
(regardless of the test file existing)src/test/scala/bar/packageSpec.scala
sticks you insrc/main/scala/bar/package.scala
(if the latter file exists)src/test/scala/foo/packageSpec.scala
sticks you insrc/main/scala/foo/package.scala
(if the latter file exists)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!