From 20bffaf93f3598d129ab654493bb866af33a6152 Mon Sep 17 00:00:00 2001 From: Carroll Wainwright Date: Sun, 24 Nov 2024 15:52:11 -0800 Subject: [PATCH] python: Highlight docstrings for classes and modules (#20486) Release Notes: - Add `string.doc` python syntax highlighting to class and module-level docstrings. Previously, only docstrings inside python functions were labeled as `string.doc`, but docstrings can exist at the class or module level too. This adds the more specific string type for each of those. *Before*: image *After*: image --- crates/languages/src/python/highlights.scm | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/crates/languages/src/python/highlights.scm b/crates/languages/src/python/highlights.scm index 6c3f027c1976597c82a4fbe1d86f0bbe8d23357b..98ed2039695c7e2fffaf6a9e1a9e8d948b8e517a 100644 --- a/crates/languages/src/python/highlights.scm +++ b/crates/languages/src/python/highlights.scm @@ -96,7 +96,16 @@ "def" name: (_) (parameters)? - body: (block (expression_statement (string) @string.doc))) + body: (block . (expression_statement (string) @string.doc))) + +(class_definition + body: (block + . (comment) @comment* + . (expression_statement (string) @string.doc))) + +(module + . (comment) @comment* + . (expression_statement (string) @string.doc)) (module (expression_statement (assignment))