From 5361354b13313cce7017b8b8da42a7d5e4989c32 Mon Sep 17 00:00:00 2001 From: TeamSpen210 Date: Mon, 25 Mar 2019 08:14:55 +1000 Subject: [PATCH] [Python] Add syntax highlighting for type comments --- Python/Python.sublime-syntax | 20 ++++++++++++++++++++ Python/syntax_test_python.py | 15 +++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/Python/Python.sublime-syntax b/Python/Python.sublime-syntax index d15e5eb32c6..6506c5995d8 100644 --- a/Python/Python.sublime-syntax +++ b/Python/Python.sublime-syntax @@ -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.comment + 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: diff --git a/Python/syntax_test_python.py b/Python/syntax_test_python.py index 13028661166..c0e3c1b58a4 100644 --- a/Python/syntax_test_python.py +++ b/Python/syntax_test_python.py @@ -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.comment +# ^^^^^^^ 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 +# ^^^^ comment.line.number-sign.python keyword.other.annotation.typecomment +# ^ comment.line.number-sign.python 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