From 05ad3294f1aeaf8d501bc6841fe8d52a727b7a20 Mon Sep 17 00:00:00 2001 From: Techatrix <19954306+Techatrix@users.noreply.github.com> Date: Tue, 24 Jan 2023 17:00:14 +0100 Subject: [PATCH] use ArrayList for dotCompletions --- src/Server.zig | 5 ++--- src/analyser/completions.zig | 8 ++------ 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/Server.zig b/src/Server.zig index 876ae28..82c0d71 100644 --- a/src/Server.zig +++ b/src/Server.zig @@ -20,7 +20,7 @@ const tracy = @import("tracy.zig"); const uri_utils = @import("uri.zig"); const diff = @import("diff.zig"); const ComptimeInterpreter = @import("ComptimeInterpreter.zig"); -const analyser_completions = @import("analyser/completions.zig"); +const analyser = @import("analyser/analyser.zig"); const data = @import("data/data.zig"); const snipped_data = @import("data/snippets.zig"); @@ -596,8 +596,7 @@ fn typeToCompletion( ), .primitive, .array_index => {}, .@"comptime" => |co| { - const items = try analyser_completions.dotCompletions(allocator, &co.interpreter.ip, co.value.ty, co.value.val, co.value.node_idx); - try list.appendSlice(allocator, items); + try analyser.completions.dotCompletions(allocator, list, &co.interpreter.ip, co.value.ty, co.value.val, co.value.node_idx); }, } } diff --git a/src/analyser/completions.zig b/src/analyser/completions.zig index 276babc..207d12c 100644 --- a/src/analyser/completions.zig +++ b/src/analyser/completions.zig @@ -4,19 +4,16 @@ const types = @import("../lsp.zig"); const Ast = std.zig.Ast; - -/// TODO use std.ArrayListUnmanaged instead of returning a slice pub fn dotCompletions( arena: std.mem.Allocator, + completions: *std.ArrayListUnmanaged(types.CompletionItem), ip: *InternPool, ty: InternPool.Index, val: InternPool.Index, node: ?Ast.Node.Index -) error{OutOfMemory}![]types.CompletionItem { +) error{OutOfMemory}!void { _ = node; - var completions = std.ArrayListUnmanaged(types.CompletionItem){}; - const key = ip.indexToKey(ty); const inner_key = switch (key) { .pointer_type => |info| if (info.size == .One) ip.indexToKey(info.elem_type) else key, @@ -160,5 +157,4 @@ pub fn dotCompletions( .union_value, => unreachable, } - return try completions.toOwnedSlice(arena); }