Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
zchee committed May 25, 2021
1 parent 0f5338d commit 77e2eb3
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 14 deletions.
64 changes: 64 additions & 0 deletions nvim/api.go

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

14 changes: 0 additions & 14 deletions nvim/api_def.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,20 +178,6 @@ func Eval(expr string) (result interface{}) {
name(nvim_eval)
}

// 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 log level.
//
// The opts arg is reserved for future use.
func Notify(msg string, logLevel int, opts map[string]interface{}) (result interface{}) {
name(nvim_notify)
}

// StringWidth calculates the number of display cells occupied by `text`.
//
// <Tab> counts as one cell.
Expand Down
1 change: 1 addition & 0 deletions nvim/api_tool.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,7 @@ var specialAPIs = map[string]bool{
"nvim_exec_lua": true,
"nvim_buf_call": true,
"nvim_set_decoration_provider": true,
"nvim_notify": true, // implements underling nlua(vim.notify)
"nvim_chan_send": true, // FUNC_API_LUA_ONLY
}

Expand Down
46 changes: 46 additions & 0 deletions nvim/nvim.go
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,52 @@ 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 == ErrorLevel {
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 == ErrorLevel {
b.WritelnErr(msg)
}

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
13 changes: 13 additions & 0 deletions nvim/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -553,3 +553,16 @@ type OptionInfo struct {
// FlagList whether the list of single char flags.
FlagList bool `msgpack:"flaglist"`
}

// LogLevel represents a nvim log level.
type LogLevel int

// list of LogLevels.
//
const (
TraceLevel LogLevel = iota
DebugLevel
InfoLevel
WarnLevel
ErrorLevel
)

0 comments on commit 77e2eb3

Please sign in to comment.