Commit 568d7e7c authored by Marco Bubke's avatar Marco Bubke
Browse files

Revert "Clang: Reparse the translation unit for unsaved file changes"

We reparse before every code completion so this code can be removed. We
will reuse some of it later.

This reverts commit 2443f18b

.

Change-Id: Ifcadfaa09b87ce5b58bfe5fe3cbaa2a86a59c5a6
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@theqtcompany.com>
parent f11d5791
......@@ -52,8 +52,7 @@ public:
~TranslationUnitData();
public:
time_point lastProjectPartChangeTimePoint;
time_point lastUnsavedFilesChangeTimePoint;
time_point lastChangeTimePoint;
ProjectPart projectPart;
Utf8String filePath;
CXTranslationUnit translationUnit = nullptr;
......@@ -64,8 +63,7 @@ public:
TranslationUnitData::TranslationUnitData(const Utf8String &filePath,
const UnsavedFiles &unsavedFiles,
const ProjectPart &projectPart)
: lastProjectPartChangeTimePoint(std::chrono::steady_clock::now()),
lastUnsavedFilesChangeTimePoint(lastProjectPartChangeTimePoint),
: lastChangeTimePoint(std::chrono::steady_clock::now()),
projectPart(projectPart),
filePath(filePath),
unsavedFiles(unsavedFiles)
......@@ -111,9 +109,10 @@ CXIndex TranslationUnit::index() const
CXTranslationUnit TranslationUnit::cxTranslationUnit() const
{
checkIfNull();
removeTranslationUnitIfProjectPartWasChanged();
removeOutdatedTranslationUnit();
createTranslationUnitIfNeeded();
reparseTranslationUnitIfUnsavedFilesAreChanged();
return d->translationUnit;
}
......@@ -132,19 +131,9 @@ const Utf8String &TranslationUnit::projectPartId() const
return d->projectPart.projectPartId();
}
const time_point &TranslationUnit::lastProjectPartChangeTimePoint() const
{
return d->lastProjectPartChangeTimePoint;
}
const time_point &TranslationUnit::lastUnsavedFilesChangeTimePoint() const
const time_point &TranslationUnit::lastChangeTimePoint() const
{
return d->lastUnsavedFilesChangeTimePoint;
}
bool TranslationUnit::isNeedingReparse() const
{
return d->lastUnsavedFilesChangeTimePoint < d->unsavedFiles.lastChangeTimePoint();
return d->lastChangeTimePoint;
}
void TranslationUnit::checkIfNull() const
......@@ -159,29 +148,19 @@ void TranslationUnit::checkIfFileExists() const
throw TranslationUnitFileNotExitsException(d->filePath);
}
void TranslationUnit::updateLastProjectPartChangeTimePoint() const
void TranslationUnit::updateLastChangeTimePoint() const
{
d->lastProjectPartChangeTimePoint = std::chrono::steady_clock::now();
d->lastChangeTimePoint = std::chrono::steady_clock::now();
}
void TranslationUnit::updateLastUnsavedFilesChangeTimePoint() const
void TranslationUnit::removeOutdatedTranslationUnit() const
{
d->lastUnsavedFilesChangeTimePoint = std::chrono::steady_clock::now();
}
void TranslationUnit::removeTranslationUnitIfProjectPartWasChanged() const
{
if (projectPartIsOutdated()) {
if (d->projectPart.lastChangeTimePoint() >= d->lastChangeTimePoint) {
clang_disposeTranslationUnit(d->translationUnit);
d->translationUnit = nullptr;
}
}
bool TranslationUnit::projectPartIsOutdated() const
{
return d->projectPart.lastChangeTimePoint() >= d->lastProjectPartChangeTimePoint;
}
void TranslationUnit::createTranslationUnitIfNeeded() const
{
if (!d->translationUnit) {
......@@ -201,7 +180,7 @@ void TranslationUnit::createTranslationUnitIfNeeded() const
// e.g. clang_codeCompleteAt() dramatically.
reparseTranslationUnit();
updateLastProjectPartChangeTimePoint();
updateLastChangeTimePoint();
}
}
......@@ -219,14 +198,6 @@ void TranslationUnit::reparseTranslationUnit() const
d->unsavedFiles.count(),
d->unsavedFiles.cxUnsavedFiles(),
clang_defaultReparseOptions(d->translationUnit));
updateLastUnsavedFilesChangeTimePoint();
}
void TranslationUnit::reparseTranslationUnitIfUnsavedFilesAreChanged() const
{
if (isNeedingReparse())
reparseTranslationUnit();
}
int TranslationUnit::defaultOptions()
......
......@@ -82,23 +82,16 @@ public:
const Utf8String &filePath() const;
const Utf8String &projectPartId() const;
const time_point &lastProjectPartChangeTimePoint() const;
const time_point &lastUnsavedFilesChangeTimePoint() const;
bool isNeedingReparse() const;
const time_point &lastChangeTimePoint() const;
private:
void checkIfNull() const;
void checkIfFileExists() const;
void updateLastProjectPartChangeTimePoint() const;
void updateLastUnsavedFilesChangeTimePoint() const;
void removeTranslationUnitIfProjectPartWasChanged() const;
bool projectPartIsOutdated() const;
void updateLastChangeTimePoint() const;
void removeOutdatedTranslationUnit() const;
void createTranslationUnitIfNeeded() const;
void checkTranslationUnitErrorCode(CXErrorCode errorCode) const;
void reparseTranslationUnit() const;
void reparseTranslationUnitIfUnsavedFilesAreChanged() const;
void printIncludes() const;
static int defaultOptions();
private:
......
......@@ -132,75 +132,15 @@ TEST(TranslationUnit, ResetedTranslationUnitIsNull)
ASSERT_TRUE(translationUnit.isNull());
}
TEST(TranslationUnit, TimeStampForProjectPartChangeIsUpdatedAsNewCxTranslationUnitIsGenerated)
TEST(TranslationUnit, TimeStampIsUpdatedAsNewCxTranslationUnitIsGenerated)
{
TranslationUnit translationUnit(Utf8StringLiteral(TESTDATA_DIR"/complete_testfile_1.cpp"), UnsavedFiles(), ProjectPart(Utf8StringLiteral("/path/to/projectfile")));
auto lastChangeTimePoint = translationUnit.lastProjectPartChangeTimePoint();
auto lastChangeTimePoint = translationUnit.lastChangeTimePoint();
std::this_thread::sleep_for(std::chrono::steady_clock::duration(1));
translationUnit.cxTranslationUnit();
ASSERT_THAT(translationUnit.lastProjectPartChangeTimePoint(), Gt(lastChangeTimePoint));
}
TEST(TranslationUnit, TimeStampForProjectPartChangeIsUpdatedAsProjectPartIsCleared)
{
ProjectPart projectPart(Utf8StringLiteral("/path/to/projectfile"));
TranslationUnit translationUnit(Utf8StringLiteral(TESTDATA_DIR"/complete_testfile_1.cpp"), UnsavedFiles(), projectPart);
translationUnit.cxTranslationUnit();
auto lastChangeTimePoint = translationUnit.lastProjectPartChangeTimePoint();
std::this_thread::sleep_for(std::chrono::steady_clock::duration(1));
projectPart.clear();
translationUnit.cxTranslationUnit();
ASSERT_THAT(translationUnit.lastProjectPartChangeTimePoint(), Gt(lastChangeTimePoint));
}
TEST(TranslationUnit, ReparseIsNeededAfterUnsavedFilesAreChanged)
{
UnsavedFiles unsavedFiles;
TranslationUnit translationUnit(Utf8StringLiteral(TESTDATA_DIR"/complete_testfile_1.cpp"),
unsavedFiles,
ProjectPart(Utf8StringLiteral("/path/to/projectfile")));
translationUnit.cxTranslationUnit();
unsavedFiles.clear();
translationUnit.cxTranslationUnit();
unsavedFiles.clear();
ASSERT_TRUE(translationUnit.isNeedingReparse());
}
TEST(TranslationUnit, NeedsNoReparseAfterUnsavedFilesAreNotChanged)
{
UnsavedFiles unsavedFiles;
TranslationUnit translationUnit(Utf8StringLiteral(TESTDATA_DIR"/complete_testfile_1.cpp"),
unsavedFiles,
ProjectPart(Utf8StringLiteral("/path/to/projectfile")));
translationUnit.cxTranslationUnit();
unsavedFiles.clear();
translationUnit.cxTranslationUnit();
ASSERT_FALSE(translationUnit.isNeedingReparse());
}
TEST(TranslationUnit, TimeStampForUnsavedFilesChange)
{
UnsavedFiles unsavedFiles;
TranslationUnit translationUnit(Utf8StringLiteral(TESTDATA_DIR"/complete_testfile_1.cpp"),
unsavedFiles,
ProjectPart(Utf8StringLiteral("/path/to/projectfile")));
translationUnit.cxTranslationUnit();
unsavedFiles.clear();
translationUnit.cxTranslationUnit();
auto lastChangeTimePoint = translationUnit.lastUnsavedFilesChangeTimePoint();
std::this_thread::sleep_for(std::chrono::steady_clock::duration(1));
unsavedFiles.clear();
translationUnit.cxTranslationUnit();
ASSERT_THAT(translationUnit.lastUnsavedFilesChangeTimePoint(), Gt(lastChangeTimePoint));
ASSERT_THAT(translationUnit.lastChangeTimePoint(), Gt(lastChangeTimePoint));
}
......
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