QmlJSTools::SemanticInfo SemanticInfoUpdater::makeNewSemanticInfo(const QmlJS::Document::Ptr &doc, const QmlJS::Snapshot &snapshot) { using namespace QmlJS; QmlJSTools::SemanticInfo semanticInfo; semanticInfo.document = doc; semanticInfo.snapshot = snapshot; ModelManagerInterface *modelManager = ModelManagerInterface::instance(); Link link(semanticInfo.snapshot, modelManager->defaultVContext(doc->language(), doc), modelManager->builtins(doc)); semanticInfo.context = link(doc, &semanticInfo.semanticMessages); ScopeChain *scopeChain = new ScopeChain(doc, semanticInfo.context); semanticInfo.setRootScopeChain(QSharedPointer<const ScopeChain>(scopeChain)); if (doc->language() == Dialect::Json) { Utils::JsonSchema *schema = QmlJSEditorPlugin::jsonManager()->schemaForFile(doc->fileName()); if (schema) { JsonCheck jsonChecker(doc); semanticInfo.staticAnalysisMessages = jsonChecker(schema); } } else { Check checker(doc, semanticInfo.context); semanticInfo.staticAnalysisMessages = checker(); } return semanticInfo; }
Link::Link(const Snapshot &snapshot, const QStringList &importPaths, const LibraryInfo &builtins) : d(new LinkPrivate) { d->valueOwner = new ValueOwner; d->snapshot = snapshot; d->importPaths = importPaths; d->builtins = builtins; d->diagnosticMessages = 0; d->allDiagnosticMessages = 0; ModelManagerInterface *modelManager = ModelManagerInterface::instance(); if (modelManager) { ModelManagerInterface::CppDataHash cppDataHash = modelManager->cppData(); // populate engine with types from C++ foreach (const ModelManagerInterface::CppData &cppData, cppDataHash) { d->valueOwner->cppQmlTypes().load(cppData.exportedTypes); } // build an object with the context properties from C++ ObjectValue *cppContextProperties = d->valueOwner->newObject(/* prototype = */ 0); foreach (const ModelManagerInterface::CppData &cppData, cppDataHash) { QHashIterator<QString, QString> it(cppData.contextProperties); while (it.hasNext()) { it.next(); const Value *value = 0; const QString cppTypeName = it.value(); if (!cppTypeName.isEmpty()) value = d->valueOwner->cppQmlTypes().objectByCppName(cppTypeName); if (!value) value = d->valueOwner->unknownValue(); cppContextProperties->setMember(it.key(), value); } }
void QmlTaskManager::updateMessagesNow() { // abort any update that's going on already m_messageCollector.cancel(); removeAllTasks(); // collect all the source files in open projects ModelManagerInterface *modelManager = ModelManagerInterface::instance(); QStringList sourceFiles; foreach (const ModelManagerInterface::ProjectInfo &info, modelManager->projectInfos()) { sourceFiles += info.sourceFiles; } // process them QFuture<FileErrorMessages> future = QtConcurrent::run<FileErrorMessages>( &collectMessages, modelManager->snapshot(), sourceFiles, modelManager->importPaths()); m_messageCollector.setFuture(future); }