Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: crystal-lang/crystal
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 017f9c969f77
Choose a base ref
...
head repository: crystal-lang/crystal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 2d2ebac624d6
Choose a head ref
  • 2 commits
  • 2 files changed
  • 2 contributors

Commits on Oct 24, 2017

  1. Copy the full SHA
    f8af24e View commit details

Commits on Oct 25, 2017

  1. Merge pull request #5176 from MakeNowJust/fix/crystal-format/indent-i…

    …mplicit-exception-handler-with-do-end
    
    Formatter: correctly indent implicit exception handler of do/end block
    asterite authored Oct 25, 2017
    Copy the full SHA
    2d2ebac View commit details
Showing with 7 additions and 4 deletions.
  1. +1 −0 spec/compiler/formatter/formatter_spec.cr
  2. +6 −4 src/compiler/crystal/tools/formatter.cr
1 change: 1 addition & 0 deletions spec/compiler/formatter/formatter_spec.cr
Original file line number Diff line number Diff line change
@@ -198,6 +198,7 @@ describe Crystal::Formatter do
assert_format "def foo\n 1\n #\n\n\nrescue\nend", "def foo\n 1\n #\n\nrescue\nend"

assert_format "loop do\n 1\nrescue\n 2\nend"
assert_format "loop do\n 1\n loop do\n 2\n rescue\n 3\n end\n 4\nend"

assert_format "foo"
assert_format "foo()"
10 changes: 6 additions & 4 deletions src/compiler/crystal/tools/formatter.cr
Original file line number Diff line number Diff line change
@@ -62,7 +62,7 @@ module Crystal
@inside_lib : Int32
@inside_struct_or_union : Int32
@dot_column : Int32?
@def_indent : Int32
@implicit_exception_handler_indent : Int32
@last_write : String
@exp_needs_indent : Bool
@inside_def : Int32
@@ -100,7 +100,7 @@ module Crystal
@inside_lib = 0
@inside_struct_or_union = 0
@dot_column = nil
@def_indent = 0
@implicit_exception_handler_indent = 0
@last_write = ""
@exp_needs_indent = true
@inside_def = 0
@@ -1317,7 +1317,7 @@ module Crystal
end

def visit(node : Def)
@def_indent = @indent
@implicit_exception_handler_indent = @indent
@inside_def += 1

write_keyword :abstract, " " if node.abstract?
@@ -2500,7 +2500,9 @@ module Crystal
write " do"
next_token_skip_space
body = format_block_args node.args, node
old_implicit_exception_handler_indent, @implicit_exception_handler_indent = @implicit_exception_handler_indent, @indent
format_nested_with_end body
@implicit_exception_handler_indent = old_implicit_exception_handler_indent
elsif @token.type == :"{"
write "," if needs_comma
write " {"
@@ -3525,7 +3527,7 @@ module Crystal
accept node.body
write_line unless skip_space_or_newline last: true
implicit_handler = true
column = @def_indent
column = @implicit_exception_handler_indent
else
if node.suffix
accept node.body