diff options
| author | Daniel Gavin <danielgavin5@hotmail.com> | 2022-09-14 18:36:39 +0200 |
|---|---|---|
| committer | Daniel Gavin <danielgavin5@hotmail.com> | 2022-09-14 18:36:39 +0200 |
| commit | b4dafb21e5ace34940242a515cfe08f663dbc832 (patch) | |
| tree | c2ce033651b9fe03c270c9ec1e53a7b1b4839237 | |
| parent | 43144347e05e03446052db1ba87a1c2c97072221 (diff) | |
| parent | ff2df9fb432064f23356346b1764269523258f04 (diff) | |
Merge branch 'master' of github.com:DanielGavin/ols
| -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 930274a..dd724c9 100644 --- a/src/odin/printer/printer.odin +++ b/src/odin/printer/printer.odin @@ -32,6 +32,8 @@ Printer :: struct { Disabled_Info :: struct { text: string, + empty: bool, + start_line: int, end_line: int, } @@ -120,11 +122,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 { @@ -132,8 +136,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; @@ -145,6 +151,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 6fa4798..9e5815b 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 +} |