Improve Python syntax highlighting (#12868)

Nigel Jose and Joseph T Lyons created

Release Notes:

- Improve syntax highlighting in Python #12578 

Before:
<img width="1181" alt="Screenshot 2024-06-08 at 01 44 54"
src="https://github.com/zed-industries/zed/assets/87859239/0b8ab26b-149b-477e-af08-8cd9f2b1c117">

After:

<img width="1184" alt="Screenshot 2024-06-10 at 01 02 35"
src="https://github.com/zed-industries/zed/assets/87859239/a319a5ea-54b7-4681-951d-130ea26aa390">

---------

Co-authored-by: Joseph T Lyons <JosephTLyons@gmail.com>

Change summary

crates/languages/src/python/highlights.scm | 29 +++++++++++++++++++++--
1 file changed, 26 insertions(+), 3 deletions(-)

Detailed changes

crates/languages/src/python/highlights.scm 🔗

@@ -1,6 +1,25 @@
+(parameter (identifier) @variable)
 (attribute attribute: (identifier) @property)
 (type (identifier) @type)
 
+; Module imports
+
+(import_statement
+  (dotted_name (identifier) @type))
+
+(import_statement
+  (aliased_import
+    name: (dotted_name (identifier) @type)
+    alias: (identifier) @type))
+
+(import_from_statement
+  (dotted_name (identifier) @type))
+
+(import_from_statement
+  (aliased_import
+    name: (dotted_name (identifier) @type)
+    alias: (identifier) @type))
+
 ; Function calls
 
 (decorator) @function
@@ -44,9 +63,13 @@
   (float)
 ] @number
 
-; Variables
-(assignment
-  left: (identifier) @variable)
+; Self references
+
+[
+  (parameters (identifier) @variable.special)
+  (attribute (identifier) @variable.special)
+  (#match? @variable.special "^self$")
+]
 
 (comment) @comment
 (string) @string