forked from qt-creator/qt-creator
qmljs: (QString -> Utils::FilePath)++
convert more QString containing paths to Utils::FilePath Change-Id: I1219d7d147993e48cfa641dc9bea72ab38c90f51 Reviewed-by: Tim Jenssen <tim.jenssen@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
committed by
Tim Jenssen
parent
0bb272d411
commit
fd89043de2
@@ -119,11 +119,11 @@ public:
|
||||
if (!url.isValid() && !url.isEmpty()) {
|
||||
setMessage(ErrInvalidUrl);
|
||||
} else {
|
||||
QString fileName = url.toLocalFile();
|
||||
Utils::FilePath fileName = Utils::FilePath::fromString(url.toLocalFile());
|
||||
if (!fileName.isEmpty()) {
|
||||
if (QFileInfo(fileName).isRelative())
|
||||
fileName = QString("/%1%2").arg(_doc->path(), fileName);
|
||||
if (!QFileInfo::exists(fileName))
|
||||
if (fileName.isRelativePath())
|
||||
fileName = _doc->path().pathAppended(fileName.path());
|
||||
if (!fileName.exists())
|
||||
setMessage(WarnFileOrDirectoryDoesNotExist);
|
||||
}
|
||||
}
|
||||
@@ -967,7 +967,7 @@ void Check::visitQmlObject(Node *ast, UiQualifiedId *typeId,
|
||||
if (checkTypeForDesignerSupport(typeId))
|
||||
addMessage(WarnUnsupportedTypeInVisualDesigner, typeErrorLocation, typeName);
|
||||
|
||||
if (typeId->next == nullptr && QFileInfo(_doc->fileName()).baseName() == typeName)
|
||||
if (typeId->next == nullptr && _doc->fileName().baseName() == typeName)
|
||||
addMessage(ErrTypeIsInstantiatedRecursively, typeErrorLocation, typeName);
|
||||
|
||||
if (checkTypeForQmlUiSupport(typeId))
|
||||
|
||||
@@ -87,20 +87,19 @@ using namespace QmlJS::AST;
|
||||
threads finish and new information becomes available.
|
||||
*/
|
||||
|
||||
Document::Document(const QString &fileName, Dialect language)
|
||||
Document::Document(const Utils::FilePath &fileName, Dialect language)
|
||||
: _engine(nullptr)
|
||||
, _ast(nullptr)
|
||||
, _bind(nullptr)
|
||||
, _fileName(QDir::cleanPath(fileName))
|
||||
, _fileName(fileName.cleanPath())
|
||||
, _editorRevision(0)
|
||||
, _language(language)
|
||||
, _parsedCorrectly(false)
|
||||
{
|
||||
QFileInfo fileInfo(fileName);
|
||||
_path = QDir::cleanPath(fileInfo.absolutePath());
|
||||
_path = fileName.absoluteFilePath().parentDir().cleanPath();
|
||||
|
||||
if (language.isQmlLikeLanguage()) {
|
||||
_componentName = fileInfo.baseName();
|
||||
_componentName = fileName.baseName();
|
||||
|
||||
if (! _componentName.isEmpty()) {
|
||||
// ### TODO: check the component name.
|
||||
@@ -120,7 +119,7 @@ Document::~Document()
|
||||
delete _engine;
|
||||
}
|
||||
|
||||
Document::MutablePtr Document::create(const QString &fileName, Dialect language)
|
||||
Document::MutablePtr Document::create(const Utils::FilePath &fileName, Dialect language)
|
||||
{
|
||||
Document::MutablePtr doc(new Document(fileName, language));
|
||||
doc->_ptr = doc;
|
||||
@@ -149,7 +148,7 @@ void Document::setLanguage(Dialect l)
|
||||
|
||||
QString Document::importId() const
|
||||
{
|
||||
return _fileName;
|
||||
return _fileName.toString();
|
||||
}
|
||||
|
||||
QByteArray Document::fingerprint() const
|
||||
@@ -213,13 +212,13 @@ void Document::setEditorRevision(int revision)
|
||||
_editorRevision = revision;
|
||||
}
|
||||
|
||||
QString Document::fileName() const
|
||||
Utils::FilePath Document::fileName() const
|
||||
{
|
||||
return _fileName;
|
||||
|
||||
}
|
||||
|
||||
QString Document::path() const
|
||||
Utils::FilePath Document::path() const
|
||||
{
|
||||
return _path;
|
||||
}
|
||||
@@ -244,7 +243,7 @@ class CollectDirectives : public Directives
|
||||
QList<SourceLocation> _locations;
|
||||
|
||||
public:
|
||||
CollectDirectives(const QString &documentPath)
|
||||
CollectDirectives(const Utils::FilePath &documentPath)
|
||||
: documentPath(documentPath)
|
||||
, isLibrary(false)
|
||||
|
||||
@@ -272,7 +271,7 @@ public:
|
||||
|
||||
virtual QList<SourceLocation> locations() { return _locations; }
|
||||
|
||||
const QString documentPath;
|
||||
const Utils::FilePath documentPath;
|
||||
bool isLibrary;
|
||||
QList<ImportInfo> imports;
|
||||
};
|
||||
@@ -471,29 +470,29 @@ Snapshot::~Snapshot()
|
||||
void Snapshot::insert(const Document::Ptr &document, bool allowInvalid)
|
||||
{
|
||||
if (document && (allowInvalid || document->qmlProgram() || document->jsProgram())) {
|
||||
const QString fileName = document->fileName();
|
||||
const QString path = document->path();
|
||||
const Utils::FilePath fileName = document->fileName();
|
||||
const Utils::FilePath path = document->path();
|
||||
remove(fileName);
|
||||
_documentsByPath[path].append(document);
|
||||
_documents.insert(fileName, document);
|
||||
CoreImport cImport;
|
||||
cImport.importId = document->importId();
|
||||
cImport.language = document->language();
|
||||
cImport.addPossibleExport(Export(ImportKey(ImportType::File, fileName),
|
||||
{}, true, QFileInfo(fileName).baseName()));
|
||||
cImport.addPossibleExport(
|
||||
Export(ImportKey(ImportType::File, fileName.toString()), {}, true, fileName.baseName()));
|
||||
cImport.fingerprint = document->fingerprint();
|
||||
_dependencies.addCoreImport(cImport);
|
||||
}
|
||||
}
|
||||
|
||||
void Snapshot::insertLibraryInfo(const QString &path, const LibraryInfo &info)
|
||||
void Snapshot::insertLibraryInfo(const Utils::FilePath &path, const LibraryInfo &info)
|
||||
{
|
||||
QTC_CHECK(!path.isEmpty());
|
||||
QTC_CHECK(info.fingerprint() == info.calculateFingerprint());
|
||||
_libraries.insert(QDir::cleanPath(path), info);
|
||||
_libraries.insert(path.cleanPath(), info);
|
||||
if (!info.wasFound()) return;
|
||||
CoreImport cImport;
|
||||
cImport.importId = path;
|
||||
cImport.importId = path.toString();
|
||||
cImport.language = Dialect::AnyLanguage;
|
||||
QSet<ImportKey> packages;
|
||||
foreach (const ModuleApiInfo &moduleInfo, info.moduleApis()) {
|
||||
@@ -509,7 +508,7 @@ void Snapshot::insertLibraryInfo(const QString &path, const LibraryInfo &info)
|
||||
}
|
||||
}
|
||||
|
||||
QStringList splitPath = path.split(QLatin1Char('/'));
|
||||
QStringList splitPath = path.path().split(QLatin1Char('/'));
|
||||
const QRegularExpression vNr(QLatin1String("^(.+)\\.([0-9]+)(?:\\.([0-9]+))?$"));
|
||||
const QRegularExpression safeName(QLatin1String("^[a-zA-Z_][[a-zA-Z0-9_]*$"));
|
||||
foreach (const ImportKey &importKey, packages) {
|
||||
@@ -526,12 +525,17 @@ void Snapshot::insertLibraryInfo(const QString &path, const LibraryInfo &info)
|
||||
break;
|
||||
ImportKey iKey(ImportType::Library, QStringList(myPath.mid(iPath)).join(QLatin1Char('.')),
|
||||
importKey.majorVersion, importKey.minorVersion);
|
||||
cImport.addPossibleExport(Export(iKey, (iPath == 1) ? QLatin1String("/") :
|
||||
QStringList(myPath.mid(0, iPath)).join(QLatin1Char('/')), true));
|
||||
Utils::FilePath newP(path);
|
||||
newP.setPath((iPath == 1)
|
||||
? QLatin1String("/")
|
||||
: QStringList(myPath.mid(0, iPath)).join(QLatin1Char('/')));
|
||||
cImport.addPossibleExport(Export(iKey, newP, true));
|
||||
}
|
||||
} else {
|
||||
QString requiredPath = QStringList(splitPath.mid(0, splitPath.size() - importKey.splitPath.size()))
|
||||
.join(QLatin1String("/"));
|
||||
Utils::FilePath requiredPath(path);
|
||||
requiredPath.setPath(
|
||||
QStringList(splitPath.mid(0, splitPath.size() - importKey.splitPath.size()))
|
||||
.join(QLatin1String("/")));
|
||||
cImport.addPossibleExport(Export(importKey, requiredPath, true));
|
||||
}
|
||||
}
|
||||
@@ -567,8 +571,11 @@ void Snapshot::insertLibraryInfo(const QString &path, const LibraryInfo &info)
|
||||
break;
|
||||
ImportKey iKey(ImportType::Library, QStringList(splitPath.mid(iPath)).join(QLatin1Char('.')),
|
||||
majorVersion, minorVersion);
|
||||
cImport.addPossibleExport(Export(iKey, (iPath == 1) ? QLatin1String("/") :
|
||||
QStringList(splitPath.mid(0, iPath)).join(QLatin1Char('/')), true));
|
||||
Utils::FilePath newP(path);
|
||||
newP.setPath((iPath == 1)
|
||||
? QLatin1String("/")
|
||||
: QStringList(splitPath.mid(0, iPath)).join(QLatin1Char('/')));
|
||||
cImport.addPossibleExport(Export(iKey, newP, true));
|
||||
}
|
||||
}
|
||||
foreach (const QmlDirParser::Component &component, info.components()) {
|
||||
@@ -580,11 +587,11 @@ void Snapshot::insertLibraryInfo(const QString &path, const LibraryInfo &info)
|
||||
_dependencies.addCoreImport(cImport);
|
||||
}
|
||||
|
||||
void Snapshot::remove(const QString &fileName)
|
||||
void Snapshot::remove(const Utils::FilePath &fileName)
|
||||
{
|
||||
Document::Ptr doc = _documents.value(fileName);
|
||||
if (!doc.isNull()) {
|
||||
const QString &path = doc->path();
|
||||
const Utils::FilePath &path = doc->path();
|
||||
|
||||
QList<Document::Ptr> docs = _documentsByPath.value(path);
|
||||
docs.removeAll(doc);
|
||||
@@ -604,9 +611,9 @@ QmlJS::ImportDependencies *Snapshot::importDependencies()
|
||||
return &_dependencies;
|
||||
}
|
||||
|
||||
Document::MutablePtr Snapshot::documentFromSource(
|
||||
const QString &code, const QString &fileName,
|
||||
Dialect language) const
|
||||
Document::MutablePtr Snapshot::documentFromSource(const QString &code,
|
||||
const Utils::FilePath &fileName,
|
||||
Dialect language) const
|
||||
{
|
||||
Document::MutablePtr newDoc = Document::create(fileName, language);
|
||||
|
||||
@@ -617,24 +624,19 @@ Document::MutablePtr Snapshot::documentFromSource(
|
||||
return newDoc;
|
||||
}
|
||||
|
||||
Document::Ptr Snapshot::document(const QString &fileName) const
|
||||
Document::Ptr Snapshot::document(const Utils::FilePath &fileName) const
|
||||
{
|
||||
return _documents.value(QDir::cleanPath(fileName));
|
||||
return _documents.value(fileName.cleanPath());
|
||||
}
|
||||
|
||||
QList<Document::Ptr> Snapshot::documentsInDirectory(const QString &path) const
|
||||
QList<Document::Ptr> Snapshot::documentsInDirectory(const Utils::FilePath &path) const
|
||||
{
|
||||
return _documentsByPath.value(QDir::cleanPath(path));
|
||||
}
|
||||
|
||||
LibraryInfo Snapshot::libraryInfo(const QString &path) const
|
||||
{
|
||||
return _libraries.value(QDir::cleanPath(path));
|
||||
return _documentsByPath.value(path.cleanPath());
|
||||
}
|
||||
|
||||
LibraryInfo Snapshot::libraryInfo(const Utils::FilePath &path) const
|
||||
{
|
||||
return _libraries.value(path.cleanPath().toString());
|
||||
return _libraries.value(path.cleanPath());
|
||||
}
|
||||
|
||||
void ModuleApiInfo::addToHash(QCryptographicHash &hash) const
|
||||
|
||||
@@ -53,12 +53,12 @@ public:
|
||||
typedef QSharedPointer<const Document> Ptr;
|
||||
typedef QSharedPointer<Document> MutablePtr;
|
||||
protected:
|
||||
Document(const QString &fileName, Dialect language);
|
||||
Document(const Utils::FilePath &fileName, Dialect language);
|
||||
|
||||
public:
|
||||
~Document();
|
||||
|
||||
static MutablePtr create(const QString &fileName, Dialect language);
|
||||
static MutablePtr create(const Utils::FilePath &fileName, Dialect language);
|
||||
|
||||
Document::Ptr ptr() const;
|
||||
|
||||
@@ -93,8 +93,8 @@ public:
|
||||
int editorRevision() const;
|
||||
void setEditorRevision(int revision);
|
||||
|
||||
QString fileName() const;
|
||||
QString path() const;
|
||||
Utils::FilePath fileName() const;
|
||||
Utils::FilePath path() const;
|
||||
QString componentName() const;
|
||||
|
||||
QList<SourceLocation> jsDirectives() const;
|
||||
@@ -107,8 +107,8 @@ private:
|
||||
AST::Node *_ast;
|
||||
Bind *_bind;
|
||||
QList<QmlJS::DiagnosticMessage> _diagnosticMessages;
|
||||
QString _fileName;
|
||||
QString _path;
|
||||
Utils::FilePath _fileName;
|
||||
Utils::FilePath _path;
|
||||
QString _componentName;
|
||||
QString _source;
|
||||
QList<SourceLocation> _jsdirectives;
|
||||
@@ -231,10 +231,10 @@ public:
|
||||
|
||||
class QMLJS_EXPORT Snapshot
|
||||
{
|
||||
typedef QHash<QString, Document::Ptr> Base;
|
||||
QHash<QString, Document::Ptr> _documents;
|
||||
QHash<QString, QList<Document::Ptr> > _documentsByPath;
|
||||
QHash<QString, LibraryInfo> _libraries;
|
||||
typedef QHash<Utils::FilePath, Document::Ptr> Base;
|
||||
QHash<Utils::FilePath, Document::Ptr> _documents;
|
||||
QHash<Utils::FilePath, QList<Document::Ptr>> _documentsByPath;
|
||||
QHash<Utils::FilePath, LibraryInfo> _libraries;
|
||||
ImportDependencies _dependencies;
|
||||
|
||||
public:
|
||||
@@ -248,20 +248,19 @@ public:
|
||||
const_iterator end() const { return _documents.end(); }
|
||||
|
||||
void insert(const Document::Ptr &document, bool allowInvalid = false);
|
||||
void insertLibraryInfo(const QString &path, const LibraryInfo &info);
|
||||
void remove(const QString &fileName);
|
||||
void insertLibraryInfo(const Utils::FilePath &path, const LibraryInfo &info);
|
||||
void remove(const Utils::FilePath &fileName);
|
||||
|
||||
const ImportDependencies *importDependencies() const;
|
||||
ImportDependencies *importDependencies();
|
||||
|
||||
Document::Ptr document(const QString &fileName) const;
|
||||
QList<Document::Ptr> documentsInDirectory(const QString &path) const;
|
||||
LibraryInfo libraryInfo(const QString &path) const; // FIXME: Remove
|
||||
Document::Ptr document(const Utils::FilePath &fileName) const;
|
||||
QList<Document::Ptr> documentsInDirectory(const Utils::FilePath &path) const;
|
||||
LibraryInfo libraryInfo(const Utils::FilePath &path) const;
|
||||
|
||||
Document::MutablePtr documentFromSource(const QString &code,
|
||||
const QString &fileName,
|
||||
Dialect language) const;
|
||||
const Utils::FilePath &fileName,
|
||||
Dialect language) const;
|
||||
};
|
||||
|
||||
} // namespace QmlJS
|
||||
|
||||
@@ -535,8 +535,14 @@ Export::Export()
|
||||
: intrinsic(false)
|
||||
{ }
|
||||
|
||||
Export::Export(ImportKey exportName, const QString &pathRequired, bool intrinsic, const QString &typeName)
|
||||
: exportName(exportName), pathRequired(pathRequired), typeName(typeName), intrinsic(intrinsic)
|
||||
Export::Export(ImportKey exportName,
|
||||
const Utils::FilePath &pathRequired,
|
||||
bool intrinsic,
|
||||
const QString &typeName)
|
||||
: exportName(exportName)
|
||||
, pathRequired(pathRequired)
|
||||
, typeName(typeName)
|
||||
, intrinsic(intrinsic)
|
||||
{ }
|
||||
|
||||
bool Export::visibleInVContext(const ViewerContext &vContext) const
|
||||
@@ -783,7 +789,8 @@ void ImportDependencies::addCoreImport(const CoreImport &import)
|
||||
if (importsLog().isDebugEnabled()) {
|
||||
QString msg = QString::fromLatin1("added import %1 for").arg(newImport.importId);
|
||||
foreach (const Export &e, newImport.possibleExports)
|
||||
msg += QString::fromLatin1("\n %1(%2)").arg(e.exportName.toString(), e.pathRequired);
|
||||
msg += QString::fromLatin1("\n %1(%2)")
|
||||
.arg(e.exportName.toString(), e.pathRequired.toUserOutput());
|
||||
qCDebug(importsLog) << msg;
|
||||
}
|
||||
}
|
||||
@@ -820,8 +827,10 @@ void ImportDependencies::removeImportCacheEntry(const ImportKey &importKey, cons
|
||||
m_importCache.remove(importKey);
|
||||
}
|
||||
|
||||
void ImportDependencies::addExport(const QString &importId, const ImportKey &importKey,
|
||||
const QString &requiredPath, const QString &typeName)
|
||||
void ImportDependencies::addExport(const QString &importId,
|
||||
const ImportKey &importKey,
|
||||
const Utils::FilePath &requiredPath,
|
||||
const QString &typeName)
|
||||
{
|
||||
if (!m_coreImports.contains(importId)) {
|
||||
CoreImport newImport(importId);
|
||||
@@ -838,8 +847,10 @@ void ImportDependencies::addExport(const QString &importId, const ImportKey &imp
|
||||
<< " (" << requiredPath << ")";
|
||||
}
|
||||
|
||||
void ImportDependencies::removeExport(const QString &importId, const ImportKey &importKey,
|
||||
const QString &requiredPath, const QString &typeName)
|
||||
void ImportDependencies::removeExport(const QString &importId,
|
||||
const ImportKey &importKey,
|
||||
const Utils::FilePath &requiredPath,
|
||||
const QString &typeName)
|
||||
{
|
||||
if (!m_coreImports.contains(importId)) {
|
||||
qCWarning(importsLog) << "non existing core import for removeExport(" << importId << ", "
|
||||
|
||||
@@ -128,10 +128,12 @@ class QMLJS_EXPORT Export
|
||||
public:
|
||||
static QString libraryTypeName();
|
||||
Export();
|
||||
Export(ImportKey exportName, const QString &pathRequired, bool intrinsic = false,
|
||||
Export(ImportKey exportName,
|
||||
const Utils::FilePath &pathRequired,
|
||||
bool intrinsic = false,
|
||||
const QString &typeName = libraryTypeName());
|
||||
ImportKey exportName;
|
||||
QString pathRequired;
|
||||
Utils::FilePath pathRequired;
|
||||
QString typeName;
|
||||
bool intrinsic;
|
||||
bool visibleInVContext(const ViewerContext &vContext) const;
|
||||
@@ -231,10 +233,14 @@ public:
|
||||
void addCoreImport(const CoreImport &import);
|
||||
void removeCoreImport(const QString &importId);
|
||||
|
||||
void addExport(const QString &importId, const ImportKey &importKey,
|
||||
const QString &requiredPath, const QString &typeName = Export::libraryTypeName());
|
||||
void removeExport(const QString &importId, const ImportKey &importKey,
|
||||
const QString &requiredPath, const QString &typeName = Export::libraryTypeName());
|
||||
void addExport(const QString &importId,
|
||||
const ImportKey &importKey,
|
||||
const Utils::FilePath &requiredPath,
|
||||
const QString &typeName = Export::libraryTypeName());
|
||||
void removeExport(const QString &importId,
|
||||
const ImportKey &importKey,
|
||||
const Utils::FilePath &requiredPath,
|
||||
const QString &typeName = Export::libraryTypeName());
|
||||
|
||||
void iterateOnLibraryImports(const ViewerContext &vContext,
|
||||
std::function<bool(const ImportMatchStrength &,
|
||||
|
||||
@@ -712,7 +712,7 @@ Value::~Value()
|
||||
{
|
||||
}
|
||||
|
||||
bool Value::getSourceLocation(QString *, int *, int *) const
|
||||
bool Value::getSourceLocation(Utils::FilePath *, int *, int *) const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -1872,7 +1872,7 @@ const ASTObjectValue *ASTObjectValue::asAstObjectValue() const
|
||||
return this;
|
||||
}
|
||||
|
||||
bool ASTObjectValue::getSourceLocation(QString *fileName, int *line, int *column) const
|
||||
bool ASTObjectValue::getSourceLocation(Utils::FilePath *fileName, int *line, int *column) const
|
||||
{
|
||||
*fileName = m_doc->fileName();
|
||||
*line = m_typeName->identifierToken.startLine;
|
||||
@@ -1962,7 +1962,7 @@ const Value *ASTVariableReference::value(ReferenceContext *referenceContext) con
|
||||
return res;
|
||||
}
|
||||
|
||||
bool ASTVariableReference::getSourceLocation(QString *fileName, int *line, int *column) const
|
||||
bool ASTVariableReference::getSourceLocation(Utils::FilePath *fileName, int *line, int *column) const
|
||||
{
|
||||
*fileName = m_doc->fileName();
|
||||
*line = m_ast->identifierToken.startLine;
|
||||
@@ -2053,7 +2053,7 @@ const ASTFunctionValue *ASTFunctionValue::asAstFunctionValue() const
|
||||
return this;
|
||||
}
|
||||
|
||||
bool ASTFunctionValue::getSourceLocation(QString *fileName, int *line, int *column) const
|
||||
bool ASTFunctionValue::getSourceLocation(Utils::FilePath *fileName, int *line, int *column) const
|
||||
{
|
||||
*fileName = m_doc->fileName();
|
||||
*line = m_ast->identifierToken.startLine;
|
||||
@@ -2110,7 +2110,7 @@ const ASTPropertyReference *ASTPropertyReference::asAstPropertyReference() const
|
||||
return this;
|
||||
}
|
||||
|
||||
bool ASTPropertyReference::getSourceLocation(QString *fileName, int *line, int *column) const
|
||||
bool ASTPropertyReference::getSourceLocation(Utils::FilePath *fileName, int *line, int *column) const
|
||||
{
|
||||
*fileName = m_doc->fileName();
|
||||
*line = m_ast->identifierToken.startLine;
|
||||
@@ -2205,7 +2205,7 @@ QString ASTSignal::argumentName(int index) const
|
||||
return param->name.toString();
|
||||
}
|
||||
|
||||
bool ASTSignal::getSourceLocation(QString *fileName, int *line, int *column) const
|
||||
bool ASTSignal::getSourceLocation(Utils::FilePath *fileName, int *line, int *column) const
|
||||
{
|
||||
*fileName = m_doc->fileName();
|
||||
*line = m_ast->identifierToken.startLine;
|
||||
@@ -2234,20 +2234,23 @@ ImportInfo ImportInfo::moduleImport(QString uri, ComponentVersion version,
|
||||
return info;
|
||||
}
|
||||
|
||||
ImportInfo ImportInfo::pathImport(const QString &docPath, const QString &path,
|
||||
ComponentVersion version, const QString &as, UiImport *ast)
|
||||
ImportInfo ImportInfo::pathImport(const Utils::FilePath &docPath,
|
||||
const QString &path,
|
||||
ComponentVersion version,
|
||||
const QString &as,
|
||||
UiImport *ast)
|
||||
{
|
||||
ImportInfo info;
|
||||
info.m_name = path;
|
||||
|
||||
QFileInfo importFileInfo(path);
|
||||
if (!importFileInfo.isAbsolute())
|
||||
importFileInfo = QFileInfo(docPath + QLatin1Char('/') + path);
|
||||
info.m_path = importFileInfo.absoluteFilePath();
|
||||
Utils::FilePath importFilePath = Utils::FilePath::fromString(path);
|
||||
if (!importFilePath.isAbsolutePath())
|
||||
importFilePath = docPath.pathAppended(path);
|
||||
info.m_path = importFilePath.absoluteFilePath().path();
|
||||
|
||||
if (importFileInfo.isFile()) {
|
||||
if (importFilePath.isFile()) {
|
||||
info.m_type = ImportType::File;
|
||||
} else if (importFileInfo.isDir()) {
|
||||
} else if (importFilePath.isDir()) {
|
||||
info.m_type = ImportType::Directory;
|
||||
} else if (path.startsWith(QLatin1String("qrc:"))) {
|
||||
ModelManagerInterface *model = ModelManagerInterface::instance();
|
||||
@@ -2258,11 +2261,11 @@ ImportInfo ImportInfo::pathImport(const QString &docPath, const QString &path,
|
||||
? ImportType::QrcDirectory
|
||||
: ImportType::QrcFile;
|
||||
} else {
|
||||
QDir dir(docPath);
|
||||
while (dir.dirName().startsWith("+"))
|
||||
dir.cdUp();
|
||||
Utils::FilePath dir = docPath;
|
||||
while (dir.fileName().startsWith("+"))
|
||||
dir = dir.parentDir();
|
||||
|
||||
const QString docPathStripped = dir.absolutePath();
|
||||
const Utils::FilePath docPathStripped = dir.absolutePath();
|
||||
if (docPathStripped != docPath)
|
||||
return pathImport(docPathStripped, path, version, as, ast);
|
||||
|
||||
|
||||
@@ -150,7 +150,7 @@ public:
|
||||
|
||||
virtual void accept(ValueVisitor *) const = 0;
|
||||
|
||||
virtual bool getSourceLocation(QString *fileName, int *line, int *column) const;
|
||||
virtual bool getSourceLocation(Utils::FilePath *fileName, int *line, int *column) const;
|
||||
};
|
||||
|
||||
template <typename RetTy> const RetTy *value_cast(const Value *)
|
||||
@@ -891,7 +891,7 @@ public:
|
||||
const AST::PatternElement *ast() const;
|
||||
private:
|
||||
const Value *value(ReferenceContext *referenceContext) const override;
|
||||
bool getSourceLocation(QString *fileName, int *line, int *column) const override;
|
||||
bool getSourceLocation(Utils::FilePath *fileName, int *line, int *column) const override;
|
||||
};
|
||||
|
||||
class QMLJS_EXPORT ASTFunctionValue: public FunctionValue
|
||||
@@ -912,7 +912,7 @@ public:
|
||||
bool isVariadic() const override;
|
||||
const ASTFunctionValue *asAstFunctionValue() const override;
|
||||
|
||||
bool getSourceLocation(QString *fileName, int *line, int *column) const override;
|
||||
bool getSourceLocation(Utils::FilePath *fileName, int *line, int *column) const override;
|
||||
};
|
||||
|
||||
class QMLJS_EXPORT ASTPropertyReference: public Reference
|
||||
@@ -930,7 +930,7 @@ public:
|
||||
AST::UiPublicMember *ast() const { return m_ast; }
|
||||
QString onChangedSlotName() const { return m_onChangedSlotName; }
|
||||
|
||||
bool getSourceLocation(QString *fileName, int *line, int *column) const override;
|
||||
bool getSourceLocation(Utils::FilePath *fileName, int *line, int *column) const override;
|
||||
|
||||
private:
|
||||
const Value *value(ReferenceContext *referenceContext) const override;
|
||||
@@ -959,7 +959,7 @@ public:
|
||||
QString argumentName(int index) const override;
|
||||
|
||||
// Value interface
|
||||
bool getSourceLocation(QString *fileName, int *line, int *column) const override;
|
||||
bool getSourceLocation(Utils::FilePath *fileName, int *line, int *column) const override;
|
||||
};
|
||||
|
||||
class QMLJS_EXPORT ASTObjectValue: public ObjectValue
|
||||
@@ -980,7 +980,7 @@ public:
|
||||
|
||||
const ASTObjectValue *asAstObjectValue() const override;
|
||||
|
||||
bool getSourceLocation(QString *fileName, int *line, int *column) const override;
|
||||
bool getSourceLocation(Utils::FilePath *fileName, int *line, int *column) const override;
|
||||
void processMembers(MemberProcessor *processor) const override;
|
||||
|
||||
QString defaultPropertyName() const;
|
||||
@@ -997,9 +997,11 @@ public:
|
||||
|
||||
static ImportInfo moduleImport(QString uri, LanguageUtils::ComponentVersion version,
|
||||
const QString &as, AST::UiImport *ast = nullptr);
|
||||
static ImportInfo pathImport(const QString &docPath, const QString &path,
|
||||
static ImportInfo pathImport(const Utils::FilePath &docPath,
|
||||
const QString &path,
|
||||
LanguageUtils::ComponentVersion version,
|
||||
const QString &as, AST::UiImport *ast = nullptr);
|
||||
const QString &as,
|
||||
AST::UiImport *ast = nullptr);
|
||||
static ImportInfo invalidImport(AST::UiImport *ast = nullptr);
|
||||
static ImportInfo implicitDirectoryImport(const QString &directory);
|
||||
static ImportInfo qrcDirectoryImport(const QString &directory);
|
||||
@@ -1041,7 +1043,7 @@ public:
|
||||
ImportInfo info;
|
||||
DependencyInfo::ConstPtr deps;
|
||||
// uri imports: path to library, else empty
|
||||
QString libraryPath;
|
||||
Utils::FilePath libraryPath;
|
||||
// whether the import succeeded
|
||||
bool valid;
|
||||
mutable bool used;
|
||||
|
||||
@@ -32,6 +32,8 @@
|
||||
#include "qmljsmodelmanagerinterface.h"
|
||||
#include "qmljsconstants.h"
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/filepath.h>
|
||||
#include <utils/porting.h>
|
||||
#include <utils/qrcparser.h>
|
||||
|
||||
@@ -93,14 +95,15 @@ public:
|
||||
const ImportInfo &importInfo);
|
||||
|
||||
bool importLibrary(const Document::Ptr &doc,
|
||||
const QString &libraryPath,
|
||||
Import *import, ObjectValue *targetObject,
|
||||
const QString &importPath = QString(),
|
||||
const Utils::FilePath &libraryPath,
|
||||
Import *import,
|
||||
ObjectValue *targetObject,
|
||||
const Utils::FilePath &importPath = Utils::FilePath(),
|
||||
bool optional = false);
|
||||
void loadQmldirComponents(ObjectValue *import,
|
||||
LanguageUtils::ComponentVersion version,
|
||||
const LibraryInfo &libraryInfo,
|
||||
const QString &libraryPath);
|
||||
const Utils::FilePath &libraryPath);
|
||||
void loadImplicitDirectoryImports(Imports *imports, const Document::Ptr &doc);
|
||||
void loadImplicitDefaultImports(Imports *imports);
|
||||
|
||||
@@ -113,8 +116,8 @@ private:
|
||||
|
||||
Snapshot m_snapshot;
|
||||
ValueOwner *m_valueOwner = nullptr;
|
||||
QStringList m_importPaths;
|
||||
QStringList m_applicationDirectories;
|
||||
QList<Utils::FilePath> m_importPaths;
|
||||
QList<Utils::FilePath> m_applicationDirectories;
|
||||
LibraryInfo m_builtins;
|
||||
ViewerContext m_vContext;
|
||||
|
||||
@@ -124,7 +127,7 @@ private:
|
||||
Document::Ptr document;
|
||||
|
||||
QList<DiagnosticMessage> *diagnosticMessages = nullptr;
|
||||
QHash<QString, QList<DiagnosticMessage>> *allDiagnosticMessages = nullptr;
|
||||
QHash<Utils::FilePath, QList<DiagnosticMessage>> *allDiagnosticMessages = nullptr;
|
||||
};
|
||||
|
||||
/*!
|
||||
@@ -182,7 +185,7 @@ Link::Link(const Snapshot &snapshot, const ViewerContext &vContext, const Librar
|
||||
fi.reportFinished();
|
||||
}
|
||||
|
||||
ContextPtr Link::operator()(QHash<QString, QList<DiagnosticMessage> > *messages)
|
||||
ContextPtr Link::operator()(QHash<Utils::FilePath, QList<DiagnosticMessage>> *messages)
|
||||
{
|
||||
d->allDiagnosticMessages = messages;
|
||||
return Context::create(d->m_snapshot, d->m_valueOwner, d->linkImports(), d->m_vContext);
|
||||
@@ -339,7 +342,8 @@ Import LinkPrivate::importFileOrDirectory(const Document::Ptr &doc, const Import
|
||||
import.object = nullptr;
|
||||
import.valid = true;
|
||||
|
||||
QString path = importInfo.path();
|
||||
QString pathStr = importInfo.path();
|
||||
Utils::FilePath path = Utils::FilePath::fromString(pathStr);
|
||||
|
||||
if (importInfo.type() == ImportType::Directory
|
||||
|| importInfo.type() == ImportType::ImplicitDirectory) {
|
||||
@@ -360,11 +364,15 @@ Import LinkPrivate::importFileOrDirectory(const Document::Ptr &doc, const Import
|
||||
} else if (importInfo.type() == ImportType::QrcFile) {
|
||||
QLocale locale;
|
||||
QStringList filePaths = ModelManagerInterface::instance()
|
||||
->filesAtQrcPath(path, &locale, nullptr, ModelManagerInterface::ActiveQrcResources);
|
||||
->filesAtQrcPath(pathStr,
|
||||
&locale,
|
||||
nullptr,
|
||||
ModelManagerInterface::ActiveQrcResources);
|
||||
if (filePaths.isEmpty())
|
||||
filePaths = ModelManagerInterface::instance()->filesAtQrcPath(path);
|
||||
filePaths = ModelManagerInterface::instance()->filesAtQrcPath(pathStr);
|
||||
if (!filePaths.isEmpty()) {
|
||||
if (Document::Ptr importedDoc = m_snapshot.document(filePaths.at(0)))
|
||||
if (Document::Ptr importedDoc = m_snapshot.document(
|
||||
Utils::FilePath::fromString(filePaths.at(0))))
|
||||
import.object = importedDoc->bind()->rootObjectValue();
|
||||
}
|
||||
} else if (importInfo.type() == ImportType::QrcDirectory){
|
||||
@@ -372,11 +380,13 @@ Import LinkPrivate::importFileOrDirectory(const Document::Ptr &doc, const Import
|
||||
|
||||
importLibrary(doc, path, &import, import.object);
|
||||
|
||||
const QMap<QString, QStringList> paths
|
||||
= ModelManagerInterface::instance()->filesInQrcPath(path);
|
||||
const QMap<QString, QStringList> paths = ModelManagerInterface::instance()->filesInQrcPath(
|
||||
pathStr);
|
||||
for (auto iter = paths.cbegin(), end = paths.cend(); iter != end; ++iter) {
|
||||
if (ModelManagerInterface::guessLanguageOfFile(iter.key()).isQmlLikeLanguage()) {
|
||||
Document::Ptr importedDoc = m_snapshot.document(iter.value().at(0));
|
||||
if (ModelManagerInterface::guessLanguageOfFile(Utils::FilePath::fromString(iter.key()))
|
||||
.isQmlLikeLanguage()) {
|
||||
Document::Ptr importedDoc = m_snapshot.document(
|
||||
Utils::FilePath::fromString(iter.value().at(0)));
|
||||
if (importedDoc && importedDoc->bind()->rootObjectValue()) {
|
||||
const QString targetName = QFileInfo(iter.key()).baseName();
|
||||
import.object->setMember(targetName, importedDoc->bind()->rootObjectValue());
|
||||
@@ -414,21 +424,24 @@ Import LinkPrivate::importNonFile(const Document::Ptr &doc, const ImportInfo &im
|
||||
const QString packageName = importInfo.name();
|
||||
const ComponentVersion version = importInfo.version();
|
||||
|
||||
QStringList libraryPaths = modulePaths(packageName, version.toString(), m_importPaths + m_applicationDirectories);
|
||||
QList<Utils::FilePath> libraryPaths = modulePaths(packageName,
|
||||
version.toString(),
|
||||
m_importPaths + m_applicationDirectories);
|
||||
|
||||
bool importFound = false;
|
||||
for (const QString &libPath : libraryPaths) {
|
||||
for (const Utils::FilePath &libPath : libraryPaths) {
|
||||
importFound = !libPath.isEmpty() && importLibrary(doc, libPath, &import, import.object);
|
||||
if (importFound)
|
||||
break;
|
||||
}
|
||||
|
||||
if (!importFound) {
|
||||
for (const QString &dir : qAsConst(m_applicationDirectories)) {
|
||||
QDirIterator it(dir, QStringList { "*.qmltypes" }, QDir::Files);
|
||||
for (const Utils::FilePath &dir : qAsConst(m_applicationDirectories)) {
|
||||
auto qmltypes = dir.dirEntries(
|
||||
Utils::FileFilter(QStringList{"*.qmltypes"}, QDir::Files));
|
||||
|
||||
// This adds the types to the C++ types, to be found below if applicable.
|
||||
if (it.hasNext())
|
||||
if (!qmltypes.isEmpty())
|
||||
importLibrary(doc, dir, &import, import.object);
|
||||
}
|
||||
}
|
||||
@@ -455,8 +468,9 @@ Import LinkPrivate::importNonFile(const Document::Ptr &doc, const ImportInfo &im
|
||||
|
||||
if (!importFound && importInfo.ast()) {
|
||||
import.valid = false;
|
||||
error(doc, locationFromRange(importInfo.ast()->firstSourceLocation(),
|
||||
importInfo.ast()->lastSourceLocation()),
|
||||
error(doc,
|
||||
locationFromRange(importInfo.ast()->firstSourceLocation(),
|
||||
importInfo.ast()->lastSourceLocation()),
|
||||
Link::tr(
|
||||
"QML module not found (%1).\n\n"
|
||||
"Import paths:\n"
|
||||
@@ -467,19 +481,21 @@ Import LinkPrivate::importNonFile(const Document::Ptr &doc, const ImportInfo &im
|
||||
"For qmlproject projects, use the importPaths property to add import paths.\n"
|
||||
"For CMake projects, make sure QML_IMPORT_PATH variable is in CMakeCache.txt.\n"
|
||||
"For qmlRegister... calls, make sure that you define the Module URI as a string literal.\n")
|
||||
.arg(importInfo.name(), m_importPaths.join(QLatin1Char('\n'))));
|
||||
.arg(importInfo.name(),
|
||||
Utils::transform(m_importPaths, [](const Utils::FilePath &p) {
|
||||
return p.toString();
|
||||
}).join("\n")));
|
||||
}
|
||||
|
||||
return import;
|
||||
}
|
||||
|
||||
bool LinkPrivate::importLibrary(const Document::Ptr &doc,
|
||||
const QString &libraryPath,
|
||||
const Utils::FilePath &libraryPath,
|
||||
Import *import,
|
||||
ObjectValue *targetObject,
|
||||
const QString &importPath,
|
||||
bool optional
|
||||
)
|
||||
const Utils::FilePath &importPath,
|
||||
bool optional)
|
||||
{
|
||||
const ImportInfo &importInfo = import->info;
|
||||
|
||||
@@ -513,25 +529,36 @@ bool LinkPrivate::importLibrary(const Document::Ptr &doc,
|
||||
subImport.valid = true;
|
||||
subImport.info = ImportInfo::moduleImport(importName, vNow, importInfo.as(), importInfo.ast());
|
||||
|
||||
const QStringList libraryPaths = modulePaths(importName, vNow.toString(), m_importPaths);
|
||||
const QList<Utils::FilePath> libraryPaths = modulePaths(importName,
|
||||
vNow.toString(),
|
||||
m_importPaths);
|
||||
subImport.libraryPath = libraryPaths.value(0); // first is the best match
|
||||
|
||||
bool subImportFound = importLibrary(doc, subImport.libraryPath, &subImport, targetObject, importPath, true);
|
||||
|
||||
if (!subImportFound && errorLoc.isValid()) {
|
||||
import->valid = false;
|
||||
if (!(optional || (toImport.flags & QmlDirParser::Import::Optional)))
|
||||
error(doc, errorLoc,
|
||||
Link::tr(
|
||||
"Implicit import '%1' of QML module '%2' not found.\n\n"
|
||||
"Import paths:\n"
|
||||
"%3\n\n"
|
||||
"For qmake projects, use the QML_IMPORT_PATH variable to add import paths.\n"
|
||||
"For Qbs projects, declare and set a qmlImportPaths property in your product "
|
||||
"to add import paths.\n"
|
||||
"For qmlproject projects, use the importPaths property to add import paths.\n"
|
||||
"For CMake projects, make sure QML_IMPORT_PATH variable is in CMakeCache.txt.\n")
|
||||
.arg(importName, importInfo.name(), m_importPaths.join(QLatin1Char('\n'))));
|
||||
if (!(optional || (toImport.flags & QmlDirParser::Import::Optional))) {
|
||||
error(doc,
|
||||
errorLoc,
|
||||
Link::tr("Implicit import '%1' of QML module '%2' not found.\n\n"
|
||||
"Import paths:\n"
|
||||
"%3\n\n"
|
||||
"For qmake projects, use the QML_IMPORT_PATH variable to add import "
|
||||
"paths.\n"
|
||||
"For Qbs projects, declare and set a qmlImportPaths property in "
|
||||
"your product "
|
||||
"to add import paths.\n"
|
||||
"For qmlproject projects, use the importPaths property to add "
|
||||
"import paths.\n"
|
||||
"For CMake projects, make sure QML_IMPORT_PATH variable is in "
|
||||
"CMakeCache.txt.\n")
|
||||
.arg(importName,
|
||||
importInfo.name(),
|
||||
Utils::transform(m_importPaths, [](const Utils::FilePath &p) {
|
||||
return p.toString();
|
||||
}).join(QLatin1Char('\n'))));
|
||||
}
|
||||
} else if (!subImport.valid) {
|
||||
import->valid = false;
|
||||
}
|
||||
@@ -576,7 +603,9 @@ bool LinkPrivate::importLibrary(const Document::Ptr &doc,
|
||||
}
|
||||
} else {
|
||||
const QString packageName = importInfo.name();
|
||||
m_valueOwner->cppQmlTypes().load(libraryPath, libraryInfo.metaObjects(), packageName);
|
||||
m_valueOwner->cppQmlTypes().load(libraryPath.toString(),
|
||||
libraryInfo.metaObjects(),
|
||||
packageName);
|
||||
const auto objects = m_valueOwner->cppQmlTypes().createObjectsForImport(packageName,
|
||||
version);
|
||||
for (const CppComponentValue *object : objects)
|
||||
@@ -627,8 +656,10 @@ void LinkPrivate::appendDiagnostic(const Document::Ptr &doc, const DiagnosticMes
|
||||
(*allDiagnosticMessages)[doc->fileName()].append(message);
|
||||
}
|
||||
|
||||
void LinkPrivate::loadQmldirComponents(ObjectValue *import, ComponentVersion version,
|
||||
const LibraryInfo &libraryInfo, const QString &libraryPath)
|
||||
void LinkPrivate::loadQmldirComponents(ObjectValue *import,
|
||||
ComponentVersion version,
|
||||
const LibraryInfo &libraryInfo,
|
||||
const Utils::FilePath &libraryPath)
|
||||
{
|
||||
// if the version isn't valid, import the latest
|
||||
if (!version.isValid())
|
||||
@@ -647,7 +678,7 @@ void LinkPrivate::loadQmldirComponents(ObjectValue *import, ComponentVersion ver
|
||||
|
||||
importedTypes.insert(component.typeName);
|
||||
if (Document::Ptr importedDoc = m_snapshot.document(
|
||||
libraryPath + QLatin1Char('/') + component.fileName)) {
|
||||
libraryPath.pathAppended(component.fileName))) {
|
||||
if (ObjectValue *v = importedDoc->bind()->rootObjectValue())
|
||||
import->setMember(component.typeName, v);
|
||||
}
|
||||
@@ -667,7 +698,7 @@ void LinkPrivate::loadImplicitDirectoryImports(Imports *imports, const Document:
|
||||
imports->append(directoryImport);
|
||||
};
|
||||
|
||||
processImport(ImportInfo::implicitDirectoryImport(doc->path()));
|
||||
processImport(ImportInfo::implicitDirectoryImport(doc->path().path()));
|
||||
const auto qrcPaths = ModelManagerInterface::instance()->qrcPathsForFile(doc->fileName());
|
||||
for (const QString &path : qrcPaths) {
|
||||
processImport(ImportInfo::qrcDirectoryImport(
|
||||
|
||||
@@ -49,7 +49,7 @@ public:
|
||||
Link(const Snapshot &snapshot, const ViewerContext &vContext, const LibraryInfo &builtins);
|
||||
|
||||
// Link all documents in snapshot, collecting all diagnostic messages (if messages != 0)
|
||||
ContextPtr operator()(QHash<QString, QList<DiagnosticMessage>> *messages = nullptr);
|
||||
ContextPtr operator()(QHash<Utils::FilePath, QList<DiagnosticMessage>> *messages = nullptr);
|
||||
|
||||
// Link all documents in snapshot, appending the diagnostic messages
|
||||
// for 'doc' in 'messages'
|
||||
|
||||
@@ -84,21 +84,21 @@ static ModelManagerInterface *g_instance = nullptr;
|
||||
static QMutex g_instanceMutex;
|
||||
static const char *qtQuickUISuffix = "ui.qml";
|
||||
|
||||
static void maybeAddPath(ViewerContext &context, const QString &path)
|
||||
static void maybeAddPath(ViewerContext &context, const Utils::FilePath &path)
|
||||
{
|
||||
if (!path.isEmpty() && !context.paths.contains(path))
|
||||
context.paths.append(path);
|
||||
}
|
||||
|
||||
static QStringList environmentImportPaths()
|
||||
static QList<Utils::FilePath> environmentImportPaths()
|
||||
{
|
||||
QStringList paths;
|
||||
QList<Utils::FilePath> paths;
|
||||
|
||||
const QStringList importPaths = QString::fromLocal8Bit(qgetenv("QML_IMPORT_PATH")).split(
|
||||
Utils::HostOsInfo::pathListSeparator(), Qt::SkipEmptyParts);
|
||||
|
||||
for (const QString &path : importPaths) {
|
||||
const QString canonicalPath = QDir(path).canonicalPath();
|
||||
const Utils::FilePath canonicalPath = Utils::FilePath::fromString(path).canonicalPath();
|
||||
if (!canonicalPath.isEmpty() && !paths.contains(canonicalPath))
|
||||
paths.append(canonicalPath);
|
||||
}
|
||||
@@ -177,15 +177,14 @@ static QHash<QString, Dialect> defaultLanguageMapping()
|
||||
return res;
|
||||
}
|
||||
|
||||
Dialect ModelManagerInterface::guessLanguageOfFile(const QString &fileName)
|
||||
Dialect ModelManagerInterface::guessLanguageOfFile(const Utils::FilePath &fileName)
|
||||
{
|
||||
QHash<QString, Dialect> lMapping;
|
||||
if (instance())
|
||||
lMapping = instance()->languageForSuffix();
|
||||
else
|
||||
lMapping = defaultLanguageMapping();
|
||||
const QFileInfo info(fileName);
|
||||
QString fileSuffix = info.suffix();
|
||||
QString fileSuffix = fileName.suffix();
|
||||
|
||||
/*
|
||||
* I was reluctant to use complete suffix in all cases, because it is a huge
|
||||
@@ -193,7 +192,7 @@ Dialect ModelManagerInterface::guessLanguageOfFile(const QString &fileName)
|
||||
*/
|
||||
|
||||
if (fileSuffix == QLatin1String("qml"))
|
||||
fileSuffix = info.completeSuffix();
|
||||
fileSuffix = fileName.completeSuffix();
|
||||
|
||||
return lMapping.value(fileSuffix, Dialect::NoLanguage);
|
||||
}
|
||||
@@ -326,7 +325,7 @@ Snapshot ModelManagerInterface::newestSnapshot() const
|
||||
return m_newestSnapshot;
|
||||
}
|
||||
|
||||
void ModelManagerInterface::updateSourceFiles(const QStringList &files,
|
||||
void ModelManagerInterface::updateSourceFiles(const QList<Utils::FilePath> &files,
|
||||
bool emitDocumentOnDiskChanged)
|
||||
{
|
||||
if (m_indexerDisabled)
|
||||
@@ -334,7 +333,7 @@ void ModelManagerInterface::updateSourceFiles(const QStringList &files,
|
||||
refreshSourceFiles(files, emitDocumentOnDiskChanged);
|
||||
}
|
||||
|
||||
QFuture<void> ModelManagerInterface::refreshSourceFiles(const QStringList &sourceFiles,
|
||||
QFuture<void> ModelManagerInterface::refreshSourceFiles(const QList<Utils::FilePath> &sourceFiles,
|
||||
bool emitDocumentOnDiskChanged)
|
||||
{
|
||||
if (sourceFiles.isEmpty())
|
||||
@@ -365,21 +364,23 @@ QFuture<void> ModelManagerInterface::refreshSourceFiles(const QStringList &sourc
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void ModelManagerInterface::fileChangedOnDisk(const QString &path)
|
||||
void ModelManagerInterface::fileChangedOnDisk(const Utils::FilePath &path)
|
||||
{
|
||||
addFuture(Utils::runAsync(&ModelManagerInterface::parse,
|
||||
workingCopyInternal(), QStringList(path),
|
||||
this, Dialect(Dialect::AnyLanguage), true));
|
||||
workingCopyInternal(),
|
||||
FilePaths({path}),
|
||||
this,
|
||||
Dialect(Dialect::AnyLanguage),
|
||||
true));
|
||||
}
|
||||
|
||||
void ModelManagerInterface::removeFiles(const QStringList &files)
|
||||
void ModelManagerInterface::removeFiles(const QList<Utils::FilePath> &files)
|
||||
{
|
||||
emit aboutToRemoveFiles(files);
|
||||
|
||||
QMutexLocker locker(&m_mutex);
|
||||
|
||||
for (const QString &file : files) {
|
||||
for (const Utils::FilePath &file : files) {
|
||||
m_validSnapshot.remove(file);
|
||||
m_newestSnapshot.remove(file);
|
||||
}
|
||||
@@ -389,8 +390,8 @@ namespace {
|
||||
bool pInfoLessThanActive(const ModelManagerInterface::ProjectInfo &p1,
|
||||
const ModelManagerInterface::ProjectInfo &p2)
|
||||
{
|
||||
QStringList s1 = p1.activeResourceFiles;
|
||||
QStringList s2 = p2.activeResourceFiles;
|
||||
QList<Utils::FilePath> s1 = p1.activeResourceFiles;
|
||||
QList<Utils::FilePath> s2 = p2.activeResourceFiles;
|
||||
if (s1.size() < s2.size())
|
||||
return true;
|
||||
if (s1.size() > s2.size())
|
||||
@@ -407,8 +408,8 @@ bool pInfoLessThanActive(const ModelManagerInterface::ProjectInfo &p1,
|
||||
bool pInfoLessThanAll(const ModelManagerInterface::ProjectInfo &p1,
|
||||
const ModelManagerInterface::ProjectInfo &p2)
|
||||
{
|
||||
QStringList s1 = p1.allResourceFiles;
|
||||
QStringList s2 = p2.allResourceFiles;
|
||||
QList<Utils::FilePath> s1 = p1.allResourceFiles;
|
||||
QList<Utils::FilePath> s2 = p2.allResourceFiles;
|
||||
if (s1.size() < s2.size())
|
||||
return true;
|
||||
if (s1.size() > s2.size())
|
||||
@@ -446,11 +447,10 @@ bool pInfoLessThanImports(const ModelManagerInterface::ProjectInfo &p1,
|
||||
|
||||
}
|
||||
|
||||
static QList<Utils::FilePath> generatedQrc(QStringList applicationDirectories)
|
||||
static QList<Utils::FilePath> generatedQrc(QList<Utils::FilePath> applicationDirectories)
|
||||
{
|
||||
QList<Utils::FilePath> res;
|
||||
for (const QString &pathStr : applicationDirectories) {
|
||||
Utils::FilePath path = Utils::FilePath::fromString(pathStr);
|
||||
for (const Utils::FilePath &path : applicationDirectories) {
|
||||
Utils::FilePath generatedQrcDir = path.pathAppended(".rcc");
|
||||
if (generatedQrcDir.isReadableDir()) {
|
||||
for (const Utils::FilePath & qrcPath: generatedQrcDir.dirEntries(FileFilter(QStringList({QStringLiteral(u"*.qrc")}), QDir::Files)))
|
||||
@@ -477,15 +477,14 @@ void ModelManagerInterface::iterateQrcFiles(
|
||||
|
||||
QSet<Utils::FilePath> pathsChecked;
|
||||
for (const ModelManagerInterface::ProjectInfo &pInfo : qAsConst(pInfos)) {
|
||||
QStringList qrcFilePaths;
|
||||
QList<Utils::FilePath> qrcFilePaths;
|
||||
if (resources == ActiveQrcResources)
|
||||
qrcFilePaths = pInfo.activeResourceFiles;
|
||||
else
|
||||
qrcFilePaths = pInfo.allResourceFiles;
|
||||
for (const Utils::FilePath &p : generatedQrc(pInfo.applicationDirectories))
|
||||
qrcFilePaths.append(p.toString());
|
||||
for (const QString &qrcFilePathStr : qAsConst(qrcFilePaths)) {
|
||||
auto qrcFilePath = Utils::FilePath::fromString(qrcFilePathStr);
|
||||
qrcFilePaths.append(p);
|
||||
for (const Utils::FilePath &qrcFilePath : qAsConst(qrcFilePaths)) {
|
||||
if (pathsChecked.contains(qrcFilePath))
|
||||
continue;
|
||||
pathsChecked.insert(qrcFilePath);
|
||||
@@ -497,13 +496,14 @@ void ModelManagerInterface::iterateQrcFiles(
|
||||
}
|
||||
}
|
||||
|
||||
QStringList ModelManagerInterface::qrcPathsForFile(const QString &file, const QLocale *locale,
|
||||
QStringList ModelManagerInterface::qrcPathsForFile(const Utils::FilePath &file,
|
||||
const QLocale *locale,
|
||||
ProjectExplorer::Project *project,
|
||||
QrcResourceSelector resources)
|
||||
{
|
||||
QStringList res;
|
||||
iterateQrcFiles(project, resources, [&](const QrcParser::ConstPtr &qrcFile) {
|
||||
qrcFile->collectResourceFilesForSourceFile(file, &res, locale);
|
||||
qrcFile->collectResourceFilesForSourceFile(file.toString(), &res, locale);
|
||||
});
|
||||
return res;
|
||||
}
|
||||
@@ -579,21 +579,20 @@ void ModelManagerInterface::updateProjectInfo(const ProjectInfo &pinfo, ProjectE
|
||||
updateImportPaths();
|
||||
|
||||
// remove files that are no longer in the project and have been deleted
|
||||
QStringList deletedFiles;
|
||||
for (const QString &oldFile : qAsConst(oldInfo.sourceFiles)) {
|
||||
if (snapshot.document(oldFile)
|
||||
&& !pinfo.sourceFiles.contains(oldFile)
|
||||
&& !QFile::exists(oldFile)) {
|
||||
QList<Utils::FilePath> deletedFiles;
|
||||
for (const Utils::FilePath &oldFile : qAsConst(oldInfo.sourceFiles)) {
|
||||
if (snapshot.document(oldFile) && !pinfo.sourceFiles.contains(oldFile)
|
||||
&& !oldFile.exists()) {
|
||||
deletedFiles += oldFile;
|
||||
}
|
||||
}
|
||||
removeFiles(deletedFiles);
|
||||
for (const QString &oldFile : qAsConst(deletedFiles))
|
||||
for (const Utils::FilePath &oldFile : qAsConst(deletedFiles))
|
||||
m_fileToProject.remove(oldFile, p);
|
||||
|
||||
// parse any files not yet in the snapshot
|
||||
QStringList newFiles;
|
||||
for (const QString &file : qAsConst(pinfo.sourceFiles)) {
|
||||
QList<Utils::FilePath> newFiles;
|
||||
for (const Utils::FilePath &file : qAsConst(pinfo.sourceFiles)) {
|
||||
if (!m_fileToProject.contains(file, p))
|
||||
m_fileToProject.insert(file, p);
|
||||
if (!snapshot.document(file))
|
||||
@@ -604,12 +603,12 @@ void ModelManagerInterface::updateProjectInfo(const ProjectInfo &pinfo, ProjectE
|
||||
|
||||
// update qrc cache
|
||||
m_qrcContents = pinfo.resourceFileContents;
|
||||
for (const QString &newQrc : qAsConst(pinfo.allResourceFiles))
|
||||
m_qrcCache.addPath(newQrc, m_qrcContents.value(newQrc));
|
||||
for (const Utils::FilePath &newQrc : qAsConst(pinfo.allResourceFiles))
|
||||
m_qrcCache.addPath(newQrc.toString(), m_qrcContents.value(newQrc));
|
||||
for (const Utils::FilePath &newQrc : generatedQrc(pinfo.applicationDirectories))
|
||||
m_qrcCache.addPath(newQrc.toString(), m_qrcContents.value(newQrc.toString()));
|
||||
for (const QString &oldQrc : qAsConst(oldInfo.allResourceFiles))
|
||||
m_qrcCache.removePath(oldQrc);
|
||||
m_qrcCache.addPath(newQrc.toString(), m_qrcContents.value(newQrc));
|
||||
for (const Utils::FilePath &oldQrc : qAsConst(oldInfo.allResourceFiles))
|
||||
m_qrcCache.removePath(oldQrc.toString());
|
||||
|
||||
m_pluginDumper->loadBuiltinTypes(pinfo);
|
||||
emit projectInfoUpdated(pinfo);
|
||||
@@ -635,7 +634,7 @@ void ModelManagerInterface::removeProjectInfo(ProjectExplorer::Project *project)
|
||||
\note Project pointer will be empty
|
||||
*/
|
||||
ModelManagerInterface::ProjectInfo ModelManagerInterface::projectInfoForPath(
|
||||
const QString &path) const
|
||||
const Utils::FilePath &path) const
|
||||
{
|
||||
ProjectInfo res;
|
||||
const auto allProjectInfos = allProjectInfosForPath(path);
|
||||
@@ -659,16 +658,14 @@ ModelManagerInterface::ProjectInfo ModelManagerInterface::projectInfoForPath(
|
||||
Returns list of project infos for \a path
|
||||
*/
|
||||
QList<ModelManagerInterface::ProjectInfo> ModelManagerInterface::allProjectInfosForPath(
|
||||
const QString &path) const
|
||||
const Utils::FilePath &path) const
|
||||
{
|
||||
QList<ProjectExplorer::Project *> projects;
|
||||
{
|
||||
QMutexLocker locker(&m_mutex);
|
||||
projects = m_fileToProject.values(path);
|
||||
if (projects.isEmpty()) {
|
||||
QFileInfo fInfo(path);
|
||||
projects = m_fileToProject.values(fInfo.canonicalFilePath());
|
||||
}
|
||||
if (projects.isEmpty())
|
||||
projects = m_fileToProject.values(path.canonicalPath());
|
||||
}
|
||||
QList<ProjectInfo> infos;
|
||||
for (ProjectExplorer::Project *project : qAsConst(projects)) {
|
||||
@@ -689,9 +686,9 @@ void ModelManagerInterface::emitDocumentChangedOnDisk(Document::Ptr doc)
|
||||
emit documentChangedOnDisk(std::move(doc));
|
||||
}
|
||||
|
||||
void ModelManagerInterface::updateQrcFile(const QString &path)
|
||||
void ModelManagerInterface::updateQrcFile(const Utils::FilePath &path)
|
||||
{
|
||||
m_qrcCache.updatePath(path, m_qrcContents.value(path));
|
||||
m_qrcCache.updatePath(path.toString(), m_qrcContents.value(path));
|
||||
}
|
||||
|
||||
void ModelManagerInterface::updateDocument(const Document::Ptr &doc)
|
||||
@@ -711,30 +708,30 @@ void ModelManagerInterface::updateLibraryInfo(const FilePath &path, const Librar
|
||||
|
||||
{
|
||||
QMutexLocker locker(&m_mutex);
|
||||
m_validSnapshot.insertLibraryInfo(path.toString(), info);
|
||||
m_newestSnapshot.insertLibraryInfo(path.toString(), info);
|
||||
m_validSnapshot.insertLibraryInfo(path, info);
|
||||
m_newestSnapshot.insertLibraryInfo(path, info);
|
||||
}
|
||||
// only emit if we got new useful information
|
||||
if (info.isValid())
|
||||
emit libraryInfoUpdated(path.toString(), info);
|
||||
emit libraryInfoUpdated(path, info);
|
||||
}
|
||||
|
||||
static QStringList filesInDirectoryForLanguages(const QString &path,
|
||||
const QList<Dialect> &languages)
|
||||
static QList<Utils::FilePath> filesInDirectoryForLanguages(const Utils::FilePath &path,
|
||||
const QList<Dialect> &languages)
|
||||
{
|
||||
const QStringList pattern = ModelManagerInterface::globPatternsForLanguages(languages);
|
||||
QStringList files;
|
||||
QList<Utils::FilePath> files;
|
||||
|
||||
const QDir dir(path);
|
||||
const auto entries = dir.entryInfoList(pattern, QDir::Files);
|
||||
for (const QFileInfo &fi : entries)
|
||||
files += fi.absoluteFilePath();
|
||||
for (const Utils::FilePath &p : path.dirEntries(FileFilter(pattern, QDir::Files)))
|
||||
files.append(p.absoluteFilePath());
|
||||
|
||||
return files;
|
||||
}
|
||||
|
||||
static void findNewImplicitImports(const Document::Ptr &doc, const Snapshot &snapshot,
|
||||
QStringList *importedFiles, QSet<QString> *scannedPaths)
|
||||
static void findNewImplicitImports(const Document::Ptr &doc,
|
||||
const Snapshot &snapshot,
|
||||
QList<Utils::FilePath> *importedFiles,
|
||||
QSet<Utils::FilePath> *scannedPaths)
|
||||
{
|
||||
// scan files that could be implicitly imported
|
||||
// it's important we also do this for JS files, otherwise the isEmpty check will fail
|
||||
@@ -747,28 +744,33 @@ static void findNewImplicitImports(const Document::Ptr &doc, const Snapshot &sna
|
||||
}
|
||||
}
|
||||
|
||||
static void findNewFileImports(const Document::Ptr &doc, const Snapshot &snapshot,
|
||||
QStringList *importedFiles, QSet<QString> *scannedPaths)
|
||||
static void findNewFileImports(const Document::Ptr &doc,
|
||||
const Snapshot &snapshot,
|
||||
QList<Utils::FilePath> *importedFiles,
|
||||
QSet<Utils::FilePath> *scannedPaths)
|
||||
{
|
||||
// scan files and directories that are explicitly imported
|
||||
const auto imports = doc->bind()->imports();
|
||||
for (const ImportInfo &import : imports) {
|
||||
const QString &importName = import.path();
|
||||
Utils::FilePath importPath = Utils::FilePath::fromString(importName);
|
||||
if (import.type() == ImportType::File) {
|
||||
if (! snapshot.document(importName))
|
||||
*importedFiles += importName;
|
||||
if (!snapshot.document(importPath))
|
||||
*importedFiles += importPath;
|
||||
} else if (import.type() == ImportType::Directory) {
|
||||
if (snapshot.documentsInDirectory(importName).isEmpty()) {
|
||||
if (! scannedPaths->contains(importName)) {
|
||||
*importedFiles += filesInDirectoryForLanguages(
|
||||
importName, doc->language().companionLanguages());
|
||||
scannedPaths->insert(importName);
|
||||
if (snapshot.documentsInDirectory(importPath).isEmpty()) {
|
||||
if (!scannedPaths->contains(importPath)) {
|
||||
*importedFiles
|
||||
+= filesInDirectoryForLanguages(importPath,
|
||||
doc->language().companionLanguages());
|
||||
scannedPaths->insert(importPath);
|
||||
}
|
||||
}
|
||||
} else if (import.type() == ImportType::QrcFile) {
|
||||
const QStringList importPaths
|
||||
= ModelManagerInterface::instance()->filesAtQrcPath(importName);
|
||||
for (const QString &importPath : importPaths) {
|
||||
for (const QString &importStr : importPaths) {
|
||||
Utils::FilePath importPath = Utils::FilePath::fromString(importStr);
|
||||
if (!snapshot.document(importPath))
|
||||
*importedFiles += importPath;
|
||||
}
|
||||
@@ -776,10 +778,13 @@ static void findNewFileImports(const Document::Ptr &doc, const Snapshot &snapsho
|
||||
const QMap<QString, QStringList> files
|
||||
= ModelManagerInterface::instance()->filesInQrcPath(importName);
|
||||
for (auto qrc = files.cbegin(), end = files.cend(); qrc != end; ++qrc) {
|
||||
if (ModelManagerInterface::guessLanguageOfFile(qrc.key()).isQmlLikeOrJsLanguage()) {
|
||||
if (ModelManagerInterface::guessLanguageOfFile(
|
||||
Utils::FilePath::fromString(qrc.key()))
|
||||
.isQmlLikeOrJsLanguage()) {
|
||||
for (const QString &sourceFile : qrc.value()) {
|
||||
if (!snapshot.document(sourceFile))
|
||||
*importedFiles += sourceFile;
|
||||
auto sourceFilePath = Utils::FilePath::fromString(sourceFile);
|
||||
if (!snapshot.document(sourceFilePath))
|
||||
*importedFiles += sourceFilePath;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -793,8 +798,9 @@ enum class LibraryStatus {
|
||||
Unknown
|
||||
};
|
||||
|
||||
static LibraryStatus libraryStatus(const FilePath &path, const Snapshot &snapshot,
|
||||
QSet<QString> *newLibraries)
|
||||
static LibraryStatus libraryStatus(const FilePath &path,
|
||||
const Snapshot &snapshot,
|
||||
QSet<Utils::FilePath> *newLibraries)
|
||||
{
|
||||
if (path.isEmpty())
|
||||
return LibraryStatus::Rejected;
|
||||
@@ -802,7 +808,7 @@ static LibraryStatus libraryStatus(const FilePath &path, const Snapshot &snapsho
|
||||
const LibraryInfo &existingInfo = snapshot.libraryInfo(path);
|
||||
if (existingInfo.isValid())
|
||||
return LibraryStatus::Accepted;
|
||||
if (newLibraries->contains(path.toString()))
|
||||
if (newLibraries->contains(path))
|
||||
return LibraryStatus::Accepted;
|
||||
// if we looked at the path before, done
|
||||
return existingInfo.wasScanned()
|
||||
@@ -813,7 +819,7 @@ static LibraryStatus libraryStatus(const FilePath &path, const Snapshot &snapsho
|
||||
static bool findNewQmlApplicationInPath(const FilePath &path,
|
||||
const Snapshot &snapshot,
|
||||
ModelManagerInterface *modelManager,
|
||||
QSet<QString> *newLibraries)
|
||||
QSet<FilePath> *newLibraries)
|
||||
{
|
||||
switch (libraryStatus(path, snapshot, newLibraries)) {
|
||||
case LibraryStatus::Accepted: return true;
|
||||
@@ -821,45 +827,43 @@ static bool findNewQmlApplicationInPath(const FilePath &path,
|
||||
default: break;
|
||||
}
|
||||
|
||||
QString qmltypesFile;
|
||||
FilePath qmltypesFile;
|
||||
|
||||
QDir dir(path.toString());
|
||||
QDirIterator it(path.toString(), QStringList { "*.qmltypes" }, QDir::Files);
|
||||
QList<Utils::FilePath> qmlTypes = path.dirEntries(
|
||||
FileFilter(QStringList{"*.qmltypes"}, QDir::Files));
|
||||
|
||||
if (!it.hasNext())
|
||||
if (qmlTypes.isEmpty())
|
||||
return false;
|
||||
|
||||
qmltypesFile = it.next();
|
||||
qmltypesFile = qmlTypes.first();
|
||||
|
||||
LibraryInfo libraryInfo = LibraryInfo(qmltypesFile);
|
||||
const QString libraryPath = dir.absolutePath();
|
||||
LibraryInfo libraryInfo = LibraryInfo(qmltypesFile.toString());
|
||||
const Utils::FilePath libraryPath = path.absolutePath();
|
||||
newLibraries->insert(libraryPath);
|
||||
modelManager->updateLibraryInfo(path, libraryInfo);
|
||||
modelManager->loadPluginTypes(QFileInfo(libraryPath).canonicalFilePath(), libraryPath,
|
||||
QString(), QString());
|
||||
modelManager->loadPluginTypes(libraryPath.canonicalPath(), libraryPath, QString(), QString());
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool findNewQmlLibraryInPath(const QString &path,
|
||||
static bool findNewQmlLibraryInPath(const Utils::FilePath &path,
|
||||
const Snapshot &snapshot,
|
||||
ModelManagerInterface *modelManager,
|
||||
QStringList *importedFiles,
|
||||
QSet<QString> *scannedPaths,
|
||||
QSet<QString> *newLibraries,
|
||||
QList<Utils::FilePath> *importedFiles,
|
||||
QSet<Utils::FilePath> *scannedPaths,
|
||||
QSet<Utils::FilePath> *newLibraries,
|
||||
bool ignoreMissing)
|
||||
{
|
||||
switch (libraryStatus(FilePath::fromString(path), snapshot, newLibraries)) {
|
||||
switch (libraryStatus(path, snapshot, newLibraries)) {
|
||||
case LibraryStatus::Accepted: return true;
|
||||
case LibraryStatus::Rejected: return false;
|
||||
default: break;
|
||||
}
|
||||
|
||||
const QDir dir(path);
|
||||
QFile qmldirFile(dir.filePath(QLatin1String("qmldir")));
|
||||
Utils::FilePath qmldirFile = path.pathAppended(QLatin1String("qmldir"));
|
||||
if (!qmldirFile.exists()) {
|
||||
if (!ignoreMissing) {
|
||||
LibraryInfo libraryInfo(LibraryInfo::NotFound);
|
||||
modelManager->updateLibraryInfo(FilePath::fromString(path), libraryInfo);
|
||||
modelManager->updateLibraryInfo(path, libraryInfo);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -869,25 +873,24 @@ static bool findNewQmlLibraryInPath(const QString &path,
|
||||
}
|
||||
|
||||
// found a new library!
|
||||
if (!qmldirFile.open(QFile::ReadOnly))
|
||||
if (!qmldirFile.isReadableFile())
|
||||
return false;
|
||||
QString qmldirData = QString::fromUtf8(qmldirFile.readAll());
|
||||
QString qmldirData = QString::fromUtf8(qmldirFile.fileContents());
|
||||
|
||||
QmlDirParser qmldirParser;
|
||||
qmldirParser.parse(qmldirData);
|
||||
|
||||
const QString libraryPath = QFileInfo(qmldirFile).absolutePath();
|
||||
const Utils::FilePath libraryPath = qmldirFile.absolutePath();
|
||||
newLibraries->insert(libraryPath);
|
||||
modelManager->updateLibraryInfo(FilePath::fromString(libraryPath), LibraryInfo(qmldirParser));
|
||||
modelManager->loadPluginTypes(QFileInfo(libraryPath).canonicalFilePath(), libraryPath,
|
||||
QString(), QString());
|
||||
modelManager->updateLibraryInfo(libraryPath, LibraryInfo(qmldirParser));
|
||||
modelManager->loadPluginTypes(libraryPath.canonicalPath(), libraryPath, QString(), QString());
|
||||
|
||||
// scan the qml files in the library
|
||||
const auto components = qmldirParser.components();
|
||||
for (const QmlDirParser::Component &component : components) {
|
||||
if (!component.fileName.isEmpty()) {
|
||||
const QFileInfo componentFileInfo(dir.filePath(component.fileName));
|
||||
const QString path = QDir::cleanPath(componentFileInfo.absolutePath());
|
||||
const FilePath componentFile = path.pathAppended(component.fileName);
|
||||
const FilePath path = componentFile.absolutePath().cleanPath();
|
||||
if (!scannedPaths->contains(path)) {
|
||||
*importedFiles += filesInDirectoryForLanguages(path, Dialect(Dialect::AnyLanguage)
|
||||
.companionLanguages());
|
||||
@@ -899,31 +902,39 @@ static bool findNewQmlLibraryInPath(const QString &path,
|
||||
return true;
|
||||
}
|
||||
|
||||
static QString modulePath(const ImportInfo &import, const QStringList &paths)
|
||||
static FilePath modulePath(const ImportInfo &import, const QList<FilePath> &paths)
|
||||
{
|
||||
if (!import.version().isValid())
|
||||
return QString();
|
||||
return FilePath();
|
||||
|
||||
const QStringList modPaths = modulePaths(import.name(), import.version().toString(), paths);
|
||||
const QList<FilePath> modPaths = modulePaths(import.name(), import.version().toString(), paths);
|
||||
return modPaths.value(0); // first is best match
|
||||
}
|
||||
|
||||
static void findNewLibraryImports(const Document::Ptr &doc, const Snapshot &snapshot,
|
||||
ModelManagerInterface *modelManager, QStringList *importedFiles,
|
||||
QSet<QString> *scannedPaths, QSet<QString> *newLibraries)
|
||||
static void findNewLibraryImports(const Document::Ptr &doc,
|
||||
const Snapshot &snapshot,
|
||||
ModelManagerInterface *modelManager,
|
||||
QList<FilePath> *importedFiles,
|
||||
QSet<Utils::FilePath> *scannedPaths,
|
||||
QSet<Utils::FilePath> *newLibraries)
|
||||
{
|
||||
// scan current dir
|
||||
findNewQmlLibraryInPath(doc->path(), snapshot, modelManager,
|
||||
importedFiles, scannedPaths, newLibraries, false);
|
||||
|
||||
// scan dir and lib imports
|
||||
const QStringList importPaths = modelManager->importPathsNames();
|
||||
const QList<FilePath> importPaths = modelManager->importPathsNames();
|
||||
const auto imports = doc->bind()->imports();
|
||||
for (const ImportInfo &import : imports) {
|
||||
switch (import.type()) {
|
||||
case ImportType::Directory:
|
||||
findNewQmlLibraryInPath(import.path(), snapshot, modelManager,
|
||||
importedFiles, scannedPaths, newLibraries, false);
|
||||
findNewQmlLibraryInPath(Utils::FilePath::fromString(import.path()),
|
||||
snapshot,
|
||||
modelManager,
|
||||
importedFiles,
|
||||
scannedPaths,
|
||||
newLibraries,
|
||||
false);
|
||||
break;
|
||||
case ImportType::Library:
|
||||
findNewQmlLibraryInPath(modulePath(import, importPaths), snapshot, modelManager,
|
||||
@@ -935,10 +946,10 @@ static void findNewLibraryImports(const Document::Ptr &doc, const Snapshot &snap
|
||||
}
|
||||
}
|
||||
|
||||
void ModelManagerInterface::parseLoop(QSet<QString> &scannedPaths,
|
||||
QSet<QString> &newLibraries,
|
||||
void ModelManagerInterface::parseLoop(QSet<Utils::FilePath> &scannedPaths,
|
||||
QSet<Utils::FilePath> &newLibraries,
|
||||
const WorkingCopy &workingCopy,
|
||||
QStringList files,
|
||||
QList<Utils::FilePath> files,
|
||||
ModelManagerInterface *modelManager,
|
||||
Dialect mainLanguage,
|
||||
bool emitDocChangedOnDisk,
|
||||
@@ -948,7 +959,7 @@ void ModelManagerInterface::parseLoop(QSet<QString> &scannedPaths,
|
||||
if (!reportProgress(qreal(i) / files.size()))
|
||||
return;
|
||||
|
||||
const QString fileName = files.at(i);
|
||||
const Utils::FilePath fileName = files.at(i);
|
||||
|
||||
Dialect language = guessLanguageOfFile(fileName);
|
||||
if (language == Dialect::NoLanguage) {
|
||||
@@ -971,12 +982,9 @@ void ModelManagerInterface::parseLoop(QSet<QString> &scannedPaths,
|
||||
contents = entry.first;
|
||||
documentRevision = entry.second;
|
||||
} else {
|
||||
QFile inFile(fileName);
|
||||
|
||||
if (inFile.open(QIODevice::ReadOnly)) {
|
||||
QTextStream ins(&inFile);
|
||||
if (fileName.isReadableFile()) {
|
||||
QTextStream ins(fileName.fileContents());
|
||||
contents = ins.readAll();
|
||||
inFile.close();
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
@@ -999,7 +1007,7 @@ void ModelManagerInterface::parseLoop(QSet<QString> &scannedPaths,
|
||||
}
|
||||
#endif
|
||||
// get list of referenced files not yet in snapshot or in directories already scanned
|
||||
QStringList importedFiles;
|
||||
QList<Utils::FilePath> importedFiles;
|
||||
|
||||
// update snapshot. requires synchronization, but significantly reduces amount of file
|
||||
// system queries for library imports because queries are cached in libraryInfo
|
||||
@@ -1015,7 +1023,7 @@ void ModelManagerInterface::parseLoop(QSet<QString> &scannedPaths,
|
||||
}
|
||||
|
||||
// add new files to parse list
|
||||
for (const QString &file : qAsConst(importedFiles)) {
|
||||
for (const Utils::FilePath &file : qAsConst(importedFiles)) {
|
||||
if (!files.contains(file))
|
||||
files.append(file);
|
||||
}
|
||||
@@ -1048,7 +1056,7 @@ private:
|
||||
|
||||
void ModelManagerInterface::parse(QFutureInterface<void> &future,
|
||||
const WorkingCopy &workingCopy,
|
||||
QStringList files,
|
||||
QList<Utils::FilePath> files,
|
||||
ModelManagerInterface *modelManager,
|
||||
Dialect mainLanguage,
|
||||
bool emitDocChangedOnDisk)
|
||||
@@ -1058,16 +1066,16 @@ void ModelManagerInterface::parse(QFutureInterface<void> &future,
|
||||
future.setProgressRange(0, progressMax);
|
||||
|
||||
// paths we have scanned for files and added to the files list
|
||||
QSet<QString> scannedPaths;
|
||||
QSet<Utils::FilePath> scannedPaths;
|
||||
// libraries we've found while scanning imports
|
||||
QSet<QString> newLibraries;
|
||||
QSet<Utils::FilePath> newLibraries;
|
||||
parseLoop(scannedPaths, newLibraries, workingCopy, std::move(files), modelManager, mainLanguage,
|
||||
emitDocChangedOnDisk, reporter);
|
||||
future.setProgressValue(progressMax);
|
||||
}
|
||||
|
||||
struct ScanItem {
|
||||
QString path;
|
||||
Utils::FilePath path;
|
||||
int depth = 0;
|
||||
Dialect language = Dialect::AnyLanguage;
|
||||
};
|
||||
@@ -1079,20 +1087,20 @@ void ModelManagerInterface::importScan(QFutureInterface<void> &future,
|
||||
bool emitDocChangedOnDisk, bool libOnly, bool forceRescan)
|
||||
{
|
||||
// paths we have scanned for files and added to the files list
|
||||
QSet<QString> scannedPaths;
|
||||
QSet<Utils::FilePath> scannedPaths;
|
||||
{
|
||||
QMutexLocker l(&modelManager->m_mutex);
|
||||
scannedPaths = modelManager->m_scannedPaths;
|
||||
}
|
||||
// libraries we've found while scanning imports
|
||||
QSet<QString> newLibraries;
|
||||
QSet<Utils::FilePath> newLibraries;
|
||||
|
||||
QVector<ScanItem> pathsToScan;
|
||||
pathsToScan.reserve(paths.size());
|
||||
{
|
||||
QMutexLocker l(&modelManager->m_mutex);
|
||||
for (const auto &path : paths) {
|
||||
QString cPath = QDir::cleanPath(path.path().toString());
|
||||
Utils::FilePath cPath = path.path().cleanPath();
|
||||
if (!forceRescan && modelManager->m_scannedPaths.contains(cPath))
|
||||
continue;
|
||||
pathsToScan.append({cPath, 0, path.language()});
|
||||
@@ -1111,7 +1119,7 @@ void ModelManagerInterface::importScan(QFutureInterface<void> &future,
|
||||
pathsToScan.pop_back();
|
||||
int pathBudget = (1 << (maxScanDepth + 2 - toScan.depth));
|
||||
if (forceRescan || !scannedPaths.contains(toScan.path)) {
|
||||
QStringList importedFiles;
|
||||
QList<Utils::FilePath> importedFiles;
|
||||
if (forceRescan ||
|
||||
(!findNewQmlLibraryInPath(toScan.path, snapshot, modelManager, &importedFiles,
|
||||
&scannedPaths, &newLibraries, true)
|
||||
@@ -1135,12 +1143,12 @@ void ModelManagerInterface::importScan(QFutureInterface<void> &future,
|
||||
}
|
||||
// always descend tree, as we might have just scanned with a smaller depth
|
||||
if (toScan.depth < maxScanDepth) {
|
||||
QDir dir(toScan.path);
|
||||
QStringList subDirs(dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot));
|
||||
Utils::FilePath dir = toScan.path;
|
||||
const QList<Utils::FilePath> subDirs = dir.dirEntries(QDir::Dirs | QDir::NoDotAndDotDot);
|
||||
workDone += 1;
|
||||
totalWork += pathBudget / 2 * subDirs.size() - pathBudget * 3 / 4 + 1;
|
||||
for (const QString &path : qAsConst(subDirs))
|
||||
pathsToScan.append({dir.absoluteFilePath(path), toScan.depth + 1, toScan.language});
|
||||
for (const Utils::FilePath &path : subDirs)
|
||||
pathsToScan.append({path.absoluteFilePath(), toScan.depth + 1, toScan.language});
|
||||
} else {
|
||||
workDone += pathBudget * 3 / 4;
|
||||
}
|
||||
@@ -1152,17 +1160,17 @@ void ModelManagerInterface::importScan(QFutureInterface<void> &future,
|
||||
// assume no work has been done
|
||||
QMutexLocker l(&modelManager->m_mutex);
|
||||
for (const auto &path : paths)
|
||||
modelManager->m_scannedPaths.remove(path.path().toString());
|
||||
modelManager->m_scannedPaths.remove(path.path());
|
||||
}
|
||||
}
|
||||
|
||||
QStringList ModelManagerInterface::importPathsNames() const
|
||||
QList<Utils::FilePath> ModelManagerInterface::importPathsNames() const
|
||||
{
|
||||
QStringList names;
|
||||
QList<Utils::FilePath> names;
|
||||
QMutexLocker l(&m_mutex);
|
||||
names.reserve(m_allImportPaths.size());
|
||||
for (const PathAndLanguage &x: m_allImportPaths)
|
||||
names << x.path().toString();
|
||||
names << x.path();
|
||||
return names;
|
||||
}
|
||||
|
||||
@@ -1186,7 +1194,7 @@ void ModelManagerInterface::maybeScan(const PathsAndLanguages &importPaths)
|
||||
{
|
||||
QMutexLocker l(&m_mutex);
|
||||
for (const PathAndLanguage &importPath : importPaths)
|
||||
if (!m_scannedPaths.contains(importPath.path().toString()))
|
||||
if (!m_scannedPaths.contains(importPath.path()))
|
||||
pathToScan.maybeInsert(importPath);
|
||||
}
|
||||
|
||||
@@ -1199,12 +1207,11 @@ void ModelManagerInterface::maybeScan(const PathsAndLanguages &importPaths)
|
||||
}
|
||||
}
|
||||
|
||||
static QList<Utils::FilePath> minimalPrefixPaths(const QStringList &paths)
|
||||
static QList<Utils::FilePath> minimalPrefixPaths(const QList<Utils::FilePath> &paths)
|
||||
{
|
||||
QList<Utils::FilePath> sortedPaths;
|
||||
// find minimal prefix, ensure '/' at end
|
||||
for (const QString &pathStr : qAsConst(paths)) {
|
||||
Utils::FilePath path = Utils::FilePath::fromString(pathStr);
|
||||
for (Utils::FilePath path : qAsConst(paths)) {
|
||||
if (!path.endsWith("/"))
|
||||
path.setPath(path.path() + "/");
|
||||
if (path.path().length() > 1)
|
||||
@@ -1227,7 +1234,7 @@ void ModelManagerInterface::updateImportPaths()
|
||||
if (m_indexerDisabled)
|
||||
return;
|
||||
PathsAndLanguages allImportPaths;
|
||||
QStringList allApplicationDirectories;
|
||||
QList<Utils::FilePath> allApplicationDirectories;
|
||||
QmlLanguageBundles activeBundles;
|
||||
QmlLanguageBundles extendedBundles;
|
||||
for (const ProjectInfo &pInfo : qAsConst(m_projects)) {
|
||||
@@ -1242,8 +1249,8 @@ void ModelManagerInterface::updateImportPaths()
|
||||
}
|
||||
|
||||
for (const ViewerContext &vContext : qAsConst(m_defaultVContexts)) {
|
||||
for (const QString &path : vContext.paths)
|
||||
allImportPaths.maybeInsert(Utils::FilePath::fromString(path), vContext.language);
|
||||
for (const Utils::FilePath &path : vContext.paths)
|
||||
allImportPaths.maybeInsert(path, vContext.language);
|
||||
allApplicationDirectories.append(vContext.applicationDirectories);
|
||||
}
|
||||
|
||||
@@ -1275,8 +1282,8 @@ void ModelManagerInterface::updateImportPaths()
|
||||
allImportPaths.maybeInsert(importPath);
|
||||
}
|
||||
|
||||
for (const QString &path : qAsConst(m_defaultImportPaths))
|
||||
allImportPaths.maybeInsert(Utils::FilePath::fromString(path), Dialect::Qml);
|
||||
for (const Utils::FilePath &path : qAsConst(m_defaultImportPaths))
|
||||
allImportPaths.maybeInsert(path, Dialect::Qml);
|
||||
allImportPaths.compact();
|
||||
allApplicationDirectories = Utils::filteredUnique(allApplicationDirectories);
|
||||
|
||||
@@ -1291,18 +1298,17 @@ void ModelManagerInterface::updateImportPaths()
|
||||
|
||||
// check if any file in the snapshot imports something new in the new paths
|
||||
Snapshot snapshot = m_validSnapshot;
|
||||
QStringList importedFiles;
|
||||
QSet<QString> scannedPaths;
|
||||
QSet<QString> newLibraries;
|
||||
QList<Utils::FilePath> importedFiles;
|
||||
QSet<Utils::FilePath> scannedPaths;
|
||||
QSet<Utils::FilePath> newLibraries;
|
||||
for (const Document::Ptr &doc : qAsConst(snapshot))
|
||||
findNewLibraryImports(doc, snapshot, this, &importedFiles, &scannedPaths, &newLibraries);
|
||||
for (const QString &pathStr : qAsConst(allApplicationDirectories)) {
|
||||
Utils::FilePath path = Utils::FilePath::fromString(pathStr);
|
||||
for (const Utils::FilePath &path : qAsConst(allApplicationDirectories)) {
|
||||
allImportPaths.maybeInsert(path, Dialect::Qml);
|
||||
findNewQmlApplicationInPath(path, snapshot, this, &newLibraries);
|
||||
}
|
||||
for (const Utils::FilePath &qrcPath : generatedQrc(allApplicationDirectories))
|
||||
updateQrcFile(qrcPath.toString());
|
||||
updateQrcFile(qrcPath);
|
||||
|
||||
updateSourceFiles(importedFiles, true);
|
||||
|
||||
@@ -1311,8 +1317,10 @@ void ModelManagerInterface::updateImportPaths()
|
||||
maybeScan(allImportPaths);
|
||||
}
|
||||
|
||||
void ModelManagerInterface::loadPluginTypes(const QString &libraryPath, const QString &importPath,
|
||||
const QString &importUri, const QString &importVersion)
|
||||
void ModelManagerInterface::loadPluginTypes(const Utils::FilePath &libraryPath,
|
||||
const Utils::FilePath &importPath,
|
||||
const QString &importUri,
|
||||
const QString &importVersion)
|
||||
{
|
||||
m_pluginDumper->loadPluginTypes(libraryPath, importPath, importUri, importVersion);
|
||||
}
|
||||
@@ -1526,25 +1534,25 @@ ViewerContext ModelManagerInterface::getVContext(const ViewerContext &vCtx,
|
||||
Q_FALLTHROUGH();
|
||||
case ViewerContext::AddAllPaths:
|
||||
{
|
||||
for (const QString &path : qAsConst(defaultVCtx.paths))
|
||||
for (const Utils::FilePath &path : qAsConst(defaultVCtx.paths))
|
||||
maybeAddPath(res, path);
|
||||
switch (res.language.dialect()) {
|
||||
case Dialect::AnyLanguage:
|
||||
case Dialect::Qml:
|
||||
maybeAddPath(res, info.qtQmlPath.toString());
|
||||
maybeAddPath(res, info.qtQmlPath);
|
||||
Q_FALLTHROUGH();
|
||||
case Dialect::QmlQtQuick2:
|
||||
case Dialect::QmlQtQuick2Ui:
|
||||
{
|
||||
if (res.language == Dialect::QmlQtQuick2 || res.language == Dialect::QmlQtQuick2Ui)
|
||||
maybeAddPath(res, info.qtQmlPath.toString());
|
||||
maybeAddPath(res, info.qtQmlPath);
|
||||
|
||||
QList<Dialect> languages = res.language.companionLanguages();
|
||||
auto addPathsOnLanguageMatch = [&](const PathsAndLanguages &importPaths) {
|
||||
for (const auto &importPath : importPaths) {
|
||||
if (languages.contains(importPath.language())
|
||||
|| importPath.language().companionLanguages().contains(res.language)) {
|
||||
maybeAddPath(res, importPath.path().toString());
|
||||
maybeAddPath(res, importPath.path());
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -1561,7 +1569,7 @@ ViewerContext ModelManagerInterface::getVContext(const ViewerContext &vCtx,
|
||||
addPathsOnLanguageMatch(pInfo.importPaths);
|
||||
}
|
||||
const auto environmentPaths = environmentImportPaths();
|
||||
for (const QString &path : environmentPaths)
|
||||
for (const Utils::FilePath &path : environmentPaths)
|
||||
maybeAddPath(res, path);
|
||||
break;
|
||||
}
|
||||
@@ -1579,14 +1587,14 @@ ViewerContext ModelManagerInterface::getVContext(const ViewerContext &vCtx,
|
||||
res.selectors.append(defaultVCtx.selectors);
|
||||
Q_FALLTHROUGH();
|
||||
case ViewerContext::AddDefaultPaths:
|
||||
for (const QString &path : qAsConst(defaultVCtx.paths))
|
||||
for (const Utils::FilePath &path : qAsConst(defaultVCtx.paths))
|
||||
maybeAddPath(res, path);
|
||||
if (res.language == Dialect::AnyLanguage || res.language == Dialect::Qml)
|
||||
maybeAddPath(res, info.qtQmlPath.toString());
|
||||
maybeAddPath(res, info.qtQmlPath);
|
||||
if (res.language == Dialect::AnyLanguage || res.language == Dialect::Qml
|
||||
|| res.language == Dialect::QmlQtQuick2 || res.language == Dialect::QmlQtQuick2Ui) {
|
||||
const auto environemntPaths = environmentImportPaths();
|
||||
for (const QString &path : environemntPaths)
|
||||
for (const Utils::FilePath &path : environemntPaths)
|
||||
maybeAddPath(res, path);
|
||||
}
|
||||
break;
|
||||
@@ -1676,7 +1684,7 @@ void ModelManagerInterface::addFuture(const QFuture<void> &future)
|
||||
m_futureSynchronizer.addFuture(future);
|
||||
}
|
||||
|
||||
Document::Ptr ModelManagerInterface::ensuredGetDocumentForPath(const QString &filePath)
|
||||
Document::Ptr ModelManagerInterface::ensuredGetDocumentForPath(const Utils::FilePath &filePath)
|
||||
{
|
||||
QmlJS::Document::Ptr document = newestSnapshot().document(filePath);
|
||||
if (!document) {
|
||||
@@ -1691,7 +1699,7 @@ Document::Ptr ModelManagerInterface::ensuredGetDocumentForPath(const QString &fi
|
||||
|
||||
void ModelManagerInterface::resetCodeModel()
|
||||
{
|
||||
QStringList documents;
|
||||
QList<Utils::FilePath> documents;
|
||||
|
||||
{
|
||||
QMutexLocker locker(&m_mutex);
|
||||
|
||||
@@ -68,12 +68,12 @@ public:
|
||||
struct ProjectInfo
|
||||
{
|
||||
QPointer<ProjectExplorer::Project> project;
|
||||
QStringList sourceFiles;
|
||||
QList<Utils::FilePath> sourceFiles;
|
||||
PathsAndLanguages importPaths;
|
||||
QStringList activeResourceFiles;
|
||||
QStringList allResourceFiles;
|
||||
QHash<QString, QString> resourceFileContents;
|
||||
QStringList applicationDirectories;
|
||||
QList<Utils::FilePath> activeResourceFiles;
|
||||
QList<Utils::FilePath> allResourceFiles;
|
||||
QHash<Utils::FilePath, QString> resourceFileContents;
|
||||
QList<Utils::FilePath> applicationDirectories;
|
||||
QHash<QString, QString> moduleMappings; // E.g.: QtQuick.Controls -> MyProject.MyControls
|
||||
|
||||
// whether trying to run qmldump makes sense
|
||||
@@ -91,18 +91,18 @@ public:
|
||||
class WorkingCopy
|
||||
{
|
||||
public:
|
||||
using Table = QHash<QString, QPair<QString, int>>;
|
||||
using Table = QHash<Utils::FilePath, QPair<QString, int>>;
|
||||
|
||||
void insert(const QString &fileName, const QString &source, int revision = 0)
|
||||
void insert(const Utils::FilePath &fileName, const QString &source, int revision = 0)
|
||||
{ m_elements.insert(fileName, {source, revision}); }
|
||||
|
||||
bool contains(const QString &fileName) const
|
||||
bool contains(const Utils::FilePath &fileName) const
|
||||
{ return m_elements.contains(fileName); }
|
||||
|
||||
QString source(const QString &fileName) const
|
||||
QString source(const Utils::FilePath &fileName) const
|
||||
{ return m_elements.value(fileName).first; }
|
||||
|
||||
QPair<QString, int> get(const QString &fileName) const
|
||||
QPair<QString, int> get(const Utils::FilePath &fileName) const
|
||||
{ return m_elements.value(fileName); }
|
||||
|
||||
Table all() const
|
||||
@@ -124,7 +124,7 @@ public:
|
||||
ModelManagerInterface(QObject *parent = nullptr);
|
||||
~ModelManagerInterface() override;
|
||||
|
||||
static Dialect guessLanguageOfFile(const QString &fileName);
|
||||
static Dialect guessLanguageOfFile(const Utils::FilePath &fileName);
|
||||
static QStringList globPatternsForLanguages(const QList<Dialect> &languages);
|
||||
static ModelManagerInterface *instance();
|
||||
static ModelManagerInterface *instanceForFuture(const QFuture<void> &future);
|
||||
@@ -135,11 +135,11 @@ public:
|
||||
QmlJS::Snapshot newestSnapshot() const;
|
||||
|
||||
void activateScan();
|
||||
void updateSourceFiles(const QStringList &files,
|
||||
bool emitDocumentOnDiskChanged);
|
||||
void fileChangedOnDisk(const QString &path);
|
||||
void removeFiles(const QStringList &files);
|
||||
QStringList qrcPathsForFile(const QString &file, const QLocale *locale = nullptr,
|
||||
void updateSourceFiles(const QList<Utils::FilePath> &files, bool emitDocumentOnDiskChanged);
|
||||
void fileChangedOnDisk(const Utils::FilePath &path);
|
||||
void removeFiles(const QList<Utils::FilePath> &files);
|
||||
QStringList qrcPathsForFile(const Utils::FilePath &file,
|
||||
const QLocale *locale = nullptr,
|
||||
ProjectExplorer::Project *project = nullptr,
|
||||
QrcResourceSelector resources = AllQrcResources);
|
||||
QStringList filesAtQrcPath(const QString &path, const QLocale *locale = nullptr,
|
||||
@@ -160,16 +160,18 @@ public:
|
||||
void updateDocument(const QmlJS::Document::Ptr& doc);
|
||||
void updateLibraryInfo(const Utils::FilePath &path, const QmlJS::LibraryInfo &info);
|
||||
void emitDocumentChangedOnDisk(QmlJS::Document::Ptr doc);
|
||||
void updateQrcFile(const QString &path);
|
||||
ProjectInfo projectInfoForPath(const QString &path) const;
|
||||
QList<ProjectInfo> allProjectInfosForPath(const QString &path) const;
|
||||
void updateQrcFile(const Utils::FilePath &path);
|
||||
ProjectInfo projectInfoForPath(const Utils::FilePath &path) const;
|
||||
QList<ProjectInfo> allProjectInfosForPath(const Utils::FilePath &path) const;
|
||||
|
||||
QStringList importPathsNames() const;
|
||||
QList<Utils::FilePath> importPathsNames() const;
|
||||
QmlJS::QmlLanguageBundles activeBundles() const;
|
||||
QmlJS::QmlLanguageBundles extendedBundles() const;
|
||||
|
||||
void loadPluginTypes(const QString &libraryPath, const QString &importPath,
|
||||
const QString &importUri, const QString &importVersion);
|
||||
void loadPluginTypes(const Utils::FilePath &libraryPath,
|
||||
const Utils::FilePath &importPath,
|
||||
const QString &importUri,
|
||||
const QString &importVersion);
|
||||
|
||||
CppDataHash cppData() const;
|
||||
LibraryInfo builtins(const Document::Ptr &doc) const;
|
||||
@@ -192,7 +194,7 @@ public:
|
||||
void addFuture(const QFuture<T> &future) { addFuture(QFuture<void>(future)); }
|
||||
void addFuture(const QFuture<void> &future);
|
||||
|
||||
QmlJS::Document::Ptr ensuredGetDocumentForPath(const QString &filePath);
|
||||
QmlJS::Document::Ptr ensuredGetDocumentForPath(const Utils::FilePath &filePath);
|
||||
static void importScan(QFutureInterface<void> &future, const WorkingCopy& workingCopyInternal,
|
||||
const PathsAndLanguages& paths, ModelManagerInterface *modelManager,
|
||||
bool emitDocChangedOnDisk, bool libOnly = true,
|
||||
@@ -205,10 +207,10 @@ public:
|
||||
signals:
|
||||
void documentUpdated(QmlJS::Document::Ptr doc);
|
||||
void documentChangedOnDisk(QmlJS::Document::Ptr doc);
|
||||
void aboutToRemoveFiles(const QStringList &files);
|
||||
void libraryInfoUpdated(const QString &path, const QmlJS::LibraryInfo &info);
|
||||
void aboutToRemoveFiles(const QList<Utils::FilePath> &files);
|
||||
void libraryInfoUpdated(const Utils::FilePath &path, const QmlJS::LibraryInfo &info);
|
||||
void projectInfoUpdated(const ProjectInfo &pinfo);
|
||||
void projectPathChanged(const QString &projectPath);
|
||||
void projectPathChanged(const Utils::FilePath &projectPath);
|
||||
|
||||
protected:
|
||||
Q_INVOKABLE void queueCppQmlTypeUpdate(const CPlusPlus::Document::Ptr &doc, bool scan);
|
||||
@@ -221,17 +223,20 @@ protected:
|
||||
virtual void addTaskInternal(const QFuture<void> &result, const QString &msg,
|
||||
const char *taskId) const;
|
||||
|
||||
QFuture<void> refreshSourceFiles(const QStringList &sourceFiles,
|
||||
QFuture<void> refreshSourceFiles(const QList<Utils::FilePath> &sourceFiles,
|
||||
bool emitDocumentOnDiskChanged);
|
||||
|
||||
static void parseLoop(QSet<QString> &scannedPaths, QSet<QString> &newLibraries,
|
||||
const WorkingCopy &workingCopyInternal, QStringList files,
|
||||
static void parseLoop(QSet<Utils::FilePath> &scannedPaths,
|
||||
QSet<Utils::FilePath> &newLibraries,
|
||||
const WorkingCopy &workingCopyInternal,
|
||||
QList<Utils::FilePath> files,
|
||||
ModelManagerInterface *modelManager,
|
||||
QmlJS::Dialect mainLanguage, bool emitDocChangedOnDisk,
|
||||
QmlJS::Dialect mainLanguage,
|
||||
bool emitDocChangedOnDisk,
|
||||
const std::function<bool(qreal)> &reportProgress);
|
||||
static void parse(QFutureInterface<void> &future,
|
||||
const WorkingCopy &workingCopyInternal,
|
||||
QStringList files,
|
||||
QList<Utils::FilePath> files,
|
||||
ModelManagerInterface *modelManager,
|
||||
QmlJS::Dialect mainLanguage,
|
||||
bool emitDocChangedOnDisk);
|
||||
@@ -257,19 +262,19 @@ private:
|
||||
QmlJS::Snapshot m_newestSnapshot;
|
||||
PathsAndLanguages m_allImportPaths;
|
||||
QList<Utils::FilePath> m_applicationPaths;
|
||||
QStringList m_defaultImportPaths;
|
||||
QList<Utils::FilePath> m_defaultImportPaths;
|
||||
QmlJS::QmlLanguageBundles m_activeBundles;
|
||||
QmlJS::QmlLanguageBundles m_extendedBundles;
|
||||
QHash<Dialect, QmlJS::ViewerContext> m_defaultVContexts;
|
||||
bool m_shouldScanImports = false;
|
||||
QSet<QString> m_scannedPaths;
|
||||
QSet<Utils::FilePath> m_scannedPaths;
|
||||
|
||||
QTimer *m_updateCppQmlTypesTimer = nullptr;
|
||||
QTimer *m_asyncResetTimer = nullptr;
|
||||
QHash<QString, QPair<CPlusPlus::Document::Ptr, bool>> m_queuedCppDocuments;
|
||||
QFuture<void> m_cppQmlTypesUpdater;
|
||||
Utils::QrcCache m_qrcCache;
|
||||
QHash<QString, QString> m_qrcContents;
|
||||
QHash<Utils::FilePath, QString> m_qrcContents;
|
||||
|
||||
CppDataHash m_cppDataHash;
|
||||
QHash<QString, QList<CPlusPlus::Document::Ptr>> m_cppDeclarationFiles;
|
||||
@@ -279,7 +284,7 @@ private:
|
||||
QMap<ProjectExplorer::Project *, ProjectInfo> m_projects;
|
||||
ProjectInfo m_defaultProjectInfo;
|
||||
ProjectExplorer::Project *m_defaultProject = nullptr;
|
||||
QMultiHash<QString, ProjectExplorer::Project *> m_fileToProject;
|
||||
QMultiHash<Utils::FilePath, ProjectExplorer::Project *> m_fileToProject;
|
||||
|
||||
PluginDumper *m_pluginDumper = nullptr;
|
||||
|
||||
|
||||
@@ -71,7 +71,10 @@ void PluginDumper::loadBuiltinTypes(const QmlJS::ModelManagerInterface::ProjectI
|
||||
metaObject()->invokeMethod(this, [=] { onLoadBuiltinTypes(info); });
|
||||
}
|
||||
|
||||
void PluginDumper::loadPluginTypes(const QString &libraryPath, const QString &importPath, const QString &importUri, const QString &importVersion)
|
||||
void PluginDumper::loadPluginTypes(const Utils::FilePath &libraryPath,
|
||||
const Utils::FilePath &importPath,
|
||||
const QString &importUri,
|
||||
const QString &importVersion)
|
||||
{
|
||||
// move to the owning thread
|
||||
metaObject()->invokeMethod(this, [=] { onLoadPluginTypes(libraryPath, importPath,
|
||||
@@ -113,9 +116,12 @@ void PluginDumper::onLoadBuiltinTypes(const QmlJS::ModelManagerInterface::Projec
|
||||
m_qtToInfo.insert(info.qtQmlPath.toString(), info);
|
||||
}
|
||||
|
||||
void PluginDumper::onLoadPluginTypes(const QString &libraryPath, const QString &importPath, const QString &importUri, const QString &importVersion)
|
||||
void PluginDumper::onLoadPluginTypes(const Utils::FilePath &libraryPath,
|
||||
const Utils::FilePath &importPath,
|
||||
const QString &importUri,
|
||||
const QString &importVersion)
|
||||
{
|
||||
const FilePath canonicalLibraryPath = FilePath::fromUserInput(libraryPath).cleanPath();
|
||||
const FilePath canonicalLibraryPath = libraryPath.cleanPath();
|
||||
if (m_runningQmldumps.values().contains(canonicalLibraryPath))
|
||||
return;
|
||||
const Snapshot snapshot = m_modelManager->snapshot();
|
||||
@@ -389,7 +395,7 @@ QFuture<PluginDumper::QmlTypeDescription> PluginDumper::loadQmlTypeDescription(c
|
||||
* \sa QmlJs::modulePath
|
||||
* \sa LinkPrivate::importNonFile
|
||||
*/
|
||||
QString PluginDumper::buildQmltypesPath(const QString &name) const
|
||||
Utils::FilePath PluginDumper::buildQmltypesPath(const QString &name) const
|
||||
{
|
||||
QString qualifiedName;
|
||||
QString version;
|
||||
@@ -401,18 +407,19 @@ QString PluginDumper::buildQmltypesPath(const QString &name) const
|
||||
version = m.captured("major") + QLatin1Char('.') + m.captured("minor");
|
||||
}
|
||||
|
||||
const QStringList paths = modulePaths(qualifiedName, version, m_modelManager->importPathsNames());
|
||||
const QList<Utils::FilePath> paths = modulePaths(qualifiedName,
|
||||
version,
|
||||
m_modelManager->importPathsNames());
|
||||
|
||||
if (paths.isEmpty())
|
||||
return QString();
|
||||
return Utils::FilePath();
|
||||
|
||||
for (const QString &path : paths) {
|
||||
QDirIterator it(path, QStringList { "*.qmltypes" }, QDir::Files);
|
||||
|
||||
if (it.hasNext())
|
||||
return it.next();
|
||||
for (const Utils::FilePath &path : paths) {
|
||||
auto qmltypes = path.dirEntries(FileFilter(QStringList{"*.qmltypes"}, QDir::Files));
|
||||
if (!qmltypes.isEmpty())
|
||||
return qmltypes.first();
|
||||
}
|
||||
return QString();
|
||||
return Utils::FilePath();
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -434,11 +441,11 @@ QFuture<PluginDumper::DependencyInfo> PluginDumper::loadDependencies(const FileP
|
||||
visited = QSharedPointer<QSet<FilePath>>(new QSet<FilePath>());
|
||||
|
||||
FilePaths dependenciesPaths;
|
||||
QString path;
|
||||
FilePath path;
|
||||
for (const FilePath &name : dependencies) {
|
||||
path = buildQmltypesPath(name.toString());
|
||||
if (!path.isNull())
|
||||
dependenciesPaths << FilePath::fromString(path);
|
||||
if (!path.isEmpty())
|
||||
dependenciesPaths << path;
|
||||
visited->insert(name);
|
||||
}
|
||||
|
||||
@@ -665,7 +672,8 @@ void PluginDumper::dump(const Plugin &plugin)
|
||||
args << QLatin1String("-nonrelocatable");
|
||||
args << plugin.importUri;
|
||||
args << plugin.importVersion;
|
||||
args << (plugin.importPath.isEmpty() ? QLatin1String(".") : plugin.importPath);
|
||||
args << (plugin.importPath.isEmpty() ? Utils::FilePath::fromString(".") : plugin.importPath)
|
||||
.toString();
|
||||
runQmlDump(info, args, plugin.qmldirPath);
|
||||
}
|
||||
|
||||
|
||||
@@ -49,15 +49,19 @@ public:
|
||||
|
||||
public:
|
||||
void loadBuiltinTypes(const QmlJS::ModelManagerInterface::ProjectInfo &info);
|
||||
void loadPluginTypes(const QString &libraryPath, const QString &importPath,
|
||||
const QString &importUri, const QString &importVersion);
|
||||
void loadPluginTypes(const Utils::FilePath &libraryPath,
|
||||
const Utils::FilePath &importPath,
|
||||
const QString &importUri,
|
||||
const QString &importVersion);
|
||||
void scheduleRedumpPlugins();
|
||||
|
||||
private:
|
||||
Q_INVOKABLE void onLoadBuiltinTypes(const QmlJS::ModelManagerInterface::ProjectInfo &info,
|
||||
bool force = false);
|
||||
Q_INVOKABLE void onLoadPluginTypes(const QString &libraryPath, const QString &importPath,
|
||||
const QString &importUri, const QString &importVersion);
|
||||
Q_INVOKABLE void onLoadPluginTypes(const Utils::FilePath &libraryPath,
|
||||
const Utils::FilePath &importPath,
|
||||
const QString &importUri,
|
||||
const QString &importVersion);
|
||||
Q_INVOKABLE void dumpAllPlugins();
|
||||
void qmlPluginTypeDumpDone(Utils::QtcProcess *process);
|
||||
void pluginChanged(const QString &pluginLibrary);
|
||||
@@ -66,7 +70,7 @@ private:
|
||||
class Plugin {
|
||||
public:
|
||||
Utils::FilePath qmldirPath;
|
||||
QString importPath;
|
||||
Utils::FilePath importPath;
|
||||
QString importUri;
|
||||
QString importVersion;
|
||||
Utils::FilePaths typeInfoPaths;
|
||||
@@ -92,7 +96,7 @@ private:
|
||||
const Utils::FilePath &importPath);
|
||||
void dump(const Plugin &plugin);
|
||||
QFuture<QmlTypeDescription> loadQmlTypeDescription(const Utils::FilePaths &path) const;
|
||||
QString buildQmltypesPath(const QString &name) const;
|
||||
Utils::FilePath buildQmltypesPath(const QString &name) const;
|
||||
|
||||
QFuture<PluginDumper::DependencyInfo> loadDependencies(const Utils::FilePaths &dependencies,
|
||||
QSharedPointer<QSet<Utils::FilePath> > visited) const;
|
||||
|
||||
@@ -291,7 +291,7 @@ static void addInstantiatingComponents(ContextPtr context, QmlComponentChain *ch
|
||||
const QString &comment = chain->document()->source().mid(commentLoc.begin(), commentLoc.length);
|
||||
|
||||
// find all @scope annotations
|
||||
QStringList additionalScopes;
|
||||
QList<Utils::FilePath> additionalScopes;
|
||||
int lastOffset = -1;
|
||||
QRegularExpressionMatch match;
|
||||
forever {
|
||||
@@ -299,13 +299,16 @@ static void addInstantiatingComponents(ContextPtr context, QmlComponentChain *ch
|
||||
lastOffset = match.capturedStart();
|
||||
if (lastOffset == -1)
|
||||
break;
|
||||
additionalScopes << QFileInfo(chain->document()->path() + QLatin1Char('/') + match.captured(1).trimmed()).absoluteFilePath();
|
||||
additionalScopes << chain->document()
|
||||
->path()
|
||||
.pathAppended(match.captured(1).trimmed())
|
||||
.absoluteFilePath();
|
||||
}
|
||||
|
||||
foreach (const QmlComponentChain *c, chain->instantiatingComponents())
|
||||
additionalScopes.removeAll(c->document()->fileName());
|
||||
|
||||
foreach (const QString &scope, additionalScopes) {
|
||||
foreach (const Utils::FilePath &scope, additionalScopes) {
|
||||
Document::Ptr doc = context->snapshot().document(scope);
|
||||
if (doc) {
|
||||
QmlComponentChain *ch = new QmlComponentChain(doc);
|
||||
@@ -343,10 +346,12 @@ void ScopeChain::initializeRootScope()
|
||||
if (!m_document->bind()->isJsLibrary()) {
|
||||
foreach (Document::Ptr otherDoc, snapshot) {
|
||||
foreach (const ImportInfo &import, otherDoc->bind()->imports()) {
|
||||
if ((import.type() == ImportType::File && m_document->fileName() == import.path())
|
||||
|| (import.type() == ImportType::QrcFile
|
||||
&& ModelManagerInterface::instance()->filesAtQrcPath(import.path())
|
||||
.contains(m_document->fileName()))) {
|
||||
if ((import.type() == ImportType::File
|
||||
&& m_document->fileName().toString() == import.path())
|
||||
|| (import.type() == ImportType::QrcFile
|
||||
&& ModelManagerInterface::instance()
|
||||
->filesAtQrcPath(import.path())
|
||||
.contains(m_document->fileName().path()))) {
|
||||
QmlComponentChain *component = new QmlComponentChain(otherDoc);
|
||||
componentScopes.insert(otherDoc.data(), component);
|
||||
chain->addInstantiatingComponent(component);
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
|
||||
#include "parser/qmljsast_p.h"
|
||||
|
||||
#include <utils/filepath.h>
|
||||
#include <utils/stringutils.h>
|
||||
|
||||
#include <QColor>
|
||||
@@ -256,8 +257,9 @@ const QStringList QmlJS::splitVersion(const QString &version)
|
||||
* \return The module paths if found, an empty string otherwise
|
||||
* \see qmlimportscanner in qtdeclarative/tools
|
||||
*/
|
||||
QStringList QmlJS::modulePaths(const QString &name, const QString &version,
|
||||
const QStringList &importPaths)
|
||||
QList<Utils::FilePath> QmlJS::modulePaths(const QString &name,
|
||||
const QString &version,
|
||||
const QList<Utils::FilePath> &importPaths)
|
||||
{
|
||||
Q_ASSERT(maybeModuleVersion(version));
|
||||
if (importPaths.isEmpty())
|
||||
@@ -267,27 +269,27 @@ QStringList QmlJS::modulePaths(const QString &name, const QString &version,
|
||||
const QStringList parts = name.split('.', Qt::SkipEmptyParts);
|
||||
auto mkpath = [](const QStringList &xs) -> QString { return xs.join(QLatin1Char('/')); };
|
||||
|
||||
QStringList result;
|
||||
QString candidate;
|
||||
QList<Utils::FilePath> result;
|
||||
Utils::FilePath candidate;
|
||||
|
||||
for (const QString &versionPart : splitVersion(sanitizedVersion)) {
|
||||
for (const QString &path : importPaths) {
|
||||
for (const Utils::FilePath &path : importPaths) {
|
||||
for (int i = parts.count() - 1; i >= 0; --i) {
|
||||
candidate = QDir::cleanPath(QString::fromLatin1("%1/%2.%3/%4")
|
||||
.arg(path,
|
||||
mkpath(parts.mid(0, i + 1)),
|
||||
versionPart,
|
||||
mkpath(parts.mid(i + 1))));
|
||||
if (QDir(candidate).exists())
|
||||
candidate = path.pathAppended(QString::fromLatin1("%2.%3/%4")
|
||||
.arg(mkpath(parts.mid(0, i + 1)),
|
||||
versionPart,
|
||||
mkpath(parts.mid(i + 1))))
|
||||
.cleanPath();
|
||||
if (candidate.exists())
|
||||
result << candidate;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Version is empty
|
||||
for (const QString &path: importPaths) {
|
||||
candidate = QDir::cleanPath(QString::fromLatin1("%1/%2").arg(path, mkpath(parts)));
|
||||
if (QDir(candidate).exists())
|
||||
for (const Utils::FilePath &path : importPaths) {
|
||||
candidate = path.pathAppended(mkpath(parts)).cleanPath();
|
||||
if (candidate.exists())
|
||||
result << candidate;
|
||||
}
|
||||
|
||||
|
||||
@@ -25,11 +25,12 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "parser/qmljsastfwd_p.h"
|
||||
#include "parser/qmljsdiagnosticmessage_p.h"
|
||||
#include "parser/qmljsengine_p.h"
|
||||
#include "qmljs_global.h"
|
||||
#include "qmljsconstants.h"
|
||||
#include "parser/qmljsastfwd_p.h"
|
||||
#include "parser/qmljsengine_p.h"
|
||||
#include "parser/qmljsdiagnosticmessage_p.h"
|
||||
#include <utils/filepath.h>
|
||||
|
||||
QT_FORWARD_DECLARE_CLASS(QColor)
|
||||
|
||||
@@ -58,8 +59,9 @@ QMLJS_EXPORT DiagnosticMessage errorMessage(const SourceLocation &loc,
|
||||
QMLJS_EXPORT bool maybeModuleVersion(const QString &version);
|
||||
|
||||
QMLJS_EXPORT const QStringList splitVersion(const QString &version);
|
||||
QMLJS_EXPORT QStringList modulePaths(const QString &moduleImportName, const QString &version,
|
||||
const QStringList &importPaths);
|
||||
QMLJS_EXPORT QList<Utils::FilePath> modulePaths(const QString &moduleImportName,
|
||||
const QString &version,
|
||||
const QList<Utils::FilePath> &importPaths);
|
||||
|
||||
template <class T>
|
||||
SourceLocation locationFromRange(const T *node)
|
||||
|
||||
@@ -43,8 +43,8 @@ struct QMLJS_EXPORT ViewerContext
|
||||
};
|
||||
|
||||
QStringList selectors;
|
||||
QStringList paths;
|
||||
QStringList applicationDirectories;
|
||||
QList<Utils::FilePath> paths;
|
||||
QList<Utils::FilePath> applicationDirectories;
|
||||
Dialect language = Dialect::Qml;
|
||||
Flags flags = AddAllPaths;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user