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

Resurrect Default src-dir and test-dir for project-types #1769

Merged
merged 2 commits into from
Apr 19, 2022

Conversation

LaurenceWarne
Copy link
Contributor

Hi, this is a proposed fix for #1765, it (re) adds a default value for the src-dir and test-dir properties for project types (= "src/" and "test/"). The main effect is for projectile-toggle-between-implementation-and-test, so these defaults will be used as a fallback if no other method can be found for finding an impl/test file.

There was a breaking change in #1734 (sorry!) which removed this fallback, so project types without a src-dir or related-files-fn property wouldn't have a method for finding corresponding test/impl files, as shown in #1765. This fallback is not always particularly useful however, for example when your implementation file doesn't contain "src/", this PR throws an error in such cases.

I've also tweaked some error messages around this area to hopefully make debugging a little easier:

Error Old Message New Message
No method was found for determining the (base) file name for a test/impl file "Project type foo not supported!" "Cannot determine a test file name, one of "test-suffix" or "test-prefix" must be set for project type foo"(or an equivalent message for test -> impl)
An appropriate test file was found for an impl file, but projectile-create-missing-test-files is not set "No matching test file found for project type foo" "Determined test file to be "foo", which does not exist. Set `projectile-create-missing-test-files' to allow `projectile-find-implementation-or-test' to create new files"
src-dir and test-dir are set for a project type, but the impl/test file does not contain these as substrings No error "Attempted to find a test file by switching this project type's (foo) src-dir property "src" with this project type's test-dir property "test", but foo/bar does not contain "src" (or an equivalent message for test -> impl)

Before submitting a PR make sure the following things have been done (and denote this
by checking the relevant checkboxes):

  • The commits are consistent with our contribution guidelines
  • You've added tests (if possible) to cover your change(s)
  • All tests are passing (eldev test)
  • The new code is not generating bytecode or M-x checkdoc warnings
  • You've updated the changelog (if adding/changing user-visible functionality)
  • You've updated the readme (if adding/changing user-visible functionality)

Thanks!

Use "src/" and "test/" as defaults for the src-dir and test-dir
attributes of a project type when toggling between implementation and
test files.

Improve error messages for implementation and test file toggling
@@ -3674,6 +3749,25 @@ to a custom function, else return nil."
#'projectile--test-name-for-impl-name)
(projectile-project-root)))))

(defmacro projectile--acond (&rest clauses)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added acond from anaphora.el (though with a tweak for emacs 25 compat) in an effort to make projectile--find-matching-file and projectile--find-matching-test a bit nicer. If you prefer it I can remove it and go back to using the chain of if-lets.

@@ -530,6 +530,22 @@ See also `projectile-update-mode-line'."
:type 'function
:package-version '(projectile . "2.0.0"))

(defcustom projectile-default-src-directory "src/"
"The default value of a project's src-dir property.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry I'm not sure the convention for :package-version, do you wait until a new release before adding this?

@bbatsov
Copy link
Owner

bbatsov commented Apr 19, 2022

The fix looks good. Thanks for tackling this!

@LaurenceWarne
Copy link
Contributor Author

Thanks 🙂

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