From 3fc7ee75c2e704892fdd38349b0088f3018c9f15 Mon Sep 17 00:00:00 2001 From: Vexu Date: Mon, 8 Jun 2020 19:07:16 +0300 Subject: [PATCH] support completion for builtin casts with explicity type parameter --- src/analysis.zig | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/analysis.zig b/src/analysis.zig index 20887fb..4831354 100644 --- a/src/analysis.zig +++ b/src/analysis.zig @@ -531,8 +531,27 @@ pub fn resolveTypeOfNode(analysis_ctx: *AnalysisContext, node: *ast.Node) ?*ast. return analysis_ctx.in_container; } + // TODO: https://github.com/ziglang/zig/issues/4335 + const cast_map = std.ComptimeStringMap(void, .{ + .{ .@"0" = "@as" }, + .{ .@"0" = "@bitCast" }, + .{ .@"0" = "@fieldParentPtr" }, + .{ .@"0" = "@floatCast" }, + .{ .@"0" = "@floatToInt" }, + .{ .@"0" = "@intCast" }, + .{ .@"0" = "@intToEnum" }, + .{ .@"0" = "@intToFloat" }, + .{ .@"0" = "@intToPtr" }, + .{ .@"0" = "@truncate" }, + .{ .@"0" = "@ptrCast" }, + }); + if (cast_map.has(call_name)) { + if (builtin_call.params_len < 1) return null; + return resolveTypeOfNode(analysis_ctx, builtin_call.paramsConst()[0]); + } + if (!std.mem.eql(u8, call_name, "@import")) return null; - if (builtin_call.params_len > 1) return null; + if (builtin_call.params_len < 1) return null; const import_param = builtin_call.paramsConst()[0]; if (import_param.id != .StringLiteral) return null;