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

[Python] Add syntax support for sphinx-style doc comments #3839

Merged
merged 1 commit into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Python/Comments.tmPreferences
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@
<key>value</key>
<string>:</string>
</dict>
<dict>
<!--
Cannot be undone using `toggle_comment` at the moment
because the earlier `TM_COMMENT_START` is tested first
and is a true prefix of this one.
-->
<key>name</key>
<string>TM_COMMENT_START_2</string>
<key>value</key>
<string>#: </string>
</dict>
</array>
</dict>
</dict>
Expand Down
10 changes: 10 additions & 0 deletions Python/Python.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,11 @@ contexts:
###[ COMMENTS ]###############################################################

comments:
# Special Sphinx comment syntax to denote documentation
# https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html#directive-autoattribute
- match: '#:'
scope: punctuation.definition.comment.python
push: comment-sphinxdoc-body
- match: \#
scope: punctuation.definition.comment.python
push:
Expand All @@ -375,6 +380,11 @@ contexts:
- match: \n
pop: 1

comment-sphinxdoc-body:
- meta_scope: comment.line.documentation.python
- match: \n
pop: 1

shebang:
- meta_include_prototype: false
- match: ^\#!
Expand Down
8 changes: 8 additions & 0 deletions Python/tests/syntax_test_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.block.documentation
"""

#: This is a prefixed "doc comment", supported by sphinx
# <- comment.line.documentation.python punctuation.definition.comment.python
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.line.documentation.python
#^ punctuation.definition.comment.python
attribute = ... #: also supported on the same line
# ^^ comment.line.documentation.python punctuation.definition.comment.python
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.line.documentation.python

r'''This is a syntax test file.
# <- storage.type.string - comment
#^^^ comment.block.documentation.python punctuation.definition.comment.begin.python
Expand Down