use ArrayList for dotCompletions

This commit is contained in:
Techatrix 2023-01-24 17:00:14 +01:00
parent 3577e719fb
commit 05ad3294f1
2 changed files with 4 additions and 9 deletions

View File

@ -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);
},
}
}

View File

@ -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);
}