Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions private/buf/buflsp/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
"iter"
"log/slog"
"math"
"slices"
"strings"

Expand Down Expand Up @@ -240,6 +241,26 @@ func completionItemsForImport(ctx context.Context, file *file, declImport ast.De
prefix := importPathText[:index]
suffix := importPathText[index:]

// We ought to also send along an AdditionalTextEdit for adding the `;` at the end of the
// line, if it doesn't already exist.
var additionalTextEdits []protocol.TextEdit
if declImport.Semicolon().IsZero() {
additionalTextEdits = append(additionalTextEdits, protocol.TextEdit{
NewText: ";",
// End of line.
Range: protocol.Range{
Start: protocol.Position{
Line: position.Line,
Character: math.MaxInt32 - 1,
},
End: protocol.Position{
Line: position.Line,
Character: math.MaxUint32,
Copy link
Contributor

@emcfarlane emcfarlane Oct 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't seem to work in neovim/vim. I tried the following change:

+		importRange := reportSpanToProtocolRange(declImport.Span())

-				Start: protocol.Position{
-					Line:      position.Line,
-					Character: math.MaxInt32 - 1,
-				},
-				End: protocol.Position{
-					Line:      position.Line,
-					Character: math.MaxUint32,
-				},
+				Start: importRange.End,
+				End:   importRange.End,

But that doesn't look like it works either (works in VSCode).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works for me in neovim, at least (I can check vim); with both mini.completion & nvim-cmp. (The trick is to make sure you're using the plugin's mapping for complete, e.g. <C-y> for nvim-cmp, assuming you've set up the defaults.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unfortunately, with vim + https://github.com/prabirshrestha/asyncomplete.vim + https://github.com/prabirshrestha/asyncomplete-lsp.vim, it looks like the plugin has a bug where it applies the additionalTextEdit, but then also inserts the completion again?:

import "google/protobuf/type.proto";import "google/protobuf/type.proto"

Going to see about reporting upstream.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

},
},
})
}

var items []protocol.CompletionItem
for importPath := range file.importToFile {
suggest := fmt.Sprintf("%q", importPath)
Expand Down Expand Up @@ -269,6 +290,7 @@ func completionItemsForImport(ctx context.Context, file *file, declImport ast.De
},
NewText: suggest[len(prefix) : len(suggest)-len(suffix)],
},
AdditionalTextEdits: additionalTextEdits,
})
}
return items
Expand Down