nsmerge

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: Apache-2.0 Imports: 6 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 nsmerge folds a namespace declaration typed or generated anew into the same-named declaration a document already holds, so re-stating `package P { ... }` adds to its body instead of replacing it. The REPL's prompt and the recording of analysis runs share it.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Apply

func Apply(src string, edits []Edit) (string, []source.Span)

Apply rewrites src with the given edits applied, and returns where each Edit's text landed in the result. An insertion inside an already-rewritten range is written at the point reached rather than dropped, so no added text is ever silently lost.

func BodyMembers

func BodyMembers(member ast.Node) ([]ast.Node, bool)

BodyMembers returns the members of a namespace member's body. Unlike declOf it does not need the body to be terminated, so it can also report what an unparseable re-declaration dropped.

func Chain

func Chain(src string, decl Decl) []string

Chain names the nested namespace declarations inside decl, top to innermost — the package nesting a generated record writes.

func Depth

func Depth(src string, decl Decl, segs []string) int

Depth reports how many of the chain's segments decl's body already holds as nested namespaces, counting from the first until one is missing.

func FindNamed

func FindNamed(members []ast.Node, name string) (int, ast.Node)

FindNamed returns the first member declaring name, and its index. Only the first is taken: a submission that declares one name twice keeps both members, so it still reports a duplicate declaration.

func MemberName

func MemberName(m ast.Node) string

MemberName returns the replaceable name a namespace member declares, or "" for a member that declares none (an import, a comment, an error node).

Types

type Decl

type Decl struct {
	Name    string
	Desc    string // "package P", as the summary renders it
	Header  string // everything before the body, whitespace-normalized
	Members []ast.Node
	Start   int
	Open    int
	Brace   int
}

func Named

func Named(src, name string, kind source.Kind, describe Describe) (Decl, bool)

Named finds the namespace declaration of the given name in an accepted snippet. It reports false unless exactly one member declares that name, so an ambiguous snippet keeps the replacement behavior.

func NamedIn

func NamedIn(src string, root *ast.RootNamespace, name string, describe Describe) (Decl, bool)

NamedIn is Named over a parse the caller already has.

func SoleNamespace

func SoleNamespace(src string, root *ast.RootNamespace, describe Describe) (Decl, bool)

type Describe

type Describe func(ast.Node) string

Describe spells a member for a report, e.g. "part def A".

type Edit

type Edit struct {
	Start, End int
	Text       string
	Own        bool
}

Edit replaces src[start:end] with text. Edits never overlap: each one covers a distinct member, or is an insertion at a body's closing brace. An own Edit marks where the submission lands, so its report scopes to what was typed.

func MergeEdits

func MergeEdits(oldSrc string, oldDecl Decl, newSrc string, newDecl Decl, path string, describe Describe) ([]Edit, []string, []string)

MergeEdits computes the edits on oldSrc that fold newDecl's members into oldDecl, plus a description of each member the new body replaces and its qualified name under path. A member redeclared as a namespace on both sides is merged in turn, so adding to a nested package keeps the nested members too.

Jump to

Keyboard shortcuts

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