forked from qt-creator/qt-creator
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: Roberto Raggi <roberto.raggi@nokia.com>
This commit is contained in:
@@ -416,6 +416,8 @@ QList<LookupItem> ClassOrNamespace::lookup_helper(const Name *name, bool searchI
|
|||||||
QList<LookupItem> result;
|
QList<LookupItem> result;
|
||||||
|
|
||||||
if (name) {
|
if (name) {
|
||||||
|
QSet<ClassOrNamespace *> processed;
|
||||||
|
|
||||||
if (const QualifiedNameId *q = name->asQualifiedNameId()) {
|
if (const QualifiedNameId *q = name->asQualifiedNameId()) {
|
||||||
if (! q->base())
|
if (! q->base())
|
||||||
result = globalNamespace()->find(q->name());
|
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()))
|
else if (ClassOrNamespace *binding = lookupType(q->base()))
|
||||||
result = binding->find(q->name());
|
result = binding->find(q->name());
|
||||||
|
|
||||||
|
lookup_helper(name, this, &result, &processed, /*templateId = */ 0);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
QSet<ClassOrNamespace *> processed;
|
|
||||||
ClassOrNamespace *binding = this;
|
ClassOrNamespace *binding = this;
|
||||||
do {
|
do {
|
||||||
lookup_helper(name, binding, &result, &processed, /*templateId = */ 0);
|
lookup_helper(name, binding, &result, &processed, /*templateId = */ 0);
|
||||||
|
@@ -121,6 +121,40 @@ static void setup(TestData *data)
|
|||||||
data->doc = data->editor->document();
|
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()
|
void CppToolsPlugin::test_completion_basic_1()
|
||||||
{
|
{
|
||||||
TestData data;
|
TestData data;
|
||||||
|
@@ -90,6 +90,7 @@ private slots:
|
|||||||
void test_codegen_definition_last_member();
|
void test_codegen_definition_last_member();
|
||||||
void test_codegen_definition_middle_member();
|
void test_codegen_definition_middle_member();
|
||||||
|
|
||||||
|
void test_completion_forward_declarations_present();
|
||||||
void test_completion_basic_1();
|
void test_completion_basic_1();
|
||||||
void test_completion_template_1();
|
void test_completion_template_1();
|
||||||
void test_completion_template_as_base();
|
void test_completion_template_as_base();
|
||||||
|
Reference in New Issue
Block a user