forked from qt-creator/qt-creator
C++: fix code completion of stl containers in internal code model
This fix makes some trick and replaces existing typedef of 'pointer'
to the simplest one(only in class unique_ptr), e.g.:
template <class _Tp>
class unique_ptr
{
typedef some_strange_things pointer;
pointer operator->();
}
is replace with
template <class _Tp>
class unique_ptr
{
typedef _Tp* pointer;
pointer operator->();
}
In most of the implementation of unique_ptr it should work.
Similar approach is done for std::list, std::vector, std::queue, std::set,
std::multiset, std::unordered_set.
It is done in this hacky way to omit problems with cyclic and complex
resolving of typedefs.
Change-Id: I1363dfc5e23d3cd2fa7af7fc27423bfbac2d894d
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
This commit is contained in:
@@ -2584,6 +2584,169 @@ void CppToolsPlugin::test_completion_data()
|
||||
" @\n"
|
||||
"}\n"
|
||||
) << _("t.p->") << QStringList({"Foo", "bar"});
|
||||
|
||||
QTest::newRow("fix_code_completion_for_unique_ptr_operator_arrow") << _(
|
||||
"namespace std {\n"
|
||||
"template<typename _Tp>\n"
|
||||
"struct unique_ptr\n"
|
||||
"{\n"
|
||||
" typedef FOO pointer;\n"
|
||||
" pointer operator->();\n"
|
||||
"};\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"struct Foo { int bar; };\n"
|
||||
"\n"
|
||||
"void func()\n"
|
||||
"{\n"
|
||||
" std::unique_ptr<Foo> ptr;\n"
|
||||
" @\n"
|
||||
"}\n"
|
||||
) << _("ptr->") << QStringList({"Foo", "bar"});
|
||||
QTest::newRow("fix_code_completion_for_unique_ptr_method_get") << _(
|
||||
"namespace std {\n"
|
||||
"template<typename _Tp>\n"
|
||||
"struct unique_ptr\n"
|
||||
"{\n"
|
||||
" typedef FOO pointer;\n"
|
||||
" pointer get();\n"
|
||||
"};\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"struct Foo { int bar; };\n"
|
||||
"\n"
|
||||
"void func()\n"
|
||||
"{\n"
|
||||
" std::unique_ptr<Foo> ptr;\n"
|
||||
" @\n"
|
||||
"}\n"
|
||||
) << _("ptr.get()->") << QStringList({"Foo", "bar"});
|
||||
QTest::newRow("fix_code_completion_for_std_vector_method_at") << _(
|
||||
"namespace std {\n"
|
||||
"template<typename _Tp>\n"
|
||||
"struct vector\n"
|
||||
"{\n"
|
||||
" typedef FOO reference;\n"
|
||||
" reference at(size_t i);\n"
|
||||
"};\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"struct Foo { int bar; };\n"
|
||||
"\n"
|
||||
"void func()\n"
|
||||
"{\n"
|
||||
" std::vector<Foo> v;\n"
|
||||
" @\n"
|
||||
"}\n"
|
||||
) << _("v.at(0).") << QStringList({"Foo", "bar"});
|
||||
QTest::newRow("fix_code_completion_for_std_vector_operator_square_brackets") << _(
|
||||
"namespace std {\n"
|
||||
"template<typename _Tp>\n"
|
||||
"struct vector\n"
|
||||
"{\n"
|
||||
" typedef FOO reference;\n"
|
||||
" reference operator[](size_t i);\n"
|
||||
"};\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"struct Foo { int bar; };\n"
|
||||
"\n"
|
||||
"void func()\n"
|
||||
"{\n"
|
||||
" std::vector<Foo> v;\n"
|
||||
" @\n"
|
||||
"}\n"
|
||||
) << _("v[0].") << QStringList({"Foo", "bar"});
|
||||
QTest::newRow("fix_code_completion_for_std_list_method_front") << _(
|
||||
"namespace std {\n"
|
||||
"template<typename _Tp>\n"
|
||||
"struct list\n"
|
||||
"{\n"
|
||||
" typedef FOO reference;\n"
|
||||
" reference front();\n"
|
||||
"};\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"struct Foo { int bar; };\n"
|
||||
"\n"
|
||||
"void func()\n"
|
||||
"{\n"
|
||||
" std::list<Foo> l;\n"
|
||||
" @\n"
|
||||
"}\n"
|
||||
) << _("l.front().") << QStringList({"Foo", "bar"});
|
||||
QTest::newRow("fix_code_completion_for_std_queue_method_front") << _(
|
||||
"namespace std {\n"
|
||||
"template<typename _Tp>\n"
|
||||
"struct queue\n"
|
||||
"{\n"
|
||||
" typedef FOO reference;\n"
|
||||
" reference front();\n"
|
||||
"};\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"struct Foo { int bar; };\n"
|
||||
"\n"
|
||||
"void func()\n"
|
||||
"{\n"
|
||||
" std::queue<Foo> l;\n"
|
||||
" @\n"
|
||||
"}\n"
|
||||
) << _("l.front().") << QStringList({"Foo", "bar"});
|
||||
QTest::newRow("fix_code_completion_for_std_set_method_begin") << _(
|
||||
"namespace std {\n"
|
||||
"template<typename _Tp>\n"
|
||||
"struct set\n"
|
||||
"{\n"
|
||||
" typedef FOO iterator;\n"
|
||||
" iterator begin();\n"
|
||||
"};\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"struct Foo { int bar; };\n"
|
||||
"\n"
|
||||
"void func()\n"
|
||||
"{\n"
|
||||
" std::set<Foo> s;\n"
|
||||
" @\n"
|
||||
"}\n"
|
||||
) << _("s.begin()->") << QStringList({"Foo", "bar"});
|
||||
QTest::newRow("fix_code_completion_for_std_multiset_method_begin") << _(
|
||||
"namespace std {\n"
|
||||
"template<typename _Tp>\n"
|
||||
"struct multiset\n"
|
||||
"{\n"
|
||||
" typedef FOO iterator;\n"
|
||||
" iterator begin();\n"
|
||||
"};\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"struct Foo { int bar; };\n"
|
||||
"\n"
|
||||
"void func()\n"
|
||||
"{\n"
|
||||
" std::multiset<Foo> s;\n"
|
||||
" @\n"
|
||||
"}\n"
|
||||
) << _("s.begin()->") << QStringList({"Foo", "bar"});
|
||||
QTest::newRow("fix_code_completion_for_std_unordered_set_method_begin") << _(
|
||||
"namespace std {\n"
|
||||
"template<typename _Tp>\n"
|
||||
"struct unordered_set\n"
|
||||
"{\n"
|
||||
" typedef FOO iterator;\n"
|
||||
" iterator begin();\n"
|
||||
"};\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"struct Foo { int bar; };\n"
|
||||
"\n"
|
||||
"void func()\n"
|
||||
"{\n"
|
||||
" std::unordered_set<Foo> s;\n"
|
||||
" @\n"
|
||||
"}\n"
|
||||
) << _("s.begin()->") << QStringList({"Foo", "bar"});
|
||||
}
|
||||
|
||||
void CppToolsPlugin::test_completion_member_access_operator()
|
||||
|
||||
Reference in New Issue
Block a user