Closed levidavidmurray closed 11 months ago
@levidavidmurray annotations are being put into the same line with the function header deliberately. Can you elaborate a bit more about what is the actual problem?
@rpc
varies in length, making it far less readable than simply keeping it above the header (in my opinion).
I took a stab at a crude implementation here and thought I hacked together enough of a solution to unblock me...
https://github.com/Scony/godot-gdscript-toolkit/assets/46084870/26a44c46-eb0c-40d9-9cc9-db0c194772f5
But I had never even heard of lark before this and couldn't figure out how to add an [annotation _NL]
rule to func_def
without it overriding ("colliding"?) with the previously defined standalone annotation rules.
https://github.com/Scony/godot-gdscript-toolkit/assets/46084870/198506b9-7d1d-4483-9c1f-af38a1b863a3
I tried a bunch of alternatives, such as compounding func_def
within _class_stmt
, but that was no better than simply leaving the grammar unchanged. I spent way more time yesterday than I should have trying to make the annotation a part of the func_def
tree... so I think I'm just going to go with a crude one off change in format_block
to prevent putting @rpc
on the same line as func def
.
I suppose this is very much personal preference and I'm going to go ahead with a very naive solution, so I won't bother making a PR. But I am curious what the ideal way to achieve this would've been.
Okay, if the problem is about readability then that's a fair point. Since functions are almost always multi-line it probably makes sense to put annotations in separate lines always. I'll explore the current test suite and I'll try incorporating your fix. Probably it should not break anything.
Yeah, the issue title was definitely a misnomer. Changed it to more accurately reflect the problem.
It looks like https://github.com/Scony/godot-gdscript-toolkit/commit/6455fa6c67856354fe37864282985748888bab60 added support for annotations within the function body, but not the function header.
Godot 4's multiplayer API has a new
@rpc
annotation, but the current formatter is putting the annotation and function header on the same line.https://github.com/Scony/godot-gdscript-toolkit/assets/46084870/441e9780-27fa-4e14-b21f-f92fd0d2709c