diff options
| author | DanielGavin <danielgavin5@hotmail.com> | 2023-06-25 15:56:43 +0200 |
|---|---|---|
| committer | DanielGavin <danielgavin5@hotmail.com> | 2023-06-25 15:56:43 +0200 |
| commit | 065a0d88b405b043e73a5649cdc56d1317cf1f2f (patch) | |
| tree | 65c8cece98da0dc94f1e73772d71a891180a9792 | |
| parent | d4574616e26477ef67d347113a218b16567086c3 (diff) | |
Fix issue with chainings `do` would increase indentation in a block
| -rw-r--r-- | .gitignore | 34 | ||||
| -rw-r--r-- | src/odin/printer/visit.odin | 3 | ||||
| -rw-r--r-- | tools/odinfmt/tests/.snapshots/for.odin | 8 | ||||
| -rw-r--r-- | tools/odinfmt/tests/for.odin | 8 |
4 files changed, 36 insertions, 17 deletions
@@ -1,17 +1,17 @@ -*.exe
-*.pdb
-*.rdbg
-*.obj
-*.bc
-*.ll
-*.sublime-project
-*.sublime-workspace
-*.lib
-*.exp
-*.sqlite
-*.suo
-*node_modules
-ols
-odinfmt
-
-
+*.exe +*.pdb +*.rdbg +*.obj +*.bc +*.ll +*.sublime-project +*.sublime-workspace +*.lib +*.exp +*.sqlite +*.suo +*node_modules +/ols +/odinfmt + + diff --git a/src/odin/printer/visit.odin b/src/odin/printer/visit.odin index cc491e1..df48bbb 100644 --- a/src/odin/printer/visit.odin +++ b/src/odin/printer/visit.odin @@ -977,6 +977,7 @@ visit_stmt :: proc( set_source_position(p, v.pos) block := visit_block_stmts(p, v.stmts, len(v.stmts) > 1) + comment_end, _ := visit_comments( p, tokenizer.Pos{line = v.end.line, offset = v.end.offset}, @@ -984,6 +985,8 @@ visit_stmt :: proc( if block_type == .Switch_Stmt && !p.config.indent_cases { document = cons(document, block, comment_end) + } else if uses_do { + document = cons(document, cons(block, comment_end)) } else { document = cons(document, nest(cons(block, comment_end))) } diff --git a/tools/odinfmt/tests/.snapshots/for.odin b/tools/odinfmt/tests/.snapshots/for.odin new file mode 100644 index 0000000..6d2ddce --- /dev/null +++ b/tools/odinfmt/tests/.snapshots/for.odin @@ -0,0 +1,8 @@ +package odinfmt_test + +a :: proc() { + bag: bit_set[0 ..< 10] = {5} + for x in 0 ..< 10 do if x in bag { + fmt.println(x) + } +} diff --git a/tools/odinfmt/tests/for.odin b/tools/odinfmt/tests/for.odin new file mode 100644 index 0000000..e4168eb --- /dev/null +++ b/tools/odinfmt/tests/for.odin @@ -0,0 +1,8 @@ +package odinfmt_test + +a :: proc() { + bag: bit_set[0 ..< 10] = {5} + for x in 0 ..< 10 do if x in bag { + fmt.println(x) + } +} |