Skip to content

Commit e2ab0ea

Browse files
authored
Merge pull request #138 from nicolasstucki/fix-#133
Fix #133: Highlight inline as a soft keyword
2 parents 858627f + 5b3c402 commit e2ab0ea

File tree

3 files changed

+87
-1
lines changed

3 files changed

+87
-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(?=(?:.(?!val|def|given))*(if|match))`,
581+
captures: {
582+
'1': {
583+
name: 'keyword.control.flow.scala'
584+
}
585+
}
586+
},
587+
{
588+
match: `\\b(inline)\\s+(?=(([\\w\\s]*(val|def|given))|(${plainid}|${backQuotedId})\\s*:))`,
589+
captures: {
590+
'1': {
591+
name: 'storage.modifier.other'
592+
}
593+
}
594+
}
595+
]
596+
},
574597
'scala-quoted': {
575598
match: "('\\{|'\\[)(?!')",
576599
name: 'constant.other.quoted.scala'
@@ -827,7 +850,7 @@ export const scalaTmLanguage: TmLanguage = {
827850
name: 'storage.modifier.access'
828851
},
829852
{
830-
match: '\\b(synchronized|@volatile|abstract|final|lazy|sealed|implicit|inline |opaque |override|@transient|@native)\\b',
853+
match: '\\b(synchronized|@volatile|abstract|final|lazy|sealed|implicit|opaque |override|@transient|@native)\\b',
831854
name: 'storage.modifier.other'
832855
}
833856
]

tests/unit/#133.test.scala

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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
42+
43+
inline if (n == 0) 1 else 2; val x = 2
44+
// ^^^^^^ keyword.control.flow.scala
45+
// ^^ keyword.control.flow.scala
46+
47+
inline if (n == 0) 1 else 2; def x = 2
48+
// ^^^^^^ keyword.control.flow.scala
49+
// ^^ keyword.control.flow.scala
50+
51+
inline f[X](x: X) match {
52+
// ^^^^^^ keyword.control.flow.scala
53+
// ^^^^^ keyword.control.flow.scala

tests/unit/#139.test.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// SYNTAX TEST "source.scala"
2+
3+
4+
inline def mkDefaultTypeable[T]: Typeable[T] = ${ TypeableMacros.impl[T] }
5+
// ^^^^^^ storage.modifier.other
6+
// ^^^ keyword.declaration.scala
7+
8+
inline given [T] as Typeable[T] = mkDefaultTypeable[T]
9+
// ^^^^^^ storage.modifier.other
10+
// ^^^^^ keyword.declaration.scala

0 commit comments

Comments
 (0)