slynch8 / 10x

10x IDE/Editor
180 stars 32 forks source link

custom index operator[] breaks autocomplete #2630

Open datgame opened 4 weeks ago

datgame commented 4 weeks ago

seems like the old https://github.com/slynch8/10x/issues/76 is still there If i have a custom operator[] for a custom type, then "." after it will suggest completions for the custom container type instead of for the type op[] is returning, i.e. the element type. works with stl types thought, like std::vector x; x[i].goodcomplete for the struct instead of std::vector.

my own vector type vs stl vector type: maybe our in-house vector class template inheritance setup is too complicated, but i thought stl was too. but maybe you have special rules for stl? note that i havent even #included stl vector here

image image

slynch8 commented 4 weeks ago

I tried #76 and it's working for me. It should be parsing the return type for the [] operator, I don't have any special code for it for stl. Can you give a simple example that doesn't work? Or just post the [] operator, maybe it's just that that isn't parsing for some reason.

datgame commented 3 weeks ago

in dev cmd.exe: cl -nologo 10x-op-index.cpp

this is a minimal working example of https://en.wikipedia.org/wiki/Curiously_recurring_template_pattern

many of our core container types are based on this

#include <vector>

struct x {int a,b,c;};

template<typename T, typename vec_t>
struct base {
    T& operator [](int i)
    {
        return ((vec_t*)this)->data[i];
    }
};

template<typename T>
struct vec : base<T, vec<T>> {
    T data[3];
};

int main() {
    std::vector<x> s;
    vec<x> v;
    s[0].a = v[0].b;

    (void)s[0]; // try adding a . last here, like s[0]. and 10x suggests: a,b,c
    (void)v[0]; // try adding a . last here, like v[0]. and 10x suggests: data operator[]
    return 0;
}