Skip to content

Highlight @example jsdoc body as source code #693

Open

Description

@mjbvz

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

Activity

  1. sheetalkamat commented on Dec 5, 2018

    @sheetalkamat
    Member

    Isnt this already scoped correctly because of #688

  2. mjbvz commented on Dec 5, 2018

    @mjbvz
    Author

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

  3. sheetalkamat commented on Dec 13, 2018

    @sheetalkamat
    Member

    Matt Bierner (@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.

  4. mjbvz commented on Dec 14, 2018

    @mjbvz
    Author

    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

  5. sheetalkamat commented on Dec 14, 2018

    @sheetalkamat
    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.

  6. mjbvz commented on Dec 14, 2018

    @mjbvz
    Author

    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.

  7. added a commit that references this issue on Apr 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions