projectile icon indicating copy to clipboard operation
projectile copied to clipboard

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

Open shouya opened this issue 4 years ago • 3 comments

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 avatar Jul 07 '21 08:07 shouya

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)

shouya avatar Jul 07 '21 08:07 shouya

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!

stale[bot] avatar Apr 16 '22 10:04 stale[bot]