forked from qt-creator/qt-creator
Clang: Fix dot-arrow-correction for not-yet-parsed unsaved content
The issue was re-producible with e.g.:
void g()
{
// Type 'foo.' as fast as possible in the next line
}
This led to "foo->" with completion results as if there was no "foo." at
all in that line.
We relied on a correct position for
translationUnit.sourceLocationAtWithoutReparsing(), but the just typed
characters were not yet reparsed. And we do not want to reparse at that
point since takes too long. We already determine the utf8 position for
the dot character, so simply use that instead.
This completes commit 17c1325cc4.
Change-Id: I669888b5c17ee63b2aec7b16c9921f9d79e281f9
Reviewed-by: David Schulz <david.schulz@theqtcompany.com>
This commit is contained in:
@@ -112,6 +112,19 @@ protected:
|
||||
readFileContent(QStringLiteral("/complete_withDotArrowCorrectionForPointer.cpp")),
|
||||
true
|
||||
};
|
||||
ClangBackEnd::FileContainer dotArrowCorrectionForPointerFileContainerBeforeTyping{
|
||||
Utf8StringLiteral(TESTDATA_DIR"/complete_withDotArrowCorrectionForPointer.cpp"),
|
||||
projectPart.projectPartId(),
|
||||
readFileContent(QStringLiteral("/complete_withDotArrowCorrectionForPointer_beforeTyping.cpp")),
|
||||
true
|
||||
};
|
||||
ClangBackEnd::FileContainer dotArrowCorrectionForPointerFileContainerAfterTyping{
|
||||
Utf8StringLiteral(TESTDATA_DIR"/complete_withDotArrowCorrectionForPointer.cpp"),
|
||||
projectPart.projectPartId(),
|
||||
readFileContent(QStringLiteral("/complete_withDotArrowCorrectionForPointer_afterTyping.cpp")),
|
||||
true
|
||||
};
|
||||
|
||||
ClangBackEnd::FileContainer dotArrowCorrectionForPointerFileContainerInitial{
|
||||
Utf8StringLiteral(TESTDATA_DIR"/complete_withDotArrowCorrectionForPointer.cpp"),
|
||||
projectPart.projectPartId(),
|
||||
@@ -313,30 +326,6 @@ TEST_F(CodeCompleter, ArrowCompletion)
|
||||
ClangBackEnd::CompletionCorrection::NoCorrection);
|
||||
}
|
||||
|
||||
TEST_F(CodeCompleter, HasDotAt)
|
||||
{
|
||||
auto myCompleter = setupCompleter(dotArrowCorrectionForPointerFileContainer);
|
||||
|
||||
ASSERT_TRUE(myCompleter.hasDotAt(5, 8));
|
||||
}
|
||||
|
||||
TEST_F(CodeCompleter, HasDotAtWithUpdatedUnsavedFile)
|
||||
{
|
||||
auto myCompleter = setupCompleter(dotArrowCorrectionForPointerFileContainerInitial);
|
||||
unsavedFiles.createOrUpdate({dotArrowCorrectionForPointerFileContainerUpdated});
|
||||
|
||||
ASSERT_TRUE(myCompleter.hasDotAt(5, 8));
|
||||
}
|
||||
|
||||
TEST_F(CodeCompleter, HasNoDotAtDueToMissingUnsavedFile)
|
||||
{
|
||||
const ClangBackEnd::FileContainer fileContainer = dotArrowCorrectionForPointerFileContainer;
|
||||
translationUnits.create({fileContainer});
|
||||
ClangBackEnd::CodeCompleter myCompleter(translationUnits.translationUnit(fileContainer));
|
||||
|
||||
ASSERT_FALSE(myCompleter.hasDotAt(5, 8));
|
||||
}
|
||||
|
||||
TEST_F(CodeCompleter, DotToArrowCompletionForPointer)
|
||||
{
|
||||
auto myCompleter = setupCompleter(dotArrowCorrectionForPointerFileContainer);
|
||||
@@ -350,6 +339,24 @@ TEST_F(CodeCompleter, DotToArrowCompletionForPointer)
|
||||
ClangBackEnd::CompletionCorrection::DotToArrowCorrection);
|
||||
}
|
||||
|
||||
TEST_F(CodeCompleter, DotToArrowCompletionForPointerInOutdatedTranslationUnit)
|
||||
{
|
||||
auto fileContainerBeforeTyping = dotArrowCorrectionForPointerFileContainerBeforeTyping;
|
||||
auto myCompleter = setupCompleter(fileContainerBeforeTyping);
|
||||
auto translationUnit = translationUnits.translationUnit(fileContainerBeforeTyping.filePath(),
|
||||
fileContainerBeforeTyping.projectPartId());
|
||||
translationUnit.cxTranslationUnit(); // Parse
|
||||
unsavedFiles.createOrUpdate({dotArrowCorrectionForPointerFileContainerAfterTyping});
|
||||
|
||||
const ClangBackEnd::CodeCompletions completions = myCompleter.complete(5, 9);
|
||||
|
||||
ASSERT_THAT(completions,
|
||||
Contains(IsCodeCompletion(Utf8StringLiteral("member"),
|
||||
CodeCompletion::VariableCompletionKind)));
|
||||
ASSERT_THAT(myCompleter.neededCorrection(),
|
||||
ClangBackEnd::CompletionCorrection::DotToArrowCorrection);
|
||||
}
|
||||
|
||||
TEST_F(CodeCompleter, NoDotToArrowCompletionForObject)
|
||||
{
|
||||
auto myCompleter = setupCompleter(noDotArrowCorrectionForObjectFileContainer);
|
||||
|
||||
Reference in New Issue
Block a user