2016-01-15 14:57:40 +01:00
|
|
|
/****************************************************************************
|
2011-10-25 23:14:27 +03:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 Dmitry Savchenko
|
|
|
|
|
** Copyright (C) 2016 Vasiliy Sorokin
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2011-10-25 23:14:27 +03:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2011-10-25 23:14:27 +03: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.
|
2011-10-25 23:14:27 +03: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.
|
2011-10-25 23:14:27 +03:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2011-10-25 23:14:27 +03:00
|
|
|
|
|
|
|
|
#include "qmljstodoitemsscanner.h"
|
|
|
|
|
|
|
|
|
|
#include <projectexplorer/project.h>
|
|
|
|
|
|
2015-03-04 16:46:23 +01:00
|
|
|
#include <qmljs/parser/qmljsengine_p.h>
|
|
|
|
|
|
2020-06-17 06:35:31 +02:00
|
|
|
#include <utils/stringutils.h>
|
|
|
|
|
|
2011-10-25 23:14:27 +03:00
|
|
|
namespace Todo {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
QmlJsTodoItemsScanner::QmlJsTodoItemsScanner(const KeywordList &keywordList, QObject *parent) :
|
|
|
|
|
TodoItemsScanner(keywordList, parent)
|
|
|
|
|
{
|
|
|
|
|
QmlJS::ModelManagerInterface *model = QmlJS::ModelManagerInterface::instance();
|
2015-01-29 10:42:16 +01:00
|
|
|
connect(model, &QmlJS::ModelManagerInterface::documentUpdated,
|
|
|
|
|
this, &QmlJsTodoItemsScanner::documentUpdated, Qt::DirectConnection);
|
2015-05-18 22:47:20 +03:00
|
|
|
|
|
|
|
|
setParams(keywordList);
|
2011-10-25 23:14:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool QmlJsTodoItemsScanner::shouldProcessFile(const QString &fileName)
|
|
|
|
|
{
|
|
|
|
|
QmlJS::ModelManagerInterface *modelManager = QmlJS::ModelManagerInterface::instance();
|
2015-05-18 22:47:20 +03:00
|
|
|
foreach (const QmlJS::ModelManagerInterface::ProjectInfo &info, modelManager->projectInfos()) {
|
2014-06-30 14:57:42 +02:00
|
|
|
if (info.sourceFiles.contains(fileName))
|
2011-10-25 23:14:27 +03:00
|
|
|
return true;
|
2015-05-18 22:47:20 +03:00
|
|
|
}
|
2011-10-25 23:14:27 +03:00
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-18 22:47:20 +03:00
|
|
|
void QmlJsTodoItemsScanner::scannerParamsChanged()
|
2011-10-25 23:14:27 +03:00
|
|
|
{
|
|
|
|
|
// We need to rescan everything known to the code model
|
|
|
|
|
// TODO: It would be nice to only tokenize the source files, not update the code model entirely.
|
|
|
|
|
|
|
|
|
|
QmlJS::ModelManagerInterface *modelManager = QmlJS::ModelManagerInterface::instance();
|
|
|
|
|
|
|
|
|
|
QStringList filesToBeUpdated;
|
|
|
|
|
foreach (const QmlJS::ModelManagerInterface::ProjectInfo &info, modelManager->projectInfos())
|
2014-07-01 11:14:05 +02:00
|
|
|
filesToBeUpdated << info.sourceFiles;
|
2011-10-25 23:14:27 +03:00
|
|
|
|
|
|
|
|
modelManager->updateSourceFiles(filesToBeUpdated, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlJsTodoItemsScanner::documentUpdated(QmlJS::Document::Ptr doc)
|
|
|
|
|
{
|
|
|
|
|
if (shouldProcessFile(doc->fileName()))
|
|
|
|
|
processDocument(doc);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlJsTodoItemsScanner::processDocument(QmlJS::Document::Ptr doc)
|
|
|
|
|
{
|
|
|
|
|
QList<TodoItem> itemList;
|
|
|
|
|
|
2020-02-28 17:51:32 +01:00
|
|
|
foreach (const QmlJS::SourceLocation &sourceLocation, doc->engine()->comments()) {
|
2011-10-25 23:14:27 +03:00
|
|
|
QString source = doc->source().mid(sourceLocation.begin(), sourceLocation.length).trimmed();
|
|
|
|
|
|
|
|
|
|
// Process every line
|
|
|
|
|
// TODO: Do not create QStringList, just iterate through a string tracking line endings.
|
2020-07-21 10:19:36 +02:00
|
|
|
QStringList commentLines = source.split('\n', Qt::SkipEmptyParts);
|
2011-10-25 23:14:27 +03:00
|
|
|
quint32 startLine = sourceLocation.startLine;
|
|
|
|
|
for (int j = 0; j < commentLines.count(); ++j) {
|
|
|
|
|
const QString &commentLine = commentLines.at(j);
|
|
|
|
|
processCommentLine(doc->fileName(), commentLine, startLine + j, itemList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
emit itemsFetched(doc->fileName(), itemList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|