zed-gdscript icon indicating copy to clipboard operation
zed-gdscript copied to clipboard

Feature request: BBCode formatting in doc strings

Open drmgc opened this issue 6 months ago • 11 comments

GDScript uses BBCode for formatting code docs.

Currently, the docstrings are shown unparsed:

Image

It would be nice to have them properly formatted. At least source code blocks and some basic formatting tags like [br], [b], etc

drmgc avatar Jun 20 '25 12:06 drmgc

It would definitely be nice, but currently it's outside of our control with Zed, unfortunately. We don't have a way to hook into what we get from the language server, as far as I know. We can only hook Zed with the language server and the debugger adapter provided by the engine and receive stuff from the engine as is.

I just checked the extension API that now has the debugger adapter support but couldn't find something that would allow us to see incoming text and transform it. If someone sees something like this moving forward, please let me know!

NathanLovato avatar Jun 20 '25 14:06 NathanLovato

BBCode is converted to markdown in the language server. It doesn't work properly for the the multi language code blocks at the moment though. But [b] should work just fine.

HolonProduction avatar Jul 08 '25 08:07 HolonProduction

I see! Thanks for the explanation. It sounds like it's a matter of adding conversion of codeblocks to markdown code fences in the language server upstream then?

NathanLovato avatar Jul 08 '25 09:07 NathanLovato

Yeah the whole BBCode -> Markdown thing has to be adjusted a bit. It's missing some stuff most notably code blocks.

HolonProduction avatar Jul 08 '25 09:07 HolonProduction

@HolonProduction may I ask if you could point me to the folder/files that would need changes in Godot? This is probably something I could contribute on my days off within the next few weeks, if nobody is already working on this.

NathanLovato avatar Jul 08 '25 09:07 NathanLovato

https://github.com/HolonProduction/godot/blob/53be3b78d1634406f1fb29e3802c608a5f5104a1/modules/gdscript/language_server/godot_lsp.h#L1941-L1991

I'm personally a bit hesitant about touching this, since I don't like the general search and replace approach. There are some edge cases that probably aren't possible to solve without using a real parser.

Implementing a quick fix for [codeblocks] shouldn't be that hard though. While you are at it, I'm pretty sure the [codeblock language="gdscript"] syntax doesn't work right now, either.

Best solution I can think of is supporting [codeblock language="gdscript"] and then replacing [language] with [codeblock language="language"] while inside of [codeblocks] before running the normal logic.

HolonProduction avatar Jul 08 '25 09:07 HolonProduction

@HolonProduction Thank you very much! The current "brute force" approach may have little caveats, though an advantage is it's also very simple code.

You could also do minimal "parsing" just for the codeblock tag, still with simple string processing (find "[codeblock", then scan from there, reading any attributes until a closing "]").

Who's/who are the maintainers of this area? I'm generally fine with contributing whatever is wanted. A bbcode scanner-based parser is a little more code but it's nothing complicated. Before starting something like this I'd just like to get the desired solution validated by the person(s) who decide what goes in to be sure it can go in.

NathanLovato avatar Jul 08 '25 11:07 NathanLovato

Not sure if we have a dedicated LSP maintainer, probably just falls under the GDScript team, you might wanna ask on Rocket chat about it.

Thing about a full parser is like that it might duplicate stuff from RichtTextLabel and LSP kinda has this problem of not getting updated correctly when other parts change. So maybe we should just stay with the minimal "brute force" way for now 🤔

HolonProduction avatar Jul 08 '25 11:07 HolonProduction

Makes sense, I'll do that! Thank you.

NathanLovato avatar Jul 08 '25 13:07 NathanLovato

Note for everyone: This issue should be fixed in a future Godot version, with this change: https://github.com/godotengine/godot/pull/108497

NathanLovato avatar Aug 25 '25 18:08 NathanLovato

Implemented by godotengine/godot#113099 (superseding godotengine/godot#108497)!

Repiteo avatar Nov 24 '25 16:11 Repiteo

Thank you! I'll keep this open for now for documentation purposes until the 4.6 stable release.

NathanLovato avatar Dec 14 '25 20:12 NathanLovato