Skip to content

Commit 2dd5afd

Browse files
committed
Fix #133: Highlight inline as a soft keyword
If it is part of an inline `if` or `match` it is highlighted as a control flow keyword. If it is part of a `def` or `val` definition it is highlighted as a declaration keyword. Otherwise, it is not highlighted.
1 parent 40dc063 commit 2dd5afd

File tree

2 files changed

+65
-1
lines changed

2 files changed

+65
-1
lines changed

src/typescript/Scala.tmLanguage.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,9 @@ export const scalaTmLanguage: TmLanguage = {
263263
{
264264
include: '#singleton-type'
265265
},
266+
{
267+
include: '#inline'
268+
},
266269
{
267270
include: '#scala-quoted'
268271
},
@@ -571,6 +574,26 @@ export const scalaTmLanguage: TmLanguage = {
571574
}
572575
}
573576
},
577+
inline: {
578+
patterns: [
579+
{
580+
match: `\\b(inline)\\b(?=(\\s+(?:${plainid}|${backQuotedId})\\s*:)|(.*(val|def)))`,
581+
captures: {
582+
'1': {
583+
name: 'storage.modifier.other'
584+
}
585+
}
586+
},
587+
{
588+
match: `\\b(inline)\\b(?=.*(if|match))`,
589+
captures: {
590+
'1': {
591+
name: 'keyword.control.flow.scala'
592+
}
593+
}
594+
}
595+
]
596+
},
574597
'scala-quoted': {
575598
match: "('\\{|'\\[)(?!')",
576599
name: 'constant.other.quoted.scala'
@@ -822,7 +845,7 @@ export const scalaTmLanguage: TmLanguage = {
822845
name: 'storage.modifier.access'
823846
},
824847
{
825-
match: '\\b(synchronized|@volatile|abstract|final|lazy|sealed|implicit|inline |opaque |override|@transient|@native)\\b',
848+
match: '\\b(synchronized|@volatile|abstract|final|lazy|sealed|implicit|opaque |override|@transient|@native)\\b',
826849
name: 'storage.modifier.other'
827850
}
828851
]

tests/unit/#133.test.scala

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// SYNTAX TEST "source.scala"
2+
3+
4+
inline val c = 0
5+
// ^^^^^^ storage.modifier.other
6+
7+
inline def power(x: Double, inline n: Int): Double =
8+
// ^^^^^^ storage.modifier.other
9+
// ^^^^^^ storage.modifier.other
10+
inline if (n == 0) 1.0
11+
// ^^^^^^ keyword.control.flow.scala
12+
else inline if (n % 2 == 1) x * power(x, n - 1)
13+
// ^^^^^^ keyword.control.flow.scala
14+
else power(x * x, n / 2)
15+
16+
17+
inline x match {
18+
// ^^^^^^ keyword.control.flow.scala
19+
// ^^^^^ keyword.control.flow.scala
20+
21+
22+
inline def power(x: Double, inline N: Int): Double =
23+
// ^^^^^^ storage.modifier.other
24+
// ^^^^^^ storage.modifier.other
25+
26+
inline def power(x: Double, inline `n`: Int): Double =
27+
// ^^^^^^ storage.modifier.other
28+
// ^^^^^^ storage.modifier.other
29+
30+
val x = inline + 2
31+
// ^^^^^^ - storage.modifier.other keyword.control.flow.scala
32+
val x = inline(x)
33+
// ^^^^^^ - storage.modifier.other keyword.control.flow.scala
34+
val x = inline[T]
35+
// ^^^^^^ - storage.modifier.other keyword.control.flow.scala
36+
37+
inline def inline(inline inline: Int): Double =
38+
// ^^^^^^ storage.modifier.other
39+
// ^^^^^^ entity.name.function.declaration
40+
// ^^^^^^ storage.modifier.other
41+
// ^^^^^^ variable.parameter.scala

0 commit comments

Comments
 (0)