bbatsov / projectile

Project Interaction Library for Emacs
https://docs.projectile.mx
GNU General Public License v3.0
4k stars 584 forks source link

Jump to non-existence test from Elixir implementation gets an unwanted filename #1686

Open shouya opened 3 years ago

shouya commented 3 years ago

Suppose I have a mix project consisting of a file lib/foo.ex, then I run (projectile-toggle-between-implementation-and-test), projectile will land on a new file at test/foo_test.ex.

The generated file name of this shape should be expected for most languages. But for Elixir, by conventions, the test files should be elixir script files (.exs) rather than elixir source files (.ex).

From Projectile doc there is customizable field :test-suffix that looks promising. However, it only affects the part of the test file name before the extname (i.e. the _test part as oppose to _test.exs).

I checked the source code and confirmed that the extname of the test file is hard-coded to be the same as the impl file.

Is there any possibility to support this feature of having different extname for test and impl files? Thanks.

shouya commented 3 years ago

My current workaround is to patch projectile--test-name-for-impl-name function like this:

  ;; Elixir: jump to *_test.exs instead of *_test.ex
  (defun shou/fix-exs-test-file-name (name)
    (cond
     ((string-suffix-p "_test.ex" name) (concat name "s"))
     (t name)))

  (advice-add #'projectile--test-name-for-impl-name
              :filter-return
              #'shou/fix-exs-test-file-name)
stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution and understanding!