From 93f863c407f9c7ece40efd89c64dd53eec6d2074 Mon Sep 17 00:00:00 2001 From: Katarzyna Marek Date: Mon, 16 Oct 2023 13:00:51 +0200 Subject: [PATCH] bugfix: add multiline comment completion --- .../dotty/tools/pc/completions/Completions.scala | 9 +++++++++ .../completions/MultilineCommentCompletion.scala | 16 ++++++++++++++++ .../pc/tests/completion/CompletionSuite.scala | 14 ++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 presentation-compiler/src/main/dotty/tools/pc/completions/MultilineCommentCompletion.scala 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 64bbbb848289..aa3fa59e518e 100644 --- a/presentation-compiler/src/main/dotty/tools/pc/completions/Completions.scala +++ b/presentation-compiler/src/main/dotty/tools/pc/completions/Completions.scala @@ -286,6 +286,15 @@ class Completions( path match case ScalaCliCompletions(dependency) => (ScalaCliCompletions.contribute(dependency), true) + + case _ + if MultilineCommentCompletion.isMultilineCommentCompletion( + pos, + text, + ) => + val values = MultilineCommentCompletion.contribute(config) + (values, true) + case _ if ScaladocCompletions.isScaladocCompletion(pos, text) => val values = ScaladocCompletions.contribute(pos, text, config) (values, true) diff --git a/presentation-compiler/src/main/dotty/tools/pc/completions/MultilineCommentCompletion.scala b/presentation-compiler/src/main/dotty/tools/pc/completions/MultilineCommentCompletion.scala new file mode 100644 index 000000000000..46a23446a7f1 --- /dev/null +++ b/presentation-compiler/src/main/dotty/tools/pc/completions/MultilineCommentCompletion.scala @@ -0,0 +1,16 @@ +package dotty.tools.pc.completions + +import scala.meta.pc.PresentationCompilerConfig + +import dotty.tools.dotc.util.SourcePosition + +object MultilineCommentCompletion: + + def contribute(config: PresentationCompilerConfig): List[CompletionValue] = + val newText = if config.isCompletionSnippetsEnabled then " $0 */" else " */" + List(CompletionValue.document("/* */", newText, "Multiline Comment")) + + def isMultilineCommentCompletion(pos: SourcePosition, text: String): Boolean = + pos.point >= 2 && + text.charAt(pos.point - 2) == '/' && + text.charAt(pos.point - 1) == '*' diff --git a/presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionSuite.scala b/presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionSuite.scala index 7ca7f9a19b04..213dd7157293 100644 --- a/presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionSuite.scala +++ b/presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionSuite.scala @@ -1486,3 +1486,17 @@ class CompletionSuite extends BaseCompletionSuite: |""".stripMargin, ) + @Test def `multiline-comment` = + checkEdit( + """|package a + |object O: + | /*@@ + | def f = 1 + |""".stripMargin, + """|package a + |object O: + | /* $0 */ + | def f = 1 + |""".stripMargin, + ) +