UNPKG

@chemzqm/neovim

Version:

NodeJS client API for vim9 and neovim

222 lines (221 loc) 8.73 kB
import { ApiInfo, VimValue } from '../types'; import { BaseApi } from './Base'; import { Buffer } from './Buffer'; import { Tabpage } from './Tabpage'; import { Window } from './Window'; import { FloatOptions, KeymapOption } from './types'; export interface UiAttachOptions { rgb?: boolean; ext_popupmenu?: boolean; ext_tabline?: boolean; ext_wildmenu?: boolean; ext_cmdline?: boolean; ext_linegrid?: boolean; ext_hlstate?: boolean; } export interface Proc { ppid: number; name: string; pid: number; } export interface AutocmdOption { group?: string | number; pattern?: string | string[]; buffer?: number; /** * Not used on vim9. */ desc?: string; command?: string; once?: boolean; nested?: boolean; /** * vim9 only, see `:h autocmd_add()` */ replace?: boolean; } export interface AugroupOption { clear?: boolean; } export type MouseButton = 'left' | 'right' | 'middle' | 'wheel'; export type ButtonAction = 'press' | 'drag' | 'release' | 'up' | 'down' | 'left' | 'right'; /** * Neovim API */ export declare class Neovim extends BaseApi { protected prefix: string; get apiInfo(): Promise<[number, ApiInfo]>; /** Get list of all buffers */ get buffers(): Promise<Buffer[]>; /** Get current buffer */ get buffer(): Promise<Buffer>; /** Retrieves a scoped option depending on type of `this` */ getOption(name: string): Promise<VimValue>; /** Set scoped option */ setOption(name: string, value: VimValue): Promise<void>; setOption(name: string, value: VimValue, isNotify: true): void; /** Set current buffer */ setBuffer(buffer: Buffer): Promise<void>; get chans(): Promise<number[]>; getChanInfo(chan: number): Promise<object>; createNamespace(name?: string): Promise<number>; get namespaces(): Promise<{ [name: string]: number; }>; get commands(): Promise<Object>; getCommands(options?: {}): Promise<Object>; /** Get list of all tabpages */ get tabpages(): Promise<Tabpage[]>; /** Get current tabpage */ get tabpage(): Promise<Tabpage>; /** Set current tabpage */ setTabpage(tabpage: Tabpage): Promise<void>; /** Get list of all windows */ get windows(): Promise<Window[]>; /** Get current window */ get window(): Promise<Window>; /** Get list of all windows */ getWindows(): Promise<Window[]>; setWindow(win: Window): Promise<void>; /** Get list of all runtime paths */ get runtimePaths(): Promise<string[]>; /** Set current directory */ setDirectory(dir: string): Promise<void>; /** Get current line. Always returns a Promise. */ get line(): Promise<string>; createNewBuffer(listed?: boolean, scratch?: boolean): Promise<Buffer>; openFloatWindow(buffer: Buffer, enter: boolean, options: FloatOptions): Promise<Window>; getLine(): Promise<string>; /** Set current line */ setLine(line: string): Promise<void>; /** Gets keymap */ getKeymap(mode: string): Promise<object[]>; /** * Add keymap by notification, replace keycodes for expr keymap enabled by default. */ setKeymap(mode: string, lhs: string, rhs: string, opts?: KeymapOption): void; deleteKeymap(mode: string, lhs: string): void; /** Gets current mode */ get mode(): Promise<{ mode: string; blocking: boolean; }>; /** Gets map of defined colors */ get colorMap(): Promise<{ [name: string]: number; }>; /** Get color by name */ getColorByName(name: string): Promise<number>; /** Get highlight by name or id */ getHighlight(nameOrId: string | number, isRgb?: boolean): Promise<object> | void; getHighlightByName(name: string, isRgb?: boolean): Promise<object>; getHighlightById(id: number, isRgb?: boolean): Promise<object>; /** Delete current line in buffer */ deleteCurrentLine(): Promise<void>; /** * Evaluates a VimL expression (:help expression). Dictionaries * and Lists are recursively expanded. On VimL error: Returns a * generic error; v:errmsg is not updated. * */ eval(expr: string): Promise<unknown>; /** * Executes lua, it's possible neovim client does not support this */ lua(code: string, args?: VimValue[]): Promise<unknown>; executeLua(code: string, args?: VimValue[]): Promise<unknown>; callDictFunction(dict: object, fname: string, args?: VimValue | VimValue[]): Promise<unknown>; /** * Use direct call on vim9 */ callVim(fname: string, args?: VimValue | VimValue[]): Promise<unknown>; callVim(fname: string, args: VimValue | VimValue[], isNotify: true): void; /** * Use direct expr command on vim9 */ evalVim(expr: string): Promise<unknown>; /** * Use direct ex on vim9 */ exVim(arg: string): void; /** Call a vim function */ call(fname: string, args?: VimValue | VimValue[]): Promise<unknown>; call(fname: string, args: VimValue | VimValue[], isNotify: true): null; /** Call a function with timer on vim*/ callTimer(fname: string, args?: VimValue | VimValue[]): Promise<null>; callTimer(fname: string, args: VimValue | VimValue[], isNotify: true): null; callAsync(fname: string, args?: VimValue | VimValue[]): Promise<unknown>; /** Alias for `call` */ callFunction(fname: string, args?: VimValue | VimValue[]): Promise<unknown> | null; /** Call Atomic calls */ callAtomic(calls: [string, VimValue[]][]): Promise<[any[], boolean]>; /** Runs a vim command */ command(arg: string): Promise<void>; command(arg: string, isNotify: true): null; /** * Runs a command and returns output. * * @deprecated Use exec instead. */ commandOutput(arg: string): Promise<string>; /** * Executes Vimscript (multiline block of Ex-commands), like * anonymous |:source| */ exec(src: string, output?: boolean): Promise<string>; /** Gets a v: variable */ getVvar(name: string): Promise<VimValue>; /** feedKeys */ feedKeys(keys: string, mode: string, escapeCsi: boolean): Promise<void>; /** Sends input keys */ input(keys: string): Promise<number>; /** * Send mouse event from GUI. Neovim only. * * @param {MouseButton} button Mouse button: one of "left", "right", "middle", "wheel", "move". * @param {ButtonAction} action For ordinary buttons, one of "press", "drag", "release". * @param {string} modifier String of modifiers each represented by a single char. * @param {number} row Mouse row-position (zero-based, like redraw events) * @param {number} col Mouse column-position (zero-based, like redraw events) * @param {number} grid Grid number if the client uses |ui-multigrid|, else 0. * @returns {Promise<null>} */ inputMouse(button: MouseButton, action: ButtonAction, modifier: string, row: number, col: number, grid?: number): Promise<null>; /** * Parse a VimL Expression * * TODO: return type, see :help */ parseExpression(expr: string, flags: string, highlight: boolean): Promise<object>; getProc(pid: number): Promise<Proc>; getProcChildren(pid: number): Promise<Proc[]>; /** Replace term codes */ replaceTermcodes(str: string, fromPart: boolean, doIt: boolean, special: boolean): Promise<string>; /** Gets width of string */ strWidth(str: string): Promise<number>; /** Write to output buffer */ outWrite(str: string): void; outWriteLine(str: string): void; /** Write to error buffer */ errWrite(str: string): void; /** Write to error buffer */ errWriteLine(str: string): void; get uis(): Promise<any[]>; uiAttach(width: number, height: number, options: UiAttachOptions): Promise<void>; uiDetach(): Promise<void>; uiTryResize(width: number, height: number): Promise<void>; /** Set UI Option */ uiSetOption(name: string, value: any): Promise<void>; /** Subscribe to nvim event broadcasts */ subscribe(event: string): Promise<void>; /** Unsubscribe to nvim event broadcasts */ unsubscribe(event: string): Promise<void>; createAugroup(name: string, option?: AugroupOption): Promise<number>; createAugroup(name: string, option: AugroupOption, isNotify: true): void; createAutocmd(event: string | string[], option?: AutocmdOption): Promise<number>; createAutocmd(event: string | string[], option: AutocmdOption, isNotify: true): void; deleteAutocmd(id: number): void; setClientInfo(name: string, version: object, type: string, methods: object, attributes: object): void; /** Quit nvim */ quit(): Promise<void>; }