diff options
| author | DanielGavin <danielgavin5@hotmail.com> | 2022-09-08 18:02:43 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-09-08 18:02:43 +0200 |
| commit | ff2df9fb432064f23356346b1764269523258f04 (patch) | |
| tree | ddd3e03a9d5f397530c0402671e2f54bcbabf49b | |
| parent | 9e3ca7b83888fdcf0228e1f71a91c07317d8a73f (diff) | |
| parent | f1128b4d7fa58e16a2f0174e72cfbc48f260c6a7 (diff) | |
Merge pull request #149 from nico-bb/master
fix for empty disabled_blocks and added test
| -rw-r--r-- | src/odin/printer/printer.odin | 7 | ||||
| -rw-r--r-- | src/odin/printer/visit.odin | 5 | ||||
| -rw-r--r-- | tools/odinfmt/tests/.snapshots/comments.odin | 6 | ||||
| -rw-r--r-- | tools/odinfmt/tests/comments.odin | 8 |
4 files changed, 24 insertions, 2 deletions
diff --git a/src/odin/printer/printer.odin b/src/odin/printer/printer.odin index b033d68..2f7518d 100644 --- a/src/odin/printer/printer.odin +++ b/src/odin/printer/printer.odin @@ -31,6 +31,8 @@ Printer :: struct { Disabled_Info :: struct { text: string, + empty: bool, + start_line: int, end_line: int, } @@ -119,11 +121,13 @@ make_printer :: proc( build_disabled_lines_info :: proc(p: ^Printer) { found_disable := false disable_position: tokenizer.Pos + empty := true for group in p.comments { for comment in group.list { if strings.contains(comment.text[:], "//odinfmt: disable") { found_disable = true + empty = true disable_position = comment.pos } else if strings.contains(comment.text[:], "//odinfmt: enable") && found_disable { @@ -131,8 +135,10 @@ build_disabled_lines_info :: proc(p: ^Printer) { end := comment.pos.offset + len(comment.text) disabled_info := Disabled_Info { + start_line = disable_position.line, end_line = comment.pos.line, text = p.src[begin:end], + empty = empty, } for line := disable_position.line; @@ -144,6 +150,7 @@ build_disabled_lines_info :: proc(p: ^Printer) { found_disable = false } } + empty = false } } diff --git a/src/odin/printer/visit.odin b/src/odin/printer/visit.odin index 9ad25fe..60e6446 100644 --- a/src/odin/printer/visit.odin +++ b/src/odin/printer/visit.odin @@ -142,8 +142,11 @@ visit_comment :: proc( document = cons(document, newline(newlines_before_comment_limited)) if comment.text[:2] != "/*" { - if comment.pos.line in p.disabled_lines { + if info, is_disabled := p.disabled_lines[comment.pos.line]; is_disabled { p.source_position = comment.pos + if info.start_line == comment.pos.line && info.empty { + return info.end_line - info.start_line, cons(escape_nest(document), text(info.text)) + } return 1, empty() } else if comment.pos.line == p.source_position.line && p.source_position.column != 1 { diff --git a/tools/odinfmt/tests/.snapshots/comments.odin b/tools/odinfmt/tests/.snapshots/comments.odin index 262d80e..5d7ffb7 100644 --- a/tools/odinfmt/tests/.snapshots/comments.odin +++ b/tools/odinfmt/tests/.snapshots/comments.odin @@ -40,3 +40,9 @@ bracket_comments_alignment :: proc() { // etc.. } } + +empty_odin_fmt_block :: proc() { + //odinfmt: disable + //a := 10 + //odinfmt: enable +} diff --git a/tools/odinfmt/tests/comments.odin b/tools/odinfmt/tests/comments.odin index a7bea72..6d0eb6f 100644 --- a/tools/odinfmt/tests/comments.odin +++ b/tools/odinfmt/tests/comments.odin @@ -39,4 +39,10 @@ bracket_comments_alignment :: proc() { a := 10 // etc.. } -}
\ No newline at end of file +} + +empty_odin_fmt_block :: proc() { + //odinfmt: disable + //a := 10 + //odinfmt: enable +} |