diff options
Diffstat (limited to 'core/Names.zig')
| -rw-r--r-- | core/Names.zig | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/core/Names.zig b/core/Names.zig index d063bd17..01dbecf0 100644 --- a/core/Names.zig +++ b/core/Names.zig @@ -128,7 +128,9 @@ pub fn typed(n: *Names, gpa: std.mem.Allocator, text: []const u8) void { // only those are scored again (and then the ones not yet scored). const grew = n.query_len > 0 and std.mem.startsWith(u8, q, n.queryText()) and std.mem.indexOfScalar(u8, q[n.query_len..], ' ') == null; n.query_len = @intCast(q.len); - @memcpy(n.query_buf[0..q.len], q); + // Its own query typed again, to score names that came after it + // (Pick.declsArrived), is the buffer itself. + std.mem.copyForwards(u8, n.query_buf[0..q.len], q); n.reach = max_rows; if (grew) { const pending = n.pending.items[n.pending_at..]; @@ -435,3 +437,15 @@ test "Names keeps its best `reach` hits first in a full sort's order, the rest a n.reachTo(max_rows + 500); try std.testing.expectEqualSlices(Hit, all[0 .. max_rows + 500], n.hits.items[0 .. max_rows + 500]); } + +test "Names takes its own query typed again: names added after it (a Symbols picker's declarations from a worker, Pick.declsArrived) are scored against it" { + const gpa = std.testing.allocator; + var n: Names = .{}; + defer n.deinit(gpa); + n.typed(gpa, "zzlast"); + for ([_][]const u8{ "fn f0001() void {", "fn zzlastfn() void {" }) |cand| try n.add(gpa, cand, 0, cand.len, 0, 0); + n.typed(gpa, n.queryText()); + while (n.busy()) n.rescore(gpa); + try std.testing.expectEqualStrings("zzlast", n.queryText()); + try std.testing.expectEqual(@as(usize, 1), n.hits.items.len); +} |
