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 ¶
- func Apply(src string, edits []Edit) (string, []source.Span)
- func BodyMembers(member ast.Node) ([]ast.Node, bool)
- func Chain(src string, decl Decl) []string
- func Depth(src string, decl Decl, segs []string) int
- func FindNamed(members []ast.Node, name string) (int, ast.Node)
- func MemberName(m ast.Node) string
- type Decl
- type Describe
- type Edit
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Apply ¶
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 ¶
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 ¶
Chain names the nested namespace declarations inside decl, top to innermost — the package nesting a generated record writes.
func Depth ¶
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 ¶
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 ¶
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 ¶
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 SoleNamespace ¶
type Edit ¶
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.