hangyav / textLSP

Language server for text spell and grammar check with various tools.
GNU General Public License v3.0
40 stars 2 forks source link

Support typst as a document format #24

Open lukasjuhrich opened 2 months ago

lukasjuhrich commented 2 months ago

Hi,

I want to make textlsp work with typst (gh). It has a working tree-sitter-implementation (this is what helix currently uses).

I have never worked with tree-sitter and would like to take this as an opportunity to learn the topic, so please treat me as completely ignorant.

What do I have to do to implement this? I assume something similar as in documents/latex, but where is the upstream grammar specified?

hangyav commented 2 months ago

Hi,

Thanks for your interest in the project. I'd be happy for a PR adding support for typst.

AFAIK there is no grammar specified for how exactly to extract text from the TS parse. So far I looked at the parse of a few files to figure out the relevant content/nodes. To do this I used a TS playground tool (neovim in my case, helix might have an equivalent or simply this).

The documentation on how to add new parsers is a bit weak at this point, but yes latex.py:_iterate_text_nodes which is the main function to implement is a good place to start. The main idea is to sequentially return TextNode objects representing words and whitespaces to build the cleaned content of a given file (textual content to be analysed by the tools). Important building blocks are paragraphs (text block separated from others by an empty line), which you can think of as atomic units for the analysers. So you might need to add empty lines even though there isn't one in the source, e.g., after a section title even if the next paragraph is not separated with and empty line. Also, take a look at the tests to see some examples.

Hope this helps to get started. Let me know if there's anything that's not clear.