Skip to content

Commit 2f326ef

Browse files
Merge pull request #109 from nicolasstucki/fix-#107
Fix #107: Identify highlighting of identifier after an `end`
2 parents 857a792 + 269b658 commit 2f326ef

File tree

2 files changed

+70
-2
lines changed

2 files changed

+70
-2
lines changed

src/typescript/Scala.tmLanguage.ts

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const idUpper = `${upperLetter}${letterOrDigit}*(?:(?<=_)${opchar}+)?`
1818
const idLower = `${lowerLetter}${letterOrDigit}*(?:(?<=_)${opchar}+)?`
1919
const plainid = `(?:${idrest}|${opchar}+)`
2020
const backQuotedId = "`[^`]+`"
21-
21+
const endOfLineMaybeWithComment = "(?=\\s*(//.*|/\\*(?!.*\\*/\\s*\\S.*).*)?$)"
2222

2323
export const scalaTmLanguage: TmLanguage = {
2424
fileTypes: [
@@ -486,9 +486,34 @@ export const scalaTmLanguage: TmLanguage = {
486486
name: 'keyword.control.flow.scala'
487487
},
488488
{
489-
match: `^\\s*end(?=\\s+(if|while|for|match|${plainid})\\s*(//.*|/\\*(?!.*\\*/\\s*\\S.*).*)?$)`,
489+
match: `^\\s*(end)\\s+(if|while|for|match)${endOfLineMaybeWithComment}`,
490490
name: 'keyword.control.flow.end.scala'
491491
},
492+
{
493+
match: `^\\s*(end)\\s+(?:(new)|(${idUpper}))${endOfLineMaybeWithComment}`,
494+
captures: {
495+
'1': {
496+
name: 'keyword.declaration.end.scala'
497+
},
498+
'2': {
499+
name: 'keyword.declaration.end.scala'
500+
},
501+
'3': {
502+
name: 'entity.name.type.declaration'
503+
}
504+
}
505+
},
506+
{
507+
match: `^\\s*(end)\\s+(${backQuotedId}|${plainid})?${endOfLineMaybeWithComment}`,
508+
captures: {
509+
'1': {
510+
name: 'keyword.declaration.end.scala'
511+
},
512+
'2': {
513+
name: 'entity.name.declaration'
514+
}
515+
}
516+
},
492517
{
493518
match: '\\b(catch|finally|try)\\b',
494519
name: 'keyword.control.exception.scala'

tests/unit/#107.test.scala

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// SYNTAX TEST "source.scala"
2+
3+
new Foo:
4+
// ^^^ keyword.declaration.scala
5+
...
6+
end new
7+
// ^^^ keyword.declaration.end.scala
8+
// ^^^ keyword.declaration.end.scala
9+
10+
end if
11+
// ^^^ keyword.control.flow.end.scala
12+
// ^^ keyword.control.flow.end.scala
13+
14+
end while
15+
// ^^^ keyword.control.flow.end.scala
16+
// ^^^^^ keyword.control.flow.end.scala
17+
18+
end for
19+
// ^^^ keyword.control.flow.end.scala
20+
// ^^^ keyword.control.flow.end.scala
21+
22+
end match
23+
// ^^^ keyword.control.flow.end.scala
24+
// ^^^^^ keyword.control.flow.end.scala
25+
26+
class Foo
27+
// ^^^ entity.name.class.declaration
28+
end Foo
29+
// ^^^ keyword.declaration.end.scala
30+
// ^^^ entity.name.type.declaration
31+
32+
def foo
33+
// ^^^ entity.name.function.declaration
34+
end bar
35+
// ^^^ keyword.declaration.end.scala
36+
// ^^^ entity.name.declaration
37+
38+
end `bar`
39+
// ^^^ keyword.declaration.end.scala
40+
// ^^^ entity.name.declaration
41+
42+
end
43+
// ^^^ keyword.declaration.end.scala

0 commit comments

Comments
 (0)