Compare commits

..

No commits in common. "a3ea183ba1a163eb58979cdeb0d924ab8aaf40c4" and "9c4f30c4ee297d6799bf00cca22e24b1431fceed" have entirely different histories.

2 changed files with 2 additions and 14 deletions

View file

@ -60,16 +60,8 @@ fn detect_prefix(text: []const u8) Prefix {
var lines = std.mem.splitScalar(u8, text, '\n'); var lines = std.mem.splitScalar(u8, text, '\n');
const line1 = lines.next() orelse return .{}; const line1 = lines.next() orelse return .{};
var prefix: []const u8 = line1; var prefix: []const u8 = line1;
var count: usize = 0; while (lines.next()) |line|
while (lines.next()) |line| {
prefix = lcp(prefix, line); prefix = lcp(prefix, line);
count += 1;
}
if (count < 1) return .{
.len = 0,
.first = &.{},
.continuation = &.{},
};
if (line1.len > prefix.len + 2 and line1[prefix.len] == '-' and line1[prefix.len + 1] == ' ') { if (line1.len > prefix.len + 2 and line1[prefix.len] == '-' and line1[prefix.len + 1] == ' ') {
const first = line1[0 .. prefix.len + 2]; const first = line1[0 .. prefix.len + 2];

View file

@ -36,7 +36,6 @@ pub const ValueType = struct {
query: ?Buffer.Selection = null, query: ?Buffer.Selection = null,
last_query: ?[]const u8 = null, last_query: ?[]const u8 = null,
commands: command.Collection(cmds) = undefined, commands: command.Collection(cmds) = undefined,
data: []const u8 = &.{},
}; };
pub const defaultValue: ValueType = .{}; pub const defaultValue: ValueType = .{};
@ -54,9 +53,7 @@ pub fn load_entries(self: *Type) !usize {
self.value.cursor = self.value.editor.get_primary().cursor; self.value.cursor = self.value.editor.get_primary().cursor;
self.value.query = null; self.value.query = null;
self.allocator.free(self.value.data); var iter: []const u8 = self.value.editor.completions.data.items;
self.value.data = try self.allocator.dupe(u8, self.value.editor.completions.data.items);
var iter: []const u8 = self.value.data;
while (iter.len > 0) { while (iter.len > 0) {
var cbor_item: []const u8 = undefined; var cbor_item: []const u8 = undefined;
if (!try cbor.matchValue(&iter, cbor.extract_cbor(&cbor_item))) return error.BadCompletion; if (!try cbor.matchValue(&iter, cbor.extract_cbor(&cbor_item))) return error.BadCompletion;
@ -93,7 +90,6 @@ pub fn load_entries(self: *Type) !usize {
} }
pub fn deinit(self: *Type) void { pub fn deinit(self: *Type) void {
self.allocator.free(self.value.data);
if (self.value.last_query) |p| self.allocator.free(p); if (self.value.last_query) |p| self.allocator.free(p);
self.value.commands.deinit(); self.value.commands.deinit();
} }