Documentation
¶
Overview ¶
Package project owns the on-disk contract generated for a TinyGo Zed project. It merges managed values into user files, preserves unrelated HuJSON content, and rejects symlinks or concurrent edits before replacement.
Index ¶
Constants ¶
const ( // ConfigPath is the project-relative source of truth for the selected target // and optional flash port. ConfigPath = ".zed/tinygo.json" )
Variables ¶
This section is empty.
Functions ¶
func Initialized ¶
Initialized reports whether the project source-of-truth configuration exists. It applies the same root and file safety checks used by write operations.
func MergeSettings ¶
func MergeSettings(input []byte, info TargetInfo) ([]byte, error)
MergeSettings returns Zed settings with TinyGo's target environment and build tags under the configuration section requested by gopls. It preserves HuJSON comments, unrelated settings, user environment entries, and non-tag build flags, and migrates the flat shape emitted by early CLI versions. It does not mutate input.
func MergeTasks ¶
MergeTasks replaces only tasks marked as managed by tinygo-zed. User tasks and their HuJSON comments retain their relative order; the flash task is omitted when canFlash is false. It does not mutate input.
func ResolveRoot ¶
ResolveRoot returns an absolute project directory after rejecting missing, non-directory, or symlinked roots and unsafe existing .zed paths.
Types ¶
type Config ¶
type Config struct {
// Target is one exact name reported by `tinygo targets`.
Target string `json:"target"`
// Port is empty when TinyGo should discover the flash port automatically.
Port string `json:"port,omitempty"`
}
Config contains the user-selected state from which Zed settings and tasks are derived. An empty Port delegates port discovery to TinyGo.
func LoadConfig ¶
LoadConfig reads ConfigPath using strict JSON decoding. Unknown fields, trailing values, and an empty target are rejected rather than ignored.
type Plan ¶
type Plan struct {
// contains filtered or unexported fields
}
Plan is a prepared set of file replacements. Preparation captures the prior contents so Apply can refuse to overwrite intervening edits.
func PrepareInit ¶
func PrepareInit(root string, config Config, info TargetInfo) (Plan, error)
PrepareInit builds a plan for a previously unconfigured project. It creates managed Zed files and adds a minimal go.mod or main.go only when absent (or, for main.go, empty); it does not write until Plan.Apply is called.
func PrepareSync ¶
func PrepareSync(root string, config Config, info TargetInfo) (Plan, error)
PrepareSync builds a plan that reconciles managed Zed files with config and info. The project must already contain ConfigPath; unrelated settings and tasks are retained.
func (Plan) Apply ¶
Apply stages every changed file before replacing any of them and refuses to proceed if a captured file changed after preparation. A non-empty Plan is single-use. Individual replacements are atomic, but the plan is not a filesystem transaction: ConfigPath is replaced first so rerunning PrepareSync repairs an interrupted application.
type TargetInfo ¶
type TargetInfo struct {
// GOROOT is TinyGo's generated Go root for the selected target and version.
GOROOT string
// GOOS and GOARCH select the target platform presented to gopls.
GOOS string
GOARCH string
// GOARM and GOMIPS are optional architecture tuning values.
GOARM string
GOMIPS string
// BuildTags is the complete tag set required for target package discovery.
BuildTags []string
// CanFlash controls whether the managed task set includes a flash task.
CanFlash bool
}
TargetInfo contains the validated TinyGo metadata needed to derive Zed configuration. BuildTags must contain at least one safe tag.