Skip to content

Enum/Union function completions missing inside slices of that type. #2393

@MaximilianHeidenreich

Description

@MaximilianHeidenreich

Zig Version

0.14.1

ZLS Version

0.14.0

Client / Code Editor / Extensions

NVIM v0.11.2

Steps to Reproduce and Observed Behavior

Create an enum or union with member functions:

const TestEnum = enum(u8) {
  .foo,
  .bar
  
  pub fn baz() TestEnum {
    return .bar;
  }
};

const TestUnion = union(enum) {
  .foo,
  .bar: u8,

  pub fn baz(num: u8) TestUnion {
    return .{ .bar = num };
  }
};

Now, given a function which takes a slice of thes enum/union, it won't display any LSP completions when inside the slice:

pub fn exampleUnions(comptime items: []const TestUnion) void {
  _ = items;
  return;
}

pub fn exampleEnums(comptime items: []const TestEnum) void {
  _ = items;
  return;
}

pub fn main() !void {
  const testUnion = exampleUnions(&.{ . });
  //                                   ^ Start typing ".", there should be completions for .foo, .bar, .baz()
  //                                     but it doesn't display anything!

  const testEnum = exampleEnums(&.{ . });
  //                                 ^ Start typing ".", there should be completions for .foo, .bar, .baz()
  //                                   but it doesn't display anything!
}

Expected Behavior

It should display the field/function completion hints:

  • .foo
  • .bar
  • .baz(): TestUnion

Relevant log output

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions