Skip to content

Commit

Permalink
Fix #103: Detect as
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasstucki committed Jul 6, 2020
1 parent 5b19916 commit b6e47aa
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 6 deletions.
35 changes: 31 additions & 4 deletions src/typescript/Scala.tmLanguage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export const scalaTmLanguage: TmLanguage = {
match: `(?x)(given\\s)?\\s*(?:(${idUpper})|(${backQuotedId}|${plainid}))\\s*(=>)\\s*(?:(${idUpper})|(${backQuotedId}|${plainid}))\\s*`,
captures: {
'1': {
name: 'keyword.other.given.scala'
name: 'keyword.import.given.scala'
},
'2': {
name: 'entity.name.class.import.renamed-from.scala'
Expand All @@ -98,7 +98,7 @@ export const scalaTmLanguage: TmLanguage = {
match: `(given\\s+)?(?:(${idUpper})|(${backQuotedId}|${plainid}))`,
captures: {
'1': {
name: 'keyword.given.import.scala'
name: 'keyword.import.given.scala'
},
'2': {
name: 'entity.name.class.import.scala'
Expand Down Expand Up @@ -127,7 +127,7 @@ export const scalaTmLanguage: TmLanguage = {
name: 'keyword.other.export.scala'
},
'2': {
name: 'keyword.other.given.scala'
name: 'keyword.other.export.given.scala'
}
},
patterns: [
Expand Down Expand Up @@ -246,6 +246,9 @@ export const scalaTmLanguage: TmLanguage = {
{
include: '#using'
},
{
include: '#as'
},
{
include: '#constants'
},
Expand Down Expand Up @@ -413,6 +416,16 @@ export const scalaTmLanguage: TmLanguage = {
}
]
},
'as': {
patterns: [
{
match: '\\s(as)\\s',
captures: {
'1': { name: 'keyword.declaration.scala' }
}
}
]
},
'string-interpolation': {
patterns: [
{
Expand Down Expand Up @@ -692,6 +705,20 @@ export const scalaTmLanguage: TmLanguage = {
}
],
name: 'meta.package.scala'
},
{
match: `\\b(given)\\s+(as)\\s`,
captures: {
'1': { name: 'keyword.declaration.scala' },
'2': { name: 'keyword.declaration.scala' }
}
},
{
match: `\\b(given)\\s+(${backQuotedId}|${plainid})?`,
captures: {
'1': { name: 'keyword.declaration.scala' },
'2': { name: 'entity.name.declaration' }
}
}
]
},
Expand Down Expand Up @@ -802,7 +829,7 @@ export const scalaTmLanguage: TmLanguage = {
name: 'storage.modifier.access'
},
{
match: '\\b(synchronized|@volatile|abstract|final|lazy|sealed|implicit|given|enum|inline |opaque |override|@transient|@native)\\b',
match: '\\b(synchronized|@volatile|abstract|final|lazy|sealed|implicit|enum|inline |opaque |override|@transient|@native)\\b',
name: 'storage.modifier.other'
}
]
Expand Down
69 changes: 69 additions & 0 deletions tests/unit/#103.test.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// SYNTAX TEST "source.scala"

given as Foo = ...
// ^^^^^ keyword.declaration.scala
// ^^ keyword.declaration.scala

given foo as Foo = ...
// ^^^^^ keyword.declaration.scala
// ^^^ entity.name.declaration
// ^^ keyword.declaration.scala

given (x: X) as Foo = ...
// ^^^^^ keyword.declaration.scala
// ^ variable.parameter.scala
// ^ meta.colon.scala
// ^ entity.name.class
// ^^ keyword.declaration.scala

given [X](x: X) as Foo = ...
// ^^^^^ keyword.declaration.scala
// ^ entity.name.class
// ^ variable.parameter.scala
// ^ meta.colon.scala
// ^ entity.name.class
// ^^ keyword.declaration.scala

given foo(x: A) as Foo = ...
// ^^^^^ keyword.declaration.scala
// ^^^ entity.name.declaration
// ^ variable.parameter.scala
// ^ meta.colon.scala
// ^ entity.name.class
// ^^ keyword.declaration.scala

given foo[X](x: X) as Foo = ...
// ^^^^^ keyword.declaration.scala
// ^^^ entity.name.declaration
// ^ entity.name.class
// ^ variable.parameter.scala
// ^ meta.colon.scala
// ^ entity.name.class
// ^^ keyword.declaration.scala

given foo[X <: Y { type A = 1; def f(using a: Int): 2 }](x: X = 2) as Foo = ...
// ^^^^^ keyword.declaration.scala
// ^^^ entity.name.declaration
// ^^^^ keyword.declaration.scala
// ^ constant.numeric.scala
// ^^^ keyword.declaration.scala
// ^ entity.name.function.declaration
// ^^^^^ keyword.declaration.scala
// ^ variable.parameter.scala
// ^ meta.colon.scala
// ^^^ entity.name.class
// ^ constant.numeric.scala
// ^ constant.numeric.scala

given (using x: X = "abs")(using y: Y = s"y: $x", y: Char = if true then 'a' else 2) as Foo = ...
// ^^^^^ keyword.declaration.scala
// ^^^^^ string.quoted.double.scala
// ^ keyword.interpolation.scala
// ^^^^ string.quoted.double.interpolated.scala
// ^^ meta.template.expression.scala
// ^^ keyword.control.flow.scala
// ^^^^ constant.language.scala
// ^^^^ keyword.control.flow.scala
// ^^^ constant.character.literal.scala
// ^^^^ keyword.control.flow.scala
// ^ constant.numeric.scala
4 changes: 2 additions & 2 deletions tests/unit/imports.test.scala
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
// ^ meta.import.scala entity.name.import.scala
// ^ meta.import.scala punctuation.definition.import
// ^ meta.import.scala meta.import.selector.scala meta.bracket.scala
// ^^^^^ meta.import.scala keyword.given.import.scala
// ^^^^^ meta.import.scala keyword.import.given.scala
// ^ meta.import.scala meta.import.selector.scala
// ^ meta.import.scala entity.name.import.scala
// ^ meta.import.scala meta.import.selector.scala
Expand All @@ -59,7 +59,7 @@
// ^ meta.import.scala entity.name.class.import.scala
// ^ meta.import.scala punctuation.definition.import
// ^ meta.import.scala meta.import.selector.scala meta.bracket.scala
// ^^^^^ meta.import.scala keyword.given.import.scala
// ^^^^^ meta.import.scala keyword.import.given.scala
// ^ meta.import.scala meta.import.selector.scala
// ^^ meta.import.scala entity.name.class.import.scala
// ^ meta.import.scala meta.import.selector.scala

0 comments on commit b6e47aa

Please sign in to comment.