Skip to content

Commit a5a5add

Browse files
committed
nvim: support neovim/neovim@561df3098146 APIs
Signed-off-by: Koichi Shiraishi <[email protected]>
1 parent 7b2e8ef commit a5a5add

File tree

3 files changed

+127
-30
lines changed

3 files changed

+127
-30
lines changed

nvim/api_def.go

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,39 @@ func OptionInfo(name string) (opinfo OptionInfo) {
388388
returnPtr()
389389
}
390390

391+
// OptionValue gets the value of an option.
392+
//
393+
// The behavior of this function matches that of |:set|: the local value of an option is returned if it exists; otherwise,
394+
// the global value is returned.
395+
// Local values always correspond to the current buffer or window.
396+
//
397+
// To get a buffer-local or window-local option for a specific buffer or window, use BufferOption() or WindowOption().
398+
//
399+
// name is the option name.
400+
//
401+
// opts is the Optional parameters.
402+
//
403+
// scope
404+
//
405+
// Analogous to |:setglobal| and |:setlocal|, respectively.
406+
func OptionValue(name string, opts map[string]OptionValueScope) (optionValue interface{}) {
407+
name(nvim_get_option_value)
408+
}
409+
410+
// SetOptionValue sets the value of an option. The behavior of this function matches that of
411+
// |:set|: for global-local options, both the global and local value are set
412+
// unless otherwise specified with {scope}.
413+
// name is the option name.
414+
//
415+
// opts is the Optional parameters.
416+
//
417+
// scope
418+
//
419+
// Analogous to |:setglobal| and |:setlocal|, respectively.
420+
func SetOptionValue(name string, value interface{}, opts map[string]OptionValueScope) {
421+
name(nvim_set_option_value)
422+
}
423+
391424
// SetOption sets an option value.
392425
func SetOption(name string, value interface{}) {
393426
name(nvim_set_option)
@@ -855,6 +888,33 @@ func EvalStatusLine(name string, opts map[string]interface{}) (statusline map[st
855888
name(nvim_eval_statusline)
856889
}
857890

891+
// AddUserCommand create a new user command.
892+
//
893+
// name is name of the new user command. Must begin with an uppercase letter.
894+
//
895+
// command is replacement command to execute when this user command is executed.
896+
// When called from Lua, the command can also be a Lua function.
897+
//
898+
// opts is optional command attributes. See |command-attributes| for more details.
899+
//
900+
// To use boolean attributes (such as |:command-bang| or |:command-bar|) set the value to "true".
901+
// In addition to the string options listed in |:command-complete|,
902+
// the "complete" key also accepts a Lua function which works like the "customlist" completion mode |:command-completion-customlist|.
903+
//
904+
// desc (string)
905+
// Used for listing the command when a Lua function is used for {command}.
906+
//
907+
// force (bool, default true)
908+
// Override any previous definition.
909+
func AddUserCommand(name string, command UserCommand, opts map[string]interface{}) {
910+
name(nvim_add_user_command)
911+
}
912+
913+
// DeleteUserCommand delete a user-defined command.
914+
func DeleteUserCommand(name string) {
915+
name(nvim_del_user_command)
916+
}
917+
858918
// buffer.c
859919

860920
// BufferLineCount gets the buffer line count.
@@ -1079,6 +1139,20 @@ func BufferMark(buffer Buffer, name string) (pos [2]int) {
10791139
name(nvim_buf_get_mark)
10801140
}
10811141

1142+
// AddBufferUserCommand create a new user command |user-commands| in the given buffer.
1143+
//
1144+
// Only commands created with |:command-buffer| or this function can be deleted with this function.
1145+
func AddBufferUserCommand(buffer Buffer, name string, command UserCommand, opts map[string]interface{}) {
1146+
name(nvim_buf_add_user_command)
1147+
}
1148+
1149+
// DeleteBufferUserCommand create a new user command |user-commands| in the given buffer.
1150+
//
1151+
// Only commands created with |:command-buffer| or this function can be deleted with this function.
1152+
func DeleteBufferUserCommand(buffer Buffer, name string) {
1153+
name(nvim_buf_del_user_command)
1154+
}
1155+
10821156
// BufferExtmarkByID beturns position for a given extmark id.
10831157
//
10841158
// opts is optional parameters.

nvim/api_tool.go

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -435,28 +435,31 @@ var nvimTypes = map[string]string{
435435
"bool": "Boolean",
436436
"int": "Integer",
437437
"interface{}": "Object",
438-
"Process": "Object",
439438
"string": "String",
440439
"float64": "Float",
441-
"ClientType": "String",
442-
443-
"Channel": "Dictionary",
444-
"*Channel": "Dictionary",
445-
"ClientVersion": "Dictionary",
446-
"HLAttrs": "Dictionary",
447-
"*HLAttrs": "Dictionary",
448-
"WindowConfig": "Dictionary",
449-
"*WindowConfig": "Dictionary",
450-
"ClientAttributes": "Dictionary",
451-
"ClientMethods": "Dictionary",
452-
"map[string]*ClientMethod": "Dictionary",
453-
"map[string]*Command": "Dictionary",
454-
"map[string][]string": "Dictionary",
455-
"map[string]bool": "Dictionary",
456-
"map[string]int": "Dictionary",
457-
"map[string]interface{}": "Dictionary",
458-
"Mode": "Dictionary",
459-
"OptionInfo": "Dictionary",
440+
441+
"ClientType": "String",
442+
"Process": "Object",
443+
"*UserCommand": "Object",
444+
445+
"Channel": "Dictionary",
446+
"*Channel": "Dictionary",
447+
"ClientVersion": "Dictionary",
448+
"HLAttrs": "Dictionary",
449+
"*HLAttrs": "Dictionary",
450+
"WindowConfig": "Dictionary",
451+
"*WindowConfig": "Dictionary",
452+
"ClientAttributes": "Dictionary",
453+
"ClientMethods": "Dictionary",
454+
"map[string]*ClientMethod": "Dictionary",
455+
"map[string]*Command": "Dictionary",
456+
"map[string][]string": "Dictionary",
457+
"map[string]bool": "Dictionary",
458+
"map[string]int": "Dictionary",
459+
"map[string]interface{}": "Dictionary",
460+
"map[string]OptionValueScope": "Dictionary",
461+
"Mode": "Dictionary",
462+
"OptionInfo": "Dictionary",
460463

461464
"[]*Channel": "Array",
462465
"[]*Process": "Array",

nvim/types.go

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -405,33 +405,53 @@ type Command struct {
405405
Definition string `msgpack:"definition"`
406406
}
407407

408-
// UserCommand is replacement command to execute when this user command is executed.
409-
type UserCommand struct {
408+
// UserCommand represesents a user command.
409+
type UserCommand interface {
410+
command()
411+
}
412+
413+
// UserVimCommand is a user Vim command executed at UserCommand.
414+
type UserVimCommand string
415+
416+
// make sure UserVimCommand implements the UserCommand interface.
417+
var _ UserCommand = (*UserVimCommand)(nil)
418+
419+
// command implements UserCommand.command.
420+
func (UserVimCommand) command() {}
421+
422+
// UserLuaCommand is a user Lua command executed at UserCommand.
423+
type UserLuaCommand struct {
410424
// Args passed to the command, if any.
411-
Args string `msgpack:"args"`
425+
Args string `msgpack:"args,omitempty"`
412426

413427
// Bang true if the command was executed with a ! modifier.
414428
Bang bool `msgpack:"bang"`
415429

416430
// StartLine is the starting line of the command range.
417-
StartLine int `msgpack:"line1"`
431+
StartLine int `msgpack:"line1,omitempty"`
418432

419433
// FinalLine is the final line of the command range.
420-
FinalLine int `msgpack:"line2"`
434+
FinalLine int `msgpack:"line2,omitempty"`
421435

422436
// Range is the number of items in the command range: 0, 1, or 2.
423-
Range int `msgpack:"range"`
437+
Range int `msgpack:"range,omitempty"`
424438

425439
// Count is the any count supplied.
426-
Count int `msgpack:"count"`
440+
Count int `msgpack:"count,omitempty"`
427441

428442
// Reg is the optional register, if specified.
429-
Reg string `msgpack:"reg"`
443+
Reg string `msgpack:"reg,omitempty"`
430444

431445
// Mode is the command modifiers, if any.
432-
Mode string `msgpack:"mods"`
446+
Mode string `msgpack:"mode,omitempty"`
433447
}
434448

449+
// make sure UserLuaCommand implements the UserCommand interface.
450+
var _ UserCommand = (*UserLuaCommand)(nil)
451+
452+
// command implements UserCommand.command.
453+
func (UserLuaCommand) command() {}
454+
435455
// TextChunk represents a text chunk.
436456
type TextChunk struct {
437457
// Text is text.
@@ -661,7 +681,7 @@ type OptionValueScope string
661681
// list of OptionValueScope.
662682
const (
663683
GlobalScope = OptionValueScope("global")
664-
LocalScope = OptionValueScope("global")
684+
LocalScope = OptionValueScope("local")
665685
)
666686

667687
// LogLevel represents a nvim log level.

0 commit comments

Comments
 (0)