From 7853e32f8093ab6195d89a490ff43f0ec62ba0e1 Mon Sep 17 00:00:00 2001 From: Jaagup Averin Date: Tue, 19 Nov 2024 19:53:36 +0200 Subject: [PATCH] python: Highlight attribute docstrings (#20763) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds more docstring highlights missing from #20486. [PEP257](https://peps.python.org/pep-0257/) defines attribute docstrings as > String literals occurring immediately after a simple assignment at the top level of a module, class, or __init__ method are called “attribute docstrings”. This PR adds `@string.doc` for such cases. Before: ![Screenshot_20241116_162257](https://github.com/user-attachments/assets/6b471cff-717e-4755-9291-d596da927dc6) After: ![Screenshot_20241116_162457](https://github.com/user-attachments/assets/96674157-9c86-45b6-8ce9-e433ca0ae8ea) Release Notes: - Added Python syntax highlighting for attribute docstrings. --------- Co-authored-by: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com> --- crates/languages/src/python/highlights.scm | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/crates/languages/src/python/highlights.scm b/crates/languages/src/python/highlights.scm index 78e5126d4094d..6c3f027c19765 100644 --- a/crates/languages/src/python/highlights.scm +++ b/crates/languages/src/python/highlights.scm @@ -98,6 +98,25 @@ (parameters)? body: (block (expression_statement (string) @string.doc))) +(module + (expression_statement (assignment)) + . (expression_statement (string) @string.doc)) + +(class_definition + body: (block + (expression_statement (assignment)) + . (expression_statement (string) @string.doc))) + +(class_definition + body: (block + (function_definition + name: (identifier) @function.method.constructor + (#eq? @function.method.constructor "__init__") + body: (block + (expression_statement (assignment)) + . (expression_statement (string) @string.doc))))) + + [ "-" "-="