zls icon indicating copy to clipboard operation
zls copied to clipboard

incorrect completions on nested generic type like std.ArrayList

Open CGQAQ opened this issue 2 years ago • 9 comments

Zig Version

0.12.0-dev.1+155c27f build with -Ddata-version="0.11.0"

Zig Language Server Version

0.12.0-dev.28+81bfc90

Steps to Reproduce

code completion of std.ArrayList is completely broken

Expected Behavior

should give me either x or y of struct Foo

Actual Behavior

image image

Sometimes will EVEN give the wrong complete items image But my collected_data_list is ArrayList of ArrayList image

P.S.

Other code completion works image

The code

const std = @import("std");

pub fn main() !void {
    const allocator = std.heap.page_allocator;

    const Foo = struct {
        x: u8,
        y: u8,
    };
    
    const ArrayList = std.ArrayList;
    const list_of_list = ArrayList(Foo).init(allocator);
    defer list_of_list.deinit();

    list_of_list.

    for (list_of_list.items) |list| {
        _ = list;
        // list.
    }
}

CGQAQ avatar Aug 08 '23 01:08 CGQAQ

Would you happen to be using Copilot?

llogick avatar Aug 11 '23 08:08 llogick

Would you happen to be using Copilot?

Yes, I am using Copilot

CGQAQ avatar Aug 16 '23 00:08 CGQAQ

did you tried latest commit, code completion was not working for me before but right now it does

Xefreh avatar Aug 16 '23 00:08 Xefreh

did you tried latest commit, code completion was not working for me before but right now it does

no, just checkout the latest commit same for me, and I disabled copilot as well

CGQAQ avatar Aug 16 '23 03:08 CGQAQ

There's nothing wrong w/ Copilot, it's just that I knew ZLS doesn't provide completions for any of those but list_of_list. (there's https://github.com/zigtools/zls/pull/1373 but it is quite partial and pretty sure doesn't work for any of these)

llogick avatar Aug 16 '23 03:08 llogick

the latest commit without copilot still gives me the wrong completion items of list_of_list

definition

image

usage

image

CGQAQ avatar Aug 16 '23 05:08 CGQAQ

const std = @import("std");

const Foo = struct {
    a: i32
};
const ListOfListOfFoo = std.ArrayList(std.ArrayList(Foo));

pub fn main() !void {
    var foo_list_of_list: ListOfListOfFoo = undefined;


    for (foo_list_of_list.items) |foo_list| {
        foo_list. // gives me `a`
    }
}

image

CGQAQ avatar Aug 16 '23 05:08 CGQAQ

This is caused by #1373 as commenting out the below shows no completion. @Techatrix It happens no matter the level of array list nesting. https://github.com/zigtools/zls/blob/81bfc90d609e688cd7179d6b02921cbd2146d1c7/src/analysis.zig#L1438-L1446

leecannon avatar Aug 16 '23 15:08 leecannon

here is a reduction that doesn't use std.ArrayList:

fn Boxed(comptime T: type) type {
    return struct { inner: T };
}
const Some = struct { alpha: u32 };
const boxed_boxed_some: Boxed(Boxed(Some)) = undefined;
const boxed_some = boxed_boxed_some.inner;
const some = boxed_some.inner;
//    ^^^^ hovering here will show 'Boxed(...)' but should be 'Some'

Techatrix avatar Oct 31 '23 19:10 Techatrix