From c09e48810925f464b9673b119d47f0bc87a729f3 Mon Sep 17 00:00:00 2001 From: Alexandros Naskos Date: Fri, 24 Jul 2020 13:20:13 +0300 Subject: [PATCH] Added addressof, fixed slice and array completions --- src/analysis.zig | 20 +++++++++++++++++++- src/main.zig | 34 +++++++++++++++++++++++++++++++++- 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/src/analysis.zig b/src/analysis.zig index 926b767..bd0b4fe 100644 --- a/src/analysis.zig +++ b/src/analysis.zig @@ -405,7 +405,7 @@ fn resolveUnwrapErrorType( .type = .{ .data = .{ .other = n }, .is_type_val = rhs.type.is_type_val }, .handle = rhs.handle, }, - .primitive, .slice => return null, + .primitive, .slice, .pointer => return null, }; if (rhs_node.cast(ast.Node.SimpleInfixOp)) |infix_op| { @@ -740,6 +740,23 @@ pub fn resolveTypeOfNodeInternal( }, bound_type_params)) orelse return null; return try resolveUnwrapErrorType(store, arena, rhs_type, bound_type_params); }, + .AddressOf => { + const prefix_op = node.cast(ast.Node.SimplePrefixOp).?; + const rhs_type = (try resolveTypeOfNodeInternal(store, arena, .{ + .node = prefix_op.rhs, + .handle = handle, + }, bound_type_params)) orelse return null; + + const rhs_node = switch (rhs_type.type.data) { + .other => |n| n, + else => return null, + }; + + return TypeWithHandle{ + .type = .{ .data = .{ .pointer = rhs_node }, .is_type_val = false }, + .handle = rhs_type.handle, + }; + }, .BuiltinCall => { const builtin_call = node.castTag(.BuiltinCall).?; const call_name = handle.tree.tokenSlice(builtin_call.builtin_token); @@ -825,6 +842,7 @@ pub fn resolveTypeOfNodeInternal( // TODO Make this better, nested levels of type vals pub const Type = struct { data: union(enum) { + pointer: *ast.Node, slice: *ast.Node, error_union: *ast.Node, other: *ast.Node, diff --git a/src/main.zig b/src/main.zig index a7bde5e..5dea5ef 100644 --- a/src/main.zig +++ b/src/main.zig @@ -281,6 +281,23 @@ fn typeToCompletion( } }, .error_union => {}, + .pointer => |n| { + if (config.operator_completions) { + try list.append(.{ + .label = "*", + .kind = .Operator, + }); + } + try nodeToCompletion( + arena, + list, + .{ .node = n, .handle = type_handle.handle }, + null, + orig_handle, + type_handle.type.is_type_val, + config, + ); + }, .other => |n| try nodeToCompletion( arena, list, @@ -416,7 +433,22 @@ fn nodeToCompletion( .detail = analysis.getContainerFieldSignature(handle.tree, field), }); }, - .ArrayType, .SliceType => {}, + .SliceType => { + try list.append(.{ + .label = "len", + .kind = .Field, + }); + try list.append(.{ + .label = "ptr", + .kind = .Field, + }); + }, + .ArrayType => { + try list.append(.{ + .label = "len", + .kind = .Field, + }); + }, .PtrType => { if (config.operator_completions) { try list.append(.{