Skip to content

Commit 5f8a7e4

Browse files
committed
Address review feedback
1 parent 2c40a21 commit 5f8a7e4

File tree

4 files changed

+39
-17
lines changed

4 files changed

+39
-17
lines changed

mtags/src/main/scala/scala/meta/internal/pc/CompletionProvider.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ import org.eclipse.{lsp4j => l}
1616

1717
class CompletionProvider(
1818
val compiler: MetalsGlobal,
19-
params: OffsetParams,
20-
clientSupportsSnippets: Boolean
19+
params: OffsetParams
2120
) {
2221
import compiler._
2322

@@ -45,6 +44,8 @@ class CompletionProvider(
4544
)
4645
val pos = unit.position(params.offset)
4746
val isSnippet = isSnippetEnabled(pos, params.text())
47+
val clientSupportsSnippets =
48+
compiler.metalsConfig.isCompletionSnippetsEnabled()
4849
val (i, completion, editRange, query) = safeCompletionsAt(pos)
4950
val start = inferIdentStart(pos, params.text())
5051
val end = inferIdentEnd(pos, params.text())

mtags/src/main/scala/scala/meta/internal/pc/Completions.scala

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ import scala.meta.internal.tokenizers.Chars
1919
*/
2020
trait Completions { this: MetalsGlobal =>
2121

22+
val clientSupportsSnippets =
23+
metalsConfig.isCompletionSnippetsEnabled()
24+
2225
/**
2326
* A member for symbols on the classpath that are not in scope, produced via workspace/symbol.
2427
*/
@@ -765,11 +768,11 @@ trait Completions { this: MetalsGlobal =>
765768
if (text.charAt(lit.pos.start - 1) != 's')
766769
List(new l.TextEdit(lit.pos.withEnd(lit.pos.start).toLSP, "s"))
767770
else Nil
768-
val dolarEdits = for {
771+
val dollarEdits = for {
769772
i <- lit.pos.start to (lit.pos.end - CURSOR.length())
770773
if text.charAt(i) == '$' && i != interpolator.dollar
771774
} yield new l.TextEdit(pos.source.position(i).withEnd(i).toLSP, "$")
772-
interpolatorEdit ++ dolarEdits
775+
interpolatorEdit ++ dollarEdits
773776
}
774777

775778
def newText(sym: Symbol): String = {
@@ -793,6 +796,7 @@ trait Completions { this: MetalsGlobal =>
793796

794797
val filter: String =
795798
text.substring(lit.pos.start, pos.point - interpolator.name.length)
799+
796800
override def contribute: List[Member] = {
797801
metalsScopeMembers(pos).collect {
798802
case s: ScopeMember
@@ -985,7 +989,7 @@ trait Completions { this: MetalsGlobal =>
985989
allParams.exists(param => param.name.startsWith(prefix))
986990
val isExplicitlyCalled = suffix.startsWith(prefix)
987991
val hasParamsToFill = allParams.count(!_.hasDefault) > 1
988-
if ((shouldShow || isExplicitlyCalled) && hasParamsToFill) {
992+
if ((shouldShow || isExplicitlyCalled) && hasParamsToFill && clientSupportsSnippets) {
989993
val editText = allParams.zipWithIndex
990994
.collect {
991995
case (param, index) if !param.hasDefault =>
@@ -1202,7 +1206,11 @@ trait Completions { this: MetalsGlobal =>
12021206
private def signature = printer.defaultMethodSignature()
12031207
private def edit = new l.TextEdit(
12041208
range,
1205-
s"$filterText$signature = $${0:???}"
1209+
if (clientSupportsSnippets) {
1210+
s"$filterText$signature = $${0:???}"
1211+
} else {
1212+
s"$filterText$signature = ???"
1213+
}
12061214
)
12071215
}
12081216

@@ -1259,7 +1267,11 @@ trait Completions { this: MetalsGlobal =>
12591267
"match",
12601268
new l.TextEdit(
12611269
editRange,
1262-
"match {\n\tcase$0\n}"
1270+
if (clientSupportsSnippets) {
1271+
"match {\n\tcase$0\n}"
1272+
} else {
1273+
"match"
1274+
}
12631275
),
12641276
completionsSymbol("match"),
12651277
label = Some("match"),
@@ -1273,7 +1285,11 @@ trait Completions { this: MetalsGlobal =>
12731285
tail
12741286
.map(_.edit.getNewText())
12751287
.mkString(
1276-
s"match {\n\t${head.edit.getNewText} $$0\n\t",
1288+
if (clientSupportsSnippets) {
1289+
"match {\n\t${head.edit.getNewText} $$0\n\t"
1290+
} else {
1291+
"match {\n\t${head.edit.getNewText}\n\t"
1292+
},
12771293
"\n\t",
12781294
"\n}"
12791295
)
@@ -1408,7 +1424,10 @@ trait Completions { this: MetalsGlobal =>
14081424
if (definitions.isTupleType(parents.selector)) {
14091425
result += new TextEditMember(
14101426
"case () =>",
1411-
new l.TextEdit(editRange, "case ($0) =>"),
1427+
new l.TextEdit(
1428+
editRange,
1429+
if (clientSupportsSnippets) "case ($0) =>" else "case () =>"
1430+
),
14121431
parents.selector.typeSymbol,
14131432
label = Some(s"case ${parents.selector} =>"),
14141433
command = metalsConfig.parameterHintsCommand().asScala
@@ -1466,8 +1485,10 @@ trait Completions { this: MetalsGlobal =>
14661485
val label = s"case $pattern =>"
14671486
new TextEditMember(
14681487
filterText = label,
1469-
edit =
1470-
new l.TextEdit(editRange, label + (if (isSnippet) " $0" else "")),
1488+
edit = new l.TextEdit(
1489+
editRange,
1490+
label + (if (isSnippet && clientSupportsSnippets) " $0" else "")
1491+
),
14711492
sym = sym,
14721493
label = Some(label),
14731494
additionalTextEdits = autoImports
@@ -1482,7 +1503,8 @@ trait Completions { this: MetalsGlobal =>
14821503
s"case _: $name",
14831504
new l.TextEdit(
14841505
editRange,
1485-
if (isSnippet) s"case $${0:_}: $name$suffix => "
1506+
if (isSnippet && clientSupportsSnippets)
1507+
s"case $${0:_}: $name$suffix => "
14861508
else s"case _: $name$suffix =>"
14871509
),
14881510
sym,

mtags/src/main/scala/scala/meta/internal/pc/MetalsGlobal.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -573,11 +573,11 @@ class MetalsGlobal(
573573

574574
def snippetCursor: String = sym.paramss match {
575575
case Nil =>
576-
"$0"
576+
if (clientSupportsSnippets) "$0" else ""
577577
case Nil :: Nil =>
578-
"()$0"
578+
if (clientSupportsSnippets) "()$0" else "()"
579579
case _ =>
580-
"($0)"
580+
if (clientSupportsSnippets) "($0)" else ""
581581
}
582582

583583
def isDefined: Boolean =

mtags/src/main/scala/scala/meta/internal/pc/ScalaPresentationCompiler.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@ case class ScalaPresentationCompiler(
8585
params: OffsetParams
8686
): CompletableFuture[CompletionList] =
8787
access.withInterruptableCompiler(emptyCompletion, params.token) { global =>
88-
new CompletionProvider(global, params, config.isCompletionSnippetsEnabled)
89-
.completions()
88+
new CompletionProvider(global, params).completions()
9089
}
9190

9291
// NOTE(olafur): hover and signature help use a "shared" compiler instance because

0 commit comments

Comments
 (0)