From 5a88f2698018ac9970ac293968106f84a8462739 Mon Sep 17 00:00:00 2001 From: Alexandros Naskos Date: Tue, 30 Mar 2021 16:45:49 +0300 Subject: [PATCH] Fixed dereference resolution of Type.data.pointer values --- src/analysis.zig | 35 +++++++++++++++++++++++++++++++---- src/main.zig | 2 +- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/src/analysis.zig b/src/analysis.zig index e15429c..88a7451 100644 --- a/src/analysis.zig +++ b/src/analysis.zig @@ -566,6 +566,13 @@ fn resolveDerefType( ) !?TypeWithHandle { const deref_node = switch (deref.type.data) { .other => |n| n, + .pointer => |n| return TypeWithHandle{ + .type = .{ + .is_type_val = false, + .data = .{ .other = n }, + }, + .handle = deref.handle, + }, else => return null, }; const tree = deref.handle.tree; @@ -1242,7 +1249,13 @@ pub fn getFieldAccessType( .unwrapped = try resolveDerefType(store, arena, current_type, &bound_type_params), }, .identifier => { - if (try lookupSymbolGlobal(store, arena, current_type.handle, tokenizer.buffer[tok.loc.start..tok.loc.end], source_index)) |child| { + if (try lookupSymbolGlobal( + store, + arena, + current_type.handle, + tokenizer.buffer[tok.loc.start..tok.loc.end], + source_index, + )) |child| { current_type = (try child.resolveType(store, arena, &bound_type_params)) orelse return null; } else return null; }, @@ -1278,11 +1291,20 @@ pub fn getFieldAccessType( tokenizer.buffer[after_period.loc.start..after_period.loc.end], !current_type.type.is_type_val, )) |child| { - current_type = (try child.resolveType(store, arena, &bound_type_params)) orelse return null; + current_type = (try child.resolveType( + store, + arena, + &bound_type_params, + )) orelse return null; } else return null; }, .question_mark => { - current_type = (try resolveUnwrapOptionalType(store, arena, current_type, &bound_type_params)) orelse return null; + current_type = (try resolveUnwrapOptionalType( + store, + arena, + current_type, + &bound_type_params, + )) orelse return null; }, else => { log.debug("Unrecognized token {} after period.", .{after_period.tag}); @@ -1291,7 +1313,12 @@ pub fn getFieldAccessType( } }, .period_asterisk => { - current_type = (try resolveDerefType(store, arena, current_type, &bound_type_params)) orelse return null; + current_type = (try resolveDerefType( + store, + arena, + current_type, + &bound_type_params, + )) orelse return null; }, .l_paren => { const current_type_node = switch (current_type.type.data) { diff --git a/src/main.zig b/src/main.zig index 722191c..3806644 100644 --- a/src/main.zig +++ b/src/main.zig @@ -1141,8 +1141,8 @@ fn completeFieldAccess( var tokenizer = std.zig.Tokenizer.init(position.line[range.start..range.end]); if (try analysis.getFieldAccessType(&document_store, arena, handle, position.absolute_index, &tokenizer)) |result| { try typeToCompletion(arena, &completions, result, handle, config); + truncateCompletions(completions.items, config.max_detail_length); } - truncateCompletions(completions.items, config.max_detail_length); try send(arena, types.Response{ .id = id,