irony-mode icon indicating copy to clipboard operation
irony-mode copied to clipboard

Completion of strictly typed enum values

Open ddovod opened this issue 8 years ago • 7 comments

Hello. Suppose we have

enum class Shape
{
    kCircle,
    kRectangle,
    kTriangle
};

void drawShape(Shape shape)
{
    switch (shape) {
        case k|
    }
}

Irony suggests kCircle, kRectangle, kTriangle here, and if I choose one, it will insert exactly this value, i.e. kCircle. But it is incorrect because it leads to broken code, so I have to insert Shape:: manually. It would be great if irony can detect such cases (afaik only enums are affected) and add type name in front of enum value. What do you think about it? Btw Xcode does it and its really handy

ddovod avatar Sep 18 '17 22:09 ddovod

Adding examples from Xcode: Before choose 2017-09-19 14 24 29

After choose 2017-09-19 14 24 42

ddovod avatar Sep 19 '17 11:09 ddovod

That's a great remark. It looks like I discard this information but libclang exposes it. It should be possible to achieve the desired results with company, but this require some work.

Sarcasm avatar Sep 19 '17 22:09 Sarcasm

Thank you very much! Yes, company reports that type in compilation popup, also if enums type is inside long namespace chain, it reports full type name with all namespaces, so it could be achievable

ddovod avatar Sep 20 '17 06:09 ddovod

One of the issue, is also to get company work with what it calls a "non-prefix" completion, quoting C-h v company-backends RET:

Non-prefix matches are also supported (candidates that don’t start with the prefix, but match it in some backend-defined way). Backends that use this feature must disable cache (return t to ‘no-cache’) and might also want to respond to ‘match’.

The good thing, is we have a good, simple test case. But now I have to convert the backend to be non-prefix and see how to "repair" the information I discard.

This makes me think, the actual method used by company-irony is slightly broken anyway and need an overhaul (https://github.com/Sarcasm/company-irony/issues/40).

Sarcasm avatar Sep 20 '17 07:09 Sarcasm

Oh, I see. If I can help somehow, just say and I'll try to do my best)

ddovod avatar Sep 20 '17 17:09 ddovod

I guess if implementing it is too challenging, the best you can do, is ask me update on this on a regular basis, that will keep my attention on this issue and not bother me. :P

Sarcasm avatar Sep 21 '17 20:09 Sarcasm

Deal :+1:

ddovod avatar Sep 21 '17 22:09 ddovod