Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nvim: implements Notify, OpenTerm and HideWindow following neovim/neovim@b274b98 #113

Merged
merged 9 commits into from
Jun 14, 2021
Merged
63 changes: 63 additions & 0 deletions nvim/api.go

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

31 changes: 31 additions & 0 deletions nvim/api_def.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,27 @@ func CreateBuffer(listed, scratch bool) (buffer Buffer) {
name(nvim_create_buf)
}

// OpenTerm opens a terminal instance in a buffer.
//
// By default (and currently the only option) the terminal will not be
// connected to an external process. Instead, input send on the channel
// will be echoed directly by the terminal. This is useful to disply
// ANSI terminal sequences returned as part of a rpc message, or similar.
//
// Note that to directly initiate the terminal using the right size, display the
// buffer in a configured window before calling this. For instance, for a
// floating display, first create an empty buffer using CreateBuffer,
// then display it using OpenWindow, and then call this function.
// Then "nvim_chan_send" cal be called immediately to process sequences
// in a virtual terminal having the intended size.
//
// The buffer arg is the buffer to use (expected to be empty).
//
// The opts arg is optional parameters. Reserved for future use.
func OpenTerm(buffer Buffer, opts map[string]interface{}) (channel int) {
name(nvim_open_term)
}

// OpenWindow open a new window.
//
// Currently this is used to open floating and external windows.
Expand Down Expand Up @@ -1252,6 +1273,16 @@ func WindowConfig(window Window) (config WindowConfig) {
returnPtr()
}

// HideWindow closes the window and hide the buffer it contains (like ":hide" with a
// windowID).
//
// Like ":hide" the buffer becomes hidden unless another window is editing it,
// or "bufhidden" is "unload", "delete" or "wipe" as opposed to ":close" or
// CloseWindow, which will close the buffer.
func HideWindow(window Window) {
name(nvim_win_hide)
}

// CloseWindow close a window.
//
// This is equivalent to |:close| with count except that it takes a window id.
Expand Down
2 changes: 2 additions & 0 deletions nvim/api_tool.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,8 @@ var specialAPIs = map[string]bool{
"nvim_exec_lua": true,
"nvim_buf_call": true,
"nvim_set_decoration_provider": true,
"nvim_chan_send": true, // FUNC_API_LUA_ONLY
"nvim_notify": true, // implements underling nlua(vim.notify)
}

func compareFunctions(functions []*Function) error {
Expand Down
47 changes: 47 additions & 0 deletions nvim/nvim.go
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,53 @@ func (b *Batch) ExecuteLua(code string, result interface{}, args ...interface{})
b.call("nvim_execute_lua", result, code, args)
}

// Notify the user with a message.
//
// Relays the call to vim.notify. By default forwards your message in the
// echo area but can be overriden to trigger desktop notifications.
//
// The msg arg is message to display to the user.
//
// The logLevel arg is the LogLevel.
//
// The opts arg is reserved for future use.
func (v *Nvim) Notify(msg string, logLevel LogLevel, opts map[string]interface{}) error {
if logLevel == LogErrorLevel {
return v.WritelnErr(msg)
}

chunks := []TextChunk{
{
Text: msg,
},
}
return v.Echo(chunks, true, opts)
}

// Notify the user with a message.
//
// Relays the call to vim.notify. By default forwards your message in the
// echo area but can be overriden to trigger desktop notifications.
//
// The msg arg is message to display to the user.
//
// The logLevel arg is the LogLevel.
//
// The opts arg is reserved for future use.
func (b *Batch) Notify(msg string, logLevel LogLevel, opts map[string]interface{}) {
if logLevel == LogErrorLevel {
b.WritelnErr(msg)
return
}

chunks := []TextChunk{
{
Text: msg,
},
}
b.Echo(chunks, true, opts)
}

// decodeExt decodes a MsgPack encoded number to go int value.
func decodeExt(p []byte) (int, error) {
switch {
Expand Down
Loading