@@ -19,6 +19,9 @@ import scala.meta.internal.tokenizers.Chars
1919 */
2020trait 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,18 +796,23 @@ 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 ] = {
797- metalsScopeMembers(pos).collect {
798- case s : ScopeMember
799- if CompletionFuzzy .matches(interpolator.name, s.sym.name) =>
800- val edit = new l.TextEdit (nameRange, newText(s.sym))
801- val filterText = filter + s.sym.name.decoded
802- new TextEditMember (
803- filterText,
804- edit,
805- s.sym,
806- additionalTextEdits = additionalEdits()
807- )
801+ if (clientSupportsSnippets) {
802+ metalsScopeMembers(pos).collect {
803+ case s : ScopeMember
804+ if CompletionFuzzy .matches(interpolator.name, s.sym.name) =>
805+ val edit = new l.TextEdit (nameRange, newText(s.sym))
806+ val filterText = filter + s.sym.name.decoded
807+ new TextEditMember (
808+ filterText,
809+ edit,
810+ s.sym,
811+ additionalTextEdits = additionalEdits()
812+ )
813+ }
814+ } else {
815+ List .empty
808816 }
809817 }
810818 }
@@ -985,7 +993,7 @@ trait Completions { this: MetalsGlobal =>
985993 allParams.exists(param => param.name.startsWith(prefix))
986994 val isExplicitlyCalled = suffix.startsWith(prefix)
987995 val hasParamsToFill = allParams.count(! _.hasDefault) > 1
988- if ((shouldShow || isExplicitlyCalled) && hasParamsToFill) {
996+ if ((shouldShow || isExplicitlyCalled) && hasParamsToFill && clientSupportsSnippets ) {
989997 val editText = allParams.zipWithIndex
990998 .collect {
991999 case (param, index) if ! param.hasDefault =>
@@ -1202,7 +1210,11 @@ trait Completions { this: MetalsGlobal =>
12021210 private def signature = printer.defaultMethodSignature()
12031211 private def edit = new l.TextEdit (
12041212 range,
1205- s " $filterText$signature = $$ {0:???} "
1213+ if (clientSupportsSnippets) {
1214+ s " $filterText$signature = $$ {0:???} "
1215+ } else {
1216+ s " $filterText$signature = ??? "
1217+ }
12061218 )
12071219 }
12081220
@@ -1259,7 +1271,11 @@ trait Completions { this: MetalsGlobal =>
12591271 " match" ,
12601272 new l.TextEdit (
12611273 editRange,
1262- " match {\n\t case$0\n }"
1274+ if (clientSupportsSnippets) {
1275+ " match {\n\t case$0\n }"
1276+ } else {
1277+ " match"
1278+ }
12631279 ),
12641280 completionsSymbol(" match" ),
12651281 label = Some (" match" ),
@@ -1273,7 +1289,11 @@ trait Completions { this: MetalsGlobal =>
12731289 tail
12741290 .map(_.edit.getNewText())
12751291 .mkString(
1276- s " match { \n\t ${head.edit.getNewText} $$ 0 \n\t " ,
1292+ if (clientSupportsSnippets) {
1293+ " match {\n\t ${head.edit.getNewText} $$0\n\t "
1294+ } else {
1295+ " match {\n\t ${head.edit.getNewText}\n\t "
1296+ },
12771297 " \n\t " ,
12781298 " \n }"
12791299 )
@@ -1408,7 +1428,10 @@ trait Completions { this: MetalsGlobal =>
14081428 if (definitions.isTupleType(parents.selector)) {
14091429 result += new TextEditMember (
14101430 " case () =>" ,
1411- new l.TextEdit (editRange, " case ($0) =>" ),
1431+ new l.TextEdit (
1432+ editRange,
1433+ if (clientSupportsSnippets) " case ($0) =>" else " case () =>"
1434+ ),
14121435 parents.selector.typeSymbol,
14131436 label = Some (s " case ${parents.selector} => " ),
14141437 command = metalsConfig.parameterHintsCommand().asScala
@@ -1466,8 +1489,10 @@ trait Completions { this: MetalsGlobal =>
14661489 val label = s " case $pattern => "
14671490 new TextEditMember (
14681491 filterText = label,
1469- edit =
1470- new l.TextEdit (editRange, label + (if (isSnippet) " $0" else " " )),
1492+ edit = new l.TextEdit (
1493+ editRange,
1494+ label + (if (isSnippet && clientSupportsSnippets) " $0" else " " )
1495+ ),
14711496 sym = sym,
14721497 label = Some (label),
14731498 additionalTextEdits = autoImports
@@ -1482,7 +1507,8 @@ trait Completions { this: MetalsGlobal =>
14821507 s " case _: $name" ,
14831508 new l.TextEdit (
14841509 editRange,
1485- if (isSnippet) s " case $$ {0:_}: $name$suffix => "
1510+ if (isSnippet && clientSupportsSnippets)
1511+ s " case $$ {0:_}: $name$suffix => "
14861512 else s " case _: $name$suffix => "
14871513 ),
14881514 sym,
0 commit comments