2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2010-01-04 11:30:14 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2010-01-04 11:30:14 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2010-01-04 11:30:14 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2010-01-04 11:30:14 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2010-12-17 16:01:08 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2010-01-04 11:30:14 +01:00
|
|
|
|
2009-11-11 10:10:00 +01:00
|
|
|
#include "qmltaskmanager.h"
|
2014-08-20 01:47:42 +02:00
|
|
|
#include "qmljseditor.h"
|
2010-07-13 17:16:43 +02:00
|
|
|
#include "qmljseditorconstants.h"
|
2010-04-16 12:42:12 +02:00
|
|
|
|
2012-02-14 16:43:51 +01:00
|
|
|
#include <coreplugin/idocument.h>
|
2012-03-07 16:40:03 +01:00
|
|
|
#include <projectexplorer/projectexplorer.h>
|
2010-07-06 12:11:15 +02:00
|
|
|
#include <projectexplorer/taskhub.h>
|
2010-07-13 17:16:43 +02:00
|
|
|
#include <qmljs/qmljsmodelmanagerinterface.h>
|
2011-07-01 13:51:53 +02:00
|
|
|
#include <qmljs/qmljscontext.h>
|
2014-08-20 01:47:42 +02:00
|
|
|
#include <qmljs/qmljsconstants.h>
|
2011-04-21 11:09:29 +02:00
|
|
|
#include <qmljs/qmljslink.h>
|
|
|
|
|
#include <qmljs/qmljscheck.h>
|
2014-08-20 01:47:42 +02:00
|
|
|
#include <utils/runextensions.h>
|
2010-04-16 12:42:12 +02:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QDebug>
|
|
|
|
|
#include <QtConcurrentRun>
|
2011-04-21 11:09:29 +02:00
|
|
|
|
2014-08-20 01:47:42 +02:00
|
|
|
using namespace ProjectExplorer;
|
2011-04-21 11:09:29 +02:00
|
|
|
using namespace QmlJS;
|
2014-08-20 01:47:42 +02:00
|
|
|
using namespace Utils;
|
2009-11-11 10:10:00 +01:00
|
|
|
|
2010-07-13 17:16:43 +02:00
|
|
|
namespace QmlJSEditor {
|
2009-11-11 10:10:00 +01:00
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
QmlTaskManager::QmlTaskManager(QObject *parent) :
|
2011-08-09 14:40:04 +02:00
|
|
|
QObject(parent),
|
|
|
|
|
m_updatingSemantic(false)
|
2009-11-11 10:10:00 +01:00
|
|
|
{
|
2011-04-21 11:09:29 +02:00
|
|
|
// displaying results incrementally leads to flickering
|
2016-06-27 22:25:11 +03:00
|
|
|
// connect(&m_messageCollector, &QFutureWatcherBase::resultsReadyAt,
|
|
|
|
|
// this, &QmlTaskManager::displayResults);
|
|
|
|
|
connect(&m_messageCollector, &QFutureWatcherBase::finished,
|
|
|
|
|
this, &QmlTaskManager::displayAllResults);
|
2011-04-21 11:09:29 +02:00
|
|
|
|
2011-08-09 14:40:04 +02:00
|
|
|
m_updateDelay.setInterval(500);
|
2011-04-21 11:09:29 +02:00
|
|
|
m_updateDelay.setSingleShot(true);
|
2016-06-27 22:25:11 +03:00
|
|
|
connect(&m_updateDelay, &QTimer::timeout, this, [this] { updateMessagesNow(); });
|
2011-04-21 11:09:29 +02:00
|
|
|
}
|
|
|
|
|
|
2014-08-20 01:47:42 +02:00
|
|
|
static QList<Task> convertToTasks(const QList<DiagnosticMessage> &messages, const FileName &fileName, Core::Id category)
|
2011-08-09 14:40:04 +02:00
|
|
|
{
|
2014-08-20 01:47:42 +02:00
|
|
|
QList<Task> result;
|
2011-08-09 14:40:04 +02:00
|
|
|
foreach (const DiagnosticMessage &msg, messages) {
|
2014-08-20 01:47:42 +02:00
|
|
|
Task::TaskType type = msg.isError() ? Task::Error : Task::Warning;
|
|
|
|
|
Task task(type, msg.message, fileName, msg.loc.startLine, category);
|
2011-08-09 14:40:04 +02:00
|
|
|
result += task;
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-20 01:47:42 +02:00
|
|
|
static QList<Task> convertToTasks(const QList<StaticAnalysis::Message> &messages, const FileName &fileName, Core::Id category)
|
2011-09-28 15:16:00 +02:00
|
|
|
{
|
|
|
|
|
QList<DiagnosticMessage> diagnostics;
|
|
|
|
|
foreach (const StaticAnalysis::Message &msg, messages)
|
|
|
|
|
diagnostics += msg.toDiagnosticMessage();
|
|
|
|
|
return convertToTasks(diagnostics, fileName, category);
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-09 14:40:04 +02:00
|
|
|
void QmlTaskManager::collectMessages(
|
|
|
|
|
QFutureInterface<FileErrorMessages> &future,
|
|
|
|
|
Snapshot snapshot, QList<ModelManagerInterface::ProjectInfo> projectInfos,
|
2013-10-16 15:08:27 +02:00
|
|
|
ViewerContext vContext, bool updateSemantic)
|
2011-04-21 11:09:29 +02:00
|
|
|
{
|
2011-08-09 14:40:04 +02:00
|
|
|
foreach (const ModelManagerInterface::ProjectInfo &info, projectInfos) {
|
|
|
|
|
QHash<QString, QList<DiagnosticMessage> > linkMessages;
|
|
|
|
|
ContextPtr context;
|
|
|
|
|
if (updateSemantic) {
|
2013-10-16 15:08:27 +02:00
|
|
|
Link link(snapshot, vContext, snapshot.libraryInfo(info.qtImportsPath));
|
2011-08-09 14:40:04 +02:00
|
|
|
context = link(&linkMessages);
|
|
|
|
|
}
|
2011-04-21 11:09:29 +02:00
|
|
|
|
2011-08-09 14:40:04 +02:00
|
|
|
foreach (const QString &fileName, info.sourceFiles) {
|
|
|
|
|
Document::Ptr document = snapshot.document(fileName);
|
|
|
|
|
if (!document)
|
|
|
|
|
continue;
|
2011-04-21 11:09:29 +02:00
|
|
|
|
2011-08-09 14:40:04 +02:00
|
|
|
FileErrorMessages result;
|
|
|
|
|
result.fileName = fileName;
|
2014-07-22 19:06:44 +02:00
|
|
|
if (document->language().isFullySupportedLanguage()) {
|
2013-03-05 14:35:15 +01:00
|
|
|
result.tasks = convertToTasks(document->diagnosticMessages(),
|
2014-08-20 01:47:42 +02:00
|
|
|
FileName::fromString(fileName),
|
|
|
|
|
Constants::TASK_CATEGORY_QML);
|
2013-03-05 14:35:15 +01:00
|
|
|
|
|
|
|
|
if (updateSemantic) {
|
|
|
|
|
result.tasks += convertToTasks(linkMessages.value(fileName),
|
2014-08-20 01:47:42 +02:00
|
|
|
FileName::fromString(fileName),
|
|
|
|
|
Constants::TASK_CATEGORY_QML_ANALYSIS);
|
2013-03-05 14:35:15 +01:00
|
|
|
|
|
|
|
|
Check checker(document, context);
|
|
|
|
|
result.tasks += convertToTasks(checker(),
|
2014-08-20 01:47:42 +02:00
|
|
|
FileName::fromString(fileName),
|
|
|
|
|
Constants::TASK_CATEGORY_QML_ANALYSIS);
|
2013-03-05 14:35:15 +01:00
|
|
|
}
|
2011-08-09 14:40:04 +02:00
|
|
|
}
|
2011-04-21 11:09:29 +02:00
|
|
|
|
2011-08-16 14:11:30 +02:00
|
|
|
if (!result.tasks.isEmpty())
|
|
|
|
|
future.reportResult(result);
|
2011-08-09 14:40:04 +02:00
|
|
|
if (future.isCanceled())
|
|
|
|
|
break;
|
|
|
|
|
}
|
2011-04-21 11:09:29 +02:00
|
|
|
}
|
2009-11-11 10:10:00 +01:00
|
|
|
}
|
|
|
|
|
|
2011-04-21 11:09:29 +02:00
|
|
|
void QmlTaskManager::updateMessages()
|
2009-11-11 10:10:00 +01:00
|
|
|
{
|
2011-04-21 11:09:29 +02:00
|
|
|
m_updateDelay.start();
|
|
|
|
|
}
|
2009-11-11 10:10:00 +01:00
|
|
|
|
2011-08-09 14:40:04 +02:00
|
|
|
void QmlTaskManager::updateSemanticMessagesNow()
|
|
|
|
|
{
|
|
|
|
|
updateMessagesNow(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlTaskManager::updateMessagesNow(bool updateSemantic)
|
2011-04-21 11:09:29 +02:00
|
|
|
{
|
2011-08-09 14:40:04 +02:00
|
|
|
// don't restart a small update if a big one is running
|
|
|
|
|
if (!updateSemantic && m_updatingSemantic)
|
|
|
|
|
return;
|
|
|
|
|
m_updatingSemantic = updateSemantic;
|
|
|
|
|
|
2011-04-21 11:09:29 +02:00
|
|
|
// abort any update that's going on already
|
|
|
|
|
m_messageCollector.cancel();
|
2011-08-16 14:11:30 +02:00
|
|
|
removeAllTasks(updateSemantic);
|
2009-11-11 10:10:00 +01:00
|
|
|
|
2011-04-21 11:09:29 +02:00
|
|
|
ModelManagerInterface *modelManager = ModelManagerInterface::instance();
|
|
|
|
|
|
|
|
|
|
// process them
|
|
|
|
|
QFuture<FileErrorMessages> future =
|
2016-02-08 16:26:19 +01:00
|
|
|
Utils::runAsync(
|
2011-08-30 09:19:56 +02:00
|
|
|
&collectMessages, modelManager->newestSnapshot(), modelManager->projectInfos(),
|
2014-07-22 19:06:44 +02:00
|
|
|
modelManager->defaultVContext(Dialect::AnyLanguage), updateSemantic);
|
2011-04-21 11:09:29 +02:00
|
|
|
m_messageCollector.setFuture(future);
|
2010-04-16 12:42:12 +02:00
|
|
|
}
|
|
|
|
|
|
2014-06-23 14:47:28 +03:00
|
|
|
void QmlTaskManager::documentsRemoved(const QStringList &path)
|
2010-04-16 12:42:12 +02:00
|
|
|
{
|
|
|
|
|
foreach (const QString &item, path)
|
|
|
|
|
removeTasksForFile(item);
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-21 11:09:29 +02:00
|
|
|
void QmlTaskManager::displayResults(int begin, int end)
|
2010-04-16 12:42:12 +02:00
|
|
|
{
|
2011-04-21 11:09:29 +02:00
|
|
|
for (int i = begin; i < end; ++i) {
|
|
|
|
|
FileErrorMessages result = m_messageCollector.resultAt(i);
|
2014-08-20 01:47:42 +02:00
|
|
|
foreach (const Task &task, result.tasks) {
|
2011-04-21 11:09:29 +02:00
|
|
|
insertTask(task);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlTaskManager::displayAllResults()
|
|
|
|
|
{
|
|
|
|
|
displayResults(0, m_messageCollector.future().resultCount());
|
2011-08-09 14:40:04 +02:00
|
|
|
m_updatingSemantic = false;
|
2011-04-21 11:09:29 +02:00
|
|
|
}
|
|
|
|
|
|
2014-08-20 01:47:42 +02:00
|
|
|
void QmlTaskManager::insertTask(const Task &task)
|
2011-04-21 11:09:29 +02:00
|
|
|
{
|
2014-08-20 01:47:42 +02:00
|
|
|
QList<Task> tasks = m_docsWithTasks.value(task.file.toString());
|
2010-04-16 12:42:12 +02:00
|
|
|
tasks.append(task);
|
2012-01-26 13:38:25 +01:00
|
|
|
m_docsWithTasks.insert(task.file.toString(), tasks);
|
2014-08-20 01:47:42 +02:00
|
|
|
TaskHub::addTask(task);
|
2010-04-16 12:42:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlTaskManager::removeTasksForFile(const QString &fileName)
|
|
|
|
|
{
|
|
|
|
|
if (m_docsWithTasks.contains(fileName)) {
|
2014-08-20 01:47:42 +02:00
|
|
|
const QList<Task> tasks = m_docsWithTasks.value(fileName);
|
|
|
|
|
foreach (const Task &task, tasks)
|
|
|
|
|
TaskHub::removeTask(task);
|
2010-04-16 12:42:12 +02:00
|
|
|
m_docsWithTasks.remove(fileName);
|
2009-11-11 10:10:00 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-16 14:11:30 +02:00
|
|
|
void QmlTaskManager::removeAllTasks(bool clearSemantic)
|
2011-04-21 11:09:29 +02:00
|
|
|
{
|
2014-08-20 01:47:42 +02:00
|
|
|
TaskHub::clearTasks(Constants::TASK_CATEGORY_QML);
|
2011-08-16 14:11:30 +02:00
|
|
|
if (clearSemantic)
|
2014-08-20 01:47:42 +02:00
|
|
|
TaskHub::clearTasks(Constants::TASK_CATEGORY_QML_ANALYSIS);
|
2011-04-21 11:09:29 +02:00
|
|
|
m_docsWithTasks.clear();
|
|
|
|
|
}
|
|
|
|
|
|
2009-11-11 10:10:00 +01:00
|
|
|
} // Internal
|
2010-02-16 13:39:13 +01:00
|
|
|
} // QmlProjectManager
|