Skip to content

Support scala3 styled imports #295

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ object ScalaFormatter {
THROW, TRAIT, TRY, /* TYPE ,*/
VAL, VAR, WHILE, WITH, YIELD,
/* USCORE, */ COLON, EQUALS, ARROW, LARROW, SUBTYPE, VIEWBOUND, SUPERTYPE, /* HASH, AT */
LBRACE, SEMI)
LBRACE, SEMI, AS)

val ENSURE_SPACE_BEFORE: Set[TokenType] = Set(
ABSTRACT, CASE, CATCH, CLASS, DEF,
Expand All @@ -577,7 +577,7 @@ object ScalaFormatter {
/* THROW, */ TRAIT, /* TRY, TYPE, */
VAL, VAR, /* WHILE, */ WITH, YIELD,
/* USCORE, COLON, */ EQUALS, /* ARROW, */ LARROW, SUBTYPE, VIEWBOUND, SUPERTYPE, /*, HASH, AT, */
RBRACE)
RBRACE, AS)
// format: ON

@throws(classOf[ScalaParserException])
Expand Down
3 changes: 2 additions & 1 deletion scalariform/src/main/scala/scalariform/lexer/Keywords.scala
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ object Keywords {
"*" -> STAR,
"|" -> PIPE,
"~" -> TILDE,
"!" -> EXCLAMATION
"!" -> EXCLAMATION,
"as" -> AS
)

}
3 changes: 2 additions & 1 deletion scalariform/src/main/scala/scalariform/lexer/Tokens.scala
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ object Tokens {
val XML_CDATA = TokenType("XML_CDATA", isXml = true)
val XML_UNPARSED = TokenType("XML_UNPARSED", isXml = true)
val XML_PROCESSING_INSTRUCTION = TokenType("XML_PROCESSING_INSTRUCTION", isXml = true)
val AS = TokenType("AS")

val KEYWORDS: Set[TokenType] = Set(
ABSTRACT, CASE, CATCH, CLASS, DEF,
Expand All @@ -106,7 +107,7 @@ object Tokens {
OBJECT, OVERRIDE, PACKAGE, PRIVATE, PROTECTED,
RETURN, SEALED, SUPER, THIS,
THROW, TRAIT, TRY, TYPE,
VAL, VAR, WHILE, WITH, YIELD
VAL, VAR, WHILE, WITH, YIELD, AS
)

val COMMENTS: Set[TokenType] = Set(LINE_COMMENT, MULTILINE_COMMENT, XML_COMMENT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1322,10 +1322,10 @@ class ScalaParser(tokens: Array[Token]) {
private def importSelector(): Expr = {
val first = wildcardOrIdent()
currentTokenType match {
case ARROW ⇒
val arrowToken = nextToken()
case ARROW | AS
val token = nextToken()
val rename = wildcardOrIdent()
makeExpr(first, arrowToken, rename)
makeExpr(first, token, rename)
case _ ⇒
makeExpr(first)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ class ImportFormatterTest extends AbstractFormatterTest {
"import foo . _" ==> "import foo._"
"import foo . bar" ==> "import foo.bar"
"import foo.{bar=>baz}" ==> "import foo.{ bar => baz }"
"import foo.{bar as baz}" ==> "import foo.{ bar as baz }"
"import foo.{bar=>baz},baz.biz" ==> "import foo.{ bar => baz }, baz.biz"
"import foo.{bar as baz},baz.biz" ==> "import foo.{ bar as baz }, baz.biz"
"""import foo.{bar => baz,
|wibble => wobble}""" ==>
"""import foo.{
Expand All @@ -29,7 +31,9 @@ class ImportFormatterTest extends AbstractFormatterTest {
"import foo . _" ==> "import foo._"
"import foo . bar" ==> "import foo.bar"
"import foo.{bar=>baz}" ==> "import foo.{bar => baz}"
"import foo.{bar as baz}" ==> "import foo.{bar as baz}"
"import foo.{bar=>baz},baz.biz" ==> "import foo.{bar => baz}, baz.biz"
"import foo.{bar as baz},baz.biz" ==> "import foo.{bar as baz}, baz.biz"
"""import foo.{bar => baz,
|wibble => wobble}""" ==>
"""import foo.{
Expand Down