QmlJS: Show semantic messages on request.

* Add 'Run Checks' action (Ctrl-Shift-C) to perform checks on
  all projects.
* Add 'QML Analysis' build issues category to separate
  clear errors from semantic analysis results.
* Disabled automatic updating of analysis results.

Change-Id: I4c948b1bd39f55655073e56c5e3ca7837f727665
Reviewed-on: http://codereview.qt.nokia.com/2850
Reviewed-by: Leandro T. C. Melo <leandro.melo@nokia.com>
Reviewed-by: Fawzi Mohamed <fawzi.mohamed@nokia.com>
This commit is contained in:
Christian Kamm
2011-08-09 14:40:04 +02:00
parent 56af8bfbe3
commit 1c3dab2948
10 changed files with 158 additions and 82 deletions

View File

@@ -53,48 +53,76 @@ namespace QmlJSEditor {
namespace Internal {
QmlTaskManager::QmlTaskManager(QObject *parent) :
QObject(parent),
m_taskHub(0)
QObject(parent),
m_taskHub(0),
m_updatingSemantic(false)
{
m_taskHub = ExtensionSystem::PluginManager::instance()->getObject<ProjectExplorer::TaskHub>();
// displaying results incrementally leads to flickering
// connect(&m_messageCollector, SIGNAL(resultsReadyAt(int,int)),
// SLOT(displayResults(int,int)));
connect(&m_messageCollector, SIGNAL(finished()),
SLOT(displayAllResults()));
m_updateDelay.setInterval(100);
m_updateDelay.setInterval(500);
m_updateDelay.setSingleShot(true);
connect(&m_updateDelay, SIGNAL(timeout()),
SLOT(updateMessagesNow()));
}
void QmlTaskManager::collectMessages(QFutureInterface<FileErrorMessages> &future,
Snapshot snapshot, QStringList files, QStringList /*importPaths*/)
static QList<ProjectExplorer::Task> convertToTasks(const QList<DiagnosticMessage> &messages, const QString &fileName, const QString &category)
{
// ### link and check error messages are disabled for now: too many false-positives!
//Context ctx(snapshot);
//QHash<QString, QList<DiagnosticMessage> > linkMessages;
//Link link(&ctx, snapshot, importPaths);
//link(&linkMessages);
QList<ProjectExplorer::Task> result;
foreach (const DiagnosticMessage &msg, messages) {
ProjectExplorer::Task::TaskType type
= msg.isError() ? ProjectExplorer::Task::Error
: ProjectExplorer::Task::Warning;
foreach (const QString &fileName, files) {
Document::Ptr document = snapshot.document(fileName);
if (!document)
continue;
ProjectExplorer::Task task(type, msg.message, fileName, msg.loc.startLine,
category);
FileErrorMessages result;
result.fileName = fileName;
result.messages = document->diagnosticMessages();
result += task;
}
return result;
}
//result.messages += linkMessages.value(fileName);
void QmlTaskManager::collectMessages(
QFutureInterface<FileErrorMessages> &future,
Snapshot snapshot, QList<ModelManagerInterface::ProjectInfo> projectInfos,
QStringList importPaths, bool updateSemantic)
{
foreach (const ModelManagerInterface::ProjectInfo &info, projectInfos) {
QHash<QString, QList<DiagnosticMessage> > linkMessages;
ContextPtr context;
if (updateSemantic) {
Link link(snapshot, importPaths, snapshot.libraryInfo(info.qtImportsPath));
context = link(&linkMessages);
}
//Check checker(document, &ctx);
//result.messages.append(checker());
foreach (const QString &fileName, info.sourceFiles) {
Document::Ptr document = snapshot.document(fileName);
if (!document)
continue;
future.reportResult(result);
if (future.isCanceled())
break;
FileErrorMessages result;
result.fileName = fileName;
result.tasks = convertToTasks(document->diagnosticMessages(),
fileName, Constants::TASK_CATEGORY_QML);
if (updateSemantic) {
result.tasks += convertToTasks(linkMessages.value(fileName),
fileName, Constants::TASK_CATEGORY_QML_ANALYSIS);
Check checker(document, context);
result.tasks += convertToTasks(checker(),
fileName, Constants::TASK_CATEGORY_QML_ANALYSIS);
}
future.reportResult(result);
if (future.isCanceled())
break;
}
}
}
@@ -103,24 +131,30 @@ void QmlTaskManager::updateMessages()
m_updateDelay.start();
}
void QmlTaskManager::updateMessagesNow()
void QmlTaskManager::updateSemanticMessagesNow()
{
updateMessagesNow(true);
}
void QmlTaskManager::updateMessagesNow(bool updateSemantic)
{
// don't restart a small update if a big one is running
if (!updateSemantic && m_updatingSemantic)
return;
m_updatingSemantic = updateSemantic;
// abort any update that's going on already
m_messageCollector.cancel();
removeAllTasks();
// collect all the source files in open projects
ModelManagerInterface *modelManager = ModelManagerInterface::instance();
QStringList sourceFiles;
foreach (const ModelManagerInterface::ProjectInfo &info, modelManager->projectInfos()) {
sourceFiles += info.sourceFiles;
}
// process them
QFuture<FileErrorMessages> future =
QtConcurrent::run<FileErrorMessages>(
&collectMessages, modelManager->snapshot(), sourceFiles,
modelManager->importPaths());
&collectMessages, modelManager->snapshot(), modelManager->projectInfos(),
modelManager->importPaths(), !updateSemantic);
m_messageCollector.setFuture(future);
}
@@ -134,14 +168,7 @@ void QmlTaskManager::displayResults(int begin, int end)
{
for (int i = begin; i < end; ++i) {
FileErrorMessages result = m_messageCollector.resultAt(i);
foreach (const DiagnosticMessage &msg, result.messages) {
ProjectExplorer::Task::TaskType type
= msg.isError() ? ProjectExplorer::Task::Error
: ProjectExplorer::Task::Warning;
ProjectExplorer::Task task(type, msg.message, result.fileName, msg.loc.startLine,
Constants::TASK_CATEGORY_QML);
foreach (const ProjectExplorer::Task &task, result.tasks) {
insertTask(task);
}
}
@@ -150,6 +177,7 @@ void QmlTaskManager::displayResults(int begin, int end)
void QmlTaskManager::displayAllResults()
{
displayResults(0, m_messageCollector.future().resultCount());
m_updatingSemantic = false;
}
void QmlTaskManager::insertTask(const ProjectExplorer::Task &task)