Documentation
¶
Overview ¶
Package editor opens a folder, or a file at a line, in the user's own editor — VS Code, Cursor, Zed or a JetBrains IDE (F18, .ai/21-app.md).
Only editors on a fixed list are driven, each through the interface its own documentation gives a script: `open -a <bundle>` on macOS, the editor's CLI with a line (`code -g <file>:<line>`, `zed <file>:<line>`, `idea --line N <file>`), and on Linux the editor's executable on PATH. Every command is an argv handed to exec — never a shell string — so no folder name can become a command. The path is the last word and is absolute, so it can never be read as a flag either.
Nothing here decides who may ask; the API refuses anything that is not a request from this machine (internal/api/editor.go).
Index ¶
Constants ¶
const MaxLine = 10_000_000
MaxLine bounds the line number: nothing real is longer, and a number that does not fit is a mistake, not a file.
Variables ¶
var ErrBadPath = errors.New("bad path")
ErrBadPath is returned for a path that is not an absolute, existing folder or file Caprock can pass on safely.
var ErrNoEditor = errors.New("no editor")
ErrNoEditor is returned when no editor Caprock can drive is installed, or the one asked for is not.
Functions ¶
func Build ¶
Build turns a request into the process that opens path (at line, when it is above zero) in e, on goos. path has already passed CheckPath.
Types ¶
type Editor ¶
type Editor struct {
// ID is the stable name the API and the setting use ("vscode").
ID string `json:"id"`
// Name is what a menu says ("VS Code").
Name string `json:"name"`
// contains filtered or unexported fields
}
Editor is one editor found on this machine.
func Detect ¶
func Detect(p nativeterm.Probe) []Editor
Detect lists the editors installed, in the order they are offered. Windows is not supported yet: its editors' launchers are batch files, which cannot be started without a command interpreter parsing the path.
type Opener ¶
type Opener struct {
// Env is the user's login-shell environment (internal/userenv).
Env func() []string
// Preferred is the editor the user picked in Settings, "" for none.
Preferred func() string
// Run carries a plan out; nativeterm.Run when nil. Swapped by tests, so
// no test ever opens an editor on someone's screen.
Run func(ctx context.Context, p nativeterm.Plan, env []string) error
// contains filtered or unexported fields
}
Opener is what the daemon hands the API: it finds the editors once, against the user's own environment, and opens a path in one.