Skip to content

Commit 93f863c

Browse files
committed
bugfix: add multiline comment completion
1 parent 55c5864 commit 93f863c

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

presentation-compiler/src/main/dotty/tools/pc/completions/Completions.scala

+9
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,15 @@ class Completions(
286286
path match
287287
case ScalaCliCompletions(dependency) =>
288288
(ScalaCliCompletions.contribute(dependency), true)
289+
290+
case _
291+
if MultilineCommentCompletion.isMultilineCommentCompletion(
292+
pos,
293+
text,
294+
) =>
295+
val values = MultilineCommentCompletion.contribute(config)
296+
(values, true)
297+
289298
case _ if ScaladocCompletions.isScaladocCompletion(pos, text) =>
290299
val values = ScaladocCompletions.contribute(pos, text, config)
291300
(values, true)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package dotty.tools.pc.completions
2+
3+
import scala.meta.pc.PresentationCompilerConfig
4+
5+
import dotty.tools.dotc.util.SourcePosition
6+
7+
object MultilineCommentCompletion:
8+
9+
def contribute(config: PresentationCompilerConfig): List[CompletionValue] =
10+
val newText = if config.isCompletionSnippetsEnabled then " $0 */" else " */"
11+
List(CompletionValue.document("/* */", newText, "Multiline Comment"))
12+
13+
def isMultilineCommentCompletion(pos: SourcePosition, text: String): Boolean =
14+
pos.point >= 2 &&
15+
text.charAt(pos.point - 2) == '/' &&
16+
text.charAt(pos.point - 1) == '*'

presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionSuite.scala

+14
Original file line numberDiff line numberDiff line change
@@ -1486,3 +1486,17 @@ class CompletionSuite extends BaseCompletionSuite:
14861486
|""".stripMargin,
14871487
)
14881488

1489+
@Test def `multiline-comment` =
1490+
checkEdit(
1491+
"""|package a
1492+
|object O:
1493+
| /*@@
1494+
| def f = 1
1495+
|""".stripMargin,
1496+
"""|package a
1497+
|object O:
1498+
| /* $0 */
1499+
| def f = 1
1500+
|""".stripMargin,
1501+
)
1502+

0 commit comments

Comments
 (0)