Skip to content

editor

import "github.com/linuskendall/cosmonaut/internal/editor"

Package editor abstracts editor-specific operations for launching and configuring remote connections to codespaces. Zed is built in as the default since cosmonaut writes Zed-flavored config files when it detects Zed; every other editor is launched as a plain external command and is expected to understand the `ssh://alias/path` URI.

Index

func ResolveNickname

func ResolveNickname(zedNickname, targetDisplayName, codespaceDisplayName, targetName string) string

ResolveNickname determines the nickname for a connection. Checks zedNickname, targetDisplayName, codespaceDisplayName, then targetName.

type Editor

Editor abstracts editor-specific operations.

type Editor interface {
    // Name returns the editor identifier (e.g. "zed", or the user's
    // custom binary name).
    Name() string
    // FindBinary locates the editor's CLI binary on PATH.
    FindBinary() (string, error)
    // ConfigureConnection sets up editor-specific config for the SSH
    // connection (e.g. Zed's settings.json). Generic editors return nil.
    ConfigureConnection(sshAlias, workspacePath, nickname string, uploadBinary *bool) error
    // LaunchRemote opens the editor connected to the remote workspace.
    LaunchRemote(sshAlias, workspacePath string) error
}

func ForName

func ForName(name string) (Editor, error)

ForName returns an Editor implementation for the given name. An empty name (or "zed" / "zeditor") returns the Zed editor with its settings.json plumbing; any other name is wired through GenericEditor — which just runs `\<name> ssh://\<alias>/\<path>` and lets the caller's editor handle the URI.

type GenericEditor

GenericEditor wraps any user-supplied editor binary. It runs the binary against an `ssh://\<alias>/\<path>` URI and lets the editor's own remote handler take it from there. Suitable for Zed-likes that understand the URI (Cursor, etc.), or for user wrapper scripts that translate it to whatever their editor wants.

type GenericEditor struct {
    // Command is the binary or wrapper script to execute. May be a bare
    // name (looked up on PATH) or an absolute path.
    Command string
}

func (*GenericEditor) ConfigureConnection

func (g *GenericEditor) ConfigureConnection(_, _, _ string, _ *bool) error

ConfigureConnection is a no-op for generic editors: we don't know how their settings file is shaped, and the caller's editor / wrapper is expected to handle whatever it needs from the URI alone.

func (*GenericEditor) FindBinary

func (g *GenericEditor) FindBinary() (string, error)

FindBinary resolves the command on PATH, or returns it as-is when it's already absolute (since the user pointed straight at a wrapper script).

func (*GenericEditor) LaunchRemote

func (g *GenericEditor) LaunchRemote(sshAlias, workspacePath string) error

LaunchRemote invokes the editor with the SSH URI. The URI form (ssh://\<alias>/\<path>) is what Zed-compatible editors expect; wrapper scripts can parse it apart if they need to call a non-URI-aware editor.

func (*GenericEditor) Name

func (g *GenericEditor) Name() string

Name returns the user-supplied binary name so settings UI can display it back to the user verbatim.

type ZedEditor

ZedEditor implements Editor for the Zed text editor.

type ZedEditor struct{}

func (*ZedEditor) ConfigureConnection

func (z *ZedEditor) ConfigureConnection(sshAlias, workspacePath, nickname string, uploadBinary *bool) error

func (*ZedEditor) FindBinary

func (z *ZedEditor) FindBinary() (string, error)

func (*ZedEditor) LaunchRemote

func (z *ZedEditor) LaunchRemote(sshAlias, workspacePath string) error

func (*ZedEditor) Name

func (z *ZedEditor) Name() string

Generated by gomarkdoc