@@ -19,6 +19,9 @@ import scala.meta.internal.tokenizers.Chars
1919 */
2020trait Completions { this : MetalsGlobal =>
2121
22+ val clientSupportsSnippets : Boolean =
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\t case$0\n }"
1270+ if (clientSupportsSnippets) {
1271+ " match {\n\t case$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+ s " match { \n\t ${head.edit.getNewText} $$ 0 \n\t "
1290+ } else {
1291+ s " 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,
0 commit comments