Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions nvim/apidef.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func ClearBufferHighlight(buffer Buffer, srcID int, startLine int, endLine int)
name(nvim_buf_clear_highlight)
}

// Set the virtual text (annotation) for a buffer line.
// SetBufferVirtualText sets the virtual text (annotation) for a buffer line.
//
// By default (and currently the only option) the text will be placed after
// the buffer text. Virtual text will never cause reflow, rather virtual
Expand All @@ -222,7 +222,7 @@ func ClearBufferHighlight(buffer Buffer, srcID int, startLine int, endLine int)
// The `opts` is optional parameters. Currently not used.
//
// The returns the nsID that was used.
func SetBufferVirtualText(buffer Buffer, nsID int, line int, chunks []interface{}, opts map[string]interface{}) int {
func SetBufferVirtualText(buffer Buffer, nsID int, line int, chunks []VirtualTextChunk, opts map[string]interface{}) int {
name(nvim_buf_set_virtual_text)
}

Expand Down
8 changes: 4 additions & 4 deletions nvim/apiimp.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 8 additions & 7 deletions nvim/apitool.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,13 +308,14 @@ var nvimTypes = map[string]string{
"[][]byte": "ArrayOf(String)",
"[]string": "ArrayOf(String)",

"Mode": "Dictionary",
"*HLAttrs": "Dictionary",
"*Channel": "Dictionary",
"[]*Channel": "Array",
"[]*Mapping": "ArrayOf(Dictionary)",
"[]*Process": "Array",
"[]*UI": "Array",
"Mode": "Dictionary",
"*HLAttrs": "Dictionary",
"*Channel": "Dictionary",
"[]*Channel": "Array",
"[]*Mapping": "ArrayOf(Dictionary)",
"[]*Process": "Array",
"[]*UI": "Array",
"[]VirtualTextChunk": "Array",
}

func convertToNvimTypes(f *Function) *Function {
Expand Down
54 changes: 43 additions & 11 deletions nvim/nvim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,15 +383,7 @@ func TestAPI(t *testing.T) {
})

t.Run("buf_attach", func(t *testing.T) {
buffer, err := v.CurrentBuffer()
if err != nil {
t.Fatal(err)
}

// clear curret buffer text
if err := v.SetBufferLines(buffer, 0, -1, true, bytes.Fields(nil)); err != nil {
t.Fatal(err)
}
clearBuffer(t, v, 0) // clear curret buffer text

type ChangedtickEvent struct {
Buffer Buffer
Expand Down Expand Up @@ -428,7 +420,7 @@ func TestAPI(t *testing.T) {
bufLinesChan <- ev
})

ok, err := v.AttachBuffer(buffer, false, make(map[string]interface{}))
ok, err := v.AttachBuffer(0, false, make(map[string]interface{})) // first 0 arg refers to the current buffer
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -480,7 +472,7 @@ func TestAPI(t *testing.T) {
}()

test := []byte("test")
if err := v.SetBufferLines(buffer, 0, -1, true, bytes.Fields(test)); err != nil {
if err := v.SetBufferLines(0, 0, -1, true, bytes.Fields(test)); err != nil { // first 0 arg refers to the current buffer
t.Fatal(err)
}

Expand All @@ -490,6 +482,39 @@ func TestAPI(t *testing.T) {
}
}
})

t.Run("virtual_text", func(t *testing.T) {
clearBuffer(t, v, 0) // clear curret buffer text

nsID, err := v.CreateNamespace("test_virtual_text")
if err != nil {
t.Fatal(err)
}

lines := []byte("ping")
if err := v.SetBufferLines(0, 0, -1, true, bytes.Fields(lines)); err != nil {
t.Fatal(err)
}

chunks := []VirtualTextChunk{
{
Text: "pong",
HLGroup: "String",
},
}
nsID2, err := v.SetBufferVirtualText(0, nsID, 0, chunks, make(map[string]interface{}))
if err != nil {
t.Fatal(err)
}

if got := nsID2; got != nsID {
t.Fatalf("namespaceID: got %d, want %d", got, nsID)
}

if err := v.ClearBufferNamespace(0, nsID, 0, -1); err != nil {
t.Fatal(err)
}
})
}

func TestDial(t *testing.T) {
Expand Down Expand Up @@ -563,3 +588,10 @@ func TestEmbedded(t *testing.T) {
t.Fatal("timeout waiting for serve to exit")
}
}

// clearBuffer clear the buffer text.
func clearBuffer(t *testing.T, v *Nvim, buffer Buffer) {
if err := v.SetBufferLines(buffer, 0, -1, true, bytes.Fields(nil)); err != nil {
t.Fatal(err)
}
}
6 changes: 6 additions & 0 deletions nvim/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,9 @@ type Command struct {
CompleteArg string `msgpack:"complete_arg,omitempty"`
Definition string `msgpack:"definition"`
}

// VirtualTextChunk represents a virtual text chunk.
type VirtualTextChunk struct {
Text string `msgpack:",array"`
HLGroup string `msgpack:",array"`
}