Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel
Language reuse for visual editors (G5): parameters, placed Features, extractFeature
Claude8c4b12a3958d
diff --git a/Aetheris.Kernel.Firmament.Tests/FirmamentLanguageReuseTests.cs b/Aetheris.Kernel.Firmament.Tests/FirmamentLanguageReuseTests.csnew file mode 100644index 00000000..21411958--- /dev/null+++ b/Aetheris.Kernel.Firmament.Tests/FirmamentLanguageReuseTests.cs@@ -0,0 +1,192 @@+using Aetheris.Kernel.Firmament.FirmamentV2;++namespace Aetheris.Kernel.Firmament.Tests;++/// <summary>Parameters and reusable Features for visual editors: the outline shows them, and the edit+/// operations that make them keep the model's geometry.</summary>+public sealed class FirmamentLanguageReuseTests+{+ private const string Bracket = """+ Model WebBracket {+ Units: mm+ Box Plate { Size: [50mm, 40mm, 8mm] }+ Modify Plate {+ Hole<Shaft> CenterMount { On: +Z Center: Point2(0mm, 0mm) Diameter: 8mm End: ThroughAll }+ }+ }++ """;++ private static FirmamentLanguageEdit Edit(string source, params FirmamentLanguageEditOperation[] operations) =>+ FirmamentLanguageEditService.Apply(source, "bracket.firmament", "1", operations);++ private static string Step(string source)+ {+ var build = FirmamentBuildAndExport.CompileSource(source);+ Assert.True(build.IsSuccess, string.Join("\n", build.Diagnostics.Select(d => d.Message)) + "\n" + source);+ return build.Value!.StepText;+ }++ [Fact]+ public void Outline_ShowsParameterValuesFeatureSignaturesAndPlacedCalls()+ {+ const string source = """+ Feature MountHole(center: Point2, diameter: Length = 3.4mm) -> Hole<Shaft> {+ return Hole<Shaft> { On: +Z Center: center Diameter: diameter End: ThroughAll }+ }+ Model M {+ Units: mm+ Static Thickness: Length = 8mm+ Box Plate { Size: [50mm, 40mm, Thickness] }+ Modify Plate {+ MountHole(center: Point2(10mm, 0mm))+ MountHole(center: Point2(-10mm, 0mm), diameter: 5mm)+ }+ }+ """;+ var outline = FirmamentLanguageOutlineService.Outline(source, "m", "1");+ var thickness = outline.Nodes.Single(n => n.Id == "M/Thickness");+ Assert.Equal("Length", thickness.Annotation);+ Assert.Equal("8mm", thickness.Value!.Text);+ Assert.Equal(source.IndexOf("8mm", StringComparison.Ordinal), thickness.Value.ValueSpan.Start);++ var feature = outline.Nodes.Single(n => n.Id == "MountHole");+ Assert.Equal([new FirmamentOutlineParameter("center", "Point2", null), new FirmamentOutlineParameter("diameter", "Length", "3.4mm")], feature.Signature);++ var calls = outline.Nodes.Where(n => n.Call).ToArray();+ Assert.Equal(["M/Modify:Plate/MountHole#1", "M/Modify:Plate/MountHole#2"], calls.Select(c => c.Id));+ Assert.Equal(["center"], calls[0].Fields.Select(f => f.Name));+ Assert.Equal(["center", "diameter"], calls[1].Fields.Select(f => f.Name));+ Assert.Equal("5mm", calls[1].Fields[1].Text);+ Assert.Equal(["M/Modify:Plate/MountHole#1", "M/Modify:Plate/MountHole#2"], outline.Nodes.Single(n => n.Id == "M/Modify:Plate").Children);+ // Each placed call depends on its Feature; the Modify no longer carries the call's use itself.+ Assert.Contains(outline.Edges, e => e.From == calls[0].Id && e.To == "MountHole" && e.Kind == "call");+ Assert.DoesNotContain(outline.Edges, e => e.From == "M/Modify:Plate" && e.To == "MountHole");+ Assert.Contains(outline.Edges, e => e.From == "M/Box:Plate" && e.To == "M/Thickness");+ }++ [Fact]+ public void PromotingADimensionToAParameter_KeepsTheGeometry()+ {+ var result = Edit(Bracket,+ new FirmamentLanguageEditOperation("insertDeclaration") { Parent = "WebBracket", First = true, Source = "Static Thickness: Length = 8mm" },+ new FirmamentLanguageEditOperation("setField") { Node = "WebBracket/Box:Plate", Field = "Size", Value = "[50mm, 40mm, Thickness]" });+ Assert.Contains(" Units: mm\n Static Thickness: Length = 8mm\n Box Plate { Size: [50mm, 40mm, Thickness] }", result.Text);+ Assert.Equal(["WebBracket/Thickness", "WebBracket/Box:Plate"], result.Nodes);+ Assert.Equal(Step(Bracket), Step(result.Text));+ }++ [Fact]+ public void ExtractFeature_PlacesACallThatBuildsTheSameGeometry()+ {+ var result = Edit(Bracket, new FirmamentLanguageEditOperation("extractFeature") { Node = "WebBracket/Modify:Plate/CenterMount", Name = "MountHole", Parameters = ["Center", "Diameter"] });+ Assert.Equal("""+ Feature MountHole(center: Point2 = Point2(0mm, 0mm), diameter: Length = 8mm) -> Hole<Shaft> {+ return Hole<Shaft> { On: +Z Center: center Diameter: diameter End: ThroughAll }+ }++ Model WebBracket {+ Units: mm+ Box Plate { Size: [50mm, 40mm, 8mm] }+ Modify Plate {+ MountHole(center: Point2(0mm, 0mm), diameter: 8mm)+ }+ }++ """, result.Text);+ Assert.Equal(["WebBracket/Modify:Plate/MountHole"], result.Nodes);+ Assert.Equal(Step(Bracket), Step(result.Text));+ }++ [Fact]+ public void PlacedCalls_CanBeAddedMovedAndRemovedLikeFeatures()+ {+ var extracted = Edit(Bracket, new FirmamentLanguageEditOperation("extractFeature") { Node = "WebBracket/Modify:Plate/CenterMount", Name = "MountHole", Parameters = ["Center"] }).Text;+ var two = Edit(extracted,+ new FirmamentLanguageEditOperation("insertFeature") { Node = "WebBracket/Box:Plate", Source = "MountHole(center: Point2(15mm, 0mm))" },+ new FirmamentLanguageEditOperation("insertFeature") { Node = "WebBracket/Box:Plate", Source = "EdgeFinish TopBreak { Face: +Z Target: Boundary Kind: Chamfer Distance: 1mm }" });+ Assert.Equal(["WebBracket/Modify:Plate/MountHole#2", "WebBracket/Modify:Plate/TopBreak"], two.Nodes);+ Assert.Contains(" MountHole(center: Point2(0mm, 0mm))\n MountHole(center: Point2(15mm, 0mm))\n EdgeFinish TopBreak", two.Text);+ Step(two.Text);++ var moved = Edit(two.Text, new FirmamentLanguageEditOperation("moveDeclaration") { Node = "WebBracket/Modify:Plate/TopBreak", First = true });+ Assert.Contains(" Modify Plate {\n EdgeFinish TopBreak { Face: +Z Target: Boundary Kind: Chamfer Distance: 1mm }\n MountHole(center: Point2(0mm, 0mm))", moved.Text);+ Assert.Equal(["WebBracket/Modify:Plate/TopBreak"], moved.Nodes);+ var down = Edit(moved.Text, new FirmamentLanguageEditOperation("moveDeclaration") { Node = "WebBracket/Modify:Plate/MountHole#1", After = "WebBracket/Modify:Plate/MountHole#2" });+ Assert.Contains("MountHole(center: Point2(15mm, 0mm))\n MountHole(center: Point2(0mm, 0mm))\n }", down.Text);++ // A placed call's arguments are its fields.+ var argued = Edit(down.Text,+ new FirmamentLanguageEditOperation("setField") { Node = "WebBracket/Modify:Plate/MountHole#1", Field = "center", Value = "Point2(12mm, 0mm)" },+ new FirmamentLanguageEditOperation("setField") { Node = "WebBracket/Modify:Plate/MountHole#1", Field = "diameter", Value = "4mm" });+ Assert.Contains("MountHole(center: Point2(12mm, 0mm), diameter: 4mm)", argued.Text);+ Assert.Contains("MountHole(center: Point2(12mm, 0mm))", Edit(argued.Text,+ new FirmamentLanguageEditOperation("removeField") { Node = "WebBracket/Modify:Plate/MountHole#1", Field = "diameter" }).Text);+ Assert.Contains("MountHole(diameter: 4mm)", Edit(argued.Text,+ new FirmamentLanguageEditOperation("removeField") { Node = "WebBracket/Modify:Plate/MountHole#1", Field = "center" }).Text);++ var removed = Edit(down.Text, new FirmamentLanguageEditOperation("removeDeclaration") { Node = "WebBracket/Modify:Plate/MountHole#2" });+ Assert.DoesNotContain("Point2(0mm, 0mm))\n", removed.Text[removed.Text.IndexOf("Modify", StringComparison.Ordinal)..]);+ Step(removed.Text);+ }++ [Fact]+ public void ExtractFeature_RefusesWhatCannotBecomeAParameterOrAFeature()+ {+ Assert.Equal("edit-extract-parameter", Assert.Throws<FirmamentLanguageEditException>(() =>+ Edit(Bracket, new FirmamentLanguageEditOperation("extractFeature") { Node = "WebBracket/Modify:Plate/CenterMount", Name = "MountHole", Parameters = ["On"] })).Code);+ Assert.Equal("edit-extract-shape", Assert.Throws<FirmamentLanguageEditException>(() =>+ Edit(Bracket, new FirmamentLanguageEditOperation("extractFeature") { Node = "WebBracket/Modify:Plate", Name = "Holes" })).Code);+ Assert.Equal("edit-extract-scope", Assert.Throws<FirmamentLanguageEditException>(() =>+ Edit(Bracket, new FirmamentLanguageEditOperation("extractFeature") { Node = "WebBracket", Name = "Whole" })).Code);+ Assert.Equal("edit-name-taken", Assert.Throws<FirmamentLanguageEditException>(() =>+ Edit(Bracket, new FirmamentLanguageEditOperation("extractFeature") { Node = "WebBracket/Modify:Plate/CenterMount", Name = "WebBracket" })).Code);+ Assert.Equal("edit-call-scope", Assert.Throws<FirmamentLanguageEditException>(() =>+ Edit(Bracket, new FirmamentLanguageEditOperation("insertDeclaration") { Parent = null, Source = "MountHole(center: Point2(0mm, 0mm))" })).Code);+ }++ [Fact]+ public void ExtractFeature_WorksForOtherFeatureKindsAndAngles()+ {+ const string source = """+ Model M {+ Units: mm+ Box Plate { Size: [60mm, 40mm, 10mm] }+ Modify Plate {+ Hole<Countersink> Sink { On: +Z Center: Point2(0mm, 0mm) Diameter: 6mm CountersinkDiameter: 12mm CountersinkAngle: 90deg End: ThroughAll }+ EdgeFinish Break { Face: +Z Target: Boundary Kind: Chamfer Distance: 1mm }+ }+ }++ """;+ var sink = Edit(source, new FirmamentLanguageEditOperation("extractFeature") { Node = "M/Modify:Plate/Sink", Name = "FlatHead", Parameters = ["Center", "CountersinkAngle"] });+ Assert.Contains("Feature FlatHead(center: Point2 = Point2(0mm, 0mm), countersinkAngle: Angle = 90deg) -> Hole<Countersink> {", sink.Text);+ var both = Edit(sink.Text, new FirmamentLanguageEditOperation("extractFeature") { Node = "M/Modify:Plate/Break", Name = "EdgeBreak", Parameters = ["Distance"] });+ Assert.Equal(Step(source), Step(both.Text));+ }++ [Fact]+ public void ExtractFeature_RefusesADeclarationSomethingRefersToAndWarnsThatTheNameGoes()+ {+ const string pmi = """+ Model A3 {+ Units: mm+ Box Plate { Size: [100mm, 70mm, 10mm] }+ Modify Plate {+ Hole<Shaft> Mount { On: +Z Center: Point2(-35mm, 20mm) Diameter: 8mm End: ThroughAll }+ }+ Pmi {+ HoleDiameter MountDiameter { Target: Mount Value: 8mm }+ }+ }++ """;+ var refused = Assert.Throws<FirmamentLanguageEditException>(() =>+ Edit(pmi, new FirmamentLanguageEditOperation("extractFeature") { Node = "A3/Modify:Plate/Mount", Name = "MountHole", Parameters = ["Center"] }));+ Assert.Equal("edit-extract-referenced", refused.Code);+ Assert.Contains("A3/Pmi/MountDiameter", refused.Message, StringComparison.Ordinal);++ var edit = Edit(Bracket, new FirmamentLanguageEditOperation("extractFeature") { Node = "WebBracket/Modify:Plate/CenterMount", Name = "MountHole", Parameters = ["Center"] });+ Assert.Contains(edit.Warnings, w => w.StartsWith("CenterMount is now a placed MountHole", StringComparison.Ordinal));+ }+}diff --git a/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentLanguageEdit.cs b/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentLanguageEdit.csindex 66afe4bb..9199c096 100644--- a/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentLanguageEdit.cs+++ b/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentLanguageEdit.cs@@ -6,7 +6,8 @@ namespace Aetheris.Kernel.Firmament.FirmamentV2;/// <summary>One structural edit, addressed by outline node ids (<see cref="FirmamentLanguageOutlineService"/>)./// <c>Kind</c> is <c>setField</c>, <c>removeField</c>, <c>insertDeclaration</c>, <c>removeDeclaration</c>,-/// <c>renameDeclaration</c>, <c>moveDeclaration</c> or <c>insertFeature</c>.</summary>+/// <c>renameDeclaration</c>, <c>moveDeclaration</c>, <c>insertFeature</c> or <c>extractFeature</c>.+/// <c>removeDeclaration</c> and <c>moveDeclaration</c> also take a call node (a placed Feature).</summary>public sealed record FirmamentLanguageEditOperation(string Kind){/// <summary>The declaration edited, removed, renamed or moved.</summary>@@ -25,6 +26,8 @@ public sealed record FirmamentLanguageEditOperation(string Kind)/// <summary>insertDeclaration and insertFeature: one declaration as source text, used instead of/// <see cref="Declaration"/>. With <see cref="Name"/> its declared name is replaced.</summary>public string? Source { get; init; }+ /// <summary>extractFeature: the fields that become parameters; the rest stay fixed in the Feature.</summary>+ public IReadOnlyList<string>? Parameters { get; init; }}/// <summary>A declaration to write: <c>Modifiers Kind<Variant> Name { Field: Value ... }</c>.</summary>@@ -78,6 +81,7 @@ public static class FirmamentLanguageEditService"renameDeclaration" => RenameDeclaration(text, before, operation, document, warnings),"moveDeclaration" => MoveDeclaration(text, before, operation),"insertFeature" => InsertFeature(text, before, operation),+ "extractFeature" => ExtractFeature(text, before, operation, document, warnings),_ => throw new FirmamentLanguageEditException("edit-unknown-operation", $"Unknown edit operation '{operation.Kind}'.")};var after = Parse(next);@@ -94,6 +98,7 @@ public static class FirmamentLanguageEditServiceprivate static (string, string?) SetField(string text, SyntaxParseResult parse, FirmamentLanguageEditOperation op){+ if (FindStatement(parse, op.Node) is { Call: true } placed) return (SetArgument(text, placed, op), placed.Id);var (id, declaration) = Find(parse, op.Node);var name = RequireIdentifier(op.Field, "field name");var value = RequireValue(op.Value, name);@@ -107,6 +112,7 @@ public static class FirmamentLanguageEditServiceprivate static (string, string?) RemoveField(string text, SyntaxParseResult parse, FirmamentLanguageEditOperation op){+ if (FindStatement(parse, op.Node) is { Call: true } placed) return (RemoveArgument(text, placed, op), placed.Id);var (id, declaration) = Find(parse, op.Node);var name = RequireIdentifier(op.Field, "field name");var matches = Fields(declaration).Where(f => f.Name.Text == name).ToArray();@@ -116,18 +122,49 @@ public static class FirmamentLanguageEditServicereturn (RemoveStatement(text, matches[0].Span), id);}+ // A placed call's fields are its named arguments: `MountHole(center: Point2(0mm, 0mm), diameter: 8mm)`.+ private static ArgumentSyntax[] Arguments((string Id, string? ParentId, StatementSyntax Statement, bool Call) placed, string name) =>+ FirmamentLanguageOutlineService.BareCall(placed.Statement)!.Arguments.Where(a => a.Name?.Text == name).ToArray();++ private static string SetArgument(string text, (string Id, string? ParentId, StatementSyntax Statement, bool Call) placed, FirmamentLanguageEditOperation op)+ {+ var name = RequireIdentifier(op.Field, "argument name");+ var value = RequireValue(op.Value, name);+ var call = FirmamentLanguageOutlineService.BareCall(placed.Statement)!;+ var matches = Arguments(placed, name);+ if (matches.Length > 1) throw new FirmamentLanguageEditException("edit-duplicate-field", $"{name} is passed {matches.Length} times; edit it in source.");+ if (matches.Length == 1) return Replace(text, matches[0].Value.Span.Start, matches[0].Value.Span.Length, value);+ var close = call.Span.Start + call.Span.Length - 1;+ return Replace(text, close, 0, (call.Arguments.Count > 0 ? ", " : "") + $"{name}: {value}");+ }++ private static string RemoveArgument(string text, (string Id, string? ParentId, StatementSyntax Statement, bool Call) placed, FirmamentLanguageEditOperation op)+ {+ var name = RequireIdentifier(op.Field, "argument name");+ var call = FirmamentLanguageOutlineService.BareCall(placed.Statement)!;+ var index = call.Arguments.ToList().FindIndex(a => a.Name?.Text == name);+ if (index < 0) throw new FirmamentLanguageEditException("edit-field-not-found", $"{placed.Id} does not pass {name}.");+ var argument = call.Arguments[index];+ // Take the separator on one side: the comma after it, or for the last argument the one before.+ int start = argument.Span.Start, end = argument.Span.Start + argument.Span.Length;+ if (index < call.Arguments.Count - 1) end = call.Arguments[index + 1].Span.Start;+ else if (index > 0) start = call.Arguments[index - 1].Span.Start + call.Arguments[index - 1].Span.Length;+ return text.Remove(start, end - start);+ }+private static (string, string?) InsertDeclaration(string text, SyntaxParseResult parse, FirmamentLanguageEditOperation op){if (op.Declaration is null && op.Source is null)throw new FirmamentLanguageEditException("edit-input-required", "insertDeclaration requires a declaration or its source.");- var declarations = FirmamentLanguageOutlineService.Declarations(parse);DeclarationSyntax? parent = null;if (op.Parent is not null) parent = Find(parse, op.Parent).Syntax;- var siblings = Siblings(declarations, op.Parent);+ var siblings = StatementSiblings(parse, op.Parent);var indent = parent is null ? "" : ChildIndent(text, parent);- var snippet = op.Declaration is { } spec ? Write(spec, indent, Unit(text)) : FromSource(op.Source!, op.Name, indent);- CheckSnippet(snippet);- var anchor = Anchor(declarations, siblings, op);+ var call = op.Declaration is null && IsCallSource(op.Source!);+ if (call && parent is null) throw new FirmamentLanguageEditException("edit-call-scope", "A call is placed inside a body, such as a Modify.");+ var snippet = op.Declaration is { } spec ? Write(spec, indent, Unit(text)) : call ? indent + op.Source!.Trim() : FromSource(op.Source!, op.Name, indent);+ if (!call) CheckSnippet(snippet);+ var anchor = Anchor(siblings, op);int at;string inserted;if (parent is null)@@ -143,10 +180,22 @@ public static class FirmamentLanguageEditService}var next = Replace(text, at, 0, inserted);var start = at + inserted.IndexOf(snippet.TrimStart(), StringComparison.Ordinal);- var created = FirmamentLanguageOutlineService.Declarations(Parse(next)).FirstOrDefault(d => d.Syntax.Span.Start == start);+ var created = FirmamentLanguageOutlineService.Statements(Parse(next)).FirstOrDefault(d => d.Statement.Span.Start == start);return (next, created.Id);}+ /// <summary>One bare call of a named Feature or function, such as <c>MountHole(center: Point2(0mm, 0mm))</c>.</summary>+ private static bool IsCallSource(string source)+ {+ var text = source.Trim();+ if (!text.EndsWith(')')) return false;+ var parse = Parse("Probe Probe {\n" + text + "\n}");+ var body = parse.Document.Statements.OfType<DeclarationSyntax>().FirstOrDefault()?.Body?.Statements ?? [];+ if (!parse.IsSuccess || body.Count != 1 || FirmamentLanguageOutlineService.BareCall(body[0]) is null)+ throw new FirmamentLanguageEditException("edit-invalid-declaration", $"'{text}' is not one call.");+ return true;+ }+/// <summary>A feature goes into the <c>Modify</c> of its body: the last one already written for/// that body among its siblings, or a new one placed right after the body.</summary>private static (string, string?) InsertFeature(string text, SyntaxParseResult parse, FirmamentLanguageEditOperation op)@@ -167,9 +216,86 @@ public static class FirmamentLanguageEditServicereturn InsertDeclaration(opened, Parse(opened), new("insertDeclaration") { Parent = modifyId, Source = op.Source, Name = op.Name });}+ /// <summary>+ /// Turn a feature into a reusable <c>Feature</c>: the declaration becomes a call of a new+ /// document-level Feature placed before the declaration's root (usually its Model). Every chosen+ /// field becomes a typed parameter defaulting to its current value, and the call passes the+ /// current values, so the model builds the same geometry. Other fields stay fixed in the Feature.+ /// The Feature's body is written one field after another on one line; comments inside the+ /// original body are not carried over. The result's node is the call.+ /// </summary>+ private static (string, string?) ExtractFeature(string text, SyntaxParseResult parse, FirmamentLanguageEditOperation op,+ string document, List<string> warnings)+ {+ var (id, declaration) = Find(parse, op.Node);+ var name = RequireIdentifier(op.Name, "Feature name");+ var declarations = FirmamentLanguageOutlineService.Declarations(parse);+ var entry = declarations.First(d => d.Id == id);+ if (entry.ParentId is null)+ throw new FirmamentLanguageEditException("edit-extract-scope", "Only a declaration inside a body, such as a feature in a Modify, becomes a placed Feature.");+ if (BodyOf(declaration) is not { } body || declaration.Body is null || body.Statements.Any(s => s is not FieldSyntax))+ throw new FirmamentLanguageEditException("edit-extract-shape", "Only a declaration written as fields becomes a Feature; this one has nested declarations or no body.");+ if (declarations.Any(d => d.ParentId is null && d.Syntax.Name?.Text == name))+ throw new FirmamentLanguageEditException("edit-name-taken", $"The document already declares {name}.");+ // A placed call has no name: whatever names this declaration would stop resolving. That is+ // a lexical use, or a name the outline cannot place but the compiler resolves by feature+ // name, such as a Pmi Target.+ var outline = FirmamentLanguageOutlineService.Outline(text, document, "edit");+ var users = outline.Edges.Where(e => e.ToDocument is null && (e.To == id || e.To.StartsWith(id + "/", StringComparison.Ordinal))).Select(e => e.From)+ .Concat(declaration.Name is { } own ? outline.Externals.Where(x => x.Name == own.Text).Select(x => x.From) : [])+ .Distinct().ToArray();+ if (users.Length > 0)+ throw new FirmamentLanguageEditException("edit-extract-referenced",+ $"{declaration.Name?.Text ?? id} is used by {string.Join(", ", users)}; a placed Feature has no name, so those uses would break.");+ var fields = body.Statements.Cast<FieldSyntax>().ToArray();+ var parameters = new List<(string Field, string Name, string Type, string Value)>();+ foreach (var requested in op.Parameters ?? [])+ {+ var field = fields.FirstOrDefault(f => f.Name.Text == requested)+ ?? throw new FirmamentLanguageEditException("edit-field-not-found", $"{id} has no {requested} field.");+ var type = ParameterType(field.Value)+ ?? throw new FirmamentLanguageEditException("edit-extract-parameter", $"{requested} cannot be a parameter: lengths, angles, numbers and Point2 values can.");+ var parameter = char.ToLowerInvariant(requested[0]) + requested[1..];+ if (parameters.Any(p => p.Name == parameter)) continue;+ parameters.Add((requested, parameter, type, text.Substring(field.Value.Span.Start, field.Value.Span.Length)));+ }+ string ValueOf(FieldSyntax f) => parameters.FirstOrDefault(p => p.Field == f.Name.Text) is { Name: { } p } ? p : text.Substring(f.Value.Span.Start, f.Value.Span.Length);+ var kind = text.Substring(declaration.Type.Span.Start, declaration.Type.Span.Length);+ var unit = Unit(text);+ var feature = $"Feature {name}({string.Join(", ", parameters.Select(p => $"{p.Name}: {p.Type} = {p.Value}"))}) -> {kind} {{\n"+ + $"{unit}return {kind} {{ {string.Join(" ", fields.Select(f => $"{f.Name.Text}: {ValueOf(f)}"))} }}\n}}";+ CheckSnippet(feature);+ var call = $"{name}({string.Join(", ", parameters.Select(p => $"{p.Name}: {p.Value}"))})";++ // The declaration becomes the call, in place; then the Feature goes before the root that holds it.+ var end = declaration.Span.Start + declaration.Span.Length;+ if (end < text.Length && text[end] == ';') end++;+ var placed = Replace(text, declaration.Span.Start, end - declaration.Span.Start, call);+ var rootId = id[..(id.IndexOf('/') is var slash && slash < 0 ? id.Length : slash)];+ var root = declarations.First(d => d.Id == rootId && d.ParentId is null).Syntax;+ var at = LineStart(placed, root.Span.Start);+ var next = Replace(placed, at, 0, feature + "\n\n");+ var callStart = declaration.Span.Start + feature.Length + 2;+ var created = FirmamentLanguageOutlineService.Statements(Parse(next)).FirstOrDefault(d => d.Call && d.Statement.Span.Start == callStart);+ if (declaration.Name is { } lost)+ warnings.Add($"{lost.Text} is now a placed {name}; the model identifies placements by their order, not by the name {lost.Text}.");+ return (next, created.Id);+ }++ private static string? ParameterType(ExpressionSyntax value) => value switch+ {+ UnarySyntax { Operator: UnaryOperator.Negative or UnaryOperator.Positive } u => ParameterType(u.Operand),+ QuantitySyntax q => q.Unit.Text switch { "mm" or "cm" or "m" or "um" or "in" => "Length", "deg" or "rad" => "Angle", _ => null },+ LiteralSyntax { Kind: LiteralKind.Number } n => n.Raw.Contains('.') ? "Float" : "Int",+ CallSyntax { Target: ReferenceSyntax { Name.Text: "Point2" } } => "Point2",+ _ => null+ };+private static (string, string?) RemoveDeclaration(string text, SyntaxParseResult parse, FirmamentLanguageEditOperation op,string document, List<string> warnings){+ var placed = FindStatement(parse, op.Node);+ if (placed.Call) return (RemoveStatement(text, placed.Statement.Span), null);var (id, declaration) = Find(parse, op.Node);var outline = FirmamentLanguageOutlineService.Outline(text, document, "edit");var inside = (string node) => node == id || node.StartsWith(id + "/", StringComparison.Ordinal);@@ -221,33 +347,31 @@ public static class FirmamentLanguageEditServiceprivate static (string, string?) MoveDeclaration(string text, SyntaxParseResult parse, FirmamentLanguageEditOperation op){- var (id, declaration) = Find(parse, op.Node);- var declarations = FirmamentLanguageOutlineService.Declarations(parse);- var parentId = declarations.First(d => d.Id == id).ParentId;+ var (id, parentId, statement, _) = FindStatement(parse, op.Node);if (op.After == id) return (text, id);- if (op.After is not null && declarations.FirstOrDefault(d => d.Id == op.After).ParentId != parentId)+ var all = FirmamentLanguageOutlineService.Statements(parse);+ if (op.After is not null && all.FirstOrDefault(d => d.Id == op.After).ParentId != parentId)throw new FirmamentLanguageEditException("edit-move-scope", "A declaration moves among its siblings; use remove and insert to move it elsewhere.");- var body = text[declaration.Span.Start..StatementEnd(text, declaration.Span)];+ var body = text[statement.Span.Start..StatementEnd(text, statement.Span)];// Resolve the anchor and parent before removing: ids can change once a sibling that shared// their name is gone (`Modify:Base` becomes `Base`), positions only shift.- var anchorBefore = Anchor(declarations, Siblings(declarations, parentId).Where(s => s.Id != id).ToArray(), op);- var parentBefore = parentId is null ? null : declarations.First(d => d.Id == parentId).Syntax;- var removed = RemoveStatement(text, declaration.Span);+ var anchorBefore = Anchor(StatementSiblings(parse, parentId).Where(s => s.Id != id).ToArray(), op);+ var parentBefore = parentId is null ? null : all.First(d => d.Id == parentId).Statement;+ var removed = RemoveStatement(text, statement.Span);var shift = text.Length - removed.Length;- var declarations2 = FirmamentLanguageOutlineService.Declarations(Parse(removed));- DeclarationSyntax? Relocate(DeclarationSyntax? before)+ var all2 = FirmamentLanguageOutlineService.Statements(Parse(removed));+ StatementSyntax? Relocate(StatementSyntax? before){if (before is null) return null;- var start = before.Span.Start > declaration.Span.Start ? before.Span.Start - shift : before.Span.Start;- return declarations2.First(d => d.Syntax.Span.Start == start && d.Syntax.Type.Name.Text == before.Type.Name.Text).Syntax;+ var start = before.Span.Start > statement.Span.Start ? before.Span.Start - shift : before.Span.Start;+ return all2.First(d => d.Statement.Span.Start == start && d.Statement.GetType() == before.GetType()).Statement;}var anchor = new AnchorPoint(Relocate(anchorBefore.After), Relocate(anchorBefore.Before));- DeclarationSyntax? parent = Relocate(parentBefore);+ var parent = Relocate(parentBefore) as DeclarationSyntax;int at; string inserted;if (parent is null){- var indent = "";- if (anchor.After is { } after) { at = StatementEnd(removed, after.Span); inserted = "\n" + indent + body; }+ if (anchor.After is { } after) { at = StatementEnd(removed, after.Span); inserted = "\n" + body; }else if (anchor.Before is { } first) { at = LineStart(removed, first.Span.Start); inserted = body + "\n"; }else { at = removed.TrimEnd().Length; inserted = "\n" + body; }}@@ -258,31 +382,43 @@ public static class FirmamentLanguageEditService}var next = Replace(removed, at, 0, inserted);var start = at + inserted.IndexOf(body, StringComparison.Ordinal);- var moved = FirmamentLanguageOutlineService.Declarations(Parse(next)).FirstOrDefault(d => d.Syntax.Span.Start == start);+ var moved = FirmamentLanguageOutlineService.Statements(Parse(next)).FirstOrDefault(d => d.Statement.Span.Start == start);return (next, moved.Id);}// ---- Placement --------------------------------------------------------------------------- private readonly record struct AnchorPoint(DeclarationSyntax? After, DeclarationSyntax? Before);+ private readonly record struct AnchorPoint(StatementSyntax? After, StatementSyntax? Before);- private static AnchorPoint Anchor(IReadOnlyList<(string Id, string? ParentId, DeclarationSyntax Syntax)> declarations,- IReadOnlyList<(string Id, string? ParentId, DeclarationSyntax Syntax)> siblings, FirmamentLanguageEditOperation op)+ private static AnchorPoint Anchor(IReadOnlyList<(string Id, StatementSyntax Statement)> siblings, FirmamentLanguageEditOperation op){if (op.After is not null){var after = siblings.FirstOrDefault(s => s.Id == op.After);- if (after.Syntax is null)+ if (after.Statement is null)throw new FirmamentLanguageEditException("edit-anchor-not-found", $"{op.After} is not a sibling at this place.");- return new(after.Syntax, null);+ return new(after.Statement, null);}- if (op.First) return siblings.Count == 0 ? new(null, null) : new(null, siblings[0].Syntax);- return siblings.Count == 0 ? new(null, null) : new(siblings[^1].Syntax, null);+ if (op.First) return siblings.Count == 0 ? new(null, null) : new(null, siblings[0].Statement);+ return siblings.Count == 0 ? new(null, null) : new(siblings[^1].Statement, null);+ }++ /// <summary>The outline nodes under a parent, declarations and placed calls, in source order.</summary>+ private static IReadOnlyList<(string Id, StatementSyntax Statement)> StatementSiblings(SyntaxParseResult parse, string? parentId) =>+ FirmamentLanguageOutlineService.Statements(parse).Where(s => s.ParentId == parentId).Select(s => (s.Id, s.Statement)).ToArray();++ private static (string Id, string? ParentId, StatementSyntax Statement, bool Call) FindStatement(SyntaxParseResult parse, string? id)+ {+ if (id is null) throw new FirmamentLanguageEditException("edit-input-required", "The operation requires a node id.");+ var match = FirmamentLanguageOutlineService.Statements(parse).FirstOrDefault(d => d.Id == id);+ return match.Statement is null+ ? throw new FirmamentLanguageEditException("edit-node-not-found", $"Nothing has the id {id}. The source may have changed.")+ : match;}/// <summary>Where a declaration goes inside a parent body, and the text to insert there.</summary>private static (int At, string Inserted) Placement(string text, DeclarationSyntax parent, string snippet,- DeclarationSyntax? after, DeclarationSyntax? before)+ StatementSyntax? after, StatementSyntax? before){if (after is not null) return Follow(text, parent, after.Span, snippet);if (before is not null)diff --git a/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentLanguageOutline.cs b/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentLanguageOutline.csindex 956d0f7c..e2e99a9a 100644--- a/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentLanguageOutline.cs+++ b/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentLanguageOutline.cs@@ -8,7 +8,21 @@ public sealed record FirmamentOutlineField(string Name, string Text, string Shappublic sealed record FirmamentOutlineNode(string Id, string Kind, string? Variant, IReadOnlyList<string> Modifiers, string? Name,bool Occurrence, string? ParentId, int Order, FirmamentOutlineSpan Span, FirmamentOutlineSpan? NameSpan, string? SchemaId,- IReadOnlyList<string> Parameters, IReadOnlyList<FirmamentOutlineField> Fields, IReadOnlyList<string> Children);+ IReadOnlyList<string> Parameters, IReadOnlyList<FirmamentOutlineField> Fields, IReadOnlyList<string> Children)+{+ /// <summary>A bare call written in a body (<c>MountHole(center: Point2(10mm, 0mm))</c>): <c>Kind</c> is the+ /// callee and <c>Fields</c> are its arguments, positional ones named <c>#1</c>, <c>#2</c>.</summary>+ public bool Call { get; init; }+ /// <summary>The value a declaration is initialized with (<c>Static Thickness: Length = 8mm</c>), named <c>=</c>.+ /// Absent for object initializers, whose fields are <c>Fields</c>.</summary>+ public FirmamentOutlineField? Value { get; init; }+ /// <summary>The declared type annotation (<c>Length</c>), as written.</summary>+ public string? Annotation { get; init; }+ /// <summary>Declared parameters with their types and defaults, as written (Feature, Template).</summary>+ public IReadOnlyList<FirmamentOutlineParameter> Signature { get; init; } = [];+}++public sealed record FirmamentOutlineParameter(string Name, string Type, string? Default);/// <summary>One resolved name use. <c>Via</c> says where the use sits in the source declaration:/// <c>field:Profile</c>, <c>clause:Using</c>, <c>clause:Over</c>, <c>target</c>, <c>body</c> (an@@ -62,13 +76,17 @@ public static class FirmamentLanguageOutlineServiceprivate sealed class Entry{+ /// <summary>The declaration, or a synthetic stand-in for a call statement (see <see cref="Call"/>).</summary>public required DeclarationSyntax Syntax { get; init; }+ /// <summary>For a bare call written in a body: the call. Calls have no name and no children.</summary>+ public CallSyntax? Call { get; init; }+ public required StatementSyntax Statement { get; init; }public required string Id { get; init; }public Entry? Parent { get; init; }public required int Order { get; init; }public List<Entry> Children { get; } = [];public string Kind => Syntax.Type.Name.Text;- public string? Name => Syntax.Name?.Text;+ public string? Name => Call is null ? Syntax.Name?.Text : null;}public static FirmamentLanguageOutline Outline(string source, string document, string revision)@@ -126,9 +144,21 @@ public static class FirmamentLanguageOutlineService{var roots = new List<Entry>();Collect(parse.Document.Statements, null, roots);- return Flatten(roots).Select(e => (e.Id, e.Parent?.Id, e.Syntax)).ToArray();+ return Flatten(roots).Where(e => e.Call is null).Select(e => (e.Id, e.Parent?.Id, e.Syntax)).ToArray();}+ /// <summary>Every outline node's statement, declarations and bare calls, under its outline id.</summary>+ internal static IReadOnlyList<(string Id, string? ParentId, StatementSyntax Statement, bool Call)> Statements(SyntaxParseResult parse)+ {+ var roots = new List<Entry>();+ Collect(parse.Document.Statements, null, roots);+ return Flatten(roots).Select(e => (e.Id, e.Parent?.Id, e.Statement, e.Call is not null)).ToArray();+ }++ /// <summary>A body statement that is just a call of a named Feature or function.</summary>+ internal static CallSyntax? BareCall(StatementSyntax statement) =>+ statement is ExpressionStatementSyntax { Value: CallSyntax { Target: ReferenceSyntax } call } ? call : null;+internal static bool NameIsUse(DeclarationSyntax declaration) =>declaration.Type.Name.Text is "Modify" or "modify" or "Recognize" || declaration.Modifiers.Any(m => m.Name.Text == "Assert");@@ -140,17 +170,32 @@ public static class FirmamentLanguageOutlineServiceprivate static void Collect(IEnumerable<StatementSyntax> statements, Entry? parent, List<Entry> into){- var declarations = statements.SelectMany(DirectDeclarations).ToList();- var segments = Segments(declarations);- for (var i = 0; i < declarations.Count; i++)+ // Inside a body, a bare call is a node too: a reused Feature placed like any other feature.+ var items = statements.SelectMany(s => DirectDeclarations(s).Select(d => ((StatementSyntax)d, d, (CallSyntax?)null))+ .Concat(parent is null ? [] : DirectCalls(s).Select(c => (c, CallStandIn(BareCall(c)!), BareCall(c))))).ToList();+ var segments = Segments(items.Select(i => i.Item2).ToList());+ for (var i = 0; i < items.Count; i++){var id = parent is null ? segments[i] : parent.Id + "/" + segments[i];- var entry = new Entry { Syntax = declarations[i], Id = id, Parent = parent, Order = i };+ var entry = new Entry { Syntax = items[i].Item2, Call = items[i].Item3, Statement = items[i].Item1, Id = id, Parent = parent, Order = i };into.Add(entry);- Collect(Body(declarations[i]), entry, entry.Children);+ if (entry.Call is null) Collect(Body(items[i].Item2), entry, entry.Children);}}+ // Bare calls reachable the way DirectDeclarations reaches declarations: through nested blocks, not mappings.+ private static IEnumerable<StatementSyntax> DirectCalls(StatementSyntax statement) => statement switch+ {+ StatementBlockSyntax b => b.Body.Statements.SelectMany(DirectCalls),+ _ when BareCall(statement) is not null => [statement],+ _ => []+ };++ // A nameless declaration whose type is the callee keeps id assignment uniform: `MountHole`, or+ // `MountHole#1` and `MountHole#2` when a body calls it twice.+ private static DeclarationSyntax CallStandIn(CallSyntax call) =>+ new(new TypeSyntax(((ReferenceSyntax)call.Target).Name, [], call.Target.Span), null, [], [], null, null, [], null, null, false, call.Span);+// Declarations reachable from a statement without passing through another declaration:// nested blocks and Pattern mappings hold declarations that belong to the enclosing one.private static IEnumerable<DeclarationSyntax> DirectDeclarations(StatementSyntax statement) => statement switch@@ -180,6 +225,10 @@ public static class FirmamentLanguageOutlineServiceprivate static FirmamentOutlineNode Node(Entry entry, string source){+ if (entry.Call is { } call)+ return new(entry.Id, entry.Kind, null, [], null, false, entry.Parent?.Id, entry.Order, Span(call.Span), null, null, [],+ call.Arguments.Select((a, i) => new FirmamentOutlineField(a.Name?.Text ?? "#" + (i + 1), Text(source, a.Value.Span),+ Shape(a.Value), Span(a.Span), Span(a.Value.Span))).ToArray(), []) { Call = true };var d = entry.Syntax;var variant = d.Type.Arguments.Count == 0 ? null: string.Join(", ", d.Type.Arguments.Select(a => Text(source, a.Span)));@@ -187,9 +236,17 @@ public static class FirmamentLanguageOutlineServicevar fields = Body(d).OfType<FieldSyntax>().Select(f => new FirmamentOutlineField(f.Name.Text,Text(source, f.Value.Span), Shape(f.Value), Span(f.Span), Span(f.Value.Span))).ToArray();var parameters = d.Parameters.Select(p => p.Name?.Text ?? Text(source, p.Span)).ToArray();+ var value = d.Initializer is { } init and not ObjectSyntax+ ? new FirmamentOutlineField("=", Text(source, init.Span), Shape(init), Span(init.Span), Span(init.Span)) : null;return new(entry.Id, entry.Kind, variant, d.Modifiers.Select(m => m.Name.Text).ToArray(), entry.Name,d.Occurrence, entry.Parent?.Id, entry.Order, Span(d.Span), d.Name is null ? null : Span(d.Name.Span), schema,- parameters, fields, entry.Children.Select(c => c.Id).ToArray());+ parameters, fields, entry.Children.Select(c => c.Id).ToArray())+ {+ Value = value,+ Annotation = d.Annotation is null ? null : Text(source, d.Annotation.Span),+ Signature = d.Parameters.Where(p => p.Name is not null).Select(p => new FirmamentOutlineParameter(p.Name!.Text,+ Text(source, p.Value.Span), p.Default is null ? null : Text(source, p.Default.Span))).ToArray(),+ };}private static string? SchemaFor(Entry entry)@@ -217,6 +274,14 @@ public static class FirmamentLanguageOutlineServiceprivate static void Resolve(Entry entry, IReadOnlyList<Entry> roots, string source, List<FirmamentOutlineEdge> edges, List<FirmamentOutlineExternal> externals){+ if (entry.Call is { } call)+ {+ var scope = new HashSet<string>(StringComparer.Ordinal);+ for (var a = entry.Parent; a is not null; a = a.Parent)+ foreach (var p in a.Syntax.Parameters) if (p.Name is not null) scope.Add(p.Name.Text);+ Walk(call, entry, roots, source, "body", scope, null, edges, externals);+ return;+ }var d = entry.Syntax;var locals = new HashSet<string>(d.Parameters.Select(p => p.Name?.Text).OfType<string>(), StringComparer.Ordinal);for (var a = entry.Parent; a is not null; a = a.Parent)@@ -257,6 +322,8 @@ public static class FirmamentLanguageOutlineServicevar vocab = VocabularyFields.Contains(f.Name.Text) || ChoiceFields.Contains(f.Name.Text);Uses(f.Value, "field:" + f.Name.Text, vocab && f.Value is ReferenceSyntax, scoped);break;+ // A bare call in a body is its own node and resolves its own uses.+ case ExpressionStatementSyntax e when scoped is null && BareCall(e) is not null: break;case ExpressionStatementSyntax e: Uses(e.Value, "body", scoped: scoped); break;case ReturnSyntax r: Uses(r.Value, "body", scoped: scoped); break;case MappingSyntax m:diff --git a/Aetheris.Web.Runtime/sdk/README.md b/Aetheris.Web.Runtime/sdk/README.mdindex 39bc4e08..4493e949 100644--- a/Aetheris.Web.Runtime/sdk/README.md+++ b/Aetheris.Web.Runtime/sdk/README.md@@ -81,6 +81,19 @@ text, with `name` replacing its declared name; `insertFeature` (`node`, `source`there is none. Whether the edited model builds is still the compiler'sdecision.+Inside a body, a bare call such as `MountHole(center: Point2(10mm, 0mm))` is an+outline node with `call: true`: its `kind` is the callee and its `fields` are the+arguments, so `setField`/`removeField` edit arguments and `moveDeclaration`/+`removeDeclaration` place and remove it like a feature; `insertFeature` also takes+a call as `source`. Value declarations carry `value` (the initializer, for a+parameter sheet) and `annotation`; Features carry `signature`.+`extractFeature` (`node`, `name`, `parameters`) turns a feature into a+document-level `Feature` whose chosen fields become typed parameters defaulting to+their current values, and leaves a call with those values in its place: the+model builds the same geometry. A placed call has no name, so extraction is+refused (`edit-extract-referenced`) while anything names the declaration,+including a Pmi `Target`, and otherwise warns that the name is not kept.+`cad.language.palette()` lists what a visual editor can add(`firmament-palette/1`): bodies (`placement: 'model'`) and features on a body(`placement: 'feature'`), each a declaration `source` with starting values.diff --git a/Aetheris.Web.Runtime/sdk/src/index.d.ts b/Aetheris.Web.Runtime/sdk/src/index.d.tsindex c628ecfd..b47b4be4 100644--- a/Aetheris.Web.Runtime/sdk/src/index.d.ts+++ b/Aetheris.Web.Runtime/sdk/src/index.d.ts@@ -34,7 +34,8 @@ export interface LanguageAnalysis { readonly document: string; readonly revisionexport interface OutlineSpan { readonly start: number; readonly length: number }export interface OutlineField { readonly name: string; readonly text: string; readonly shape: 'quantity' | 'number' | 'string' | 'boolean' | 'version' | 'entityreference' | 'reference' | 'member' | 'sequence' | 'call' | 'specialization' | 'object' | 'expression' | 'other'; readonly span: OutlineSpan; readonly valueSpan: OutlineSpan }/** One declaration. `id` is its name path (`MotorMount/Modify:Body/Pilot`): stable across edits that keep names, kinds and nesting. */-export interface OutlineNode { readonly id: string; readonly kind: string; readonly variant: string | null; readonly modifiers: readonly string[]; readonly name: string | null; readonly occurrence: boolean; readonly parentId: string | null; readonly order: number; readonly span: OutlineSpan; readonly nameSpan: OutlineSpan | null; readonly schemaId: string | null; readonly parameters: readonly string[]; readonly fields: readonly OutlineField[]; readonly children: readonly string[] }+export interface OutlineNode { readonly id: string; readonly kind: string; readonly variant: string | null; readonly modifiers: readonly string[]; readonly name: string | null; readonly occurrence: boolean; readonly parentId: string | null; readonly order: number; readonly span: OutlineSpan; readonly nameSpan: OutlineSpan | null; readonly schemaId: string | null; readonly parameters: readonly string[]; readonly fields: readonly OutlineField[]; readonly children: readonly string[]; /** A bare call placed in a body (`MountHole(center: …)`): `kind` is the callee, `fields` its arguments (positional ones named `#1`…). */ readonly call?: boolean; /** The initializer of a value declaration (`Static Thickness: Length = 8mm`), named `=`. */ readonly value?: OutlineField | null; /** The declared type annotation, as written. */ readonly annotation?: string | null; /** Declared parameters with types and defaults (Feature, Template). */ readonly signature?: readonly OutlineParameter[] }+export interface OutlineParameter { readonly name: string; readonly type: string; readonly default: string | null }/** A resolved name use from one declaration to another. `via` is `field:<Name>`, `clause:<Using|Over|On|From|Key>`, `target`, `body`, `argument:<Name|type>`, `annotation`, `result` or `initializer`; nested object fields append `.<Name>`. */export interface OutlineEdge { readonly from: string; readonly to: string; readonly kind: 'reference' | 'call' | 'specialization' | 'modifies' | 'asserts' | 'recognizes'; readonly via: string; readonly member: string | null; readonly span: OutlineSpan; readonly ambiguous: boolean; readonly toDocument: string | null }/** A name use no declaration answers: a builtin, a vocabulary word, or a declaration outside the given documents. */@@ -50,7 +51,8 @@ export type LanguageEditOperation =| { readonly kind: 'removeDeclaration'; readonly node: string }| { readonly kind: 'renameDeclaration'; readonly node: string; readonly name: string }| { readonly kind: 'moveDeclaration'; readonly node: string; readonly after?: string; readonly first?: boolean }- | { readonly kind: 'insertFeature'; readonly node: string; readonly source: string; readonly name?: string };+ | { readonly kind: 'insertFeature'; readonly node: string; readonly source: string; readonly name?: string }+ | { readonly kind: 'extractFeature'; readonly node: string; readonly name: string; readonly parameters?: readonly string[] };/** The edited source and the single replacement `[start, start + length)` → `replacement` that produces it from the original. `nodes` holds the outline id each operation left behind (created, renamed or edited), in order; removals add none. */export interface LanguageEdit { readonly document: string; readonly revision: string; readonly text: string; readonly changed: boolean; readonly edit: { readonly start: number; readonly length: number; readonly replacement: string }; readonly nodes: readonly string[]; readonly warnings: readonly string[] }/** Something a visual editor can add. `placement` `model` inserts with `insertDeclaration`; `feature` with `insertFeature` on a body. `source` declares `nameStem`; pass a unique `name` with the insert. Every item is proven to build. */