From 042fc82e994a22d13418d9b14c9fef93dc010931 Mon Sep 17 00:00:00 2001 From: Finn Evers Date: Tue, 4 Mar 2025 08:41:10 +0100 Subject: [PATCH] python: Fix and improve highlighting (#25813) Closes #25803 Closes #25707 This PR fixes the highlighting regression described in #25803 by fixing the priorities of highlights as described in the [comment within the file itself](https://github.com/zed-industries/zed/blob/5b66ea15638b004c45bbf4e4dd0b576aa6cdcebc/crates/languages/src/python/highlights.scm#L1). A nice side-effect of this is that scoped constants or other identifiers are now also more accurately highlighted, as seen in the screenshots below. While I was at it, I also adressed the highlighting issue for default typed idenfiers. | This PR | PR | | --- | --- | | Preview | preview | | Stable | stable | Release Notes: - Fixed constants not being highlighted in Python-files. - Improved Python-highlighting for default function arguments and scoped identifiers. --- crates/languages/src/python/highlights.scm | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/crates/languages/src/python/highlights.scm b/crates/languages/src/python/highlights.scm index a6c20cd6bc666867558778066960e086d342964a..8f7868168740760e6ea75736071ff7a3b70cbc45 100644 --- a/crates/languages/src/python/highlights.scm +++ b/crates/languages/src/python/highlights.scm @@ -1,4 +1,6 @@ ; Identifier naming conventions; these "soft conventions" should stay at the top of the file as they're often overridden +(identifier) @variable +(attribute attribute: (identifier) @property) ; CamelCase for classes ((identifier) @type.class @@ -8,8 +10,6 @@ ((identifier) @constant (#match? @constant "^_*[A-Z][A-Z0-9_]*$")) -(identifier) @variable -(attribute attribute: (identifier) @property) (type (identifier) @type) (generic_type (identifier) @type) (comment) @comment @@ -61,6 +61,8 @@ (identifier) @function.arguments) ; Typed parameters (default_parameter name: (identifier) @function.arguments) ; Default parameters + (typed_default_parameter + name: (identifier) @function.arguments) ; Typed default parameters ])) ; Keyword arguments