Repository: scalameta/scalameta (scala)

Issue:
partial functions using fewerBraces incorrectly reports an error
### Describe the bug

Using fewerBraces syntax on partial functions incorrectly renders an error

![image](https://user-images.githubusercontent.com/25370730/194426655-9c02d480-ce07-440d-b049-e6aaffc82b14.png)

This code compiles correctly in SBT. In the example above, the error disappears when reverting to the old curly brace syntax. E.g.

![image](https://user-images.githubusercontent.com/25370730/194428348-9bcf16d4-a391-4d0c-aff2-d9ec2c86d963.png)


### Expected behavior

This code should not report an error

### Operating system

Windows

### Editor/Extension

VS Code

### Version of Metals

v0.11.9

### Extra context or search terms

_No response_

Pull request:
It's not an ideal solution, but regions are a bit of black magic unfortunately. The other solutions might be more complex then this.

Fixes https://github.com/scalameta/scalameta/issues/2900

Patch:
diff --git a/scalameta/parsers/shared/src/main/scala/scala/meta/internal/parsers/LazyTokenIterator.scala b/scalameta/parsers/shared/src/main/scala/scala/meta/internal/parsers/LazyTokenIterator.scala
index cb2911c7ab..ca9949c323 100644
--- a/scalameta/parsers/shared/src/main/scala/scala/meta/internal/parsers/LazyTokenIterator.scala
+++ b/scalameta/parsers/shared/src/main/scala/scala/meta/internal/parsers/LazyTokenIterator.scala
@@ -102,11 +102,19 @@ private[parsers] class LazyTokenIterator private (
 
   def observeIndented(): Boolean = {
     observeIndented0 { (i, prev) =>
+      /* When adding RegionIndent (we wrap the current code block in indentation)
+       * we might no longer need the region added on the current token.
+       *
+       * In case the region was needed, we will add it again as we haven't yet progressed
+       * to the next token.
+       */
       val undoRegionChange =
         prev.headOption match {
           case Some(RegionParen(_)) if token.is[LeftParen] => prev.tail
           case Some(RegionEnumArtificialMark) if token.is[KwEnum] => prev.tail
           case Some(_: RegionBrace) if token.is[LeftBrace] => prev.tail
+          //  Handle fewer braces and partial function.
+          case Some(RegionArrow) if dialect.allowFewerBraces && token.is[KwCase] => prev.tail
           case _ => prev
         }
       RegionIndent(i, false) :: undoRegionChange


Test patch:
diff --git a/tests/shared/src/test/scala/scala/meta/tests/parsers/dotty/FeverBracesSuite.scala b/tests/shared/src/test/scala/scala/meta/tests/parsers/dotty/FeverBracesSuite.scala
index 37081a8926..999d824c84 100644
--- a/tests/shared/src/test/scala/scala/meta/tests/parsers/dotty/FeverBracesSuite.scala
+++ b/tests/shared/src/test/scala/scala/meta/tests/parsers/dotty/FeverBracesSuite.scala
@@ -161,6 +161,66 @@ class FeverBracesSuite extends BaseDottySuite {
     )
   }
 
+  test("multi-case") {
+    runTestAssert[Stat](
+      """|def main =
+         |  val firstLine = files.map: 
+         |    case A(a) =>
+         |      a         
+         |    case B(b) =>
+         |      b
+         |  def hello = ???
+         |""".stripMargin,
+      assertLayout = Some(
+        """|def main = {
+           |  val firstLine = files.map({
+           |    case A(a) => a
+           |    case B(b) => b
+           |  })
+           |  def hello = ???
+           |}
+           |""".stripMargin
+      )
+    )(
+      Defn.Def(
+        Nil,
+        Term.Name("main"),
+        Nil,
+        Nil,
+        None,
+        Term.Block(
+          List(
+            Defn.Val(
+              Nil,
+              List(Pat.Var(Term.Name("firstLine"))),
+              None,
+              Term.Apply(
+                Term.Select(Term.Name("files"), Term.Name("map")),
+                List(
+                  Term.PartialFunction(
+                    List(
+                      Case(
+                        Pat.Extract(Term.Name("A"), List(Pat.Var(Term.Name("a")))),
+                        None,
+                        Term.Name("a")
+                      ),
+                      Case(
+                        Pat.Extract(Term.Name("B"), List(Pat.Var(Term.Name("b")))),
+                        None,
+                        Term.Name("b")
+                      )
+                    )
+                  )
+                )
+              )
+            ),
+            Defn.Def(Nil, Term.Name("hello"), Nil, Nil, None, Term.Name("???"))
+          )
+        )
+      )
+    )
+  }
+
   test("multiple") {
     runTestAssert[Stat](
       """|def O =