tiny.smg.context
Defined in tiny.smg.
Source context packing and bounded inspection of persisted syntactic relationships.
API (14)
Actions
Public operations.
buildbuildFromReaderinspect: Inspects an existing graph without blocking on publication or changing its state.toJsontoText
Types and contracts
Public types and contracts.
EntryInspectOptionsInspection: Retained rows and storage decoding use caller-backed dynamic_unbounded allocation.ResultSection
Namespaces
Public namespaces.
Source
Source: tools/smg/src/context/pack.zig:25
zig
pub const Entry = struct { name: []const u8, type: []const u8, section: Section, relation: []const u8, level: []const u8, content: []const u8, tokens: usize, file: ?[]const u8 = null, line: ?i64 = null,};Source: tools/smg/src/context/pack.zig:37
zig
pub const Result = struct { target: []const u8, entries: []const Entry, total_tokens: usize, budget: i64, truncated: bool,};Source: tools/smg/src/context/pack.zig:16
zig
pub const Section = enum(u8) { about, owner, usages, impact, tests, dependencies,};Source: tools/smg/src/context/inspect.zig:9
zig
/// Inspects an existing graph without blocking on publication or changing its state.pub fn run( allocator: std.mem.Allocator, root: []const u8, targets: []const []const u8, options: model.Options,) !model.Inspection { try model.validate(root, targets, options); var result = model.Inspection{ .arena = std.heap.ArenaAllocator.init(allocator), .result = undefined, }; errdefer result.deinit(); const owned = result.arena.allocator(); const owned_root = try std.fs.path.resolve(owned, &.{root}); var builder = model.Builder{ .allocator = owned, .root = owned_root, .options = options, .deadline_ns = sys.time.nanoTimestamp() + @as(i128, options.deadline_ms) * 1_000_000, .report = .{ .limits = options.limits, .deadline_ms = options.deadline_ms, .expand = .{ .cwd = owned_root, .argv = &.{ "smg", "context", targets[0], "--format", "json" }, } }, }; std.debug.assert(options.limits.rows <= model.rows_max); try initialize(&builder, targets); collect(allocator, &builder) catch |err| { if (err == error.OutOfMemory) return err; builder.report.state = failureState(err); builder.report.coverage.traversal_complete = false; builder.report.problems = try owned.dupe([]const u8, &.{@errorName(err)}); }; result.result = try builder.finish(); return result;}Source: tools/smg/src/context/pack.zig:45
zig
pub fn build(allocator: std.mem.Allocator, graph: graph_mod.Graph, root: []const u8, name: []const u8, budget: i64, with_source: bool, limits: limits_mod.Context) !Result { return try buildSource( allocator, .{ .graph = graph }, root, name, budget, with_source, limits, );}Source: tools/smg/src/context/pack.zig:57
zig
pub fn buildFromReader( allocator: std.mem.Allocator, reader: *smg.storage.database.Reader, root: []const u8, name: []const u8, budget: i64, with_source: bool, limits: limits_mod.Context,) !Result { return try buildSource( allocator, .{ .stored = reader }, root, name, budget, with_source, limits, );}Source: tools/smg/src/context/pack.zig:157
zig
pub fn toJson(allocator: std.mem.Allocator, result: Result) ![]const u8 { var out: std.Io.Writer.Allocating = .init(allocator); var writer = pretty_json.Writer.init(&out.writer, .minified); try writer.beginObject(); try writer.objectField("target"); try writer.write(result.target); try writer.objectField("total_tokens"); try writer.write(result.total_tokens); try writer.objectField("budget"); try writer.write(result.budget); try writer.objectField("truncated"); try writer.write(result.truncated); try writer.objectField("sections"); try writer.beginObject(); inline for (std.meta.tags(Section)) |section| { try writer.objectField(@tagName(section)); try writer.write(sectionEntryCount(result.entries, section)); } try writer.endObject(); try writer.objectField("entries"); try writer.beginArray(); for (result.entries) |entry| { try writer.beginObject(); try writer.objectField("name"); try writer.write(entry.name); try writer.objectField("type"); try writer.write(entry.type); try writer.objectField("section"); try writer.write(@tagName(entry.section)); try writer.objectField("relation"); try writer.write(entry.relation); try writer.objectField("level"); try writer.write(entry.level); try writer.objectField("tokens"); try writer.write(entry.tokens); try writer.objectField("content"); try writer.write(entry.content); if (entry.file) |file| { try writer.objectField("file"); try writer.write(file); } if (entry.line) |line| { try writer.objectField("line"); try writer.write(line); } try writer.endObject(); } try writer.endArray(); try writer.endObject(); try out.writer.writeByte('\n'); return try out.toOwnedSlice();}Source: tools/smg/src/context/pack.zig:210
zig
pub fn toText(allocator: std.mem.Allocator, result: Result) ![]const u8 { return try toTextWithOptions(allocator, result, .{ .width = 88 });}Source: tools/smg/src/context/root.zig
zig
//! Source context packing and bounded inspection of persisted syntactic relationships.const pack = @import("pack.zig");const inspection = @import("inspect.zig");pub const model = @import("model.zig");pub const query = @import("query.zig");pub const source = @import("source.zig");pub const render = @import("render.zig");pub const Section = pack.Section;pub const Entry = pack.Entry;pub const Result = pack.Result;pub const build = pack.build;pub const buildFromReader = pack.buildFromReader;pub const toJson = pack.toJson;pub const toText = pack.toText;pub const Inspection = model.Inspection;pub const InspectOptions = model.Options;pub const inspect = inspection.run;Source: tools/smg/src/root.zig:19
zig
pub const context = @import("context/root.zig");Audit
| Definitions | 9 |
|---|---|
| Public names | 9 |
| Members | 20 |
| Version | 26.7.0 |
| Revision | daab053ee433 |