Pure-D / serve-d

D LSP server (dlang language server protocol server)
MIT License
200 stars 48 forks source link

Templated struct/function autocompletion support #229

Open UARTman opened 2 years ago

UARTman commented 2 years ago

Currently autocompletion doesn't work with https://dlang.org/spec/class.html#alias-this .

Example:

struct Scoped(T)
{
    T payload;

    alias payload this;

    @disable this();
    @disable this(this);

    ~this()
    {
        .destroy(payload);
    }
}

class DisplayArea: DrawingArea {
    Chip8Display display;
    this(Chip8Display d) {
        display = d;
        super();
        addOnDraw(&draw);
    }

    bool draw(Scoped!Context ctx, Widget w) {
        Pattern pattern = Pattern.createForSurface(display.surface);
        pattern.setFilter(cairo_filter_t.NEAREST);

        ctx.scale(4, 4);

        ctx.setSource(pattern);
        ctx.paint();

        return true;
    }
}

In this case an attempt to auto-complete ctx. within the draw function doesn't show any Context functions/members.

WebFreak001 commented 2 years ago

see https://github.com/dlang-community/DCD/issues/12

ryuukk commented 2 years ago

alias this works, if you replace T by Context, you'll get proper completion

The problem is with the template, DCD doesn't resolve it

I began work on this, currently i managed to get templated functions to work

PR here: https://github.com/dlang-community/dsymbol/pull/178

I will see if i can make this one to work too!