Commit 283ddb8d authored by Marco Bubke's avatar Marco Bubke

Clang: Use timer in ClangIpcServer in the file watcher to send diagnostics

One mechanism for all diagnostic updates is better to maintain.

Change-Id: I774577bfa343162ded362977a0727a12379d1eab
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@theqtcompany.com>
parent 0267f286
......@@ -59,14 +59,6 @@ ClangFileSystemWatcher::ClangFileSystemWatcher(TranslationUnits &translationUnit
&QFileSystemWatcher::fileChanged,
this,
&ClangFileSystemWatcher::updateTranslationUnitsWithChangedDependencies);
connect(&changedDiagnosticsTimer,
&QTimer::timeout,
this,
&ClangFileSystemWatcher::sendChangedDiagnostics);
changedDiagnosticsTimer.setSingleShot(true);
changedDiagnosticsTimer.setInterval(100);
}
void ClangFileSystemWatcher::addFiles(const QSet<Utf8String> &filePaths)
......@@ -77,13 +69,9 @@ void ClangFileSystemWatcher::addFiles(const QSet<Utf8String> &filePaths)
void ClangFileSystemWatcher::updateTranslationUnitsWithChangedDependencies(const QString &filePath)
{
translationUnits.updateTranslationUnitsWithChangedDependencies(filePath);
changedDiagnosticsTimer.start();
watcher.addPath(filePath);
}
void ClangFileSystemWatcher::sendChangedDiagnostics()
{
translationUnits.sendChangedDiagnostics();
emit fileChanged();
}
} // namespace ClangBackEnd
......@@ -33,7 +33,6 @@
#include <QFileSystemWatcher>
#include <QSet>
#include <QTimer>
class Utf8String;
......@@ -50,13 +49,14 @@ public:
void addFiles(const QSet<Utf8String> &filePaths);
signals:
void fileChanged();
private:
void updateTranslationUnitsWithChangedDependencies(const QString &filePath);
void sendChangedDiagnostics();
private:
QFileSystemWatcher watcher;
QTimer changedDiagnosticsTimer;
TranslationUnits &translationUnits;
};
......
......@@ -69,6 +69,10 @@ ClangIpcServer::ClangIpcServer()
QObject::connect(&sendDiagnosticsTimer,
&QTimer::timeout,
[this] () { translationUnits.sendChangedDiagnostics(); });
QObject::connect(translationUnits.clangFileSystemWatcher(),
&ClangFileSystemWatcher::fileChanged,
[this] () { sendDiagnosticsTimer.start(); });
}
void ClangIpcServer::end()
......
......@@ -42,6 +42,7 @@
#include <utf8string.h>
#include <QMap>
#include <QTimer>
namespace ClangBackEnd {
......
......@@ -166,6 +166,11 @@ QVector<FileContainer> TranslationUnits::newerFileContainers(const QVector<FileC
return newerContainers;
}
const ClangFileSystemWatcher *TranslationUnits::clangFileSystemWatcher() const
{
return &fileSystemWatcher;
}
void TranslationUnits::createOrUpdateTranslationUnit(const FileContainer &fileContainer)
{
TranslationUnit::FileExistsCheck checkIfFileExists = fileContainer.hasUnsavedFileContent() ? TranslationUnit::DoNotCheckIfFileExists : TranslationUnit::CheckIfFileExists;
......
......@@ -71,6 +71,8 @@ public:
QVector<FileContainer> newerFileContainers(const QVector<FileContainer> &fileContainers) const;
const ClangFileSystemWatcher *clangFileSystemWatcher() const;
private:
void createOrUpdateTranslationUnit(const FileContainer &fileContainer);
std::vector<TranslationUnit>::iterator findTranslationUnit(const FileContainer &fileContainer);
......
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