Skip to content

Highlight @example jsdoc body as source code #693

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

Open
mjbvz opened this issue Dec 5, 2018 · 6 comments
Open

Highlight @example jsdoc body as source code #693

mjbvz opened this issue Dec 5, 2018 · 6 comments

Comments

@mjbvz
Copy link
Contributor

mjbvz commented Dec 5, 2018

TS and JS Grammar Extension version: 0.0.47 / latest

Code
For a js doc body such as:

/**
 * @example
 * 1 + 1
 */
const a = 1

We mark the body of the @example block specially but do not actually syntax highlight it. I added an injection grammar in VS Code that does this: https://github.com/Microsoft/vscode/blob/master/extensions/typescript-basics/syntaxes/ExampleJsDoc.injection.tmLanguage.json

May be worth including in the core grammar. Let me know if you agree. The injection grammar will not work as is, we're relying on another injection grammar that handles separating the leading stars of the doc block from the documentation content itself

@sheetalkamat
Copy link
Member

Isnt this already scoped correctly because of #688

@mjbvz
Copy link
Contributor Author

mjbvz commented Dec 5, 2018

This is for highlighting the content 1 + 1 as typescript. Right now, it is just treated as a single token

@sheetalkamat
Copy link
Member

@mjbvz I don't think that's as easy as it seems .. I think that need to be handled by editors (by removing starting * on each line). Without that the results will be too unpredictable.

@mjbvz
Copy link
Contributor Author

mjbvz commented Dec 14, 2018

We use a while rule to do this, see: https://github.com/Microsoft/vscode/blob/master/extensions/typescript-basics/syntaxes/ExampleJsDoc.injection.tmLanguage.json

It consumes the leading * on each line so that the regular js/ts grammar runs without modification inside the comment

@sheetalkamat
Copy link
Member

I still don't understand how multiline example is going to work. Where do you consume leading * wasn't able to figure that out.

@mjbvz
Copy link
Contributor Author

mjbvz commented Dec 14, 2018

Looks like the logic that was moved into this file: https://github.com/Microsoft/vscode/blob/master/extensions/typescript-basics/syntaxes/MarkdownDocumentationInjection.tmLanguage.json

The while rule is run on every line until it fails. In this case, it consumes the leading * so that rules inside the while never see it.

mjbvz added a commit to mjbvz/TypeScript-TmLanguage that referenced this issue Apr 8, 2019
Fixes microsoft#467

Adds a begin/while rule so that doc blocks also consume the leading *. This approach has been used by VS Code to support highlighting example blocks (see microsoft#693)

Remove the `invalid.illegal.type.jsdoc` rule since we now can highlight multiline types better
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants