Commit ef5dc8c6 authored by Christian Kamm's avatar Christian Kamm

QmlJS: Avoid frequent libraryInfoUpdated emissions.

Also don't require a rehighlight of every open document when the
signal is emitted.

Reviewed-by: Roberto Raggi
parent 033a0ff1
......@@ -676,7 +676,7 @@ QmlJSTextEditor::QmlJSTextEditor(QWidget *parent) :
connect(m_modelManager, SIGNAL(documentUpdated(QmlJS::Document::Ptr)),
this, SLOT(onDocumentUpdated(QmlJS::Document::Ptr)));
connect(m_modelManager, SIGNAL(libraryInfoUpdated(QString,QmlJS::LibraryInfo)),
this, SLOT(forceSemanticRehighlight()));
this, SLOT(forceSemanticRehighlightIfCurrentEditor()));
connect(this->document(), SIGNAL(modificationChanged(bool)), this, SLOT(modificationChanged(bool)));
}
......@@ -1465,6 +1465,13 @@ void QmlJSTextEditor::forceSemanticRehighlight()
m_semanticHighlighter->rehighlight(currentSource(/* force = */ true));
}
void QmlJSEditor::QmlJSTextEditor::forceSemanticRehighlightIfCurrentEditor()
{
Core::EditorManager *editorManager = Core::EditorManager::instance();
if (editorManager->currentEditor() == editableInterface())
forceSemanticRehighlight();
}
void QmlJSTextEditor::semanticRehighlight()
{
m_semanticHighlighter->rehighlight(currentSource());
......
......@@ -192,6 +192,7 @@ private slots:
void renameIdUnderCursor();
void semanticRehighlight();
void forceSemanticRehighlightIfCurrentEditor();
void updateSemanticInfo(const QmlJSEditor::SemanticInfo &semanticInfo);
void onCursorPositionChanged();
void onRefactorMarkerClicked(const TextEditor::RefactorMarker &marker);
......
......@@ -349,7 +349,7 @@ static void findNewFileImports(const Document::Ptr &doc, const Snapshot &snapsho
static void findNewLibraryImports(const Document::Ptr &doc, const Snapshot &snapshot,
ModelManager *modelManager,
QStringList *importedFiles, QSet<QString> *scannedPaths)
QStringList *importedFiles, QSet<QString> *scannedPaths, QSet<QString> *newLibraries)
{
// scan library imports
const QStringList importPaths = modelManager->importPaths();
......@@ -364,6 +364,8 @@ static void findNewLibraryImports(const Document::Ptr &doc, const Snapshot &snap
// if we know there is a library, done
if (snapshot.libraryInfo(targetPath).isValid())
break;
if (newLibraries->contains(targetPath))
break;
// if there is a qmldir file, we found a new library!
if (dir.exists("qmldir")) {
......@@ -375,8 +377,10 @@ static void findNewLibraryImports(const Document::Ptr &doc, const Snapshot &snap
qmldirParser.setSource(qmldirData);
qmldirParser.parse();
modelManager->updateLibraryInfo(QFileInfo(qmldirFile).absolutePath(),
LibraryInfo(qmldirParser));
const QString libraryPath = QFileInfo(qmldirFile).absolutePath();
newLibraries->insert(libraryPath);
modelManager->updateLibraryInfo(libraryPath,
LibraryInfo(qmldirParser));
// scan the qml files in the library
foreach (const QmlDirParser::Component &component, qmldirParser.components()) {
......@@ -425,6 +429,8 @@ void ModelManager::parse(QFutureInterface<void> &future,
// paths we have scanned for files and added to the files list
QSet<QString> scannedPaths;
// libraries we've found while scanning imports
QSet<QString> newLibraries;
for (int i = 0; i < files.size(); ++i) {
future.setProgressValue(qreal(i) / files.size() * progressRange);
......@@ -471,7 +477,7 @@ void ModelManager::parse(QFutureInterface<void> &future,
QStringList importedFiles;
findNewImplicitImports(doc, snapshot, &importedFiles, &scannedPaths);
findNewFileImports(doc, snapshot, &importedFiles, &scannedPaths);
findNewLibraryImports(doc, snapshot, modelManager, &importedFiles, &scannedPaths);
findNewLibraryImports(doc, snapshot, modelManager, &importedFiles, &scannedPaths, &newLibraries);
// add new files to parse list
foreach (const QString &file, importedFiles) {
......@@ -547,8 +553,9 @@ void ModelManager::updateImportPaths()
Snapshot snapshot = _snapshot;
QStringList importedFiles;
QSet<QString> scannedPaths;
QSet<QString> newLibraries;
foreach (const Document::Ptr &doc, snapshot)
findNewLibraryImports(doc, snapshot, this, &importedFiles, &scannedPaths);
findNewLibraryImports(doc, snapshot, this, &importedFiles, &scannedPaths, &newLibraries);
updateSourceFiles(importedFiles, true);
}
......
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