Skip to content

Update syntax: alternative block comment and nvim-lsp based highlights for bold and italic#106

Open
yangwenbo99 wants to merge 2 commits intokaarmu:mainfrom
yangwenbo99:fea/bold
Open

Update syntax: alternative block comment and nvim-lsp based highlights for bold and italic#106
yangwenbo99 wants to merge 2 commits intokaarmu:mainfrom
yangwenbo99:fea/bold

Conversation

@yangwenbo99
Copy link
Copy Markdown
Contributor

Hi,

I just have some time to fix two problems I have encountered in recent months.

The first one is inserting a "/*" in a large document stresses my CPU and destroys the whole file's syntax. I use Vim's C syntax highlight file's strategy to replace the block comment.

The second issue is about italic and bold fonts. I added an option "typst_syntax_use_lsp" to use LSP for highlighting. See the attachment for the effects.

Since there are so many marginal cases for Typst syntax, I am thinking that syntax highlighting should probably be done using LSP in the future. However, the current LSP is rather limited in highlighting, as it does not provide any tree-based highlighting.

Before:
Screenshot

After:
Screenshot

kaarmu added a commit that referenced this pull request Aug 25, 2024
@kaarmu kaarmu added the bug Something isn't working label Aug 25, 2024
@kaarmu
Copy link
Copy Markdown
Owner

kaarmu commented Aug 25, 2024

Thanks for the PR!

I've seperated the comment fix to branch fix-106-comment. Can you just double-check that I didn't miss anything/that it fixes your issue with performance.

Regarding bold/italics, I really appreciate relying on LSP. Though, I want to hold on to that a little bit. Moreover, even though LSPs can perhaps better/more easily capture the right highlight group, I am also aiming to have standalone support as much as possible.

@yangwenbo99
Copy link
Copy Markdown
Contributor Author

I think fix-106-comment is good.

For bold/italics, on the one hand, I do think it is very challenging to do it using vim's syntax file. On the other hand, there are a lot of restrictions for LSP-based highlighting, even though it is faster and more robust:

  • the built-in LSP only exists in Neovim. I am not even sure whether other LSP clients for vim provide the same interface
  • current Typst LSP server only provides token-based highlighting. It does not give support tree-based information. This means, we cannot use it to support collapse.

In my proposed (temporary) modification, I added an option for users to choose whether to use LSP or not.

In the long run, I think it would be better to offer two options, (a) pure vim syntax file highlighting, with limited capability and (b) (mostly) LSP/treesitter-based highlighting.

There is already a treesitter implementation for typst, and I am looking at it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants