Commit 74a458bc authored by Leandro Melo's avatar Leandro Melo

C++: Improve completion when forward declarations present

This fixes one of the issues mentioned in the report below.
THe other part will come in a separate patch.

Task-number: QTCREATORBUG-7730

Change-Id: I9f56a9bcec8a881dab3ab60f40c5b71f296466da
Reviewed-by: default avatarRoberto Raggi <roberto.raggi@nokia.com>
parent b53d5628
......@@ -416,6 +416,8 @@ QList<LookupItem> ClassOrNamespace::lookup_helper(const Name *name, bool searchI
QList<LookupItem> result;
if (name) {
QSet<ClassOrNamespace *> processed;
if (const QualifiedNameId *q = name->asQualifiedNameId()) {
if (! q->base())
result = globalNamespace()->find(q->name());
......@@ -423,10 +425,11 @@ QList<LookupItem> ClassOrNamespace::lookup_helper(const Name *name, bool searchI
else if (ClassOrNamespace *binding = lookupType(q->base()))
result = binding->find(q->name());
lookup_helper(name, this, &result, &processed, /*templateId = */ 0);
return result;
}
QSet<ClassOrNamespace *> processed;
ClassOrNamespace *binding = this;
do {
lookup_helper(name, binding, &result, &processed, /*templateId = */ 0);
......
......@@ -121,6 +121,40 @@ static void setup(TestData *data)
data->doc = data->editor->document();
}
void CppToolsPlugin::test_completion_forward_declarations_present()
{
TestData data;
data.srcText = "\n"
"class Foo\n"
"{\n"
" struct Bar;\n"
" int i;\n"
"};\n"
"\n"
"struct Foo::Bar \n"
"{\n"
" Bar() {}\n"
"};\n"
"\n"
"@\n"
"// padding so we get the scope right\n";
setup(&data);
Utils::ChangeSet change;
change.insert(data.pos, "Foo::Bar::");
QTextCursor cursor(data.doc);
change.apply(&cursor);
data.pos += 10;
QStringList expected;
expected.append("Bar");
QStringList completions = getCompletions(data);
QCOMPARE(completions, expected);
}
void CppToolsPlugin::test_completion_basic_1()
{
TestData data;
......
......@@ -90,6 +90,7 @@ private slots:
void test_codegen_definition_last_member();
void test_codegen_definition_middle_member();
void test_completion_forward_declarations_present();
void test_completion_basic_1();
void test_completion_template_1();
void test_completion_template_as_base();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment