Merge pull request #1697 from zed-industries/css-highlighting-fixes

Max Brunsfeld created

Highlighting fixes

Change summary

crates/zed/src/languages/c/highlights.scm          |  2 
crates/zed/src/languages/cpp/highlights.scm        |  4 +-
crates/zed/src/languages/css/highlights.scm        | 12 ++++++----
crates/zed/src/languages/javascript/highlights.scm |  6 ++--
crates/zed/src/languages/python/highlights.scm     |  2 
crates/zed/src/languages/rust/highlights.scm       | 17 +++------------
crates/zed/src/languages/typescript/highlights.scm |  6 ++--
styles/src/themes/common/base16.ts                 | 12 +++++-----
styles/src/themes/common/theme.ts                  |  2 
9 files changed, 28 insertions(+), 35 deletions(-)

Detailed changes

crates/zed/src/languages/c/highlights.scm 🔗

@@ -86,7 +86,7 @@
 (identifier) @variable
 
 ((identifier) @constant
- (#match? @constant "^[A-Z][A-Z\\d_]*$"))
+ (#match? @constant "^_*[A-Z][A-Z\\d_]*$"))
 
 (call_expression
   function: (identifier) @function)

crates/zed/src/languages/cpp/highlights.scm 🔗

@@ -37,11 +37,11 @@
 (type_identifier) @type
 
 ((identifier) @constant
- (#match? @constant "^[A-Z][A-Z\\d_]*$"))
+ (#match? @constant "^_*[A-Z][A-Z\\d_]*$"))
 
 (field_identifier) @property
 (statement_identifier) @label
-(this) @variable.builtin
+(this) @variable.special
 
 [
   "break"

crates/zed/src/languages/css/highlights.scm 🔗

@@ -41,10 +41,13 @@
 
 (function_name) @function
 
-((property_name) @variable
- (#match? @variable "^--"))
-((plain_value) @variable
- (#match? @variable "^--"))
+(
+  [
+    (property_name)
+    (plain_value)
+  ] @variable.special
+  (#match? @variable.special "^--")
+)
 
 [
   "@media"
@@ -70,7 +73,6 @@
 (unit) @type
 
 [
-  "#"
   ","
   ":"
 ] @punctuation.delimiter

crates/zed/src/languages/javascript/highlights.scm 🔗

@@ -51,12 +51,12 @@
   (shorthand_property_identifier)
   (shorthand_property_identifier_pattern)
  ] @constant
- (#match? @constant "^[A-Z_][A-Z\\d_]+$"))
+ (#match? @constant "^_*[A-Z_][A-Z\\d_]*$"))
 
 ; Literals
 
-(this) @variable.builtin
-(super) @variable.builtin
+(this) @variable.special
+(super) @variable.special
 
 [
   (true)

crates/zed/src/languages/rust/highlights.scm 🔗

@@ -1,6 +1,6 @@
 (type_identifier) @type
 (primitive_type) @type.builtin
-(self) @variable.builtin
+(self) @variable.special
 (field_identifier) @property
 
 (call_expression
@@ -27,22 +27,13 @@
 
 ; Identifier conventions
 
-; Assume uppercase names are enum constructors
-((identifier) @variant
- (#match? @variant "^[A-Z]"))
-
-; Assume that uppercase names in paths are types
-((scoped_identifier
-  path: (identifier) @type)
- (#match? @type "^[A-Z]"))
-((scoped_identifier
-  path: (scoped_identifier
-    name: (identifier) @type))
+; Assume uppercase names are types/enum-constructors
+((identifier) @type
  (#match? @type "^[A-Z]"))
 
 ; Assume all-caps names are constants
 ((identifier) @constant
- (#match? @constant "^[A-Z][A-Z\\d_]+$"))
+ (#match? @constant "^_*[A-Z][A-Z\\d_]*$"))
 
 [
   "("

crates/zed/src/languages/typescript/highlights.scm 🔗

@@ -51,12 +51,12 @@
   (shorthand_property_identifier)
   (shorthand_property_identifier_pattern)
  ] @constant
- (#match? @constant "^[A-Z_][A-Z\\d_]+$"))
+ (#match? @constant "^_*[A-Z_][A-Z\\d_]*$"))
 
 ; Literals
 
-(this) @variable.builtin
-(super) @variable.builtin
+(this) @variable.special
+(super) @variable.special
 
 [
   (true)

styles/src/themes/common/base16.ts 🔗

@@ -185,6 +185,10 @@ export function createTheme(
       color: sample(ramps.neutral, 7),
       weight: fontWeights.normal,
     },
+    "variable.special": {
+      color: sample(ramps.blue, 0.80),
+      weight: fontWeights.normal,
+    },
     comment: {
       color: sample(ramps.neutral, 5),
       weight: fontWeights.normal,
@@ -210,15 +214,11 @@ export function createTheme(
       weight: fontWeights.normal,
     },
     constructor: {
-      color: sample(ramps.blue, 0.5),
-      weight: fontWeights.normal,
-    },
-    variant: {
-      color: sample(ramps.blue, 0.5),
+      color: sample(ramps.cyan, 0.5),
       weight: fontWeights.normal,
     },
     property: {
-      color: sample(ramps.blue, 0.5),
+      color: sample(ramps.blue, 0.6),
       weight: fontWeights.normal,
     },
     enum: {

styles/src/themes/common/theme.ts 🔗

@@ -43,7 +43,7 @@ export interface Syntax {
   keyword: SyntaxHighlightStyle;
   function: SyntaxHighlightStyle;
   type: SyntaxHighlightStyle;
-  variant: SyntaxHighlightStyle;
+  constructor: SyntaxHighlightStyle;
   property: SyntaxHighlightStyle;
   enum: SyntaxHighlightStyle;
   operator: SyntaxHighlightStyle;