From b4b1541b27e7d45483e8819264ba7ab6c1fdd148 Mon Sep 17 00:00:00 2001 From: Katarzyna Marek Date: Wed, 24 Jul 2024 12:46:24 +0200 Subject: [PATCH] fix: don't add suffix if brackets already present --- .../tools/pc/completions/Completions.scala | 4 +++ .../completion/CompletionSnippetSuite.scala | 31 +++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/presentation-compiler/src/main/dotty/tools/pc/completions/Completions.scala b/presentation-compiler/src/main/dotty/tools/pc/completions/Completions.scala index db578e32663f..a657df224ab6 100644 --- a/presentation-compiler/src/main/dotty/tools/pc/completions/Completions.scala +++ b/presentation-compiler/src/main/dotty/tools/pc/completions/Completions.scala @@ -65,6 +65,10 @@ class Completions( */ case (fun) :: (appl: GenericApply) :: _ if appl.fun == fun => false + /* In case of `T@@[]` we should not add snippets. + */ + case tpe :: (appl: AppliedTypeTree) :: _ if appl.tpt == tpe => + false case _ :: (withcursor @ Select(fun, name)) :: (appl: GenericApply) :: _ if appl.fun == withcursor && name.decoded == Cursor.value => false diff --git a/presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionSnippetSuite.scala b/presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionSnippetSuite.scala index 5769304919ca..2c91f71d8d19 100644 --- a/presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionSnippetSuite.scala +++ b/presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionSnippetSuite.scala @@ -451,3 +451,34 @@ class CompletionSnippetSuite extends BaseCompletionSuite: """.stripMargin, filter = _.contains("bar: Int") ) + + @Test def `brackets-already-present` = + check( + """|package a + |case class AAA[T]() + |object O { + | val l: AA@@[Int] = ??? + |} + |""".stripMargin, + """|AAA a + |ArrowAssoc scala.Predef + |""".stripMargin, + ) + + @Test def `brackets-already-present-edit` = + checkEdit( + """|package a + |case class AAA[T]() + |object O { + | val l: AA@@[Int] = ??? + |} + |""".stripMargin, + """|package a + |case class AAA[T]() + |object O { + | val l: AAA[Int] = ??? + |} + |""".stripMargin, + assertSingleItem = false, + ) +