From fdc97748002f7ca612b04977fd8b8e74b9b05468 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?fn=20=E2=8C=83=20=E2=8C=A5?= <70830482+FnControlOption@users.noreply.github.com> Date: Wed, 23 Feb 2022 10:35:49 -0800 Subject: [PATCH] Fix indentation of ASTNode#to_s(emit_doc: true) --- spec/compiler/parser/to_s_spec.cr | 1 + src/compiler/crystal/syntax/to_s.cr | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/spec/compiler/parser/to_s_spec.cr b/spec/compiler/parser/to_s_spec.cr index 1b907c74048d..dc0465639fe9 100644 --- a/spec/compiler/parser/to_s_spec.cr +++ b/spec/compiler/parser/to_s_spec.cr @@ -117,6 +117,7 @@ describe "ASTNode#to_s" do expect_to_s "macro foo\n\\{%@type %}\nend" expect_to_s "enum A : B\nend" expect_to_s "# doc\ndef foo\nend", emit_doc: true + expect_to_s "class Foo\n # doc\n def foo\n end\nend", emit_doc: true expect_to_s "foo[x, y, a: 1, b: 2]" expect_to_s "foo[x, y, a: 1, b: 2] = z" expect_to_s %(@[Foo(1, 2, a: 1, b: 2)]) diff --git a/src/compiler/crystal/syntax/to_s.cr b/src/compiler/crystal/syntax/to_s.cr index 743c48244069..947f9259c91c 100644 --- a/src/compiler/crystal/syntax/to_s.cr +++ b/src/compiler/crystal/syntax/to_s.cr @@ -25,12 +25,12 @@ module Crystal def visit_any(node) if @emit_doc && (doc = node.doc) && !doc.empty? - doc.each_line(chomp: false) do |line| - append_indent + doc.each_line(chomp: true) do |line| @str << "# " @str << line + newline + append_indent end - @str.puts end if (macro_expansion_pragmas = @macro_expansion_pragmas) && (loc = node.location) && (filename = loc.filename).is_a?(String)