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
- Variables
- func Follow(abs string, line int)
- func FollowThen(abs string, line int, done func(result string))
- func IsNvim(argv []string) bool
- func Pack(v any) ([]byte, error)
- func Register(r *tools.Registry)
- func SetAccess(a Access)
- func SetStartConfig(mode string)
- func SetSyncOnEdit(on bool)
- func SetWriteHook(fn func(abs string))
- func StartConfig() string
- func SyncOnEdit() bool
- func Tool() tools.Tool
- func Unpack(b []byte) (any, error)
- func UnsavedContent(abs string) (string, bool)
- type Access
- type Args
- type Client
- type Ext
- type Notify
- type Session
Constants ¶
const ToolName = "editor"
ToolName is the editor tool's name.
Variables ¶
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 ¶
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 ¶
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 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 UnsavedContent ¶
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.
func ParseAccess ¶
ParseAccess reads a setting value. It accepts the names the settings screen uses and their aliases.
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 NewClient ¶
func NewClient(conn io.ReadWriteCloser, notify Notify) *Client
NewClient runs the RPC protocol over conn. notify may be nil.
func (*Client) Call ¶
Call invokes method with args and returns its result. The context bounds the wait; a call that times out may still run in Neovim.
type Ext ¶
Ext is a MessagePack extension value. Neovim uses extension types for buffer, window and tabpage handles.
type Notify ¶
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 ¶
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 ¶
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) 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) Follow ¶
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.