tact-lang / tact-docs

Tact main documentation
https://docs.tact-lang.org
40 stars 36 forks source link

See if we can re-use tree-sitter-tact for syntax highlighting in code snippets #198

Open anton-trunov opened 2 months ago

anton-trunov commented 2 months ago

It should be in principle possible, since GitHub uses it in Linguist.

No more regex-based highlighting! :)

This would make things like #183 much easier

novusnota commented 2 months ago

It is possible, but would require some workarounds to fix contexts.

For example, the following is how tree-sitter tries to parse a small snippet of a single statement. Notice, that it fails because of lack of proper context:

image

And here's when we add more context to the statement, such as the body of a global static function fun _(). Now, tree-sitter is able to parse everything correctly:

image

This workaround will make many code snippets a tad more verbose, so there are other approaches trying to pre-process code blocks as if they were encapsulated in global static function bodies in the first place.

Moreover, the TextMate grammar docs are using needs to exist in order for VSCode extension and Sublime Text package to work. So, after a discussion with @anton-trunov we figured, that it's best to improve the current TextMate grammar and make a single upstream source of it, such that tact-docs, tact-vscode, upcoming Sublime Text package, Nujan IDE and others can consume it to get decent syntax highlighting.

Closing this issue as wontfix, at least for the foreseeable future :)

anton-trunov commented 2 months ago

Closing this issue as wontfix, at least for the foreseeable future :)

Maybe not today or next month, but in a year. Admittedly, we don't the manpower to work on this now. But what if someone from the TON community comes along and gets excited to work on something like this. Especially because we have a grants and bounties program to support community members.

novusnota commented 2 months ago

would require some workarounds to fix contexts

We may try to do something like the expandable/collapsible code blocks, as seen in Kotlin docs:

Collapsed code block

Expanded code block

Additionally, and this is well out of scope of this issue, we may try to bring Blueprint test runner (or some other approach) into docs to support running Tact's code blocks directly in docs.