From bde509fa749da60beb4ac378afd3ade15297bb91 Mon Sep 17 00:00:00 2001 From: Marshall Bowers Date: Thu, 8 Feb 2024 14:20:21 -0500 Subject: [PATCH] Expose Python docstrings for syntax highlighting (#7587) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This PR extends our Tree-sitter highlights for Python to allow highlighting docstrings differently from other strings. Docstrings in Python will now use `string.doc` instead of just `string`, which will allow for them to be styled independently of other strings. If no `string.doc` is present in the theme, then it will fall back to using the `string` styles. Screenshot 2024-02-08 at 1 52 21 PM This is slightly different than the approach I took in #7585 in that we are still treating docstrings as strings by default (which appears to be the more common behavior), but allowing theme authors to hook in and style them separately, if desired. Release Notes: - Added ability add custom styles for Python docstrings using `string.doc` ([#7346](https://github.com/zed-industries/zed/issues/7346)). --- crates/zed/src/languages/python/highlights.scm | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/crates/zed/src/languages/python/highlights.scm b/crates/zed/src/languages/python/highlights.scm index 71ab963d82664db4dd9a66b9e9ac0e85449caf57..0d85c8b6a9354a00ee8574ad5e76b659e22639cd 100644 --- a/crates/zed/src/languages/python/highlights.scm +++ b/crates/zed/src/languages/python/highlights.scm @@ -52,6 +52,14 @@ "{" @punctuation.special "}" @punctuation.special) @embedded +; Docstrings. +(function_definition + "async"? + "def" + name: (_) + (parameters)? + body: (block (expression_statement (string) @string.doc))) + [ "-" "-=" @@ -122,4 +130,4 @@ "yield" "match" "case" -] @keyword \ No newline at end of file +] @keyword