editor

package
v0.91.0 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2026 License: Apache-2.0 Imports: 11 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 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

View Source
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

View Source
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.

View Source
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

func Build(goos string, e Editor, path string, line int) (nativeterm.Plan, error)

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.

func CheckPath

func CheckPath(path string, line int, stat func(string) (os.FileInfo, error)) error

CheckPath validates what an editor is asked to open: absolute, clean, no control characters, and present on disk. stat is os.Stat in production.

func IDs

func IDs() []string

IDs lists every editor id this build knows, installed or not — what the setting may be set to.

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.

func Pick

func Pick(es []Editor, preferred string) (Editor, bool)

Pick returns the preferred editor if it is installed, else the first one found. ok is false when there is none.

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.

func (*Opener) List

func (o *Opener) List() ([]Editor, string)

List is the installed editors and the id of the one used when none is named: the user's choice if it is installed, else the first found.

func (*Opener) Open

func (o *Opener) Open(ctx context.Context, id, path string, line int) (Editor, error)

Open opens path, at line when it is above zero, in the editor with this id, or the preferred one.

Jump to

Keyboard shortcuts

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