Skip to content

Commit f4c4478

Browse files
committed
nvim: implements neovim/neovim@ead61e5a52ab APIs
1 parent 7a4aec6 commit f4c4478

File tree

3 files changed

+147
-0
lines changed

3 files changed

+147
-0
lines changed

nvim/apidef.go

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,49 @@ func BufferMark(buffer Buffer, name string) [2]int {
170170
name(nvim_buf_get_mark)
171171
}
172172

173+
// BufferExtmarkByID returns position for a given extmark id.
174+
func BufferExtmarkByID(buffer Buffer, nsID int, id int) []int {
175+
name(nvim_buf_get_extmark_by_id)
176+
}
177+
178+
// BufferExtmarks gets extmarks in "traversal order" from a charwise region defined by
179+
// buffer positions (inclusive, 0-indexed).
180+
//
181+
// Region can be given as (row,col) tuples, or valid extmark ids (whose
182+
// positions define the bounds). 0 and -1 are understood as (0,0) and (-1,-1)
183+
// respectively, thus the following are equivalent:
184+
//
185+
// BufferExtmarks(0, myNS, 0, -1, {})
186+
// BufferExtmarks(0, myNS, [0,0], [-1,-1], {})
187+
//
188+
// If `end` is less than `start`, traversal works backwards. (Useful
189+
// with `limit`, to get the first marks prior to a given position.)
190+
//
191+
// The `opts` is additional options. Supports the key:
192+
// limit: (int) Maximum number of marks to return.
193+
func BufferExtmarks(buffer Buffer, nsID int, start interface{}, end interface{}, opt map[string]interface{}) []ExtMarks {
194+
name(nvim_buf_get_extmarks)
195+
}
196+
197+
// SetBufferExtmark creates or updates an extmark.
198+
//
199+
// To create a new extmark, pass id=0. The extmark id will be returned.
200+
// To move an existing mark, pass its id.
201+
//
202+
// It is also allowed to create a new mark by passing in a previously unused
203+
// id, but the caller must then keep track of existing and unused ids itself.
204+
// (Useful over RPC, to avoid waiting for the return value.)
205+
//
206+
// Currently opts arg not used.
207+
func SetBufferExtmark(buffer Buffer, nsID int, extmarkID int, line int, col int, opts map[string]interface{}) int {
208+
name(nvim_buf_set_extmark)
209+
}
210+
211+
// DeleteBufferExtmark removes an extmark.
212+
func DeleteBufferExtmark(buffer Buffer, nsID int, extmarkID int) bool {
213+
name(nvim_buf_del_extmark)
214+
}
215+
173216
// AddBufferHighlight adds a highlight to buffer and returns the source id of
174217
// the highlight.
175218
//
@@ -242,6 +285,20 @@ func SetBufferVirtualText(buffer Buffer, nsID int, line int, chunks []VirtualTex
242285
name(nvim_buf_set_virtual_text)
243286
}
244287

288+
// BufferVirtualText gets the virtual text (annotation) for a buffer line.
289+
//
290+
// The virtual text is returned as list of lists, whereas the inner lists have
291+
// either one or two elements. The first element is the actual text, the
292+
// optional second element is the highlight group.
293+
//
294+
// The format is exactly the same as given to SetBufferVirtualText.
295+
//
296+
// If there is no virtual text associated with the given line, an empty list
297+
// is returned.
298+
func BufferVirtualText(buffer Buffer, lnum int) []VirtualTextChunk {
299+
name(nvim_buf_get_virtual_text)
300+
}
301+
245302
// TabpageWindows returns the windows in a tabpage.
246303
func TabpageWindows(tabpage Tabpage) []Window {
247304
name(nvim_tabpage_list_wins)
@@ -318,6 +375,19 @@ func TryResizeUIGrid(grid, width, height int) {
318375
name(nvim_ui_try_resize_grid)
319376
}
320377

378+
// SetPumHeight tells Nvim the number of elements displaying in the popumenu, to decide
379+
// <PageUp> and <PageDown> movement.
380+
//
381+
// height is popupmenu height, must be greater than zero.
382+
func SetPumHeight(height int) {
383+
name(nvim_ui_pum_set_height)
384+
}
385+
386+
// Exec executes Vimscript (multiline block of Ex-commands), like anonymous source.
387+
func Exec(src string, output bool) string {
388+
name(nvim_exec)
389+
}
390+
321391
// Command executes a single ex command.
322392
func Command(cmd string) {
323393
name(nvim_command)
@@ -328,6 +398,11 @@ func HLByID(id int, rgb bool) *HLAttrs {
328398
name(nvim_get_hl_by_id)
329399
}
330400

401+
// HLIDByName gets a highlight group by name.
402+
func HLIDByName(name string) int {
403+
name(nvim_get_hl_id_by_name)
404+
}
405+
331406
// HLByName gets a highlight definition by name.
332407
func HLByName(name string, rgb bool) *HLAttrs {
333408
name(nvim_get_hl_by_name)
@@ -375,8 +450,11 @@ func ReplaceTermcodes(str string, fromPart bool, doLT bool, special bool) string
375450
}
376451

377452
// CommandOutput executes a single ex command and returns the output.
453+
//
454+
// Deprecated: Use Exec() instead.
378455
func CommandOutput(cmd string) string {
379456
name(nvim_command_output)
457+
deprecatedSince(7)
380458
}
381459

382460
// Eval evaluates the expression expr using the Vim internal expression
@@ -570,6 +648,49 @@ func Namespaces() map[string]int {
570648
name(nvim_get_namespaces)
571649
}
572650

651+
// Paste pastes at cursor, in any mode.
652+
//
653+
// Invokes the `vim.paste` handler, which handles each mode appropriately.
654+
// Sets redo/undo. Faster than Input(). Lines break at LF ("\n").
655+
//
656+
// Errors ('nomodifiable', `vim.paste()` failure, …) are reflected in `err`
657+
// but do not affect the return value (which is strictly decided by
658+
// `vim.paste()`). On error, subsequent calls are ignored ("drained") until
659+
// the next paste is initiated (phase 1 or -1).
660+
//
661+
// data
662+
// multiline input. May be binary (containing NUL bytes).
663+
// crlf
664+
// also break lines at CR and CRLF.
665+
// phase
666+
// -1 is paste in a single call (i.e. without streaming).
667+
//
668+
// To "stream" a paste, call Paste sequentially with these `phase` values:
669+
// 1: starts the paste (exactly once)
670+
// 2: continues the paste (zero or more times)
671+
// 3: ends the paste (exactly once)
672+
func Paste(data string, crlf bool, phase int) bool {
673+
name(nvim_paste)
674+
}
675+
676+
// Put puts text at cursor, in any mode.
677+
//
678+
// Compare :put and p which are always linewise.
679+
//
680+
// lines is readfile() style list of lines.
681+
//
682+
// type is edit behavior: any getregtype() result, or:
683+
// "b": blockwise-visual mode (may include width, e.g. "b3")
684+
// "c": characterwise mode
685+
// "l": linewise mode
686+
// "" : guess by contents, see setreg()
687+
// after is insert after cursor (like `p`), or before (like `P`).
688+
//
689+
// follow is place cursor at end of inserted text.
690+
func Put(lines []string, typ string, after bool, follow bool) {
691+
name(nvim_put)
692+
}
693+
573694
// Subscribe subscribes to a Nvim event.
574695
func Subscribe(event string) {
575696
name(nvim_subscribe)
@@ -588,6 +709,24 @@ func ColorMap() map[string]int {
588709
name(nvim_get_color_map)
589710
}
590711

712+
// Context gets a map of the current editor state.
713+
// This API still under development.
714+
//
715+
// The `opts` is optional parameters.
716+
//
717+
// types
718+
// List of context-types to gather: "regs", "jumps", "bufs", "gvars", "funcs", "sfuncs".
719+
// empty for all context.
720+
func Context(opts map[string][]string) map[string]interface{} {
721+
name(nvim_get_context)
722+
}
723+
724+
// LoadContext sets the current editor state from the given context map.
725+
// This API still under development.
726+
func LoadContext(dict map[string]interface{}) interface{} {
727+
name(nvim_load_context)
728+
}
729+
591730
// Mode gets Nvim's current mode.
592731
func Mode() Mode {
593732
name(nvim_get_mode)

nvim/apitool.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ var nvimTypes = map[string]string{
310310
"[]*Channel": "Array",
311311
"[]*Process": "Array",
312312
"[]*UI": "Array",
313+
"[]ExtMarks": "Array",
313314
"[]VirtualTextChunk": "Array",
314315

315316
"[2]int": "ArrayOf(Integer, 2)",

nvim/types.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,3 +292,10 @@ type WindowConfig struct {
292292
External bool `msgpack:"external,omitempty"`
293293
Style string `msgpack:"style,omitempty"`
294294
}
295+
296+
// ExtMarks represents a BufferExtmarks returns type.
297+
type ExtMarks struct {
298+
ExtmarkID int `msgpack:",array"`
299+
Row int
300+
Col int
301+
}

0 commit comments

Comments
 (0)