Scala 3 Indentation with onComplete

I have some code

def decryptRoute(keyId: String, data: ByteString) = onComplete(decrypt(keyId, ByteString(data))) {
  case Failure(cause) => complete(HttpEntity(ContentTypes.`text/html(UTF-8)`, s"<h1>decrypting failure</h1>"))
  case Success(value) => complete(HttpEntity(ContentTypes.`application/octet-stream`, value))
}

but I cannot seem to find a way to eliminate the surrounding { case… }. I am using IntelliJ with the Dotty support.

Should what I am trying to do be possible, and how? Or am I experiencing some limitation in IntelliJ support for Dotty?

By the rules defined at https://dotty.epfl.ch/docs/reference/other-new-features/indentation.html#optional-braces you cannot seem to remove the braces in your case:

An indent is inserted at a line break, if

1. An indentation region can start at the current position in the source, and
2. the first token on the next line has an indentation width strictly greater than the current indentation width

An indentation region can start

* after the leading parameters of an extension, or
* after a with in a given instance, or
* after a ": at end of line" token (see below)
* after one of the following tokens:

=  =>  ?=>  <-  catch  do  else  finally  for  if  match  return  then  throw  try  while  yield
1 Like

Thanks, I read that too, but could not understand that description.

With -Yindent-colons enabled, using : after onComplete(decrypt(keyId, ByteString(data))) should work. If the rules haven’t changed again…

2 Likes