Skip to content

Commit

Permalink
[Python] Add syntax highlighting for type comments
Browse files Browse the repository at this point in the history
  • Loading branch information
TeamSpen210 committed Mar 24, 2019
1 parent 8c76dd3 commit 5850d11
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Python/Python.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,26 @@ contexts:
pop: true

comments:
- match: '(#)\s*(type)(:)'
captures:
1: punctuation.definition.comment.python comment.line.number-sign.python
2: keyword.other.annotation.typecomment
3: punctuation.separator.annotation.typecomment
push:
- match: 'ignore'
scope: keyword.other.annotation.typecomment.ignore
set:
- include: comments_noannotation
- match: \n
pop: true
- include: comments_noannotation
- include: expressions
- match: \n
pop: true

- include: comments_noannotation

comments_noannotation:
- match: "#"
scope: punctuation.definition.comment.python
push:
Expand Down
15 changes: 15 additions & 0 deletions Python/syntax_test_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -1350,6 +1350,21 @@ class Starship:
# ^ punctuation.separator.annotation.variable.python
# ^ keyword.operator.assignment

primes = 5 # type: ignore # type: ignore
# ^ punctuation.definition.comment.python
# ^^^^ keyword.other.annotation.typecomment
# ^ punctuation.separator.annotation.typecomment
# ^^^^^^ keyword.other.annotation.typecomment.ignore
# ^ comment.line.number-sign.python punctuation.definition.comment.python
# ^^^^^^^^^^^^^ comment.line.number-sign.python - keyword

primes = 5 # type: List[int] # comment
# ^ punctuation.definition.comment.python
# ^^^^ keyword.other.annotation.typecomment
# ^ punctuation.separator.annotation.typecomment
# ^ comment.line.number-sign.python punctuation.definition.comment.python
# ^^^^^^^ comment.line.number-sign.python


# <- - meta
# ensure we're not leaking a context

0 comments on commit 5850d11

Please sign in to comment.