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

Fix block start pattern #583

Merged
merged 1 commit into from
Mar 13, 2025

Conversation

erszcz
Copy link
Contributor

@erszcz erszcz commented Mar 13, 2025

Hey,

Thanks for maintaining great support for Vim!

This PR fixes a somewhat annoying indentation issue that surfaced with:

Wallaby.Browser.fill_in(some_input_box, with: "some text")

The regex pattern used to discover a block when it spotted a with. This lead to the following code:

defmodule Broken do
  def test do
    f(:arg1, with: :arg2)
  end # ...when we hit Enter/Return here...
end

Being improperly indented:

defmodule Broken do
  def test do
    f(:arg1, with: :arg2)
      end
end

The more withs, the merrier:

defmodule Broken do
  def test do
    f(:arg1, with: :arg2)
    |> g(with: :arg3)
  end

      def test2 do # with 2 `with`s this line got indented like this

  end
end

This commit uses a negative lookahead to make sure the block start pattern only matches if the keyword is not immediately followed by a : colon character.

The regex pattern used to discover a block when it spotted a `with`.
This lead to the following code:

```elixir
defmodule Broken do
  def test do
    f(:arg1, with: :arg2)
  end # ...when we hit Enter/Return here...
end
```

Being improperly indented:

```elixir
defmodule Broken do
  def test do
    f(:arg1, with: :arg2)
      end
end
```

The more `with`s, the merrier:

```elixir
defmodule Broken do
  def test do
    f(:arg1, with: :arg2)
    |> g(with: :arg3)
  end

      def test2 do # with 2 `with`s this line got indented like this

  end
end
```

This commit uses a negative lookahead to make sure the block start pattern
only matches if the keyword is not immediately followed
by a `:` colon character.
@sodapopcan
Copy link
Collaborator

Oh thank you for this! This actually gives me an idea of what is causing some other indentation issues 🤔

@sodapopcan sodapopcan merged commit 1ec9aab into elixir-editors:master Mar 13, 2025
@erszcz erszcz deleted the fix-block-start-pattern branch March 13, 2025 23:07
@sodapopcan
Copy link
Collaborator

Oh man, I just ran into this... this is exactly what has been causing this super-annoying indentation problem all this time! Thanks again!!!!

@erszcz
Copy link
Contributor Author

erszcz commented Mar 20, 2025

I'm glad I could help! Thanks again for a great plugin!

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

2 participants