Skip to content

Commit 0352d72

Browse files
Merge pull request #173 from camilaagw/fix-153-highlight-correctly-multiple-variable-statement
Fix #153: Highlight correctly multiple variable statement
2 parents fb991cf + 27c7da0 commit 0352d72

File tree

3 files changed

+66
-5
lines changed

3 files changed

+66
-5
lines changed

src/typescript/Scala.tmLanguage.ts

+24-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const idUpper = `${upperLetter}${letterOrDigit}*(?:(?<=_)${opchar}+)?`
1818
const idLower = `${lowerLetter}${letterOrDigit}*(?:(?<=_)${opchar}+)?`
1919
const plainid = `(?:${idrest}|${opchar}+)`
2020
const backQuotedId = "`[^`]+`"
21+
const anyId = `(?:${plainid}|${backQuotedId})`
2122
const endOfLineMaybeWithComment = "(?=\\s*(//.*|/\\*(?!.*\\*/\\s*\\S.*).*)?$)"
2223

2324
export const scalaTmLanguage: TmLanguage = {
@@ -661,8 +662,30 @@ export const scalaTmLanguage: TmLanguage = {
661662
}
662663
}
663664
},
665+
{ // val (x1, x2) = tup // val Some(x) = opt
666+
match: `\\b(?:(val)|(var))(?=\\s+(${anyId})?\\()`,
667+
captures: {
668+
'1': {
669+
name: 'keyword.declaration.stable.scala'
670+
},
671+
'2': {
672+
name: 'keyword.declaration.volatile.scala'
673+
}
674+
}
675+
},
676+
{ // val x1, x2 = y
677+
match: `\\b(?:(val)|(var))\\s+(?:${anyId})(?=\\s*,)`,
678+
captures: {
679+
'1': {
680+
name: 'keyword.declaration.stable.scala'
681+
},
682+
'2': {
683+
name: 'keyword.declaration.volatile.scala'
684+
}
685+
}
686+
},
664687
{
665-
match: `\\b(?:(val)|(var))\\s+(?:(${idUpper}(\\s*,\\s*${idUpper})*|${backQuotedId}|${plainid})|(?=\\())`,
688+
match: `\\b(?:(val)|(var))\\s+(${anyId})`,
666689
captures: {
667690
'1': {
668691
name: 'keyword.declaration.stable.scala'

tests/snap/scala_spec.test.scala.snap

+1-1
Original file line numberDiff line numberDiff line change
@@ -949,7 +949,7 @@
949949
#^^ source.scala
950950
# ^^^ source.scala keyword.declaration.stable.scala
951951
# ^ source.scala
952-
# ^^^^ source.scala variable.other.declaration.scala
952+
# ^^^^ source.scala entity.name.class
953953
# ^ source.scala meta.bracket.scala
954954
# ^ source.scala
955955
# ^ source.scala meta.bracket.scala

tests/unit/#51.test.scala

+41-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,47 @@
33
object Enum extends Enumeration {
44
val Foo, Bar, Baz = Value
55
// ^^^ keyword.declaration.stable.scala
6-
// ^^^ variable.other.declaration.scala
7-
// ^^^ variable.other.declaration.scala
8-
// ^^^ variable.other.declaration.scala
6+
// ^^^ - variable.other.declaration.scala
7+
// ^^^ - variable.other.declaration.scala
8+
// ^^^ - variable.other.declaration.scala
99
// ^^^^^ entity.name.class
1010

11+
val foo, bar, baz = Value
12+
// ^^^ keyword.declaration.stable.scala
13+
// ^^^ - variable.other.declaration.scala
14+
// ^^^ - variable.other.declaration.scala
15+
// ^^^ - variable.other.declaration.scala
16+
// ^^^^^ entity.name.class
17+
18+
val (foo
19+
// ^^^ keyword.declaration.stable.scala
20+
// ^^^ - variable.other.declaration.scala
21+
22+
val `foo`,
23+
// ^^^ keyword.declaration.stable.scala
24+
// ^^^^^ - variable.other.declaration.scala
25+
26+
var Foo,
27+
// ^^^ keyword.declaration.volatile.scala
28+
// ^^^ - variable.other.declaration.scala
29+
30+
var foo,
31+
// ^^^ keyword.declaration.volatile.scala
32+
// ^^^ - variable.other.declaration.scala
33+
34+
var `foo`,
35+
// ^^^ keyword.declaration.volatile.scala
36+
// ^^^^^ - variable.other.declaration.scala
37+
38+
var (foo
39+
// ^^^ keyword.declaration.volatile.scala
40+
// ^^^ - variable.other.declaration.scala
41+
42+
val Some(x) =
43+
// ^^^ keyword.declaration.stable.scala
44+
// ^^^^ - variable.other.declaration.scala
45+
46+
val some(x) =
47+
// ^^^ keyword.declaration.stable.scala
48+
// ^^^^ - variable.other.declaration.scala
1149
}

0 commit comments

Comments
 (0)