editor

package
v1.37.0-beta.2 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package editor resolves the command that opens a path in the user's editor, shared by the dashboard's "open in editor" links and the `lerd code` command.

Index

Constants

This section is empty.

Variables

View Source
var Editors = []Editor{
	{"vscode", "Visual Studio Code", "code", gotoArgs, "vscode://file/{file}:{line}", []string{"Visual Studio Code.app"}, []string{"com.visualstudio.code"}},
	{"cursor", "Cursor", "cursor", gotoArgs, "cursor://file/{file}:{line}", []string{"Cursor.app"}, nil},
	{"vscodium", "VSCodium", "codium", gotoArgs, "vscodium://file/{file}:{line}", []string{"VSCodium.app"}, []string{"com.vscodium.codium"}},
	{"windsurf", "Windsurf", "windsurf", gotoArgs, "windsurf://file/{file}:{line}", []string{"Windsurf.app"}, nil},
	{"sublime", "Sublime Text", "subl", locArgs, "subl://open?url=file://{file}&line={line}", []string{"Sublime Text.app"}, []string{"com.sublimetext.three"}},
	{"zed", "Zed", "zed", locArgs, "zed://file/{file}:{line}", []string{"Zed.app"}, []string{"dev.zed.Zed"}},
	{"phpstorm", "PhpStorm", "phpstorm", jetbrainsArgs, "phpstorm://open?file={file}&line={line}", []string{"PhpStorm.app"}, []string{"com.jetbrains.PhpStorm"}},
	{"idea", "IntelliJ IDEA", "idea", jetbrainsArgs, "idea://open?file={file}&line={line}", []string{"IntelliJ IDEA.app", "IntelliJ IDEA Ultimate.app", "IntelliJ IDEA CE.app"}, []string{"com.jetbrains.IntelliJ-IDEA-Ultimate", "com.jetbrains.IntelliJ-IDEA-Community"}},
	{"webstorm", "WebStorm", "webstorm", jetbrainsArgs, "webstorm://open?file={file}&line={line}", []string{"WebStorm.app"}, []string{"com.jetbrains.WebStorm"}},
}

Editors is the curated list, probed on PATH in this order when nothing is configured. They open a directory as a bare argument, which DirCommand uses.

Functions

func Command

func Command(file string, line int) []string

Command resolves the argv to open file at line. A configured `editor` template wins (with {file}/{line} substitution, or the file appended when it has neither placeholder); otherwise the first GUI editor found on PATH is used, falling back to the platform opener.

func DirCommand

func DirCommand(dir string) []string

DirCommand resolves the argv to open a directory, the project-shaped variant of Command. A configured template is reused with {file} as the directory and {line} dropped, since a directory has no line to jump to. There is no platform-opener fallback: xdg-open would hand the directory to the file manager rather than an editor, so nil means "no editor found" and the caller should say so.

func For

func For(file string, line int) (argv []string, url string, err error)

For resolves how to open file at line in the chosen editor: a listed one by its binary when that is on PATH, otherwise by its URL, for the dashboard to hand to the desktop. A URL template is filled in the same way; anything else, including no choice at all, resolves as Command does.

func IsTemplate

func IsTemplate(choice string) bool

IsTemplate reports whether a choice is a custom editor rather than a listed one: a command or a URL naming where the file goes with {file}.

func IsURLTemplate

func IsURLTemplate(choice string) bool

IsURLTemplate reports whether a custom editor is reached by its URL scheme.

func Valid

func Valid(choice string) bool

Valid reports whether the setting may choose this editor: a listed one, a custom template, or none.

Types

type Editor

type Editor struct {
	ID    string `json:"id"`
	Label string `json:"label"`
	// contains filtered or unexported fields
}

Editor is one editor lerd knows how to open a file in: the binary that jumps to file:line, and the URL scheme the editor registers with the desktop, which is how it is reached when its binary is not on PATH (a JetBrains IDE installed through Toolbox, say). The ID is what a site's `editor` names.

func Known

func Known(id string) (Editor, bool)

Known returns the curated editor with this ID.

func (Editor) Installed

func (e Editor) Installed() bool

Installed reports whether the editor is on this machine: its binary on PATH, a desktop entry claiming its URL scheme (how JetBrains Toolbox and Flatpak install them on Linux), or its app bundle on macOS.

Jump to

Keyboard shortcuts

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