Skip to content

Commit 95e4628

Browse files
committed
Consistent highlight on derives' qualIds
fix: #239 vscode-scala-syntax couldn't provide consistent highlights for `C` and `D` in `derives C, D`. Consider we have the following code ```scala enum A extends B derives C, D ``` Previously, `B` and `C` have the following TextMate Scopes ``` entity.other.inherited-class.scala source.scala ``` while `D` has ``` entity.name.class source.scala ``` because it had accepted only one qualId after `derived` https://github.com/scala/vscode-scala-syntax/blob/0b2b1e8829254f0d190e723d3a49874cb7d135c0/src/typescript/Scala.tmLanguage.ts#L1156 even though Scala3 syntax allows us to put multiple qualIds. Therefore, the first one will have `entity.other.inherited-class.scala`, but the following qualIds won't be named as `entity.other.inherited-class.scala`. Instead, falllback to `entity.name.class` based on it's name (upper camel). This commit makes it provide consistent highlight for each qualId after `derives` keyword. Now, both `C` and `D` will have `entity.name.class` instead of `entity.other.inherited-class.scala`. It would be ideal to put `entity.other.inherited-class.scala` to both `C` and `D`, but it looks like impossible with TextMate grammer. Because, according to the [syntax](https://dotty.epfl.ch/docs/reference/contextual/derivation.html#syntax) (see the syntax spec for Scala3 here https://docs.scala-lang.org/scala3/reference/syntax.html) we can't tell where's the end of `derives` clause. In the complete program, we can tell `{` or `:` is the end of `derives` clause, but it messes up if the program is incomplete like ```scala enum A extends B derives C, D ``` where there's no `:` or `{`. Just give up providing `entity.other.inherited-class.scala` and put `entity.name.class` based on their name (upper camel).
1 parent 0b2b1e8 commit 95e4628

File tree

4 files changed

+47
-4
lines changed

4 files changed

+47
-4
lines changed

src/typescript/Scala.tmLanguage.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,9 @@ export const scalaTmLanguage: TmLanguage = {
241241
{
242242
include: '#inheritance'
243243
},
244+
{
245+
include: '#derives'
246+
},
244247
{
245248
include: '#extension'
246249
},
@@ -1153,7 +1156,7 @@ export const scalaTmLanguage: TmLanguage = {
11531156
inheritance: {
11541157
patterns: [
11551158
{
1156-
match: `\\b(extends|with|derives)\\b\\s*(${idUpper}|${backQuotedId}|(?=\\([^\\)]+=>)|(?=${plainid})|(?="))?`,
1159+
match: `\\b(extends|with)\\b\\s*(${idUpper}|${backQuotedId}|(?=\\([^\\)]+=>)|(?=${plainid})|(?="))?`,
11571160
captures: {
11581161
'1': {
11591162
name: 'keyword.declaration.scala'
@@ -1165,6 +1168,10 @@ export const scalaTmLanguage: TmLanguage = {
11651168
}
11661169
]
11671170
},
1171+
derives: {
1172+
match: 'derives',
1173+
name: 'keyword.declaration.scala'
1174+
},
11681175
extension: {
11691176
patterns: [
11701177
{

0 commit comments

Comments
 (0)