Skip to content

Commit e3638e2

Browse files
authored
nvim: implements Notify, OpenTerm and HideWindow following neovim/neovim@b274b98 (#113)
* nvim: ignore nvim_chan_send because FUNC_API_LUA_ONLY * nvim: add LogLevel * nvim: add nvim_notify to specialAPIs for implements handy * nvim: implements Notify * nvim: go generate * nvim: remove unnecessary Anchor empty value * nvim: add OpenTerm testcase * nvim: add HideWindow testcase * nvim: add Notify testcase
1 parent 2542aa1 commit e3638e2

File tree

6 files changed

+434
-12
lines changed

6 files changed

+434
-12
lines changed

nvim/api.go

Lines changed: 63 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

nvim/api_def.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,27 @@ func CreateBuffer(listed, scratch bool) (buffer Buffer) {
422422
name(nvim_create_buf)
423423
}
424424

425+
// OpenTerm opens a terminal instance in a buffer.
426+
//
427+
// By default (and currently the only option) the terminal will not be
428+
// connected to an external process. Instead, input send on the channel
429+
// will be echoed directly by the terminal. This is useful to disply
430+
// ANSI terminal sequences returned as part of a rpc message, or similar.
431+
//
432+
// Note that to directly initiate the terminal using the right size, display the
433+
// buffer in a configured window before calling this. For instance, for a
434+
// floating display, first create an empty buffer using CreateBuffer,
435+
// then display it using OpenWindow, and then call this function.
436+
// Then "nvim_chan_send" cal be called immediately to process sequences
437+
// in a virtual terminal having the intended size.
438+
//
439+
// The buffer arg is the buffer to use (expected to be empty).
440+
//
441+
// The opts arg is optional parameters. Reserved for future use.
442+
func OpenTerm(buffer Buffer, opts map[string]interface{}) (channel int) {
443+
name(nvim_open_term)
444+
}
445+
425446
// OpenWindow open a new window.
426447
//
427448
// Currently this is used to open floating and external windows.
@@ -1252,6 +1273,16 @@ func WindowConfig(window Window) (config WindowConfig) {
12521273
returnPtr()
12531274
}
12541275

1276+
// HideWindow closes the window and hide the buffer it contains (like ":hide" with a
1277+
// windowID).
1278+
//
1279+
// Like ":hide" the buffer becomes hidden unless another window is editing it,
1280+
// or "bufhidden" is "unload", "delete" or "wipe" as opposed to ":close" or
1281+
// CloseWindow, which will close the buffer.
1282+
func HideWindow(window Window) {
1283+
name(nvim_win_hide)
1284+
}
1285+
12551286
// CloseWindow close a window.
12561287
//
12571288
// This is equivalent to |:close| with count except that it takes a window id.

nvim/api_tool.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,8 @@ var specialAPIs = map[string]bool{
420420
"nvim_exec_lua": true,
421421
"nvim_buf_call": true,
422422
"nvim_set_decoration_provider": true,
423+
"nvim_chan_send": true, // FUNC_API_LUA_ONLY
424+
"nvim_notify": true, // implements underling nlua(vim.notify)
423425
}
424426

425427
func compareFunctions(functions []*Function) error {

nvim/nvim.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,53 @@ func (b *Batch) ExecuteLua(code string, result interface{}, args ...interface{})
673673
b.call("nvim_execute_lua", result, code, args)
674674
}
675675

676+
// Notify the user with a message.
677+
//
678+
// Relays the call to vim.notify. By default forwards your message in the
679+
// echo area but can be overriden to trigger desktop notifications.
680+
//
681+
// The msg arg is message to display to the user.
682+
//
683+
// The logLevel arg is the LogLevel.
684+
//
685+
// The opts arg is reserved for future use.
686+
func (v *Nvim) Notify(msg string, logLevel LogLevel, opts map[string]interface{}) error {
687+
if logLevel == LogErrorLevel {
688+
return v.WritelnErr(msg)
689+
}
690+
691+
chunks := []TextChunk{
692+
{
693+
Text: msg,
694+
},
695+
}
696+
return v.Echo(chunks, true, opts)
697+
}
698+
699+
// Notify the user with a message.
700+
//
701+
// Relays the call to vim.notify. By default forwards your message in the
702+
// echo area but can be overriden to trigger desktop notifications.
703+
//
704+
// The msg arg is message to display to the user.
705+
//
706+
// The logLevel arg is the LogLevel.
707+
//
708+
// The opts arg is reserved for future use.
709+
func (b *Batch) Notify(msg string, logLevel LogLevel, opts map[string]interface{}) {
710+
if logLevel == LogErrorLevel {
711+
b.WritelnErr(msg)
712+
return
713+
}
714+
715+
chunks := []TextChunk{
716+
{
717+
Text: msg,
718+
},
719+
}
720+
b.Echo(chunks, true, opts)
721+
}
722+
676723
// decodeExt decodes a MsgPack encoded number to go int value.
677724
func decodeExt(p []byte) (int, error) {
678725
switch {

0 commit comments

Comments
 (0)