Skip to content

Broken indentation inside with statements #385

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

Closed
voger opened this issue Dec 6, 2017 · 5 comments
Closed

Broken indentation inside with statements #385

voger opened this issue Dec 6, 2017 · 5 comments
Labels

Comments

@voger
Copy link

voger commented Dec 6, 2017

For some reason I get weird indentation inside with statements. Here is an example

Actual

  def resend_confirmation(username) when is_binary(username) do
    with user = %User{confirmed_at: nil} <- get_by(username: username) do
      {:ok, user} = 
        user 
        |> DB.add_confirm_token 
        |> update_user() 
                                                                         Log.info(%Log{user: user.id, message: "send new confirmation"}) 
                                                                         send_welcome(user)
                                                                         {:ok, user}
    else
      nil ->
        {:error, "not found"}
      %User{email: email} ->
        Email.already_confirmed(email)
        {:error, "already confirmed"}
    end
  end

Expected

  def resend_confirmation(username) when is_binary(username) do
    with user = %User{confirmed_at: nil} <- get_by(username: username) do
      {:ok, user} = 
        user 
        |> DB.add_confirm_token 
        |> update_user() 
        Log.info(%Log{user: user.id, message: "send new confirmation"}) 
        send_welcome(user)
        {:ok, user}
    else
      nil ->
        {:error, "not found"}
      %User{email: email} ->
        Email.already_confirmed(email)
        {:error, "already confirmed"}
    end
  end

Another example

Actual

  def create_user(params) do
    profile = UserProfile.registration_changeset(%UserProfile{}, params)

    user_cs =
      %User{}
      |> User.registration_changeset(params)
      |> put_assoc(:user_profile, profile)

    with {:ok, user} <- Repo.insert(user_cs, returning: false) do
      Log.info(%Log{user: user.id, message: "user created"})
                                                                 send_welcome(user)
                                                                 {:ok, user}
    end
  end

Expected

  def create_user(params) do
    profile = UserProfile.registration_changeset(%UserProfile{}, params)

    user_cs =
      %User{}
      |> User.registration_changeset(params)
      |> put_assoc(:user_profile, profile)

    with {:ok, user} <- Repo.insert(user_cs, returning: false) do
      Log.info(%Log{user: user.id, message: "user created"})
      send_welcome(user)
      {:ok, user} 
    end
  end

P.S.: Is there any way to disable indentation temporarily until a solution for this issue is found?

@jbodah
Copy link
Collaborator

jbodah commented Dec 6, 2017

Thanks for this. with has a few known issues but it's good to have these for test cases

P.S.: Is there any way to disable indentation temporarily until a solution for this issue is found?

I would recommend forking this repo and stubbing this function to just return -1 https://github.com/elixir-editors/vim-elixir/blob/master/autoload/elixir/indent.vim#L319

@jbodah jbodah added the bug label Dec 6, 2017
@dylan-chong
Copy link

This situation may also be relevant

When with is in a sigil, it seems to be able to confuse the indenting

  r = ~r"with"
              waaaaaaa

If ~r is removed, indenting works as expected

@clarkenciel
Copy link

having with in comments also seems to break indentation after the comment.

# This file is responsible for configuring your application
# and its dependencies with the aid of the Mix.Config module.
                            use Mix.Config

                            import_config "#{Mix.env}.exs"

vs.

# This file is responsible for configuring your application
# and its dependencies 
use Mix.Config

import_config "#{Mix.env}.exs"

@jbodah
Copy link
Collaborator

jbodah commented Jan 22, 2018

@clarkenciel thanks for the report, pulling this out into it's own issue

@jbodah
Copy link
Collaborator

jbodah commented Aug 3, 2018

Fixed in 1543e37

@jbodah jbodah closed this as completed Aug 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants