Skip to content

Commit 77042c6

Browse files
authored
Merge pull request scala#116 from nicolasstucki/fix-#103-2
Fix scala#103: Detect `as`
2 parents e377b96 + 03641e3 commit 77042c6

File tree

3 files changed

+107
-6
lines changed

3 files changed

+107
-6
lines changed

src/typescript/Scala.tmLanguage.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export const scalaTmLanguage: TmLanguage = {
7575
match: `(?x)(given\\s)?\\s*(?:(${idUpper})|(${backQuotedId}|${plainid}))\\s*(=>)\\s*(?:(${idUpper})|(${backQuotedId}|${plainid}))\\s*`,
7676
captures: {
7777
'1': {
78-
name: 'keyword.other.given.scala'
78+
name: 'keyword.other.import.given.scala'
7979
},
8080
'2': {
8181
name: 'entity.name.class.import.renamed-from.scala'
@@ -98,7 +98,7 @@ export const scalaTmLanguage: TmLanguage = {
9898
match: `(given\\s+)?(?:(${idUpper})|(${backQuotedId}|${plainid}))`,
9999
captures: {
100100
'1': {
101-
name: 'keyword.given.import.scala'
101+
name: 'keyword.other.import.given.scala'
102102
},
103103
'2': {
104104
name: 'entity.name.class.import.scala'
@@ -127,7 +127,7 @@ export const scalaTmLanguage: TmLanguage = {
127127
name: 'keyword.other.export.scala'
128128
},
129129
'2': {
130-
name: 'keyword.other.given.scala'
130+
name: 'keyword.other.export.given.scala'
131131
}
132132
},
133133
patterns: [
@@ -546,6 +546,12 @@ export const scalaTmLanguage: TmLanguage = {
546546
{
547547
match: '(<-|←|->|→|=>|⇒|\\?|\\:+|@|\\|)+',
548548
name: 'keyword.operator.scala'
549+
},
550+
{
551+
match: '\\s(as)\\s',
552+
captures: {
553+
'1': { name: 'keyword.declaration.scala' }
554+
}
549555
}
550556
]
551557
},
@@ -692,6 +698,14 @@ export const scalaTmLanguage: TmLanguage = {
692698
}
693699
],
694700
name: 'meta.package.scala'
701+
},
702+
{
703+
match: `\\b(given)\\b\\s*(?:\\b(as)\\b|(${backQuotedId}|(?!//|/\\*)${plainid})?)`,
704+
captures: {
705+
'1': { name: 'keyword.declaration.scala' },
706+
'2': { name: 'keyword.declaration.scala' },
707+
'3': { name: 'entity.name.declaration' }
708+
}
695709
}
696710
]
697711
},
@@ -802,7 +816,7 @@ export const scalaTmLanguage: TmLanguage = {
802816
name: 'storage.modifier.access'
803817
},
804818
{
805-
match: '\\b(synchronized|@volatile|abstract|final|lazy|sealed|implicit|given|enum|inline |opaque |override|@transient|@native)\\b',
819+
match: '\\b(synchronized|@volatile|abstract|final|lazy|sealed|implicit|enum|inline |opaque |override|@transient|@native)\\b',
806820
name: 'storage.modifier.other'
807821
}
808822
]

tests/unit/#103.test.scala

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
// SYNTAX TEST "source.scala"
2+
3+
given as Foo = ...
4+
// ^^^^^ keyword.declaration.scala
5+
// ^^ keyword.declaration.scala
6+
7+
given foo as Foo = ...
8+
// ^^^^^ keyword.declaration.scala
9+
// ^^^ entity.name.declaration
10+
// ^^ keyword.declaration.scala
11+
12+
given (x: X) as Foo = ...
13+
// ^^^^^ keyword.declaration.scala
14+
// ^ variable.parameter.scala
15+
// ^ meta.colon.scala
16+
// ^ entity.name.class
17+
// ^^ keyword.declaration.scala
18+
19+
given [X](x: X) as Foo = ...
20+
// ^^^^^ keyword.declaration.scala
21+
// ^ entity.name.class
22+
// ^ variable.parameter.scala
23+
// ^ meta.colon.scala
24+
// ^ entity.name.class
25+
// ^^ keyword.declaration.scala
26+
27+
given foo(x: A) as Foo = ...
28+
// ^^^^^ keyword.declaration.scala
29+
// ^^^ entity.name.declaration
30+
// ^ variable.parameter.scala
31+
// ^ meta.colon.scala
32+
// ^ entity.name.class
33+
// ^^ keyword.declaration.scala
34+
35+
given foo[X](x: X) as Foo = ...
36+
// ^^^^^ keyword.declaration.scala
37+
// ^^^ entity.name.declaration
38+
// ^ entity.name.class
39+
// ^ variable.parameter.scala
40+
// ^ meta.colon.scala
41+
// ^ entity.name.class
42+
// ^^ keyword.declaration.scala
43+
44+
given foo[X <: Y { type A = 1; def f(using a: Int): 2 }](x: X = 2) as Foo = ...
45+
// ^^^^^ keyword.declaration.scala
46+
// ^^^ entity.name.declaration
47+
// ^^^^ keyword.declaration.scala
48+
// ^ constant.numeric.scala
49+
// ^^^ keyword.declaration.scala
50+
// ^ entity.name.function.declaration
51+
// ^^^^^ keyword.declaration.scala
52+
// ^ variable.parameter.scala
53+
// ^ meta.colon.scala
54+
// ^^^ entity.name.class
55+
// ^ constant.numeric.scala
56+
// ^ constant.numeric.scala
57+
58+
given (using x: X = "abs")(using y: Y = s"y: $x", y: Char = if true then 'a' else 2) as Foo = ...
59+
// ^^^^^ keyword.declaration.scala
60+
// ^^^^^ string.quoted.double.scala
61+
// ^ keyword.interpolation.scala
62+
// ^^^^ string.quoted.double.interpolated.scala
63+
// ^^ meta.template.expression.scala
64+
// ^^ keyword.control.flow.scala
65+
// ^^^^ constant.language.scala
66+
// ^^^^ keyword.control.flow.scala
67+
// ^^^ constant.character.literal.scala
68+
// ^^^^ keyword.control.flow.scala
69+
// ^ constant.numeric.scala
70+
71+
given // this should be a comment
72+
// ^^^^^ keyword.declaration.scala
73+
// ^^ punctuation.definition.comment.scala
74+
// ^^^^^^^^^^^^^^^^^^^^^^^^^ comment.line.double-slash.scala
75+
as Foo
76+
// ^^ keyword.declaration.scala
77+
78+
given// this should be a comment
79+
// ^^^^^ keyword.declaration.scala
80+
// ^^ punctuation.definition.comment.scala
81+
// ^^^^^^^^^^^^^^^^^^^^^^^^ comment.line.double-slash.scala
82+
83+
given /* this should be a comment */
84+
// ^^^^^ keyword.declaration.scala
85+
// ^^ punctuation.definition.comment.scala
86+
// ^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.block.scala
87+
// ^^ punctuation.definition.comment.scala

tests/unit/imports.test.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
// ^ meta.import.scala entity.name.import.scala
4949
// ^ meta.import.scala punctuation.definition.import
5050
// ^ meta.import.scala meta.import.selector.scala meta.bracket.scala
51-
// ^^^^^ meta.import.scala keyword.given.import.scala
51+
// ^^^^^ meta.import.scala keyword.other.import.given.scala
5252
// ^ meta.import.scala meta.import.selector.scala
5353
// ^ meta.import.scala entity.name.import.scala
5454
// ^ meta.import.scala meta.import.selector.scala
@@ -59,7 +59,7 @@
5959
// ^ meta.import.scala entity.name.class.import.scala
6060
// ^ meta.import.scala punctuation.definition.import
6161
// ^ meta.import.scala meta.import.selector.scala meta.bracket.scala
62-
// ^^^^^ meta.import.scala keyword.given.import.scala
62+
// ^^^^^ meta.import.scala keyword.other.import.given.scala
6363
// ^ meta.import.scala meta.import.selector.scala
6464
// ^^ meta.import.scala entity.name.class.import.scala
6565
// ^ meta.import.scala meta.import.selector.scala

0 commit comments

Comments
 (0)