1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
// Copyright (C) 2016 Dmitry Savchenko
// Copyright (C) 2016 Vasiliy Sorokin
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "qmljstodoitemsscanner.h"
#include <projectexplorer/project.h>
#include <qmljs/parser/qmljsengine_p.h>
#include <utils/stringutils.h>
namespace Todo {
namespace Internal {
QmlJsTodoItemsScanner::QmlJsTodoItemsScanner(const KeywordList &keywordList, QObject *parent) :
TodoItemsScanner(keywordList, parent)
{
QmlJS::ModelManagerInterface *model = QmlJS::ModelManagerInterface::instance();
connect(model, &QmlJS::ModelManagerInterface::documentUpdated,
this, &QmlJsTodoItemsScanner::documentUpdated, Qt::DirectConnection);
setParams(keywordList);
}
bool QmlJsTodoItemsScanner::shouldProcessFile(const Utils::FilePath &fileName)
{
QmlJS::ModelManagerInterface *modelManager = QmlJS::ModelManagerInterface::instance();
const QList<QmlJS::ModelManagerInterface::ProjectInfo> infoList = modelManager->projectInfos();
for (const QmlJS::ModelManagerInterface::ProjectInfo &info : infoList) {
if (info.sourceFiles.contains(fileName))
return true;
}
return false;
}
void QmlJsTodoItemsScanner::scannerParamsChanged()
{
// 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();
Utils::FilePaths filesToBeUpdated;
for (const QmlJS::ModelManagerInterface::ProjectInfo &info : modelManager->projectInfos())
filesToBeUpdated << info.sourceFiles;
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;
const QList<QmlJS::SourceLocation> sourceLocations = doc->engine()->comments();
for (const QmlJS::SourceLocation &sourceLocation : sourceLocations) {
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.
QStringList commentLines = source.split('\n', Qt::SkipEmptyParts);
quint32 startLine = sourceLocation.startLine;
for (int j = 0; j < commentLines.count(); ++j) {
const QString &commentLine = commentLines.at(j);
processCommentLine(doc->fileName().toUrlishString(), commentLine, startLine + j, itemList);
}
}
emit itemsFetched(doc->fileName().toUrlishString(), itemList);
}
}
}
|