Skip to content

Commit 6a6c735

Browse files
authored
LSP fix type completion prefix (#4122)
1 parent 1a4a46c commit 6a6c735

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

private/buf/buflsp/completion.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -612,16 +612,21 @@ func typeReferencesToCompletionItems(
612612
}
613613
}
614614
}
615+
parentPrefix := string(parentFullName) + "."
616+
packagePrefix := string(current.ir.Package()) + "."
615617
return func(yield func(protocol.CompletionItem) bool) {
616618
editRange := reportSpanToProtocolRange(span)
617619
prefix, suffix := splitSpan(span, offset)
618620
for _, symbol := range fileSymbolTypesIter {
619621
if !symbol.ir.Kind().IsType() {
620622
continue
621623
}
622-
label := strings.TrimPrefix(string(symbol.ir.FullName()), string(parentFullName))
623-
label = strings.TrimPrefix(label, string(current.ir.Package()))
624-
label = strings.TrimPrefix(label, ".")
624+
label := string(symbol.ir.FullName())
625+
if strings.HasPrefix(label, parentPrefix) {
626+
label = label[len(parentPrefix):]
627+
} else if strings.HasPrefix(label, packagePrefix) {
628+
label = label[len(packagePrefix):]
629+
}
625630
if !strings.HasPrefix(label, prefix) || !strings.HasSuffix(label, suffix) {
626631
continue
627632
}

0 commit comments

Comments
 (0)