Skip to content

Commit

Permalink
Refine syntax highlighting for Python docstrings
Browse files Browse the repository at this point in the history
* Add highlighting for module- and class-level docstrings
* Add highlighting for additional docstrings as described in PEP 257
* Remove highlighting for non-docstring string literals in functions
  • Loading branch information
jfmontanaro committed Nov 20, 2024
1 parent 3c57a40 commit a3a8a4f
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions crates/languages/src/python/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -91,21 +91,27 @@
"}" @punctuation.special) @embedded

; Docstrings.
(module
.(expression_statement (string) @string.doc)+)

(class_definition
body: (block .(expression_statement (string) @string.doc)+))

(function_definition
"async"?
"def"
name: (_)
(parameters)?
body: (block (expression_statement (string) @string.doc)))
body: (block .(expression_statement (string) @string.doc)+))

(module
(expression_statement (assignment))
. (expression_statement (string) @string.doc))
. (expression_statement (string) @string.doc)+)

(class_definition
body: (block
(expression_statement (assignment))
. (expression_statement (string) @string.doc)))
. (expression_statement (string) @string.doc)+))

(class_definition
body: (block
Expand All @@ -114,7 +120,7 @@
(#eq? @function.method.constructor "__init__")
body: (block
(expression_statement (assignment))
. (expression_statement (string) @string.doc)))))
. (expression_statement (string) @string.doc)+))))


[
Expand Down

0 comments on commit a3a8a4f

Please sign in to comment.