Skip to content

Fix #133: Highlight inline as a soft keyword #138

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion src/typescript/Scala.tmLanguage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,9 @@ export const scalaTmLanguage: TmLanguage = {
{
include: '#singleton-type'
},
{
include: '#inline'
},
{
include: '#scala-quoted'
},
Expand Down Expand Up @@ -571,6 +574,26 @@ export const scalaTmLanguage: TmLanguage = {
}
}
},
inline: {
patterns: [
{
match: `\\b(inline)\\b(?=(?:.(?!val|def|given))*(if|match))`,
captures: {
'1': {
name: 'keyword.control.flow.scala'
}
}
},
{
match: `\\b(inline)\\s+(?=(([\\w\\s]*(val|def|given))|(${plainid}|${backQuotedId})\\s*:))`,
captures: {
'1': {
name: 'storage.modifier.other'
}
}
}
]
},
'scala-quoted': {
match: "('\\{|'\\[)(?!')",
name: 'constant.other.quoted.scala'
Expand Down Expand Up @@ -822,7 +845,7 @@ export const scalaTmLanguage: TmLanguage = {
name: 'storage.modifier.access'
},
{
match: '\\b(synchronized|@volatile|abstract|final|lazy|sealed|implicit|inline |opaque |override|@transient|@native)\\b',
match: '\\b(synchronized|@volatile|abstract|final|lazy|sealed|implicit|opaque |override|@transient|@native)\\b',
name: 'storage.modifier.other'
}
]
Expand Down
53 changes: 53 additions & 0 deletions tests/unit/#133.test.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// SYNTAX TEST "source.scala"


inline val c = 0
// ^^^^^^ storage.modifier.other

inline def power(x: Double, inline n: Int): Double =
// ^^^^^^ storage.modifier.other
// ^^^^^^ storage.modifier.other
inline if (n == 0) 1.0
// ^^^^^^ keyword.control.flow.scala
else inline if (n % 2 == 1) x * power(x, n - 1)
// ^^^^^^ keyword.control.flow.scala
else power(x * x, n / 2)


inline x match {
// ^^^^^^ keyword.control.flow.scala
// ^^^^^ keyword.control.flow.scala


inline def power(x: Double, inline N: Int): Double =
// ^^^^^^ storage.modifier.other
// ^^^^^^ storage.modifier.other

inline def power(x: Double, inline `n`: Int): Double =
// ^^^^^^ storage.modifier.other
// ^^^^^^ storage.modifier.other

val x = inline + 2
// ^^^^^^ - storage.modifier.other keyword.control.flow.scala
val x = inline(x)
// ^^^^^^ - storage.modifier.other keyword.control.flow.scala
val x = inline[T]
// ^^^^^^ - storage.modifier.other keyword.control.flow.scala

inline def inline(inline inline: Int): Double =
// ^^^^^^ storage.modifier.other
// ^^^^^^ entity.name.function.declaration
// ^^^^^^ storage.modifier.other
// ^^^^^^ variable.parameter.scala

inline if (n == 0) 1 else 2; val x = 2
// ^^^^^^ keyword.control.flow.scala
// ^^ keyword.control.flow.scala

inline if (n == 0) 1 else 2; def x = 2
// ^^^^^^ keyword.control.flow.scala
// ^^ keyword.control.flow.scala

inline f[X](x: X) match {
// ^^^^^^ keyword.control.flow.scala
// ^^^^^ keyword.control.flow.scala
10 changes: 10 additions & 0 deletions tests/unit/#139.test.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SYNTAX TEST "source.scala"


inline def mkDefaultTypeable[T]: Typeable[T] = ${ TypeableMacros.impl[T] }
// ^^^^^^ storage.modifier.other
// ^^^ keyword.declaration.scala

inline given [T] as Typeable[T] = mkDefaultTypeable[T]
// ^^^^^^ storage.modifier.other
// ^^^^^ keyword.declaration.scala