prettier-plugin-motoko
prettier-plugin-motoko copied to clipboard
complex indenting example with odd behaviour
This was motoko code generated by Go. I try and make the generator as close to the prettified output as possible.
so then I put a newline after update(, and Ctrl-S
and then finally one after do { on line 81, and Ctrl-S
I've found myself just trying to enter random newlines to make it format correctly, and I wasn't sure this was the desired behaviour.
This looks like a possible regression from #56. I'll see if there's a way to make this work in the way you're expecting.
If you get a chance, would you mind sending this code snippet (or anything with similar behavior) in plain text so I can play around with it?
here we go
// punch
switch (update(
M.content_Ability, "punch", [("iconId", #text(do { switch (TextMap.get(pks, itemKey("iconId", "xxx"))) { case (?pk) { pk }; case (null) { "ERR" } } }))])) {
case (#ok res) { buf.add(res) };
case (#err e) { return #err(e) };
};
// punch
switch (
update(
M.content_Ability,
"punch",
[("iconId", #text(do { switch (TextMap.get(pks, itemKey("iconId", "xxx"))) { case (?pk) { pk }; case (null) { "ERR" } } }))],
),
) {
case (#ok res) { buf.add(res) };
case (#err e) { return #err(e) };
};
// punch
switch (
update(
M.content_Ability,
"punch",
[(
"iconId",
#text(
do {
switch (TextMap.get(pks, itemKey("iconId", "xxx"))) {
case (?pk) { pk };
case (null) { "ERR" };
};
},
),
)],
),
) {
case (#ok res) { buf.add(res) };
case (#err e) { return #err(e) };
};
At the moment, the formatter is very selective about adding line breaks within parentheses. You might be able to get around this by adding newlines in expression blocks. For example, would it be possible to output do {\n ... }
, switch {\n ...}
, etc. in your code generation? This should work if you're expecting to run the formatter directly afterwards. Otherwise, let me know and I'll increase the priority of fixing this issue.
thats fine, no rush :) we've got less of a focus on this I just wondered if it was some low hanging thing to fix.