forked from qt-creator/qt-creator
Less annoying syntax checker.
This commit is contained in:
@@ -240,6 +240,9 @@ void Document::startSkippingBlocks(unsigned start)
|
||||
|
||||
void Document::stopSkippingBlocks(unsigned stop)
|
||||
{
|
||||
if (_skippedBlocks.isEmpty())
|
||||
return;
|
||||
|
||||
unsigned start = _skippedBlocks.back().begin();
|
||||
if (start > stop)
|
||||
_skippedBlocks.removeLast(); // Ignore this block, it's invalid.
|
||||
|
@@ -69,6 +69,7 @@
|
||||
#include <QtCore/QDebug>
|
||||
#include <QtCore/QMutexLocker>
|
||||
#include <QtCore/QTime>
|
||||
#include <QtCore/QTimer>
|
||||
|
||||
using namespace CppTools;
|
||||
using namespace CppTools::Internal;
|
||||
@@ -454,6 +455,12 @@ CppModelManager::CppModelManager(QObject *parent)
|
||||
ProjectExplorer::SessionManager *session = m_projectExplorer->session();
|
||||
QTC_ASSERT(session, return);
|
||||
|
||||
m_updateEditorSelectionsTimer = new QTimer(this);
|
||||
m_updateEditorSelectionsTimer->setInterval(500);
|
||||
m_updateEditorSelectionsTimer->setSingleShot(true);
|
||||
connect(m_updateEditorSelectionsTimer, SIGNAL(timeout()),
|
||||
this, SLOT(updateEditorSelections()));
|
||||
|
||||
connect(session, SIGNAL(projectAdded(ProjectExplorer::Project*)),
|
||||
this, SLOT(onProjectAdded(ProjectExplorer::Project*)));
|
||||
|
||||
@@ -717,8 +724,8 @@ void CppModelManager::onDocumentUpdated(Document::Ptr doc)
|
||||
continue;
|
||||
else if (lines.contains(m.line()))
|
||||
continue;
|
||||
else if (lines.size() == MAX_SELECTION_COUNT)
|
||||
break; // we're done.
|
||||
//else if (lines.size() == MAX_SELECTION_COUNT)
|
||||
//break; // we're done.
|
||||
|
||||
lines.insert(m.line());
|
||||
|
||||
@@ -740,12 +747,42 @@ void CppModelManager::onDocumentUpdated(Document::Ptr doc)
|
||||
sel.cursor = c;
|
||||
selections.append(sel);
|
||||
}
|
||||
ed->setExtraSelections(TextEditor::BaseTextEditor::CodeWarningsSelection, selections);
|
||||
|
||||
QList<Editor> todo;
|
||||
foreach (Editor e, todo) {
|
||||
if (e.widget != ed)
|
||||
todo.append(e);
|
||||
}
|
||||
|
||||
Editor e;
|
||||
e.widget = ed;
|
||||
e.selections = selections;
|
||||
todo.append(e);
|
||||
m_todo = todo;
|
||||
postEditorUpdate();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CppModelManager::postEditorUpdate()
|
||||
{
|
||||
m_updateEditorSelectionsTimer->start(500);
|
||||
}
|
||||
|
||||
void CppModelManager::updateEditorSelections()
|
||||
{
|
||||
foreach (Editor ed, m_todo) {
|
||||
if (! ed.widget)
|
||||
continue;
|
||||
|
||||
ed.widget->setExtraSelections(TextEditor::BaseTextEditor::CodeWarningsSelection,
|
||||
ed.selections);
|
||||
}
|
||||
|
||||
m_todo.clear();
|
||||
}
|
||||
|
||||
void CppModelManager::onProjectAdded(ProjectExplorer::Project *)
|
||||
{
|
||||
QMutexLocker locker(&mutex);
|
||||
|
@@ -41,6 +41,8 @@
|
||||
#include <QMap>
|
||||
#include <QFutureInterface>
|
||||
#include <QMutex>
|
||||
#include <QTimer>
|
||||
#include <QTextEdit>
|
||||
|
||||
namespace Core {
|
||||
class ICore;
|
||||
@@ -49,6 +51,7 @@ class IEditor;
|
||||
|
||||
namespace TextEditor {
|
||||
class ITextEditor;
|
||||
class BaseTextEditor;
|
||||
}
|
||||
|
||||
namespace ProjectExplorer {
|
||||
@@ -86,6 +89,9 @@ public:
|
||||
|
||||
void emitDocumentUpdated(CPlusPlus::Document::Ptr doc);
|
||||
|
||||
void stopEditorSelectionsUpdate()
|
||||
{ m_updateEditorSelectionsTimer->stop(); }
|
||||
|
||||
Q_SIGNALS:
|
||||
void projectPathChanged(const QString &projectPath);
|
||||
|
||||
@@ -102,6 +108,8 @@ private Q_SLOTS:
|
||||
void onAboutToRemoveProject(ProjectExplorer::Project *project);
|
||||
void onSessionUnloaded();
|
||||
void onProjectAdded(ProjectExplorer::Project *project);
|
||||
void postEditorUpdate();
|
||||
void updateEditorSelections();
|
||||
|
||||
private:
|
||||
QMap<QString, QByteArray> buildWorkingCopyList();
|
||||
@@ -163,6 +171,15 @@ private:
|
||||
enum {
|
||||
MAX_SELECTION_COUNT = 5
|
||||
};
|
||||
|
||||
struct Editor {
|
||||
QPointer<TextEditor::BaseTextEditor> widget;
|
||||
QList<QTextEdit::ExtraSelection> selections;
|
||||
};
|
||||
|
||||
QList<Editor> m_todo;
|
||||
|
||||
QTimer *m_updateEditorSelectionsTimer;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
@@ -35,6 +35,7 @@
|
||||
#include "cppmodelmanager.h"
|
||||
|
||||
#include <texteditor/itexteditor.h>
|
||||
#include <texteditor/basetexteditor.h>
|
||||
|
||||
#include <QTimer>
|
||||
|
||||
@@ -68,12 +69,14 @@ void CppEditorSupport::setTextEditor(TextEditor::ITextEditor *textEditor)
|
||||
updateDocument();
|
||||
}
|
||||
|
||||
QString CppEditorSupport::contents() const
|
||||
QString CppEditorSupport::contents()
|
||||
{
|
||||
if (! _textEditor)
|
||||
return QString();
|
||||
else if (! _cachedContents.isEmpty())
|
||||
_cachedContents = _textEditor->contents();
|
||||
|
||||
return _textEditor->contents();
|
||||
return _cachedContents;
|
||||
}
|
||||
|
||||
int CppEditorSupport::updateDocumentInterval() const
|
||||
@@ -83,7 +86,20 @@ void CppEditorSupport::setUpdateDocumentInterval(int updateDocumentInterval)
|
||||
{ _updateDocumentInterval = updateDocumentInterval; }
|
||||
|
||||
void CppEditorSupport::updateDocument()
|
||||
{ _updateDocumentTimer->start(_updateDocumentInterval); }
|
||||
{
|
||||
if (TextEditor::BaseTextEditor *edit = qobject_cast<TextEditor::BaseTextEditor*>(_textEditor->widget())) {
|
||||
const QList<QTextEdit::ExtraSelection> selections =
|
||||
edit->extraSelections(TextEditor::BaseTextEditor::CodeWarningsSelection);
|
||||
|
||||
if (! selections.isEmpty())
|
||||
edit->setExtraSelections(TextEditor::BaseTextEditor::CodeWarningsSelection,
|
||||
QList<QTextEdit::ExtraSelection>());
|
||||
|
||||
_modelManager->stopEditorSelectionsUpdate();
|
||||
}
|
||||
|
||||
_updateDocumentTimer->start(_updateDocumentInterval);
|
||||
}
|
||||
|
||||
void CppEditorSupport::updateDocumentNow()
|
||||
{
|
||||
@@ -91,7 +107,9 @@ void CppEditorSupport::updateDocumentNow()
|
||||
_updateDocumentTimer->start(_updateDocumentInterval);
|
||||
} else {
|
||||
_updateDocumentTimer->stop();
|
||||
|
||||
QStringList sourceFiles(_textEditor->file()->fileName());
|
||||
_cachedContents = _textEditor->contents();
|
||||
_documentParser = _modelManager->refreshSourceFiles(sourceFiles);
|
||||
}
|
||||
}
|
||||
|
@@ -65,7 +65,7 @@ public:
|
||||
int updateDocumentInterval() const;
|
||||
void setUpdateDocumentInterval(int updateDocumentInterval);
|
||||
|
||||
QString contents() const;
|
||||
QString contents();
|
||||
|
||||
private Q_SLOTS:
|
||||
void updateDocument();
|
||||
@@ -79,6 +79,7 @@ private:
|
||||
QTimer *_updateDocumentTimer;
|
||||
int _updateDocumentInterval;
|
||||
QFuture<void> _documentParser;
|
||||
QString _cachedContents;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
Reference in New Issue
Block a user