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

Add elixir-format function to format Elixir 1.6 files. #406

Merged
merged 2 commits into from May 27, 2018

Conversation

anildigital
Copy link
Contributor

@anildigital anildigital commented Oct 14, 2017

elixir-format function formats Elixir 1.6 files with new mix format command which will be available from Elixir 1.6.

@anildigital
Copy link
Contributor Author

anildigital commented Feb 9, 2018

@tonini Here is PR for elixir-format support in emacs-elixir. Let me know if you want any changes, I can do that. Hopefully this becomes part of emacs-elixir and see further contributions

@Trevoke
Copy link
Contributor

Trevoke commented Feb 14, 2018

Hi @anildigital - I'll get to this Monday, I promise.

@tonini
Copy link
Contributor

tonini commented Feb 15, 2018

Hi,

This looks nice, I would consider to add two add to things:

  1. Add a test suite for it.
  2. Include it into the emacs-* namespace something like elixir-format.....

@anildigital
Copy link
Contributor Author

@tonini I don't have any clue to write a test suite. I will see if anyone can help me. @ckruse

@ckruse
Copy link

ckruse commented Feb 18, 2018 via email

@anildigital
Copy link
Contributor Author

anildigital commented Feb 19, 2018

@ckruse @jekku @Trevoke You can do changes in https://github.com/anildigital/mix-format.el so that I can send updated PR here. I will be adding you all as Co-Authors to this PR. Thanks.

@anildigital
Copy link
Contributor Author

@Trevoke any update?

@Trevoke
Copy link
Contributor

Trevoke commented Feb 21, 2018

Hi @anildigital, I realize I didn't communicate well with you, I'm sorry. I'm a new maintainer of elixir-mode, and since Tonini beat me to the punch of requesting these changes, I thought you didn't need my input for now.

As far as the tests go, there are instructions in the CONTRIBUTING.md file and existing examples of tests you can use to guide yourself:

@anildigital
Copy link
Contributor Author

Thanks. I will follow these links. cc @ckruse

ckruse pushed a commit to anildigital/mix-format.el that referenced this pull request Mar 9, 2018
@draveness
Copy link

Hi, is this pull request ready to be merged?

@ckruse
Copy link

ckruse commented Mar 20, 2018

I'm not sure. I implemented tests and renamed everything to have a elixir-format- prefix. On my side everything seems to be ready for the merge.

@anildigital
Copy link
Contributor Author

Hi @ckruse we need to merge changes done in https://github.com/anildigital/mix-format.el to this PR. But before that.. could you please send a PR to https://github.com/anildigital/emacs-elixir with tests. I this test-helper.el is conflicting there. Thanks.

@lucca65
Copy link

lucca65 commented May 17, 2018

Hey! First of all, thanks for the effort on developing this feature! Any idea when this will be merged? Thanks!

@johnhamelink
Copy link

How would I test this in Spacemacs? 😄

@Trevoke
Copy link
Contributor

Trevoke commented May 21, 2018 via email

@anildigital anildigital changed the title Add mix-format function to format Elixir 1.6 files. Add elixir-format function to format Elixir 1.6 files. May 24, 2018
@anildigital
Copy link
Contributor Author

Hi @Trevoke @tonini, I have updated the PR with tests. The build is failing for an obvious reason, as tests are run against Elixir 1.0.5 version. Could you please check what can be done so that this PR can be merged. Thanks.

README.md Outdated
## Elixir Format

### Setup of elixir-format
Customize the elixir and mix pathes
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be paths.

@Trevoke
Copy link
Contributor

Trevoke commented May 26, 2018

Great, thank you for everyone's hard work.

I will figure out why the build is failing. In the meanwhile, @anildigital, I have a few requests:

  1. Please make sure the elixir-format functions are available to anyone who requires elixir-mode directly - it does not make sense to provide the formatting functions as part of this major mode without making them directly available. Also please adjust the README accordingly.
  2. Please change the README for the "format before save" section - it should just be the following:
;; Create a buffer-local hook to run elixir-format on save, only when we enable elixir-mode.
(add-hook 'elixir-mode-hook
          (lambda () (add-hook 'before-save-hook 'elixir-format nil t)))
  1. Please delete the elixir-format-before-save function, as using it may cause emacs to behave in unexpected ways for users of this mode.
  2. I'm unable to see in the tests how this code will behave if someone tries to call the format function with a version of Elixir that does not have the format task available. Which test covers this?

Thanks again for working on this!

@Trevoke
Copy link
Contributor

Trevoke commented May 26, 2018

@anildigital I have fixed the build. Please bring in the changes from this repo so you get the updated build config and Travis can do its work.

@anildigital anildigital force-pushed the master branch 3 times, most recently from 1c7a3db to 96e41d0 Compare May 27, 2018 10:04
@anildigital anildigital force-pushed the master branch 12 times, most recently from 0c31b83 to cf4357b Compare May 27, 2018 14:54
@anildigital
Copy link
Contributor Author

anildigital commented May 27, 2018

@Trevoke I have made changes as requested. The build is still failing for some reason I could not figure out. I ran tests on macOS and Ubuntu OSes and tests ran fine.

Regarding #4 you mentioned, I think devs mostly will be coding with Elixir 1.6 now on. It would be overkill to check Elixir version everytime we call the elixir-format function. Also even if someone configures this plugin and tries to use Elixir 1.5 and earlier version, the mix format command would fail, giving an error. Hope this consideration is fine.

@Trevoke
Copy link
Contributor

Trevoke commented May 27, 2018

Hi @anildigital, thank you! Now we can see how the PR compares to the existing test suite.

Regarding calling elixir-format with an older version of Elixir, an error message displayed to the user is all I would like. What I was asking was, "where is the test that shows the error message to the user"? It sounds like that is already existing behavior, I just would like it formalized in a test so we can formalize what the expected behavior is from now on.

Re: the failures, you can find information about them by following this link:

https://travis-ci.org/elixir-editors/emacs-elixir/builds/384390061

When you ran your tests, what were the versions of emacs, elixir and erlang that you were using?
One thing to remember is that we must maintain multiple versions of emacs as well, so even if you had success with your own version of emacs, it is no guarantee that will work everywhere else.

Most of the build jobs are failures where some code receives nil and expects a string, and the build that's running with 1.6.0 has four tests failing:

FAILED elixir-format-should-message-on-error
FAILED elixir-format-should-run-hook-before-formatting
FAILED indents-a-buffer
FAILED indents-a-buffer-and-undoes-changes

This build is also running on emacs 24.3.

@anildigital anildigital force-pushed the master branch 2 times, most recently from f5c2f33 to 687b9e2 Compare May 27, 2018 17:16
Co-Authored-By: Christian Kruse <ckruse@users.noreply.github.com>
Co-Authored-By: Peter Urbak <dragonwasrobot@users.noreply.github.com>
@anildigital
Copy link
Contributor Author

Thanks a lot, @Trevoke, builds are passing now with all supported versions.

I spent some time to specially handle the case where elixir-format is run with Elixir version lesser than 1.6. It's a bit complicated to capture that as currently, we are messaging "elixir-format failed: ..." message when it fails. Could we add that feature as separate PR? Thanks.

@Trevoke
Copy link
Contributor

Trevoke commented May 27, 2018

Hi @anildigital, I was trying to work with the package and I didn't realize there was an orthogonal error. I fixed it on your side and now I'm completely OK with this being merged in as-is. It turned out I wasn't seeing the error buffer pop up and I was worried that it took away from usability. I really like the way this was put together!

Thank you and everyone else for all their hard work, I'm merging it in. I'll wait a little bit before creating a stable release on Melpa.

@Trevoke Trevoke merged commit 8721118 into elixir-editors:master May 27, 2018
J3RN pushed a commit to J3RN/emacs-elixir that referenced this pull request Apr 24, 2021
* Purge consolidated protocols before compilation

Fixes elixir-editors#395

* move to dialyzer_test.exs

* add comments

* warn if ls fails
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.

None yet

7 participants