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*:
<img width="288" alt="image"
src="https://github.com/user-attachments/assets/5a6c4c9d-709c-40e2-8316-31c95084a1a9">

*After*:
<img width="294" alt="image"
src="https://github.com/user-attachments/assets/8212bfa2-2288-4623-aa63-f748a2295ada">
This commit is contained in:
Carroll Wainwright 2024-11-24 15:52:11 -08:00 committed by GitHub
parent 3dcb94c204
commit 20bffaf93f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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))