forked from qt-creator/qt-creator
qmljs: handle js directives .pragma and .import
The directives .pragma and .import are not included in the AST. Their source code locations are not stored in any other place. As a result, when reformatting the source, they simply disappear. This patch keep track of their source code locations, so they are not removed when reformatting the source code. This patch contains also some modification in the lexer that should probably be ported to the qtdeclarative version. Task-number: QTCREATORBUG-13038 Change-Id: I5d568abf02d37a584d4d246939736aaec5af5053 Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
@@ -29,6 +29,7 @@
|
||||
#include "parser/qmljsast_p.h"
|
||||
#include "parser/qmljsastvisitor_p.h"
|
||||
#include "parser/qmljsengine_p.h"
|
||||
#include "parser/qmljslexer_p.h"
|
||||
|
||||
#include <QString>
|
||||
#include <QTextBlock>
|
||||
@@ -118,6 +119,23 @@ public:
|
||||
_hadEmptyLine = false;
|
||||
_binaryExpDepth = 0;
|
||||
|
||||
|
||||
// emit directives
|
||||
const QList<SourceLocation> &directives = _doc->jsDirectives();
|
||||
for (const auto &d: directives) {
|
||||
quint32 line = 1;
|
||||
int i = 0;
|
||||
while (line++ < d.startLine && i++ >= 0)
|
||||
i = _doc->source().indexOf(QChar('\n'), i);
|
||||
quint32 offset = static_cast<quint32>(i) + d.startColumn;
|
||||
int endline = _doc->source().indexOf('\n', static_cast<int>(offset) + 1);
|
||||
int end = endline == -1 ? _doc->source().length() : endline;
|
||||
quint32 length = static_cast<quint32>(end) - offset;
|
||||
out(SourceLocation(offset, length, d.startLine, d.startColumn));
|
||||
}
|
||||
if (!directives.isEmpty())
|
||||
newLine();
|
||||
|
||||
accept(node);
|
||||
|
||||
// emit the final comments
|
||||
|
||||
Reference in New Issue
Block a user