Skip to content

Commit

Permalink
Backport "bugfix: add multiline comment completion" to LTS (#20714)
Browse files Browse the repository at this point in the history
Backports #18703 to the LTS branch.

PR submitted by the release tooling.
[skip ci]
  • Loading branch information
WojciechMazur authored Jun 22, 2024
2 parents 2d78092 + 427c444 commit a76f9a2
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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) == '*'
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

0 comments on commit a76f9a2

Please sign in to comment.