Skip to content

Mark documentation comment blocks as Markdown.#37

Open
AndreasBackx wants to merge 1 commit intodustypomerleau:mainfrom
AndreasBackx:doc-comments-markdown
Open

Mark documentation comment blocks as Markdown.#37
AndreasBackx wants to merge 1 commit intodustypomerleau:mainfrom
AndreasBackx:doc-comments-markdown

Conversation

@AndreasBackx
Copy link
Copy Markdown

@AndreasBackx AndreasBackx commented Dec 24, 2022

This adds support for marking the content inside of a doc comment as markdown. Additionally the following identifiers are marked as documentation blocks as well:

  • //!
  • /*!

These were previously identified as the double slash / non-doc variant. These are defined in the Rust spec: https://doc.rust-lang.org/reference/comments.html

Examples of how this looks in VS Code:

image

image

It still defaults to the comment foreground colour for codeblocks in VS Code, though my guess is that this is a VS Code issue? Might even be an issue of my own theme.

image

Looking at the default theme, it definitely seems like an issue for my theme:

image

This comes from my original issue microsoft/vscode#169676 and I hope to sync this to the PR for VS Code as well: microsoft/vscode#169956. #20 also suggested this feature.

Let me know what you think. 😃

bors added a commit to rust-lang/rust-analyzer that referenced this pull request May 24, 2023
…Veykril

[editors/code] add markdown syntax highlighting to doc comments

_This is a continuation of microsoft/vscode#169956 and dustypomerleau/rust-syntax#37 (that repo is no longer maintained: dustypomerleau/rust-syntax#39 (comment)). The VS Code team seemed to prefer this being inside of an extension._

This adds Markdown highlighting to doc comment lines and blocks. Currently it is thus regarded both as a comment and as Markdown which leads to normally foreground text being in the colour of the comment and the rest highlighted like Markdown or its own embedded languages in code blocks.

![image](https://github.com/rust-lang/rust-analyzer/assets/1593486/c84f2e83-faea-47ca-853d-3728a07b2b66)

![image](https://github.com/rust-lang/rust-analyzer/assets/1593486/f4191425-32cd-451c-ae3a-29a0970ce7a2)

Block comments are supported, but currently not when there is a `*` at the start of the line:
![image](https://github.com/rust-lang/rust-analyzer/assets/1593486/ce3b58d5-9dca-4376-bffe-4f5a54acbe37)
![image](https://github.com/rust-lang/rust-analyzer/assets/1593486/b73a5ee6-a178-4aef-a0e4-3d75e4e7d8e5)

I'm not entirely sure if I can easily fix this, I'd need to find a way to make the content ignore the `*`. Though I'm unsure if it's important as there are [conventions against using block comments](
https://rust-lang.github.io/rfcs/1574-more-api-documentation-conventions.html#use-line-comments) and using them without `*` does work. All of this TextMate grammar is so hard to find documentation on that _honestly_ I'd just not want to support this considering the effort.

Let me know what everyone thinks of this being in rust-analyzer. I've personally found it hard to write large amounts of Rust documentation due to the lack of Markdown syntax highlighting.

Also, thank you `@adenine-dev` as well for making this available in the interim and your enthousiasm. Wanted to get this PR out sooner, but life gets in the way.
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

Successfully merging this pull request may close these issues.

1 participant