From e768fbf5d1be697d329e1f862c2b40ac168296fc Mon Sep 17 00:00:00 2001 From: Christian Kamm Date: Thu, 11 Aug 2011 13:52:02 +0200 Subject: [PATCH] QmlJS: Rename SemanticHighlighter -> SemanticInfoUpdater. Since it doesn't do any highlighting... Change-Id: I45d20735535fa1885153a725d0ca894326ce53db Reviewed-on: http://codereview.qt.nokia.com/2862 Reviewed-by: Fawzi Mohamed --- src/plugins/qmljseditor/qmljseditor.cpp | 48 +++++++++---------- src/plugins/qmljseditor/qmljseditor.h | 18 +++---- src/plugins/qmljseditor/qmljseditor.pro | 12 +++-- src/plugins/qmljseditor/qmljseditorplugin.cpp | 2 +- ...ghter.cpp => qmljssemanticinfoupdater.cpp} | 22 ++++----- ...ghlighter.h => qmljssemanticinfoupdater.h} | 26 +++++----- 6 files changed, 66 insertions(+), 62 deletions(-) rename src/plugins/qmljseditor/{qmljssemantichighlighter.cpp => qmljssemanticinfoupdater.cpp} (86%) rename src/plugins/qmljseditor/{qmljssemantichighlighter.h => qmljssemanticinfoupdater.h} (81%) diff --git a/src/plugins/qmljseditor/qmljseditor.cpp b/src/plugins/qmljseditor/qmljseditor.cpp index 285482d6758..103d1fc90b0 100644 --- a/src/plugins/qmljseditor/qmljseditor.cpp +++ b/src/plugins/qmljseditor/qmljseditor.cpp @@ -37,7 +37,7 @@ #include "qmljseditorplugin.h" #include "qmloutlinemodel.h" #include "qmljsfindreferences.h" -#include "qmljssemantichighlighter.h" +#include "qmljssemanticinfoupdater.h" #include "qmljsautocompleter.h" #include "qmljscompletionassist.h" #include "qmljsquickfixassist.h" @@ -661,8 +661,8 @@ QmlJSTextEditorWidget::QmlJSTextEditorWidget(QWidget *parent) : { qRegisterMetaType("QmlJSEditor::SemanticInfo"); - m_semanticHighlighter = new SemanticHighlighter(this); - m_semanticHighlighter->start(); + m_semanticInfoUpdater = new SemanticInfoUpdater(this); + m_semanticInfoUpdater->start(); setParenthesesMatchingEnabled(true); setMarksVisible(true); @@ -680,10 +680,10 @@ QmlJSTextEditorWidget::QmlJSTextEditorWidget(QWidget *parent) : m_updateUsesTimer->setSingleShot(true); connect(m_updateUsesTimer, SIGNAL(timeout()), this, SLOT(updateUsesNow())); - m_semanticRehighlightTimer = new QTimer(this); - m_semanticRehighlightTimer->setInterval(UPDATE_DOCUMENT_DEFAULT_INTERVAL); - m_semanticRehighlightTimer->setSingleShot(true); - connect(m_semanticRehighlightTimer, SIGNAL(timeout()), this, SLOT(forceSemanticRehighlightIfCurrentEditor())); + m_localReparseTimer = new QTimer(this); + m_localReparseTimer->setInterval(UPDATE_DOCUMENT_DEFAULT_INTERVAL); + m_localReparseTimer->setSingleShot(true); + connect(m_localReparseTimer, SIGNAL(timeout()), this, SLOT(forceReparseIfCurrentEditor())); connect(this, SIGNAL(textChanged()), this, SLOT(updateDocument())); @@ -719,15 +719,15 @@ QmlJSTextEditorWidget::QmlJSTextEditorWidget(QWidget *parent) : m_oldCursorPosition = -1; if (m_modelManager) { - m_semanticHighlighter->setModelManager(m_modelManager); + m_semanticInfoUpdater->setModelManager(m_modelManager); connect(m_modelManager, SIGNAL(documentUpdated(QmlJS::Document::Ptr)), this, SLOT(onDocumentUpdated(QmlJS::Document::Ptr))); connect(m_modelManager, SIGNAL(libraryInfoUpdated(QString,QmlJS::LibraryInfo)), - this, SLOT(forceSemanticRehighlightIfCurrentEditor())); + this, SLOT(forceReparseIfCurrentEditor())); connect(this->document(), SIGNAL(modificationChanged(bool)), this, SLOT(modificationChanged(bool))); } - connect(m_semanticHighlighter, SIGNAL(changed(QmlJSEditor::SemanticInfo)), + connect(m_semanticInfoUpdater, SIGNAL(updated(QmlJSEditor::SemanticInfo)), this, SLOT(updateSemanticInfo(QmlJSEditor::SemanticInfo))); connect(this, SIGNAL(refactorMarkerClicked(TextEditor::RefactorMarker)), @@ -739,8 +739,8 @@ QmlJSTextEditorWidget::QmlJSTextEditorWidget(QWidget *parent) : QmlJSTextEditorWidget::~QmlJSTextEditorWidget() { hideContextPane(); - m_semanticHighlighter->abort(); - m_semanticHighlighter->wait(); + m_semanticInfoUpdater->abort(); + m_semanticInfoUpdater->wait(); } SemanticInfo QmlJSTextEditorWidget::semanticInfo() const @@ -853,15 +853,15 @@ void QmlJSTextEditorWidget::onDocumentUpdated(QmlJS::Document::Ptr doc) || doc->editorRevision() != document()->revision()) { // maybe a dependency changed: schedule a potential rehighlight // will not rehighlight if the current editor changes away from this file - m_semanticRehighlightTimer->start(); + m_localReparseTimer->start(); return; } if (doc->ast()) { // got a correctly parsed (or recovered) file. - const SemanticHighlighterSource source = currentSource(/*force = */ true); - m_semanticHighlighter->rehighlight(source); + const SemanticInfoUpdaterSource source = currentSource(/*force = */ true); + m_semanticInfoUpdater->update(source); } else { // show parsing errors QList selections; @@ -1496,28 +1496,28 @@ void QmlJSTextEditorWidget::setTabSettings(const TextEditor::TabSettings &ts) TextEditor::BaseTextEditorWidget::setTabSettings(ts); } -void QmlJSTextEditorWidget::forceSemanticRehighlight() +void QmlJSTextEditorWidget::forceReparse() { - m_semanticHighlighter->rehighlight(currentSource(/* force = */ true)); + m_semanticInfoUpdater->update(currentSource(/* force = */ true)); } -void QmlJSEditor::QmlJSTextEditorWidget::forceSemanticRehighlightIfCurrentEditor() +void QmlJSEditor::QmlJSTextEditorWidget::forceReparseIfCurrentEditor() { Core::EditorManager *editorManager = Core::EditorManager::instance(); if (editorManager->currentEditor() == editor()) - forceSemanticRehighlight(); + forceReparse(); } -void QmlJSTextEditorWidget::semanticRehighlight() +void QmlJSTextEditorWidget::reparse() { - m_semanticHighlighter->rehighlight(currentSource()); + m_semanticInfoUpdater->update(currentSource()); } void QmlJSTextEditorWidget::updateSemanticInfo(const SemanticInfo &semanticInfo) { if (semanticInfo.revision() != document()->revision()) { // got outdated semantic info - semanticRehighlight(); + reparse(); return; } @@ -1620,7 +1620,7 @@ QVector QmlJSTextEditorWidget::highlighterFormatCategories() return categories; } -SemanticHighlighterSource QmlJSTextEditorWidget::currentSource(bool force) +SemanticInfoUpdaterSource QmlJSTextEditorWidget::currentSource(bool force) { int line = 0, column = 0; convertPosition(position(), &line, &column); @@ -1633,7 +1633,7 @@ SemanticHighlighterSource QmlJSTextEditorWidget::currentSource(bool force) code = toPlainText(); // get the source code only when needed. const unsigned revision = document()->revision(); - SemanticHighlighterSource source(snapshot, fileName, code, + SemanticInfoUpdaterSource source(snapshot, fileName, code, line, column, revision); source.force = force; return source; diff --git a/src/plugins/qmljseditor/qmljseditor.h b/src/plugins/qmljseditor/qmljseditor.h index ed271c8ef60..932920fc394 100644 --- a/src/plugins/qmljseditor/qmljseditor.h +++ b/src/plugins/qmljseditor/qmljseditor.h @@ -68,8 +68,8 @@ class FindReferences; namespace Internal { class QmlOutlineModel; -class SemanticHighlighter; -struct SemanticHighlighterSource; +class SemanticInfoUpdater; +struct SemanticInfoUpdaterSource; } // namespace Internal struct QMLJSEDITOR_EXPORT Declaration @@ -140,7 +140,7 @@ public: // attributes private: QSharedPointer m_rootScopeChain; - friend class Internal::SemanticHighlighter; + friend class Internal::SemanticInfoUpdater; }; class QMLJSEDITOR_EXPORT QmlJSTextEditorWidget : public TextEditor::BaseTextEditorWidget @@ -170,7 +170,7 @@ public: public slots: virtual void setTabSettings(const TextEditor::TabSettings &ts); - void forceSemanticRehighlight(); + void forceReparse(); void followSymbolUnderCursor(); void findUsages(); void renameUsages(); @@ -197,8 +197,8 @@ private slots: void updateUses(); void updateUsesNow(); - void semanticRehighlight(); - void forceSemanticRehighlightIfCurrentEditor(); + void reparse(); + void forceReparseIfCurrentEditor(); void updateSemanticInfo(const QmlJSEditor::SemanticInfo &semanticInfo); void onCursorPositionChanged(); void onRefactorMarkerClicked(const TextEditor::RefactorMarker &marker); @@ -221,7 +221,7 @@ private: void setSelectedElements(); QString wordUnderCursor() const; - Internal::SemanticHighlighterSource currentSource(bool force = false); + Internal::SemanticInfoUpdaterSource currentSource(bool force = false); QModelIndex indexForPosition(unsigned cursorPosition, const QModelIndex &rootIndex = QModelIndex()) const; bool hideContextPane(); @@ -229,7 +229,7 @@ private: QTimer *m_updateDocumentTimer; QTimer *m_updateUsesTimer; - QTimer *m_semanticRehighlightTimer; + QTimer *m_localReparseTimer; QTimer *m_updateOutlineTimer; QTimer *m_updateOutlineIndexTimer; QTimer *m_cursorPositionTimer; @@ -241,7 +241,7 @@ private: QTextCharFormat m_occurrencesUnusedFormat; QTextCharFormat m_occurrenceRenameFormat; - Internal::SemanticHighlighter *m_semanticHighlighter; + Internal::SemanticInfoUpdater *m_semanticInfoUpdater; SemanticInfo m_semanticInfo; QList m_quickFixes; diff --git a/src/plugins/qmljseditor/qmljseditor.pro b/src/plugins/qmljseditor/qmljseditor.pro index 78c09fdf8fc..b519de6e7b0 100644 --- a/src/plugins/qmljseditor/qmljseditor.pro +++ b/src/plugins/qmljseditor/qmljseditor.pro @@ -29,14 +29,14 @@ HEADERS += \ qmljscomponentnamedialog.h \ qmljsfindreferences.h \ qmljseditoreditable.h \ - qmljssemantichighlighter.h \ qmljsautocompleter.h \ jsfilewizard.h \ qmljssnippetprovider.h \ qmljsreuse.h \ qmljsquickfixassist.h \ qmljscompletionassist.h \ - qmljsquickfix.h + qmljsquickfix.h \ + qmljssemanticinfoupdater.h SOURCES += \ qmljseditor.cpp \ @@ -59,14 +59,14 @@ SOURCES += \ qmljscomponentnamedialog.cpp \ qmljsfindreferences.cpp \ qmljseditoreditable.cpp \ - qmljssemantichighlighter.cpp \ qmljsautocompleter.cpp \ jsfilewizard.cpp \ qmljssnippetprovider.cpp \ qmljsreuse.cpp \ qmljsquickfixassist.cpp \ qmljscompletionassist.cpp \ - qmljsquickfix.cpp + qmljsquickfix.cpp \ + qmljssemanticinfoupdater.cpp RESOURCES += qmljseditor.qrc OTHER_FILES += QmlJSEditor.mimetypes.xml @@ -74,3 +74,7 @@ OTHER_FILES += QmlJSEditor.mimetypes.xml FORMS += \ quicktoolbarsettingspage.ui \ qmljscomponentnamedialog.ui + + + + diff --git a/src/plugins/qmljseditor/qmljseditorplugin.cpp b/src/plugins/qmljseditor/qmljseditorplugin.cpp index 7f8c5853a08..8f0d04434c4 100644 --- a/src/plugins/qmljseditor/qmljseditorplugin.cpp +++ b/src/plugins/qmljseditor/qmljseditorplugin.cpp @@ -326,7 +326,7 @@ void QmlJSEditorPlugin::currentEditorChanged(Core::IEditor *editor) return; else if (QmlJSTextEditorWidget *textEditor = qobject_cast(editor->widget())) { - textEditor->forceSemanticRehighlight(); + textEditor->forceReparse(); } } diff --git a/src/plugins/qmljseditor/qmljssemantichighlighter.cpp b/src/plugins/qmljseditor/qmljssemanticinfoupdater.cpp similarity index 86% rename from src/plugins/qmljseditor/qmljssemantichighlighter.cpp rename to src/plugins/qmljseditor/qmljssemanticinfoupdater.cpp index ce327575b58..6ba69bd4247 100644 --- a/src/plugins/qmljseditor/qmljssemantichighlighter.cpp +++ b/src/plugins/qmljseditor/qmljssemanticinfoupdater.cpp @@ -30,7 +30,7 @@ ** **************************************************************************/ -#include "qmljssemantichighlighter.h" +#include "qmljssemanticinfoupdater.h" #include #include @@ -41,39 +41,39 @@ namespace QmlJSEditor { namespace Internal { -SemanticHighlighter::SemanticHighlighter(QObject *parent) +SemanticInfoUpdater::SemanticInfoUpdater(QObject *parent) : QThread(parent), m_done(false), m_modelManager(0) { } -SemanticHighlighter::~SemanticHighlighter() +SemanticInfoUpdater::~SemanticInfoUpdater() { } -void SemanticHighlighter::abort() +void SemanticInfoUpdater::abort() { QMutexLocker locker(&m_mutex); m_done = true; m_condition.wakeOne(); } -void SemanticHighlighter::rehighlight(const SemanticHighlighterSource &source) +void SemanticInfoUpdater::update(const SemanticInfoUpdaterSource &source) { QMutexLocker locker(&m_mutex); m_source = source; m_condition.wakeOne(); } -bool SemanticHighlighter::isOutdated() +bool SemanticInfoUpdater::isOutdated() { QMutexLocker locker(&m_mutex); const bool outdated = ! m_source.fileName.isEmpty() || m_done; return outdated; } -void SemanticHighlighter::run() +void SemanticInfoUpdater::run() { setPriority(QThread::LowestPriority); @@ -84,7 +84,7 @@ void SemanticHighlighter::run() m_condition.wait(&m_mutex); const bool done = m_done; - const SemanticHighlighterSource source = m_source; + const SemanticInfoUpdaterSource source = m_source; m_source.clear(); m_mutex.unlock(); @@ -99,12 +99,12 @@ void SemanticHighlighter::run() m_lastSemanticInfo = info; m_mutex.unlock(); - emit changed(info); + emit updated(info); } } } -SemanticInfo SemanticHighlighter::semanticInfo(const SemanticHighlighterSource &source) +SemanticInfo SemanticInfoUpdater::semanticInfo(const SemanticInfoUpdaterSource &source) { m_mutex.lock(); const int revision = m_lastSemanticInfo.revision(); @@ -146,7 +146,7 @@ SemanticInfo SemanticHighlighter::semanticInfo(const SemanticHighlighterSource & return semanticInfo; } -void SemanticHighlighter::setModelManager(QmlJS::ModelManagerInterface *modelManager) +void SemanticInfoUpdater::setModelManager(QmlJS::ModelManagerInterface *modelManager) { m_modelManager = modelManager; } diff --git a/src/plugins/qmljseditor/qmljssemantichighlighter.h b/src/plugins/qmljseditor/qmljssemanticinfoupdater.h similarity index 81% rename from src/plugins/qmljseditor/qmljssemantichighlighter.h rename to src/plugins/qmljseditor/qmljssemanticinfoupdater.h index 98a677a1824..c621d476177 100644 --- a/src/plugins/qmljseditor/qmljssemantichighlighter.h +++ b/src/plugins/qmljseditor/qmljssemanticinfoupdater.h @@ -30,8 +30,8 @@ ** **************************************************************************/ -#ifndef SEMANTICHIGHLIGHTER_H -#define SEMANTICHIGHLIGHTER_H +#ifndef SEMANTICINFOUPDATER_H +#define SEMANTICINFOUPDATER_H #include "qmljseditor.h" @@ -43,7 +43,7 @@ namespace QmlJSEditor { namespace Internal { -struct SemanticHighlighterSource +struct SemanticInfoUpdaterSource { QmlJS::Snapshot snapshot; QString fileName; @@ -53,11 +53,11 @@ struct SemanticHighlighterSource int revision; bool force; - SemanticHighlighterSource() + SemanticInfoUpdaterSource() : line(0), column(0), revision(0), force(false) { } - SemanticHighlighterSource(const QmlJS::Snapshot &snapshot, + SemanticInfoUpdaterSource(const QmlJS::Snapshot &snapshot, const QString &fileName, const QString &code, int line, int column, @@ -79,33 +79,33 @@ struct SemanticHighlighterSource } }; -class SemanticHighlighter: public QThread +class SemanticInfoUpdater: public QThread { Q_OBJECT public: - SemanticHighlighter(QObject *parent = 0); - virtual ~SemanticHighlighter(); + SemanticInfoUpdater(QObject *parent = 0); + virtual ~SemanticInfoUpdater(); void abort(); - void rehighlight(const SemanticHighlighterSource &source); + void update(const SemanticInfoUpdaterSource &source); void setModelManager(QmlJS::ModelManagerInterface *modelManager); Q_SIGNALS: - void changed(const QmlJSEditor::SemanticInfo &semanticInfo); + void updated(const QmlJSEditor::SemanticInfo &semanticInfo); protected: virtual void run(); private: bool isOutdated(); - SemanticInfo semanticInfo(const SemanticHighlighterSource &source); + SemanticInfo semanticInfo(const SemanticInfoUpdaterSource &source); private: QMutex m_mutex; QWaitCondition m_condition; bool m_done; - SemanticHighlighterSource m_source; + SemanticInfoUpdaterSource m_source; SemanticInfo m_lastSemanticInfo; QmlJS::ModelManagerInterface *m_modelManager; }; @@ -113,4 +113,4 @@ private: } // namespace Internal } // namespace QmlJSEditor -#endif // SEMANTICHIGHLIGHTER_H +#endif // SEMANTICINFOUPDATER_H