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

Rust Extension: Embed Markdown in comment blocks #169676

Closed
AndreasBackx opened this issue Dec 20, 2022 · 1 comment
Closed

Rust Extension: Embed Markdown in comment blocks #169676

AndreasBackx opened this issue Dec 20, 2022 · 1 comment
Assignees
Labels
*extension-candidate Issue identified as good extension implementation

Comments

@AndreasBackx
Copy link
Contributor

This is a continuation of #98437 which was closed as it was a duplicate issue from the Atom Rust extension, though that is archived now.

VS Code makes it possible to embed languages by specifying it in the grammar list of the extension. Would it be possible to make the Rust grammar include Markdown for its comment blocks? I am willing to see if this is possible using something like the following in https://github.com/microsoft/vscode/blob/main/extensions/rust/package.json:

{
  "name": "rust",
  // ...
  "contributes": {
    // ...
    "grammars": [
      {
        "language": "rust",
        "path": "./syntaxes/rust.tmLanguage.json",
        "scopeName": "source.rust",
        "embeddedLanguages": {
          // Enable for documentation comments
          "comment.line.documentation.rust": "markdown",
          "comment.block.documentation.rust": "markdown",
          // Enable for general comments as well?
          "comment.line.double-slash.rust": "markdown",
          "comment.block.rust": "markdown"
        }
      }
    ]
  },
  // ...
}

This was mentioned in rust-lang/rust-analyzer#3495 and a proof of concept was done in rust-lang/rust-analyzer#4488 by @Veetaha, though it seems like the most ideal location would perhaps be to make VS Code aware of this?

I am unsure whether there would be a need to make changes to how the comment block scopes work as they might be all separate per line, which might be an issue for Markdown code going over multiple lines. Is this something that VS Code supports? For example:

/// _Will this next line
/// still be italic?_
async fn foo() -> Result<()> {
	// ...
}

The "JSDoc Markdown highlighting" extension by @mattbierner implements this functionality solely via grammar injection in very few lines of code. @matklad mentions an injection approach should also be taken in the aforementioned rust-analyzer issue, though I'm uncertain if grammar injection was referred to. Should we go a similar route or could we directly implement it with embedded languages?

Is this not implemented in the TypeScript extension due to TypeScript not using Markdown like Rust? I hope this is something we could add the the Rust extension as Rust chose Markdown specifically.

@alexr00
Copy link
Member

alexr00 commented Jan 4, 2023

As discussed here this can be done in an extension.

@alexr00 alexr00 closed this as completed Jan 4, 2023
@alexr00 alexr00 added the *extension-candidate Issue identified as good extension implementation label Jan 4, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Feb 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
*extension-candidate Issue identified as good extension implementation
Projects
None yet
Development

No branches or pull requests

3 participants