forked from qt-creator/qt-creator
Clang: Correct member access operator if possible
1 struct Foo { int member; };
2 void f(Foo *foo)
3 {
4 foo.<REQUEST COMPLETION> // correct '.' to '->' and provide results
5 }
The preferred approach would be to check if "foo" in line 4 is of
pointer type, but there is no suitable cursor (only CompoundStmt) at
that position since the code is usually not yet parsed and thus invalid.
Thus, just run the completion as is. If there are not any results for a
dot completion, re-run the completion with "." exchanged by "->". This
approach is inherently slower than the preferred approach implemented in
the built-in code model.
The following rare cases are not handled:
1) Requesting completion after white space:
Works: foo.<COMPLETE HERE>
Fails: foo. <COMPLETE HERE>
2) Opening a file and requesting completion (ctrl+space) without prior
editing. No editing before triggering completion means that no
unsaved file is generated on the backend side, which is a
requirement for the correction.
Task-number: QTCREATORBUG-11581
Change-Id: I6bc8e8594778774ab342755fdb01a8a3e5c52ba0
Reviewed-by: Marco Bubke <marco.bubke@theqtcompany.com>
This commit is contained in:
@@ -689,6 +689,7 @@ class ProjectLessCompletionTest
|
||||
{
|
||||
public:
|
||||
ProjectLessCompletionTest(const QByteArray &testFileName,
|
||||
const QString &textToInsert = QString(),
|
||||
const QStringList &includePaths = QStringList())
|
||||
{
|
||||
CppTools::Tests::TestCase garbageCollectionGlobalSnapshot;
|
||||
@@ -697,8 +698,11 @@ public:
|
||||
const TestDocument testDocument(testFileName, globalTemporaryDir());
|
||||
QVERIFY(testDocument.isCreatedAndHasValidCursorPosition());
|
||||
OpenEditorAtCursorPosition openEditor(testDocument);
|
||||
|
||||
QVERIFY(openEditor.succeeded());
|
||||
|
||||
if (!textToInsert.isEmpty())
|
||||
openEditor.editor()->insert(textToInsert);
|
||||
|
||||
proposal = completionResults(openEditor.editor(), includePaths);
|
||||
}
|
||||
|
||||
@@ -880,7 +884,9 @@ void ClangCodeCompletionTest::testCompletePreprocessorKeywords()
|
||||
void ClangCodeCompletionTest::testCompleteIncludeDirective()
|
||||
{
|
||||
CppTools::Tests::TemporaryCopiedDir testDir(qrcPath("exampleIncludeDir"));
|
||||
ProjectLessCompletionTest t("includeDirectiveCompletion.cpp", QStringList(testDir.path()));
|
||||
ProjectLessCompletionTest t("includeDirectiveCompletion.cpp",
|
||||
QString(),
|
||||
QStringList(testDir.path()));
|
||||
|
||||
QVERIFY(hasItem(t.proposal, "file.h"));
|
||||
QVERIFY(hasItem(t.proposal, "otherFile.h"));
|
||||
@@ -931,6 +937,18 @@ void ClangCodeCompletionTest::testCompleteConstructorAndFallbackToGlobalCompleti
|
||||
QVERIFY(!hasSnippet(t.proposal, "class"));
|
||||
}
|
||||
|
||||
void ClangCodeCompletionTest::testCompleteWithDotToArrowCorrection()
|
||||
{
|
||||
// Inserting the dot for this test is important since it will send the editor
|
||||
// content to the backend and thus generate an unsaved file on the backend
|
||||
// side. The unsaved file enables us to do the dot to arrow correction.
|
||||
|
||||
ProjectLessCompletionTest t("dotToArrowCorrection.cpp",
|
||||
QStringLiteral("."));
|
||||
|
||||
QVERIFY(hasItem(t.proposal, "member"));
|
||||
}
|
||||
|
||||
void ClangCodeCompletionTest::testCompleteProjectDependingCode()
|
||||
{
|
||||
const TestDocument testDocument("completionWithProject.cpp");
|
||||
|
||||
Reference in New Issue
Block a user