2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2010-01-04 11:30:14 +01:00
|
|
|
**
|
2014-01-07 13:27:11 +01:00
|
|
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
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
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
2010-01-04 11:30:14 +01:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
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"
|
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>
|
2011-04-21 11:09:29 +02:00
|
|
|
#include <qmljs/qmljslink.h>
|
|
|
|
|
#include <qmljs/qmljscheck.h>
|
|
|
|
|
#include <qmljseditor/qmljseditor.h>
|
|
|
|
|
#include <qmljseditor/qmljseditoreditable.h>
|
2010-04-16 12:42:12 +02:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QDebug>
|
|
|
|
|
#include <QtConcurrentRun>
|
2012-02-09 09:35:03 +01:00
|
|
|
#include <utils/runextensions.h>
|
2011-04-21 11:09:29 +02:00
|
|
|
|
|
|
|
|
using namespace QmlJS;
|
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
|
|
|
|
|
// connect(&m_messageCollector, SIGNAL(resultsReadyAt(int,int)),
|
|
|
|
|
// SLOT(displayResults(int,int)));
|
|
|
|
|
connect(&m_messageCollector, SIGNAL(finished()),
|
|
|
|
|
SLOT(displayAllResults()));
|
|
|
|
|
|
2011-08-09 14:40:04 +02:00
|
|
|
m_updateDelay.setInterval(500);
|
2011-04-21 11:09:29 +02:00
|
|
|
m_updateDelay.setSingleShot(true);
|
|
|
|
|
connect(&m_updateDelay, SIGNAL(timeout()),
|
|
|
|
|
SLOT(updateMessagesNow()));
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-26 13:38:25 +01:00
|
|
|
static QList<ProjectExplorer::Task> convertToTasks(const QList<DiagnosticMessage> &messages, const Utils::FileName &fileName, const Core::Id &category)
|
2011-08-09 14:40:04 +02:00
|
|
|
{
|
|
|
|
|
QList<ProjectExplorer::Task> result;
|
|
|
|
|
foreach (const DiagnosticMessage &msg, messages) {
|
|
|
|
|
ProjectExplorer::Task::TaskType type
|
|
|
|
|
= msg.isError() ? ProjectExplorer::Task::Error
|
|
|
|
|
: ProjectExplorer::Task::Warning;
|
|
|
|
|
|
|
|
|
|
ProjectExplorer::Task task(type, msg.message, fileName, msg.loc.startLine,
|
|
|
|
|
category);
|
|
|
|
|
|
|
|
|
|
result += task;
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-26 13:38:25 +01:00
|
|
|
static QList<ProjectExplorer::Task> convertToTasks(const QList<StaticAnalysis::Message> &messages, const Utils::FileName &fileName, const 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;
|
2013-03-05 14:35:15 +01:00
|
|
|
if (Document::isFullySupportedLanguage(document->language())) {
|
|
|
|
|
result.tasks = convertToTasks(document->diagnosticMessages(),
|
|
|
|
|
Utils::FileName::fromString(fileName),
|
|
|
|
|
Core::Id(Constants::TASK_CATEGORY_QML));
|
|
|
|
|
|
|
|
|
|
if (updateSemantic) {
|
|
|
|
|
result.tasks += convertToTasks(linkMessages.value(fileName),
|
|
|
|
|
Utils::FileName::fromString(fileName),
|
|
|
|
|
Core::Id(Constants::TASK_CATEGORY_QML_ANALYSIS));
|
|
|
|
|
|
|
|
|
|
Check checker(document, context);
|
|
|
|
|
result.tasks += convertToTasks(checker(),
|
|
|
|
|
Utils::FileName::fromString(fileName),
|
|
|
|
|
Core::Id(Constants::TASK_CATEGORY_QML_ANALYSIS));
|
|
|
|
|
}
|
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 =
|
|
|
|
|
QtConcurrent::run<FileErrorMessages>(
|
2011-08-30 09:19:56 +02:00
|
|
|
&collectMessages, modelManager->newestSnapshot(), modelManager->projectInfos(),
|
2014-06-02 19:36:32 +02:00
|
|
|
modelManager->defaultVContext(Language::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);
|
2011-08-09 14:40:04 +02:00
|
|
|
foreach (const ProjectExplorer::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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlTaskManager::insertTask(const ProjectExplorer::Task &task)
|
|
|
|
|
{
|
2012-01-26 13:38:25 +01:00
|
|
|
QList<ProjectExplorer::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);
|
2013-08-15 12:14:46 +02:00
|
|
|
ProjectExplorer::TaskHub::addTask(task);
|
2010-04-16 12:42:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlTaskManager::removeTasksForFile(const QString &fileName)
|
|
|
|
|
{
|
|
|
|
|
if (m_docsWithTasks.contains(fileName)) {
|
|
|
|
|
const QList<ProjectExplorer::Task> tasks = m_docsWithTasks.value(fileName);
|
|
|
|
|
foreach (const ProjectExplorer::Task &task, tasks)
|
2013-08-15 12:14:46 +02:00
|
|
|
ProjectExplorer::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
|
|
|
{
|
2013-08-15 12:14:46 +02:00
|
|
|
ProjectExplorer::TaskHub::clearTasks(Constants::TASK_CATEGORY_QML);
|
2011-08-16 14:11:30 +02:00
|
|
|
if (clearSemantic)
|
2013-08-15 12:14:46 +02:00
|
|
|
ProjectExplorer::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
|