QList<QmlJSEditor::FindReferences::Usage> FindImplementation::run(const QString &fileName, const QString &typeName, const QString &itemName) { QList<QmlJSEditor::FindReferences::Usage> usages; QmlJS::ModelManagerInterface *modelManager = ModelManagerInterface::instance(); //Parse always the latest version of document QmlJS::Dialect dialect = QmlJS::ModelManagerInterface::guessLanguageOfFile(fileName); QmlJS::Document::MutablePtr documentUpdate = QmlJS::Document::create(fileName, dialect); documentUpdate->setSource(modelManager->workingCopy().source(fileName)); if (documentUpdate->parseQml()) modelManager->updateDocument(documentUpdate); Document::Ptr document = modelManager->snapshot().document(fileName); if (!document) return usages; QmlJS::Link link(modelManager->snapshot(), modelManager->defaultVContext(document->language(), document), modelManager->builtins(document)); ContextPtr context = link(); ScopeChain scopeChain(document, context); const ObjectValue *targetValue = scopeChain.context()->lookupType(document.data(), QStringList(typeName)); FindImplementationVisitor visitor(document, context); FindImplementationVisitor::Results results = visitor(typeName, itemName, targetValue); foreach (const AST::SourceLocation &location, results) { usages.append(QmlJSEditor::FindReferences::Usage(fileName, matchingLine(location.offset, document->source()), location.startLine, location.startColumn - 1, location.length)); }
void QmlJSEditorWidget::updateCodeWarnings(Document::Ptr doc) { if (doc->ast()) { setExtraSelections(CodeWarningsSelection, QList<QTextEdit::ExtraSelection>()); } else if (doc->language().isFullySupportedLanguage()) { // show parsing errors QList<QTextEdit::ExtraSelection> selections; appendExtraSelectionsForMessages(&selections, doc->diagnosticMessages(), document()); setExtraSelections(CodeWarningsSelection, selections); } else { setExtraSelections(CodeWarningsSelection, QList<QTextEdit::ExtraSelection>()); } }
void QmlTaskManager::collectMessages( QFutureInterface<FileErrorMessages> &future, Snapshot snapshot, QList<ModelManagerInterface::ProjectInfo> projectInfos, ViewerContext vContext, bool updateSemantic) { foreach (const ModelManagerInterface::ProjectInfo &info, projectInfos) { QHash<QString, QList<DiagnosticMessage> > linkMessages; ContextPtr context; if (updateSemantic) { Link link(snapshot, vContext, snapshot.libraryInfo(info.qtImportsPath)); context = link(&linkMessages); } foreach (const QString &fileName, info.sourceFiles) { Document::Ptr document = snapshot.document(fileName); if (!document) continue; FileErrorMessages result; result.fileName = fileName; if (Document::isFullySupportedLanguage(document->language())) { result.tasks = convertToTasks(document->diagnosticMessages(), Utils::FileName::fromString(fileName), Core::Id(Constants::TASK_CATEGORY_QML)); if (updateSemantic) { result.tasks += convertToTasks(linkMessages.value(fileName), Utils::FileName::fromString(fileName), Core::Id(Constants::TASK_CATEGORY_QML_ANALYSIS)); Check checker(document, context); result.tasks += convertToTasks(checker(), Utils::FileName::fromString(fileName), Core::Id(Constants::TASK_CATEGORY_QML_ANALYSIS)); } } if (!result.tasks.isEmpty()) future.reportResult(result); if (future.isCanceled()) break; } }