@@ -317,7 +317,7 @@ object OverrideCompletions:
317
317
.sortBy(_.sourcePos.start)
318
318
val source = indexedContext.ctx.source
319
319
320
- val shouldCompleteBraces = decls.isEmpty && hasBraces (text, defn).isEmpty
320
+ val shouldCompleteBraces = decls.isEmpty && hasBracesOrColon (text, defn).isEmpty
321
321
322
322
val (startIndent, indent, lastIndent) =
323
323
calcIndent(defn, decls, source, text, shouldCompleteBraces)
@@ -470,7 +470,7 @@ object OverrideCompletions:
470
470
private def inferEditPosition (text : String , defn : TargetDef )(using
471
471
Context
472
472
): SourcePosition =
473
- val span = hasBraces (text, defn)
473
+ val span = hasBracesOrColon (text, defn)
474
474
.map { offset =>
475
475
defn.sourcePos.span.withStart(offset + 1 ).withEnd(offset + 1 )
476
476
}
@@ -480,7 +480,9 @@ object OverrideCompletions:
480
480
defn.sourcePos.withSpan(span)
481
481
end inferEditPosition
482
482
483
- private def hasBraces (text : String , defn : TargetDef ): Option [Int ] =
483
+ private def hasBracesOrColon (text : String , defn : TargetDef )(using
484
+ Context
485
+ ): Option [Int ] =
484
486
def hasSelfTypeAnnot = defn match
485
487
case td : TypeDef =>
486
488
td.rhs match
@@ -489,12 +491,20 @@ object OverrideCompletions:
489
491
case _ => false
490
492
case _ => false
491
493
val start = defn.span.start
492
- val offset =
494
+ val braceOffset =
493
495
if hasSelfTypeAnnot then text.indexOf(" =>" , start) + 1
494
496
else text.indexOf(" {" , start)
495
- if offset > 0 && offset < defn.span.end then Some (offset)
496
- else None
497
- end hasBraces
497
+ if braceOffset > 0 && braceOffset < defn.span.end then Some (braceOffset)
498
+ else hasColon(text, defn)
499
+ end hasBracesOrColon
500
+
501
+ private def hasColon (text : String , defn : TargetDef )(using
502
+ Context
503
+ ): Option [Int ] =
504
+ defn match
505
+ case td : TypeDef if text.charAt(td.rhs.span.end) == ':' =>
506
+ Some (td.rhs.span.end)
507
+ case _ => None
498
508
499
509
private def fallbackFromParent (parent : Tree , name : String )(using Context ) =
500
510
val stats = parent match
0 commit comments