Please sign in to comment.
Add hints on mismatched do/end and others pairs
When you are working on large files and you add new code, you may forget to add a `do` or an `end`. In those cases, the error message usually points to the first `do` or the last `end` in the file, which are usually far away from the source of the error. This pull request adds a simple heuristic based on the indentation of the tokens, to try to provide hints of where the source may be. Those hints are not deterministic but they may be able to point users to the source of the problem. For example, in this case: defmodule MyApp do def one do # end def two do end end we know that we now that `def two do` is happening on the same indentation as `def one do`, which may mean that `def one do` was not closed properly. We store this as a hint in case the terminators do not match later. Similarly, in the case below: defmodule MyApp do def one end def two do end end The `end` on line 3 will end-up closing the defmodule `do`, on line 1. Because their indentation do not match, it may be that there is a missing `do`, where the `end` was supposed to align. Some basic testing show those heuristics work on the majority of the cases, but we will only be sure when we have enough feedback from the community.
- Loading branch information...
Showing with 282 additions and 162 deletions.
- +18 −9 lib/elixir/src/elixir.erl
- +3 −1 lib/elixir/src/elixir.hrl
- +0 −4 lib/elixir/src/elixir_errors.erl
- +4 −4 lib/elixir/src/elixir_interpolation.erl
- +6 −10 lib/elixir/src/elixir_parser.yrl
- +167 −115 lib/elixir/src/elixir_tokenizer.erl
- +75 −10 lib/elixir/test/elixir/kernel/errors_test.exs
- +1 −1 lib/elixir/test/erlang/string_test.erl
- +5 −5 lib/elixir/test/erlang/tokenizer_test.erl
- +3 −3 lib/iex/test/iex/interaction_test.exs
Oops, something went wrong.