Add visible v1 diagnostics guardrails

This commit is contained in:
slhx agent
2026-06-21 05:38:52 +02:00
parent a1600e511a
commit 8658f7cc95
7 changed files with 180 additions and 7 deletions
+15 -2
View File
@@ -1,4 +1,5 @@
const std = @import("std");
const diagnostics = @import("diagnostics.zig");
// Minimal repo index for file picker/tree behavior.
// req: repo/001, ui/002, testing/001, testing/002, testing/003, testing/004
@@ -88,16 +89,24 @@ pub const Index = struct {
}
pub fn searchRowsAlloc(self: *const Index, allocator: std.mem.Allocator, query: []const u8, include_ignored: bool) ![][]const u8 {
return self.searchRowsLimitedAlloc(allocator, query, include_ignored, diagnostics.max_search_rows);
}
pub fn searchRowsLimitedAlloc(self: *const Index, allocator: std.mem.Allocator, query: []const u8, include_ignored: bool, limit: usize) ![][]const u8 {
try validateQuery(query);
if (limit == 0) return Error.InvalidQuery;
var rows = std.ArrayList([]const u8).empty;
errdefer {
for (rows.items) |row| allocator.free(row);
rows.deinit(allocator);
}
var truncated = false;
for (self.entries.items) |entry| {
if (!include_ignored and self.isIgnored(entry.path)) continue;
try appendSearchRowsForEntry(allocator, &rows, entry, query);
try appendSearchRowsForEntry(allocator, &rows, entry, query, limit, &truncated);
if (truncated) break;
}
if (truncated) try rows.append(allocator, try diagnostics.searchTruncatedRowAlloc(allocator, rows.items.len, limit));
return rows.toOwnedSlice(allocator);
}
@@ -147,11 +156,15 @@ fn validateQuery(query: []const u8) !void {
}
}
fn appendSearchRowsForEntry(allocator: std.mem.Allocator, rows: *std.ArrayList([]const u8), entry: Entry, query: []const u8) !void {
fn appendSearchRowsForEntry(allocator: std.mem.Allocator, rows: *std.ArrayList([]const u8), entry: Entry, query: []const u8, limit: usize, truncated: *bool) !void {
var line_no: usize = 1;
var lines = std.mem.splitScalar(u8, entry.content, '\n');
while (lines.next()) |line| : (line_no += 1) {
if (std.mem.indexOf(u8, line, query)) |column_zero| {
if (rows.items.len >= limit) {
truncated.* = true;
return;
}
const preview = try previewAlloc(allocator, line);
defer allocator.free(preview);
try rows.append(allocator, try std.fmt.allocPrint(