Clang: Improve diagnostic update timer

Start the timer after a translation unit change and stop after every
diagnostic is sent. We should decrease the interval as we are
sending the diagnostics because otherwise the sending is delayed to much.
If the file watcher is emitting a file change we should only react
to changes of files which have no editor open.

Change-Id: I5431b4bf6b4c0b825bfc74bb9c697bb2d198fa26
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
This commit is contained in:
Marco Bubke
2015-10-13 12:54:22 +02:00
parent 08ca3eb480
commit 0eaa9f668c
7 changed files with 64 additions and 10 deletions

View File

@@ -59,6 +59,10 @@
namespace ClangBackEnd {
namespace {
const int sendDiagnosticsTimerInterval = 300;
}
ClangIpcServer::ClangIpcServer()
: translationUnits(projects, unsavedFiles)
{
@@ -67,14 +71,26 @@ ClangIpcServer::ClangIpcServer()
client()->diagnosticsChanged(message);
});
sendDiagnosticsTimer.setInterval(300);
QObject::connect(&sendDiagnosticsTimer,
&QTimer::timeout,
[this] () { translationUnits.sendChangedDiagnostics(); });
[this] () {
try {
auto diagnostSendState = translationUnits.sendChangedDiagnostics();
if (diagnostSendState == DiagnosticSendState::MaybeThereAreMoreDiagnostics)
sendDiagnosticsTimer.setInterval(0);
else
sendDiagnosticsTimer.stop();
} catch (const std::exception &exception) {
qWarning() << "Error in ClangIpcServer::sendDiagnosticsTimer:" << exception.what();
}
});
QObject::connect(translationUnits.clangFileSystemWatcher(),
&ClangFileSystemWatcher::fileChanged,
[this] () { sendDiagnosticsTimer.start(); });
[this] (const Utf8String &filePath)
{
startSendDiagnosticTimerIfFileIsNotATranslationUnit(filePath);
});
}
void ClangIpcServer::end()
@@ -91,7 +107,7 @@ void ClangIpcServer::registerTranslationUnitsForEditor(const ClangBackEnd::Regis
if (newerFileContainers.size() > 0) {
unsavedFiles.createOrUpdate(newerFileContainers);
translationUnits.createOrUpdate(newerFileContainers);
sendDiagnosticsTimer.start();
sendDiagnosticsTimer.start(sendDiagnosticsTimerInterval);
}
} catch (const ProjectPartDoNotExistException &exception) {
client()->projectPartsDoNotExist(ProjectPartsDoNotExistMessage(exception.projectPartIds()));
@@ -147,7 +163,7 @@ void ClangIpcServer::registerUnsavedFilesForEditor(const RegisterUnsavedFilesFor
try {
unsavedFiles.createOrUpdate(message.fileContainers());
translationUnits.updateTranslationUnitsWithChangedDependencies(message.fileContainers());
sendDiagnosticsTimer.start();
sendDiagnosticsTimer.start(sendDiagnosticsTimerInterval);
} catch (const ProjectPartDoNotExistException &exception) {
client()->projectPartsDoNotExist(ProjectPartsDoNotExistMessage(exception.projectPartIds()));
} catch (const std::exception &exception) {
@@ -209,4 +225,10 @@ void ClangIpcServer::requestDiagnostics(const RequestDiagnosticsMessage &message
}
}
void ClangIpcServer::startSendDiagnosticTimerIfFileIsNotATranslationUnit(const Utf8String &filePath)
{
if (!translationUnits.hasTranslationUnit(filePath))
sendDiagnosticsTimer.start(0);
}
}