Skip to content

Commit f5bf325

Browse files
Add additionalTextEdit for trailing ; in import statement (#4110)
1 parent 2d2a07e commit f5bf325

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

private/buf/buflsp/completion.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"fmt"
2222
"iter"
2323
"log/slog"
24+
"math"
2425
"slices"
2526
"strings"
2627

@@ -435,6 +436,26 @@ func completionItemsForImport(ctx context.Context, file *file, declImport ast.De
435436
prefix := importPathText[:index]
436437
suffix := importPathText[index:]
437438

439+
// We ought to also send along an AdditionalTextEdit for adding the `;` at the end of the
440+
// line, if it doesn't already exist.
441+
var additionalTextEdits []protocol.TextEdit
442+
if declImport.Semicolon().IsZero() {
443+
additionalTextEdits = append(additionalTextEdits, protocol.TextEdit{
444+
NewText: ";",
445+
// End of line.
446+
Range: protocol.Range{
447+
Start: protocol.Position{
448+
Line: position.Line,
449+
Character: math.MaxInt32 - 1,
450+
},
451+
End: protocol.Position{
452+
Line: position.Line,
453+
Character: math.MaxUint32,
454+
},
455+
},
456+
})
457+
}
458+
438459
var items []protocol.CompletionItem
439460
for importPath := range file.importToFile {
440461
suggest := fmt.Sprintf("%q", importPath)
@@ -458,6 +479,7 @@ func completionItemsForImport(ctx context.Context, file *file, declImport ast.De
458479
},
459480
NewText: suggest[len(prefix) : len(suggest)-len(suffix)],
460481
},
482+
AdditionalTextEdits: additionalTextEdits,
461483
})
462484
}
463485
return items

0 commit comments

Comments
 (0)