Documentation comments for both Python and Rust #11993
Open
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.
Someone asked in the Matrix chat yesterday about documentation comments in Python🐍. And I accidentally learned how tree-sitter syntax highlighting works to get doc comments working.
While I was there I figured I may as well do it for Rust🦀 too!
Rust documentation comments are
/// this is a documentation comment
and have the tree-sitter scopes:
["source_file", "impl_item", "declaration_list", "line_comment", "doc_comment"]
So adding a search for line_comments that contain doc_comments lets us isolate them and then themes can target
@comment.documentation
Python documentation comments are
Tree-Sitter scopes:
["module", "expression_statement", "string", "string_content"]
Because the doc comments are also valid strings the suggested code looks for expression_statements that contain strings and that start with
"""
.Regular
"""
strings aren't affected because they'reassignment > string
instead ofexpression_statement > string
Thank you! 😃