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

Change to mix.exs directory before format #420

Merged
merged 1 commit into from
Mar 19, 2019

Conversation

michaelvobrien
Copy link
Contributor

  • Set the default-directory to where mix.exs is located, because mix
    is meant to be run from the project root directory. Also, mix format
    looks for .formatter.exs files in subdirectories.

  • If mix.exs is NOT found, the original default-directory and
    default formatter are used for mix format.

  • Create the temp file in the current directory, because mix format
    uses path patterns.

See:

- Set the `default-directory` to where mix.exs is located, because mix
  is meant to be run from the project root directory. Also, mix format
  looks for .formatter.exs files in subdirectories.

- If mix.exs is NOT found, the original `default-directory` and
  default formatter are used for mix format.

- Create the temp file in the current directory, because mix format
  uses path patterns.

See:

- elixir-lang/elixir#7328 (comment)

- elixir-lang/elixir#7398 (comment)
@Trevoke
Copy link
Contributor

Trevoke commented Jun 5, 2018

This is related to #415.

@axelson
Copy link
Contributor

axelson commented Nov 2, 2018

Will this work with an umbrella project where the .formatter.exs to be used is in the umbrella root? I ask because it seems like the code will pick up on the apps/web_project/mix.exs without looking for the the root mix.exs.

@Trevoke
Copy link
Contributor

Trevoke commented Nov 7, 2018

This issue is mostly related to #415 and #421 -- in #415, it came up that the root formatter in an umbrella app had an umbrella option that could be created. This indicates that the problem may be a tad more complex: if there are two formatter.exs, one in the umbrella app and one in the root, which one should take precedence?

Looking at the code now I'm a tad worried because default-directory is an emacs-provided variable and I don't much like modifying them. We need to look into what can be done to not rely on that value.

@Trevoke
Copy link
Contributor

Trevoke commented Nov 7, 2018

  1. As per the issue mentioned by @axelson I wrote something on the plane today which may solve the problem, assuming we want to give the top-most formatter precedence: https://github.com/Trevoke/lsp-elixir/blob/master/lsp-elixir.el#L71

  2. As for not overriding default-directory, I think it's slightly cleaner to do something like this:

(with-temp-buffer
  (find-file directory-to-visit)
  (do-stuff))

@Trevoke Trevoke merged commit b86aab2 into elixir-editors:master Mar 19, 2019
J3RN pushed a commit to J3RN/emacs-elixir that referenced this pull request Apr 24, 2021
* Switch to github workflows

Travis open source version is going away at the end of the year. Also
the wait times are an hour+

* Update versions of elixir/erlang tested
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants