Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve syntax highlighting using a Language Server Protocol implementation #686

Open
2 of 14 tasks
ggrossetie opened this issue Jan 10, 2023 · 10 comments
Open
2 of 14 tasks

Comments

@ggrossetie
Copy link
Member

ggrossetie commented Jan 10, 2023

We currently rely on a TextMate grammar but it cannot properly parse AsciiDoc.

I think we should migrate to semantic highlighting: code.visualstudio.com/api/language-extensions/semantic-highlight-guide or LSP: code.visualstudio.com/api/language-extensions/language-server-extension-guide

If someone wants to give it a try, please feel free to do so!

Related issues:

@ggrossetie
Copy link
Member Author

It's worth noting that semantic tokens do not support embedded languages:

microsoft/vscode#163292

In other words, source blocks won't be properly highlighted in AsciiDoc.

I don't think we should adopt the semantic tokens feature until embedded languages are supported.

I guess our only solution right now is to use LSP.

@ggrossetie ggrossetie changed the title Improve syntax highlighting using a semantic token provider Improve syntax highlighting using a Language Server Protocol implementation Nov 12, 2023
@ViToni
Copy link
Contributor

ViToni commented Mar 26, 2024

Is this basically the same issue as #625 ?

@ggrossetie
Copy link
Member Author

Initially, I thought it would be possible to implement a syntax highlighter using semantic token provider, that's why I've created a new issue.

Since we need to use LSP, it's indeed a duplicate of #625. I think we should close #625 in favor of this one.

@ViToni
Copy link
Contributor

ViToni commented Mar 26, 2024

Looking into LSP has been on my ToDo list for a long time. This issue might be somethIng to get this action item checked off. Wondering though if it might be better to have a dedicated project for that as a LSP implementation (e.g. asciidoctor-lsp) could be used independently of this extension.

@ggrossetie
Copy link
Member Author

@ViToni If you want to work on it that would be awesome! Yes, we should create a dedicated project! In case you've missed it, the AsciiDoc specification is under way:

The current syntax highlighter is broken and we could do so much more with a proper LSP (suggestion, lint, reformat and so on)

@ViToni
Copy link
Contributor

ViToni commented Mar 26, 2024

@ggrossetie I'd try to get my feets wet. Not sure how far I get, but at least I'd like to give it a try.
I'll join the chat in the next days.

@ViToni
Copy link
Contributor

ViToni commented Apr 3, 2024

Related to: asciidoctor/asciidoctor#3630

@ggrossetie
Copy link
Member Author

ggrossetie commented Feb 27, 2025

@ViToni I'm starting to experiment a bit with LSP and semantic tokens. I think the first step is to establish a list of token types and token modifiers.

As far as I understand, LSP relies on semantic tokens to do syntax highlighting : https://microsoft.github.io/language-server-protocol/specifications/specification-3-16/#textDocument_semanticTokens

@ggrossetie
Copy link
Member Author

It's worth noting that semantic tokens do not support embedded languages:
microsoft/vscode#163292

Having said that, it's possible to mix semantic tokens and TextMate grammars. The trick is to suppress semantic tokens for source block.

@ViToni if you are still interested, I think we should focus on writing a semantic token provider. We can then port this code over to the server (LSP).

@ggrossetie
Copy link
Member Author

I think the first step is to establish a list of token types and token modifiers.

@ahus1 I guess you did pretty much the same things for the Intellij plugin? I found: https://github.com/asciidoctor/asciidoctor-intellij-plugin/blob/main/src/main/java/org/asciidoc/intellij/lexer/AsciiDocTokenTypes.java

Do you think it would make sense to share a common list of token types for syntax highlighting? Here's what I have so far:

  • documentTitle
  • documentAuthor
  • documentAuthorEmail
  • documentRevision
  • attributeKey
  • attributeValue
  • attributeReference
  • attributeSoftWrap
  • attributeHardWrap
  • listContinuation
  • listMark
  • blockAttrList
  • blockTitle
  • formattingText
  • formattingMark

Token modifiers:

  • constrained
  • unconstrained
  • strong
  • emphasis
  • code

In quite a few cases, an element will have both markup and text. For example, for the document title, = (markup) and Document title (text).

I don't know if we should use different token types? i.e., documentTitleMark for the token = and documentTitleText for the token Document title? Or just use documentTitle on = Document title?
Implementation wise, we could use the concept of modifiers to have documentTitle with modifier mark on = and documentTitle on Document title with the modifier text.

Regarding overlapping tokens, clients (IDE) might or might not support them:

<documentTitle><markup>=</markup> <text>Document title</text></documentTitle>

So for compatibility, it's probably safer to not use them if we can.

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

No branches or pull requests

2 participants