Skip to content
This repository has been archived by the owner on Oct 18, 2024. It is now read-only.

Commit

Permalink
fix(editor): update syntax highlights for Java and Kotlin (fixes #1051)
Browse files Browse the repository at this point in the history
  • Loading branch information
itsaky committed Jul 16, 2023
1 parent afcc178 commit b9d84e4
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"type": "#4fc3f7",
"keyword": "#ff6060",
"operator": "#4fc3f7",
"attribute": "#4fc3f7",
"attribute": "#afb42b",
"variable": "#ba68c8",
"field" : "#f0be4b",
"constant": "#f0be4b",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"variable": "@onSurface",
"constant.builtin": "@keyword",
"type": "@type",
"attribute": "@type",
"attribute": "@attribute",
"function.declaration": "@func.decl",
"function.invocation": "@func.call",
"variable.field": "@field",
Expand Down
13 changes: 10 additions & 3 deletions editor/src/main/assets/editor/schemes/default-dark/kotlin.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
"fg": "@keyword",
"bold": true
},
"label": {
"fg": "@keyword",
"bold": true
},
"type.qualifier": {
"fg": "@keyword",
"bold": true
Expand Down Expand Up @@ -66,16 +70,19 @@
"bold": true
},
"number": "@number",
"variable": "@onSurface",
"identifier": "@onSurface",
"parameter": "@variable",
"constant.builtin": "@keyword",
"type": "@type",
"attribute": "@type",
"attribute": "@attribute",
"function.declaration": "@func.decl",
"function.invocation": "@func.call",
"operator": "@operator",
"punctuation.special": "@kt.punctuation.special",
"constructor": "@kt.constructor",
"property": "@kt.property"
"property.class": "@kt.property",
"property.top_level": "@kt.property",
"property.local": "@onSurface",
"bracket": "@onSurface"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
scheme.name=AndroidIDE Default - Dark

# The version code of the color scheme
scheme.version=11
scheme.version=12

# Whether the scheme is dark or light
scheme.isDark=true
Expand Down
2 changes: 1 addition & 1 deletion editor/src/main/assets/editor/schemes/default/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"type": "#1976d2",
"keyword": "#d32f2f",
"operator": "#1976d2",
"attribute": "#1976d2",
"attribute": "#827717",
"variable": "#ba68c8",
"field" : "#ff6f00",
"constant": "#ff6f00",
Expand Down
2 changes: 1 addition & 1 deletion editor/src/main/assets/editor/schemes/default/java.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"variable": "@onSurface",
"constant.builtin": "@keyword",
"type": "@type",
"attribute": "@type",
"attribute": "@attribute",
"function.declaration": "@func.decl",
"function.invocation": "@func.call",
"variable.field": "@field",
Expand Down
13 changes: 10 additions & 3 deletions editor/src/main/assets/editor/schemes/default/kotlin.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
"fg": "@keyword",
"bold": true
},
"label": {
"fg": "@keyword",
"bold": true
},
"type.qualifier": {
"fg": "@keyword",
"bold": true
Expand Down Expand Up @@ -66,16 +70,19 @@
"bold": true
},
"number": "@number",
"variable": "@onSurface",
"identifier": "@onSurface",
"parameter": "@variable",
"constant.builtin": "@keyword",
"type": "@type",
"attribute": "@type",
"attribute": "@attribute",
"function.declaration": "@func.decl",
"function.invocation": "@func.call",
"operator": "@operator",
"punctuation.special": "@kt.punctuation.special",
"constructor": "@kt.constructor",
"property": "@kt.property"
"property.class": "@kt.property",
"property.top_level": "@kt.property",
"property.local": "@onSurface",
"bracket": "@onSurface"
}
}
2 changes: 1 addition & 1 deletion editor/src/main/assets/editor/schemes/default/scheme.prop
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
scheme.name=AndroidIDE Default

# The version code of the color scheme
scheme.version=11
scheme.version=12

# Whether the scheme is dark or light
scheme.isDark=false
Expand Down
10 changes: 7 additions & 3 deletions editor/src/main/assets/editor/treesitter/java/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,16 @@
; Annotations

(annotation
name: (identifier) @attribute)
"@" @attribute
name: (identifier) @attribute
(annotation_argument_list
(element_value_pair
key: (identifier) @variable.field)))

(marker_annotation
"@" @attribute
name: (identifier) @attribute)

"@" @operator

; Types

(type_identifier) @type
Expand Down
51 changes: 36 additions & 15 deletions editor/src/main/assets/editor/treesitter/kt/highlights.scm
Original file line number Diff line number Diff line change
@@ -1,25 +1,35 @@
;;; Identifiers

(simple_identifier) @variable
(simple_identifier) @identifier

; `this` this keyword inside classes
(this_expression) @variable.builtin

; `super` keyword inside classes
(super_expression) @variable.builtin

(class_parameter
(simple_identifier) @property)
(statements
(property_declaration
(variable_declaration
(simple_identifier) @property.local)))

(source_file
(property_declaration
(variable_declaration
(simple_identifier) @property.top_level)))

(class_body
(property_declaration
(variable_declaration
(simple_identifier) @property)))
(simple_identifier) @property.class)))

(class_parameter
(simple_identifier) @property.class)

; id_1.id_2.id_3: `id_2` and `id_3` are assumed as object properties
(_
(navigation_suffix
(simple_identifier) @property))
(simple_identifier) @property.class))

; SCREAMING CASE identifiers are assumed to be constants
((simple_identifier) @constant
Expand Down Expand Up @@ -93,16 +103,25 @@
(setter
("set") @function.builtin)

(primary_constructor) @constructor
(primary_constructor
"constructor" @keyword
(class_parameter
(simple_identifier) @property.class
(_
(type_identifier) @type )))

(secondary_constructor
("constructor") @constructor)
("constructor") @keyword)

(constructor_delegation_call
[ "this" "super" ] @keyword)

(constructor_invocation
(user_type
(type_identifier) @constructor))

(anonymous_initializer
("init") @constructor)
("init") @function.invocation)

(parameter
(simple_identifier) @parameter)
Expand Down Expand Up @@ -263,9 +282,6 @@
"interface"
"fun"
; "typeof" ; NOTE: It is reserved for future use
] @keyword

[
"fun"
"for"
"do"
Expand All @@ -282,6 +298,8 @@
"break"
] @keyword

(label) @label

(annotation
"@" @attribute (use_site_target)? @attribute)
(annotation
Expand Down Expand Up @@ -340,12 +358,15 @@
"as?"
".."
"->"
"(" ")"
"[" "]"
"{" "}"
"."
","
";"
":"
"::"
] @operator
] @operator

[
"(" ")"
"[" "]"
"{" "}"
] @bracket
5 changes: 2 additions & 3 deletions editor/src/main/assets/editor/treesitter/kt/locals.scm
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@
(variable_declaration
(simple_identifier) @definition.parameter)))

(class_body
(property_declaration
(property_declaration
(variable_declaration
(simple_identifier) @definition.field)))
(simple_identifier) @definition.field))

(class_declaration
(primary_constructor
Expand Down

0 comments on commit b9d84e4

Please sign in to comment.