Commit 609bc2a3 authored by Nikolai Kosjar's avatar Nikolai Kosjar
Browse files

Clang: Avoid needless reparse after first parse



Change-Id: Ie97818f29d1df61380cd1c22ef2598091050b10d
Reviewed-by: default avatarMarco Bubke <marco.bubke@theqtcompany.com>
parent 6deaf6b2
......@@ -83,8 +83,8 @@ public:
CXTranslationUnit translationUnit = nullptr;
CXIndex index = nullptr;
uint documentRevision = 0;
bool needsToBeReparsed = false;
bool hasNewDiagnostics = false;
bool needsToBeReparsed = false;
bool hasNewDiagnostics = true;
};
TranslationUnitData::TranslationUnitData(const Utf8String &filePath,
......
......@@ -62,10 +62,8 @@ void TranslationUnits::create(const QVector<FileContainer> &fileContainers)
{
checkIfTranslationUnitsDoesNotExists(fileContainers);
for (const FileContainer &fileContainer : fileContainers) {
for (const FileContainer &fileContainer : fileContainers)
createTranslationUnit(fileContainer);
updateTranslationUnitsWithChangedDependency(fileContainer.filePath());
}
}
void TranslationUnits::update(const QVector<FileContainer> &fileContainers)
......
......@@ -77,11 +77,18 @@ using ClangBackEnd::TranslationUnitDoesNotExistMessage;
using ClangBackEnd::ProjectPartsDoNotExistMessage;
using ClangBackEnd::UpdateTranslationUnitsForEditorMessage;
MATCHER_P3(HasDirtyTranslationUnit, filePath, projectPartId, documentRevision,
MATCHER_P5(HasDirtyTranslationUnit,
filePath,
projectPartId,
documentRevision,
isNeedingReparse,
hasNewDiagnostics,
std::string(negation ? "isn't" : "is")
+ " translation unit with file path "+ PrintToString(filePath)
+ " and project " + PrintToString(projectPartId)
+ " and document revision " + PrintToString(documentRevision)
+ " and isNeedingReparse = " + PrintToString(isNeedingReparse)
+ " and hasNewDiagnostics = " + PrintToString(hasNewDiagnostics)
)
{
auto &&translationUnits = arg.translationUnitsForTestOnly();
......@@ -89,16 +96,24 @@ MATCHER_P3(HasDirtyTranslationUnit, filePath, projectPartId, documentRevision,
auto translationUnit = translationUnits.translationUnit(filePath, projectPartId);
if (translationUnit.documentRevision() == documentRevision) {
if (translationUnit.hasNewDiagnostics()) {
if (translationUnit.isNeedingReparse())
return true;
if (translationUnit.hasNewDiagnostics() && !hasNewDiagnostics) {
*result_listener << "hasNewDiagnostics is true";
return false;
} else if (!translationUnit.hasNewDiagnostics() && hasNewDiagnostics) {
*result_listener << "hasNewDiagnostics is false";
return false;
}
if (translationUnit.isNeedingReparse() && !isNeedingReparse) {
*result_listener << "isNeedingReparse is true";
return false;
} else if (!translationUnit.isNeedingReparse() && isNeedingReparse) {
*result_listener << "isNeedingReparse is false";
return false;
}
*result_listener << "hasNewDiagnostics is false";
return false;
return true;
}
*result_listener << "revision number is " << PrintToString(translationUnit.documentRevision());
......@@ -406,8 +421,18 @@ TEST_F(ClangIpcServer, TicketNumberIsForwarded)
clangServer.completeCode(completeCodeMessage);
}
TEST_F(ClangIpcServer, TranslationUnitIsDirtyAfterCreation)
TEST_F(ClangIpcServer, TranslationUnitAfterCreationNeedsNoReparseAndHasNewDiagnostics)
{
ASSERT_THAT(clangServer, HasDirtyTranslationUnit(functionTestFilePath, projectPartId, 0));
ASSERT_THAT(clangServer, HasDirtyTranslationUnit(functionTestFilePath, projectPartId, 0U, false, true));
}
TEST_F(ClangIpcServer, TranslationUnitAfterUpdateNeedsReparseAndHasNewDiagnostics)
{
const auto fileContainer = FileContainer(functionTestFilePath, projectPartId,unsavedContent(unsavedTestFilePath), true, 1);
clangServer.updateTranslationUnitsForEditor({{fileContainer}});
ASSERT_THAT(clangServer, HasDirtyTranslationUnit(functionTestFilePath, projectPartId, 1U, true, true));
}
}
......@@ -194,6 +194,38 @@ TEST_F(TranslationUnit, DependedFilePaths)
Contains(Utf8StringLiteral(TESTDATA_DIR"/translationunits.h"))));
}
TEST_F(TranslationUnit, NeedsNoReparseAfterCreation)
{
translationUnit.cxTranslationUnit();
ASSERT_FALSE(translationUnit.isNeedingReparse());
}
TEST_F(TranslationUnit, HasNewDiagnosticsAfterCreation)
{
translationUnit.cxTranslationUnit();
ASSERT_TRUE(translationUnit.hasNewDiagnostics());
}
TEST_F(TranslationUnit, NeedsReparseAfterChangeOfMainFile)
{
translationUnit.cxTranslationUnit();
translationUnit.setDirtyIfDependencyIsMet(translationUnitFilePath);
ASSERT_TRUE(translationUnit.isNeedingReparse());
}
TEST_F(TranslationUnit, HasNewDiagnosticsAfterChangeOfMainFile)
{
translationUnit.cxTranslationUnit();
translationUnit.setDirtyIfDependencyIsMet(translationUnitFilePath);
ASSERT_TRUE(translationUnit.hasNewDiagnostics());
}
TEST_F(TranslationUnit, NoNeedForReparsingForIndependendFile)
{
translationUnit.cxTranslationUnit();
......@@ -234,6 +266,7 @@ TEST_F(TranslationUnit, NeedsNoReparsingAfterReparsing)
TEST_F(TranslationUnit, HasNoNewDiagnosticsForIndependendFile)
{
translationUnit.cxTranslationUnit();
translationUnit.diagnostics(); // Reset hasNewDiagnostics
translationUnit.setDirtyIfDependencyIsMet(Utf8StringLiteral(TESTDATA_DIR"/otherfiles.h"));
......
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