nvim

package
v2.10.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 29, 2026 License: MIT Imports: 22 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package nvim drives an editor that Scribe runs beside the chat. The editor runs on a pseudo-terminal, as any program does; when it is Neovim it also listens on a Unix socket, and this package talks to it over msgpack-RPC. Through that connection Scribe reloads a buffer after the agent writes its file, moves the cursor to the lines the agent changed, hears about the user's saves, and answers the agent's editor tool (see tool.go).

Index

Constants

View Source
const ToolName = "editor"

ToolName is the editor tool's name.

Variables

View Source
var ErrClosed = errors.New("neovim connection closed")

ErrClosed is returned by calls on a client that has been closed or whose connection has ended.

Functions

func Follow

func Follow(abs string, line int)

Follow is Session.Follow on the open editor. It does nothing when no editor is open, and runs the RPC work off the caller's goroutine, so the agent loop does not wait for the screen.

func FollowThen

func FollowThen(abs string, line int, done func(result string))

FollowThen is Follow, then done(result) with what Session.Follow reported ("followed", "modified" or "busy"). done runs on another goroutine and is not called when no editor is open.

func IsNvim

func IsNvim(argv []string) bool

IsNvim reports whether argv runs Neovim.

func Pack

func Pack(v any) ([]byte, error)

Pack encodes v.

func Register

func Register(r *tools.Registry)

Register adds the editor tool to r.

func SetAccess

func SetAccess(a Access)

SetAccess changes the agent editor access.

func SetStartConfig

func SetStartConfig(mode string)

SetStartConfig picks the Neovim config a new editor starts with. "none" starts Neovim with -u NONE; anything else, including "", means the user's own config. (A LazyVim bootstrap mode is not built: it needs the network on first run and a shipped init.lua.)

func SetSyncOnEdit

func SetSyncOnEdit(on bool)

SetSyncOnEdit turns the follow of agent edits into the open buffer on or off.

func SetWriteHook

func SetWriteHook(fn func(abs string))

SetWriteHook sets the function called with the absolute path of each file the user saves in Neovim. The agent's own writes through the editor tool are not reported. nil clears it.

func StartConfig

func StartConfig() string

StartConfig is the Neovim config mode a new editor starts with.

func SyncOnEdit

func SyncOnEdit() bool

SyncOnEdit reports whether agent edits follow into the open buffer.

func Tool

func Tool() tools.Tool

Tool returns the editor tool for the agent.

func Unpack

func Unpack(b []byte) (any, error)

Unpack decodes one MessagePack value from b, which must hold exactly one.

func UnsavedContent

func UnsavedContent(abs string) (string, bool)

UnsavedContent returns what the editor holds for abs when the user has unsaved edits in it, so an agent read sees those edits and not the file on disk. It reports false when the file is not open with changes, when no editor is open, or when two or more reads are already running. Callers fall back to the disk in every case but the first.

Types

type Access

type Access int

Access is the agent's access to the editor, the "Agent editor access" setting: always, only while the editor is open, or never.

const (
	AccessOn       Access = iota // "on": the tool is available (default)
	AccessWhenOpen               // "when-open": only while the editor is open
	AccessOff                    // "off": the tool is disabled
)

func GetAccess

func GetAccess() Access

GetAccess is the current agent editor access.

func ParseAccess

func ParseAccess(s string) (Access, error)

ParseAccess reads a setting value. It accepts the names the settings screen uses and their aliases.

func (Access) Label

func (a Access) Label() string

Label is the setting's name as the settings screen shows it.

func (Access) String

func (a Access) String() string

String is the setting's name, as ParseAccess reads it.

type Args

type Args struct {
	Action      string  `json:"action"`
	File        string  `json:"file"`
	StartLine   int     `json:"startLine"`
	EndLine     int     `json:"endLine"`
	Replacement *string `json:"replacement"`
	Line        int     `json:"line"`
	Col         int     `json:"col"`
	Search      string  `json:"search"`
	NewName     string  `json:"newName"`
	Jump        bool    `json:"jump"`
	Text        *string `json:"text"`
	Register    string  `json:"register"`
	Count       int     `json:"count"`
	Index       int     `json:"index"`
	Title       string  `json:"title"`
}

Args is the editor tool's input.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is a connection to a Neovim RPC socket. Methods are safe for concurrent use.

func Dial

func Dial(path string, notify Notify) (*Client, error)

Dial connects to a Neovim listening on the socket path.

func NewClient

func NewClient(conn io.ReadWriteCloser, notify Notify) *Client

NewClient runs the RPC protocol over conn. notify may be nil.

func (*Client) Call

func (c *Client) Call(ctx context.Context, method string, args ...any) (any, error)

Call invokes method with args and returns its result. The context bounds the wait; a call that times out may still run in Neovim.

func (*Client) Close

func (c *Client) Close() error

Close ends the connection. Pending calls fail with ErrClosed.

func (*Client) Done

func (c *Client) Done() <-chan struct{}

Done is closed when the connection has ended.

func (*Client) Send

func (c *Client) Send(method string, args ...any) error

Send sends a notification with no reply.

type Ext

type Ext struct {
	Type int8
	Data []byte
}

Ext is a MessagePack extension value. Neovim uses extension types for buffer, window and tabpage handles.

type Notify

type Notify func(method string, args []any)

Notify handles one notification from Neovim. It runs on the read loop, so it must not block for long and must not call Client.Call.

type Session

type Session struct {
	Pane *term.Pane
	// contains filtered or unexported fields
}

Session is one editor run on a pane. Pane is what the TUI draws. The RPC connection is only set up for Neovim, once it is listening.

func Current

func Current() *Session

Current is the open editor's session, or nil when no editor is open.

func Start

func Start(argv []string, dir string, w, h int) (*Session, error)

Start runs argv in dir on a pseudo-terminal of w x h cells. When argv is Neovim it is given --listen with a socket of its own, and the RPC connection is made in the background. Start makes the session the Current one.

func (*Session) Call

func (s *Session) Call(ctx context.Context, method string, args ...any) (any, error)

Call makes an RPC call to the editor, waiting for the connection first.

func (*Session) Close

func (s *Session) Close()

Close ends the editor: the process is killed, the connection and socket are released, and the session stops being the Current one.

func (*Session) Closed

func (s *Session) Closed() bool

Closed reports whether Close has run.

func (*Session) Follow

func (s *Session) Follow(abs string, line int) string

Follow shows the agent's change to abs in the editor: the file is opened or reloaded and the cursor moves to line (1-based; 0 keeps the cursor). It reports what it did: "followed", "modified" (the user has unsaved edits in that file) or "busy" (the user has unsaved edits in another file). It returns at once when no RPC connection is up.

func (*Session) Lua

func (s *Session) Lua(ctx context.Context, code string, args ...any) (any, error)

Lua runs code in the editor with args available as ... and returns what the code returns.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL