Skip to content

Are Type Tooltips Possible? #469

Open
@munael

Description

@munael

In some LSP implementations, like for example PyLance for Python, you can get hints like this:
image

Right now with code-d I do not see any such tooltips when hovering over variables (or aliases, or function names, and so on), or after pressing ctrl+k ctrl+i.

Further, the auto-completion are extremely limited. I don't know if that's expected or I'm missing something.

For example, I don't get any auto-complete suggestions for struct methods.
image

What limited auto-complete suggestions are available also often do not show up if I'm writing in the middle of an expression. It has to be at the end of the line.

Ideally, I'd like tooltips to work in at least each of the following situations:

struct Thing {
    int x;
    int f(int y) => x + y;
    int f2(int y) {
        return x + y;
    }
}

struct Fing(T) {
    T t;
}

void func() {
    Thing thing;
    thing.f();  // Auto-complete: Suggest function `f`.
    thing.f2(); // This works, but not the short version.
    thing;      // Tooltips: Show type of `thing`.
    alias Fint = Fing!int;
    Fing fint;
    fint.t;     // Tooltips and Auto-complete: Should show `t` as having type `int` not `T`.
}

Range copy(Range)(Range range)
if (isInputRange!Range)
{
    static if (isRandomAccessRange!Range)
    {
        const tlen = range.length;
        const slen = range.length;
        assert(tlen >= slen,
                "Cannot copy a source range into a smaller target range.");

        immutable overlaps = () @trusted {
            return source.ptr < target.ptr + tlen &&
                   target.ptr < source.ptr + slen; };
        // Can any tooltips at all be shown in this situation?
        // 1. Types in `overlaps`.
        // 2. The typing of `.length` in `range`, based on the checks in `isRandomAccessRange` which must pass for this static if branch to be active.
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions