Commit 14b27183 authored by Nikolai Kosjar's avatar Nikolai Kosjar
Browse files

Clang: Rename TranslationUnit(s) to Document(s)



The "TranslationUnit parts" moved already to TranslationUnitCore.

Change-Id: I2bea7847e2b3e84fbfacc3d2dc43f180873349ac
Reviewed-by: David Schulz's avatarDavid Schulz <david.schulz@qt.io>
parent 6a2e1194
......@@ -10,7 +10,7 @@ HEADERS += $$PWD/clangcodemodelserver.h \
$$PWD/unsavedfile.h \
$$PWD/unsavedfiles.h \
$$PWD/projects.h \
$$PWD/translationunits.h \
$$PWD/clangdocuments.h \
$$PWD/translationunitparseerrorexception.h \
$$PWD/translationunitreparseerrorexception.h \
$$PWD/projectpart.h \
......@@ -29,7 +29,7 @@ HEADERS += $$PWD/clangcodemodelserver.h \
$$PWD/commandlinearguments.h \
$$PWD/cursor.h \
$$PWD/skippedsourceranges.h \
$$PWD/clangtranslationunit.h \
$$PWD/clangdocument.h \
$$PWD/clangtranslationunitupdater.h \
$$PWD/clangtype.h \
$$PWD/highlightingmark.h \
......@@ -60,7 +60,7 @@ SOURCES += $$PWD/clangcodemodelserver.cpp \
$$PWD/unsavedfile.cpp \
$$PWD/unsavedfiles.cpp \
$$PWD/projects.cpp \
$$PWD/translationunits.cpp \
$$PWD/clangdocuments.cpp \
$$PWD/translationunitparseerrorexception.cpp \
$$PWD/translationunitreparseerrorexception.cpp \
$$PWD/projectpart.cpp \
......@@ -78,7 +78,7 @@ SOURCES += $$PWD/clangcodemodelserver.cpp \
$$PWD/commandlinearguments.cpp \
$$PWD/cursor.cpp \
$$PWD/skippedsourceranges.cpp \
$$PWD/clangtranslationunit.cpp \
$$PWD/clangdocument.cpp \
$$PWD/clangtranslationunitupdater.cpp \
$$PWD/clangtype.cpp \
$$PWD/highlightingmark.cpp \
......
......@@ -25,6 +25,7 @@
#include "clangcodemodelserver.h"
#include "clangdocuments.h"
#include "clangfilesystemwatcher.h"
#include "codecompleter.h"
#include "diagnosticset.h"
......@@ -35,7 +36,6 @@
#include "translationunitfilenotexitexception.h"
#include "translationunitisnullexception.h"
#include "translationunitparseerrorexception.h"
#include "translationunits.h"
#include <clangbackendipcdebugutils.h>
#include <cmbcodecompletedmessage.h>
......@@ -85,7 +85,7 @@ int delayedDocumentAnnotationsTimerInterval()
} // anonymous
ClangCodeModelServer::ClangCodeModelServer()
: translationUnits(projects, unsavedFiles)
: documents(projects, unsavedFiles)
, updateDocumentAnnotationsTimeOutInMs(delayedDocumentAnnotationsTimerInterval())
{
updateDocumentAnnotationsTimer.setSingleShot(true);
......@@ -96,7 +96,7 @@ ClangCodeModelServer::ClangCodeModelServer()
processJobsForDirtyAndVisibleDocuments();
});
QObject::connect(translationUnits.clangFileSystemWatcher(),
QObject::connect(documents.clangFileSystemWatcher(),
&ClangFileSystemWatcher::fileChanged,
[this](const Utf8String &filePath) {
ClangCodeModelServer::startDocumentAnnotationsTimerIfFileIsNotATranslationUnit(filePath);
......@@ -113,10 +113,10 @@ void ClangCodeModelServer::registerTranslationUnitsForEditor(const ClangBackEnd:
TIME_SCOPE_DURATION("ClangCodeModelServer::registerTranslationUnitsForEditor");
try {
auto createdTranslationUnits = translationUnits.create(message.fileContainers());
auto createdTranslationUnits = documents.create(message.fileContainers());
unsavedFiles.createOrUpdate(message.fileContainers());
translationUnits.setUsedByCurrentEditor(message.currentEditorFilePath());
translationUnits.setVisibleInEditors(message.visibleEditorFilePaths());
documents.setUsedByCurrentEditor(message.currentEditorFilePath());
documents.setVisibleInEditors(message.visibleEditorFilePaths());
processInitialJobsForDocuments(createdTranslationUnits);
} catch (const ProjectPartDoNotExistException &exception) {
......@@ -131,9 +131,9 @@ void ClangCodeModelServer::updateTranslationUnitsForEditor(const UpdateTranslati
TIME_SCOPE_DURATION("ClangCodeModelServer::updateTranslationUnitsForEditor");
try {
const auto newerFileContainers = translationUnits.newerFileContainers(message.fileContainers());
const auto newerFileContainers = documents.newerFileContainers(message.fileContainers());
if (newerFileContainers.size() > 0) {
translationUnits.update(newerFileContainers);
documents.update(newerFileContainers);
unsavedFiles.createOrUpdate(newerFileContainers);
updateDocumentAnnotationsTimer.start(updateDocumentAnnotationsTimeOutInMs);
......@@ -152,7 +152,7 @@ void ClangCodeModelServer::unregisterTranslationUnitsForEditor(const ClangBackEn
TIME_SCOPE_DURATION("ClangCodeModelServer::unregisterTranslationUnitsForEditor");
try {
translationUnits.remove(message.fileContainers());
documents.remove(message.fileContainers());
unsavedFiles.remove(message.fileContainers());
} catch (const TranslationUnitDoesNotExistException &exception) {
client()->translationUnitDoesNotExist(TranslationUnitDoesNotExistMessage(exception.fileContainer()));
......@@ -169,7 +169,7 @@ void ClangCodeModelServer::registerProjectPartsForEditor(const RegisterProjectPa
try {
projects.createOrUpdate(message.projectContainers());
translationUnits.setTranslationUnitsDirtyIfProjectPartChanged();
documents.setDocumentsDirtyIfProjectPartChanged();
processJobsForDirtyAndVisibleDocuments();
} catch (const std::exception &exception) {
......@@ -196,7 +196,7 @@ void ClangCodeModelServer::registerUnsavedFilesForEditor(const RegisterUnsavedFi
try {
unsavedFiles.createOrUpdate(message.fileContainers());
translationUnits.updateTranslationUnitsWithChangedDependencies(message.fileContainers());
documents.updateDocumentsWithChangedDependencies(message.fileContainers());
updateDocumentAnnotationsTimer.start(updateDocumentAnnotationsTimeOutInMs);
} catch (const ProjectPartDoNotExistException &exception) {
......@@ -212,7 +212,7 @@ void ClangCodeModelServer::unregisterUnsavedFilesForEditor(const UnregisterUnsav
try {
unsavedFiles.remove(message.fileContainers());
translationUnits.updateTranslationUnitsWithChangedDependencies(message.fileContainers());
documents.updateDocumentsWithChangedDependencies(message.fileContainers());
} catch (const TranslationUnitDoesNotExistException &exception) {
client()->translationUnitDoesNotExist(TranslationUnitDoesNotExistMessage(exception.fileContainer()));
} catch (const ProjectPartDoNotExistException &exception) {
......@@ -227,10 +227,9 @@ void ClangCodeModelServer::completeCode(const ClangBackEnd::CompleteCodeMessage
TIME_SCOPE_DURATION("ClangCodeModelServer::completeCode");
try {
auto translationUnit = translationUnits.translationUnit(message.filePath(),
message.projectPartId());
auto document = documents.document(message.filePath(), message.projectPartId());
JobRequest jobRequest = createJobRequest(translationUnit, JobRequest::Type::CompleteCode);
JobRequest jobRequest = createJobRequest(document, JobRequest::Type::CompleteCode);
jobRequest.line = message.line();
jobRequest.column = message.column();
jobRequest.ticketNumber = message.ticketNumber();
......@@ -251,10 +250,10 @@ void ClangCodeModelServer::requestDocumentAnnotations(const RequestDocumentAnnot
TIME_SCOPE_DURATION("ClangCodeModelServer::requestDocumentAnnotations");
try {
auto translationUnit = translationUnits.translationUnit(message.fileContainer().filePath(),
message.fileContainer().projectPartId());
auto document = documents.document(message.fileContainer().filePath(),
message.fileContainer().projectPartId());
const JobRequest jobRequest = createJobRequest(translationUnit,
const JobRequest jobRequest = createJobRequest(document,
JobRequest::Type::RequestDocumentAnnotations);
jobs().add(jobRequest);
......@@ -273,22 +272,22 @@ void ClangCodeModelServer::updateVisibleTranslationUnits(const UpdateVisibleTran
TIME_SCOPE_DURATION("ClangCodeModelServer::updateVisibleTranslationUnits");
try {
translationUnits.setUsedByCurrentEditor(message.currentEditorFilePath());
translationUnits.setVisibleInEditors(message.visibleEditorFilePaths());
documents.setUsedByCurrentEditor(message.currentEditorFilePath());
documents.setVisibleInEditors(message.visibleEditorFilePaths());
updateDocumentAnnotationsTimer.start(0);
} catch (const std::exception &exception) {
qWarning() << "Error in ClangCodeModelServer::updateVisibleTranslationUnits:" << exception.what();
}
}
const TranslationUnits &ClangCodeModelServer::translationUnitsForTestOnly() const
const Documents &ClangCodeModelServer::documentsForTestOnly() const
{
return translationUnits;
return documents;
}
void ClangCodeModelServer::startDocumentAnnotationsTimerIfFileIsNotATranslationUnit(const Utf8String &filePath)
{
if (!translationUnits.hasTranslationUnitWithFilePath(filePath))
if (!documents.hasDocumentWithFilePath(filePath))
updateDocumentAnnotationsTimer.start(0);
}
......@@ -304,11 +303,9 @@ bool ClangCodeModelServer::isTimerRunningForTestOnly() const
void ClangCodeModelServer::addJobRequestsForDirtyAndVisibleDocuments()
{
for (const auto &translationUnit : translationUnits.translationUnits()) {
if (translationUnit.isNeedingReparse() && translationUnit.isVisibleInEditor()) {
jobs().add(createJobRequest(translationUnit,
JobRequest::Type::UpdateDocumentAnnotations));
}
for (const auto &document : documents.documents()) {
if (document.isNeedingReparse() && document.isVisibleInEditor())
jobs().add(createJobRequest(document, JobRequest::Type::UpdateDocumentAnnotations));
}
}
......@@ -318,30 +315,27 @@ void ClangCodeModelServer::processJobsForDirtyAndVisibleDocuments()
jobs().process();
}
void ClangCodeModelServer::processInitialJobsForDocuments(
const std::vector<TranslationUnit> &translationUnits)
void ClangCodeModelServer::processInitialJobsForDocuments(const std::vector<Document> &documents)
{
for (const auto &translationUnit : translationUnits) {
jobs().add(createJobRequest(translationUnit,
JobRequest::Type::UpdateDocumentAnnotations));
jobs().add(createJobRequest(translationUnit,
JobRequest::Type::CreateInitialDocumentPreamble));
for (const auto &document : documents) {
jobs().add(createJobRequest(document, JobRequest::Type::UpdateDocumentAnnotations));
jobs().add(createJobRequest(document, JobRequest::Type::CreateInitialDocumentPreamble));
}
jobs().process();
}
JobRequest ClangCodeModelServer::createJobRequest(const TranslationUnit &translationUnit,
JobRequest ClangCodeModelServer::createJobRequest(const Document &document,
JobRequest::Type type) const
{
JobRequest jobRequest;
jobRequest.type = type;
jobRequest.requirements = JobRequest::requirementsForType(type);
jobRequest.filePath = translationUnit.filePath();
jobRequest.projectPartId = translationUnit.projectPartId();
jobRequest.filePath = document.filePath();
jobRequest.projectPartId = document.projectPartId();
jobRequest.unsavedFilesChangeTimePoint = unsavedFiles.lastChangeTimePoint();
jobRequest.documentRevision = translationUnit.documentRevision();
const ProjectPart &projectPart = projects.project(translationUnit.projectPartId());
jobRequest.documentRevision = document.documentRevision();
const ProjectPart &projectPart = projects.project(document.projectPartId());
jobRequest.projectChangeTimePoint = projectPart.lastChangeTimePoint();
return jobRequest;
......@@ -358,7 +352,7 @@ Jobs &ClangCodeModelServer::jobs()
// Jobs needs a reference to the client, but the client is not known at
// construction time of ClangCodeModelServer, so construct Jobs in a
// lazy manner.
jobs_.reset(new Jobs(translationUnits, unsavedFiles, projects, *client()));
jobs_.reset(new Jobs(documents, unsavedFiles, projects, *client()));
}
return *jobs_.data();
......
......@@ -29,8 +29,8 @@
#include "projectpart.h"
#include "projects.h"
#include "clangtranslationunit.h"
#include "translationunits.h"
#include "clangdocument.h"
#include "clangdocuments.h"
#include "unsavedfiles.h"
#include "clangjobs.h"
......@@ -59,7 +59,7 @@ public:
void requestDocumentAnnotations(const RequestDocumentAnnotationsMessage &message) override;
public /*for tests*/:
const TranslationUnits &translationUnitsForTestOnly() const;
const Documents &documentsForTestOnly() const;
const Jobs &jobsForTestOnly();
bool isTimerRunningForTestOnly() const;
void setUpdateDocumentAnnotationsTimeOutInMsForTestsOnly(int value);
......@@ -70,15 +70,14 @@ private:
void startDocumentAnnotationsTimerIfFileIsNotATranslationUnit(const Utf8String &filePath);
void addJobRequestsForDirtyAndVisibleDocuments();
void processJobsForDirtyAndVisibleDocuments();
void processInitialJobsForDocuments(const std::vector<TranslationUnit> &translationUnits);
void processInitialJobsForDocuments(const std::vector<Document> &documents);
JobRequest createJobRequest(const TranslationUnit &translationUnit,
JobRequest::Type type) const;
JobRequest createJobRequest(const Document &document, JobRequest::Type type) const;
private:
ProjectParts projects;
UnsavedFiles unsavedFiles;
TranslationUnits translationUnits;
Documents documents;
QScopedPointer<Jobs> jobs_;
QTimer updateDocumentAnnotationsTimer;
......
......@@ -61,9 +61,9 @@ bool CompleteCodeJob::prepareAsyncRun()
QTC_ASSERT(jobRequest.type == JobRequest::Type::CompleteCode, return false);
try {
m_pinnedTranslationUnit = context().translationUnitForJobRequest();
m_pinnedDocument = context().documentForJobRequest();
const TranslationUnitCore translationUnitCore = m_pinnedTranslationUnit.translationUnitCore();
const TranslationUnitCore translationUnitCore = m_pinnedDocument.translationUnitCore();
const UnsavedFiles unsavedFiles = *context().unsavedFiles;
const quint32 line = jobRequest.line;
const quint32 column = jobRequest.column;
......
......@@ -26,7 +26,7 @@
#pragma once
#include "clangasyncjob.h"
#include "clangtranslationunit.h"
#include "clangdocument.h"
#include <clangbackendipc/codecompletion.h>
......@@ -47,7 +47,7 @@ public:
void finalizeAsyncRun() override;
private:
TranslationUnit m_pinnedTranslationUnit;
Document m_pinnedDocument;
};
} // namespace ClangBackEnd
......@@ -49,11 +49,11 @@ bool CreateInitialDocumentPreambleJob::prepareAsyncRun()
QTC_ASSERT(jobRequest.type == JobRequest::Type::CreateInitialDocumentPreamble, return false);
try {
m_pinnedTranslationUnit = context().translationUnitForJobRequest();
m_pinnedFileContainer = m_pinnedTranslationUnit.fileContainer();
m_pinnedDocument = context().documentForJobRequest();
m_pinnedFileContainer = m_pinnedDocument.fileContainer();
const TranslationUnitCore translationUnitCore = m_pinnedTranslationUnit.translationUnitCore();
const TranslationUnitUpdateInput updateInput = m_pinnedTranslationUnit.createUpdateInput();
const TranslationUnitCore translationUnitCore = m_pinnedDocument.translationUnitCore();
const TranslationUnitUpdateInput updateInput = m_pinnedDocument.createUpdateInput();
setRunner([translationUnitCore, updateInput]() {
return runAsyncHelper(translationUnitCore, updateInput);
});
......
......@@ -26,7 +26,7 @@
#pragma once
#include "clangasyncjob.h"
#include "clangtranslationunit.h"
#include "clangdocument.h"
namespace ClangBackEnd {
......@@ -37,7 +37,7 @@ public:
void finalizeAsyncRun() override;
private:
TranslationUnit m_pinnedTranslationUnit;
Document m_pinnedDocument;
FileContainer m_pinnedFileContainer;
};
......
......@@ -23,8 +23,9 @@
**
****************************************************************************/
#include "clangtranslationunit.h"
#include "clangdocument.h"
#include "clangdocuments.h"
#include "clangstring.h"
#include "clangunsavedfilesshallowarguments.h"
#include "codecompleter.h"
......@@ -35,7 +36,6 @@
#include "translationunitreparseerrorexception.h"
#include "clangtranslationunitcore.h"
#include "clangtranslationunitupdater.h"
#include "translationunits.h"
#include "unsavedfiles.h"
#include "unsavedfile.h"
......@@ -49,17 +49,17 @@
namespace ClangBackEnd {
class TranslationUnitData
class DocumentData
{
public:
TranslationUnitData(const Utf8String &filePath,
const ProjectPart &projectPart,
const Utf8StringVector &fileArguments,
TranslationUnits &translationUnits);
~TranslationUnitData();
DocumentData(const Utf8String &filePath,
const ProjectPart &projectPart,
const Utf8StringVector &fileArguments,
Documents &documents);
~DocumentData();
public:
TranslationUnits &translationUnits;
Documents &documents;
const Utf8String filePath;
const Utf8StringVector fileArguments;
......@@ -80,11 +80,11 @@ public:
bool isVisibleInEditor = false;
};
TranslationUnitData::TranslationUnitData(const Utf8String &filePath,
const ProjectPart &projectPart,
const Utf8StringVector &fileArguments,
TranslationUnits &translationUnits)
: translationUnits(translationUnits),
DocumentData::DocumentData(const Utf8String &filePath,
const ProjectPart &projectPart,
const Utf8StringVector &fileArguments,
Documents &documents)
: documents(documents),
filePath(filePath),
fileArguments(fileArguments),
projectPart(projectPart),
......@@ -94,74 +94,74 @@ TranslationUnitData::TranslationUnitData(const Utf8String &filePath,
dependedFilePaths.insert(filePath);
}
TranslationUnitData::~TranslationUnitData()
DocumentData::~DocumentData()
{
clang_disposeTranslationUnit(translationUnit);
clang_disposeIndex(index);
}
TranslationUnit::TranslationUnit(const Utf8String &filePath,
const ProjectPart &projectPart,
const Utf8StringVector &fileArguments,
TranslationUnits &translationUnits,
FileExistsCheck fileExistsCheck)
: d(std::make_shared<TranslationUnitData>(filePath,
projectPart,
fileArguments,
translationUnits))
Document::Document(const Utf8String &filePath,
const ProjectPart &projectPart,
const Utf8StringVector &fileArguments,
Documents &documents,
FileExistsCheck fileExistsCheck)
: d(std::make_shared<DocumentData>(filePath,
projectPart,
fileArguments,
documents))
{
if (fileExistsCheck == CheckIfFileExists)
checkIfFileExists();
}
TranslationUnit::~TranslationUnit() = default;
TranslationUnit::TranslationUnit(const TranslationUnit &) = default;
TranslationUnit &TranslationUnit::operator=(const TranslationUnit &) = default;
Document::~Document() = default;
Document::Document(const Document &) = default;
Document &Document::operator=(const Document &) = default;
TranslationUnit::TranslationUnit(TranslationUnit &&other)
Document::Document(Document &&other)
: d(std::move(other.d))
{
}
TranslationUnit &TranslationUnit::operator=(TranslationUnit &&other)
Document &Document::operator=(Document &&other)
{
d = std::move(other.d);
return *this;
}
void TranslationUnit::reset()
void Document::reset()
{
d.reset();
}
bool TranslationUnit::isNull() const
bool Document::isNull() const
{
return !d;
}
bool TranslationUnit::isIntact() const
bool Document::isIntact() const
{
return !isNull()
&& fileExists()
&& !d->hasParseOrReparseFailed;
}
Utf8String TranslationUnit::filePath() const
Utf8String Document::filePath() const
{
checkIfNull();
return d->filePath;
}
Utf8StringVector TranslationUnit::fileArguments() const
Utf8StringVector Document::fileArguments() const
{
checkIfNull();
return d->fileArguments;
}
FileContainer TranslationUnit::fileContainer() const
FileContainer Document::fileContainer() const
{
checkIfNull();
......@@ -172,103 +172,103 @@ FileContainer TranslationUnit::fileContainer() const
d->documentRevision);
}
Utf8String TranslationUnit::projectPartId() const
Utf8String Document::projectPartId() const
{
checkIfNull();
return d->projectPart.projectPartId();
}
const ProjectPart &TranslationUnit::projectPart() const
const ProjectPart &Document::projectPart() const
{
checkIfNull();
return d->projectPart;
}
const time_point TranslationUnit::lastProjectPartChangeTimePoint() const
const time_point Document::lastProjectPartChangeTimePoint() const
{
checkIfNull();
return d->lastProjectPartChangeTimePoint;
}
bool TranslationUnit::isProjectPartOutdated() const
bool Document::isProjectPartOutdated() const
{
checkIfNull();
return d->projectPart.lastChangeTimePoint() >= d->lastProjectPartChangeTimePoint;
}
uint TranslationUnit::documentRevision() const
uint Document::documentRevision() const
{
checkIfNull();
return d->documentRevision;
}
void TranslationUnit::setDocumentRevision(uint revision)
void Document::setDocumentRevision(uint revision)
{
checkIfNull();
d->documentRevision = revision;
}
bool TranslationUnit::isUsedByCurrentEditor() const
bool Document::isUsedByCurrentEditor() const
{
checkIfNull();
return d->isUsedByCurrentEditor;
}
void TranslationUnit::setIsUsedByCurrentEditor(bool isUsedByCurrentEditor)
void Document::setIsUsedByCurrentEditor(bool isUsedByCurrentEditor)
{
checkIfNull();
d->isUsedByCurrentEditor = isUsedByCurrentEditor;
}
bool TranslationUnit::isVisibleInEditor() const
bool Document::isVisibleInEditor() const
{
checkIfNull();
return d->isVisibleInEditor;
}
void TranslationUnit::setIsVisibleInEditor(bool isVisibleInEditor)
void Document::setIsVisibleInEditor(bool isVisibleInEditor)
{
checkIfNull();
d->isVisibleInEditor = isVisibleInEditor;
}
time_point TranslationUnit::isNeededReparseChangeTimePoint() const
time_point Document::isNeededReparseChangeTimePoint() const
{
checkIfNull();