feat: more semantic tokens for Markdown/Verso#13674
Open
david-christiansen wants to merge 3 commits into
Open
Conversation
This PR adds semantic tokens for Markdown and Verso that correspond to those available in editor themes for Markdown. With a small update to editors, docstrings can be consistently formatted without needing to reimplement either complex parser client-side.
|
Mathlib CI status (docs):
|
Collaborator
|
Reference manual CI status:
|
|
I took a closer look at this for lean.nvim last night. TL;DR it's awesome having semantic tokens here, we had disabled our markdown parser as getting it right alongside Lean was torture. How precisely it looks depends on the theme of course, but e.g. out of the box on mine, this is what this looks like:
A few specific comments in case helpful:
All the above being said, yeah this is a great improvement! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

This PR adds semantic tokens for Markdown and Verso that correspond to those available in editor themes for Markdown. With a small update to editors, docstrings can be consistently formatted without needing to reimplement either complex parser client-side.
The changes include:
New semantic tokens that represent markup. One of them is not use in Lean per se:
markupPlainTextis intended for Verso proper, which should not be styled as though it's in a doc comment.The
Lean.Server.FileWorker.Markdownmodule hierarchy, which includes a mostly-conformant CommonMark parser that is very particular about tracking source locations. It deviates from CommonMark as follows:It passes all other tests in the spec.
Lean.Server.FileWorker.SemanticHighlightingnow emits the new tokens based on a Markdown parse. I considered moving this code out of that module, but it would have required a broader reorganization so I erred on the side of not disturbing things. I can do it if you'd like, though.Lean.Server.ProtocolOverviewmentions the custom tokens in the semantic token method descriptions. I didn't see another natural place to describe it.To test this, I Clauded up a verso of vscode-lean4 with the following extra rules:
Under
semanticTokenScopes, I added:and under
configurationDefaults:There's apparently no way to have
markupPlainTextjust be the default face, so I did this somewhat baroque setup. The others all just made sense.Here's the result:
