diff --git a/src/typescript/Scala.tmLanguage.ts b/src/typescript/Scala.tmLanguage.ts index c8c1d88..186b9a5 100644 --- a/src/typescript/Scala.tmLanguage.ts +++ b/src/typescript/Scala.tmLanguage.ts @@ -18,7 +18,7 @@ const idUpper = `${upperLetter}${letterOrDigit}*(?:(?<=_)${opchar}+)?` const idLower = `${lowerLetter}${letterOrDigit}*(?:(?<=_)${opchar}+)?` const plainid = `(?:${idrest}|${opchar}+)` const backQuotedId = "`[^`]+`" - +const endOfLineMaybeWithComment = "(?=\\s*(//.*|/\\*(?!.*\\*/\\s*\\S.*).*)?$)" export const scalaTmLanguage: TmLanguage = { fileTypes: [ @@ -486,9 +486,34 @@ export const scalaTmLanguage: TmLanguage = { name: 'keyword.control.flow.scala' }, { - match: `^\\s*end(?=\\s+(if|while|for|match|${plainid})\\s*(//.*|/\\*(?!.*\\*/\\s*\\S.*).*)?$)`, + match: `^\\s*(end)\\s+(if|while|for|match)${endOfLineMaybeWithComment}`, name: 'keyword.control.flow.end.scala' }, + { + match: `^\\s*(end)\\s+(?:(new)|(${idUpper}))${endOfLineMaybeWithComment}`, + captures: { + '1': { + name: 'keyword.declaration.end.scala' + }, + '2': { + name: 'keyword.declaration.end.scala' + }, + '3': { + name: 'entity.name.type.declaration' + } + } + }, + { + match: `^\\s*(end)\\s+(${backQuotedId}|${plainid})?${endOfLineMaybeWithComment}`, + captures: { + '1': { + name: 'keyword.declaration.end.scala' + }, + '2': { + name: 'entity.name.declaration' + } + } + }, { match: '\\b(catch|finally|try)\\b', name: 'keyword.control.exception.scala' diff --git a/tests/unit/#107.test.scala b/tests/unit/#107.test.scala new file mode 100644 index 0000000..48b86a5 --- /dev/null +++ b/tests/unit/#107.test.scala @@ -0,0 +1,43 @@ +// SYNTAX TEST "source.scala" + + new Foo: +// ^^^ keyword.declaration.scala + ... + end new +// ^^^ keyword.declaration.end.scala +// ^^^ keyword.declaration.end.scala + + end if +// ^^^ keyword.control.flow.end.scala +// ^^ keyword.control.flow.end.scala + + end while +// ^^^ keyword.control.flow.end.scala +// ^^^^^ keyword.control.flow.end.scala + + end for +// ^^^ keyword.control.flow.end.scala +// ^^^ keyword.control.flow.end.scala + + end match +// ^^^ keyword.control.flow.end.scala +// ^^^^^ keyword.control.flow.end.scala + + class Foo +// ^^^ entity.name.class.declaration + end Foo +// ^^^ keyword.declaration.end.scala +// ^^^ entity.name.type.declaration + + def foo +// ^^^ entity.name.function.declaration + end bar +// ^^^ keyword.declaration.end.scala +// ^^^ entity.name.declaration + + end `bar` +// ^^^ keyword.declaration.end.scala +// ^^^ entity.name.declaration + + end +// ^^^ keyword.declaration.end.scala \ No newline at end of file