void addMessages(QList<QmlJS::DiagnosticMessage> messages, const Document::Ptr &doc) { foreach (const DiagnosticMessage &d, messages) { int line = d.loc.startLine; int column = qMax(1U, d.loc.startColumn); int length = d.loc.length; int begin = d.loc.begin(); if (d.loc.length == 0) { QString source(doc->source()); int end = begin; if (begin == source.size() || source.at(begin) == QLatin1Char('\n') || source.at(begin) == QLatin1Char('\r')) { while (begin > end - column && !source.at(--begin).isSpace()) { } } else { while (end < source.size() && source.at(++end).isLetterOrNumber()) { } } column += begin - d.loc.begin(); length = end-begin; } QTextCharFormat format; if (d.isWarning()) format.setUnderlineColor(Qt::darkYellow); else format.setUnderlineColor(Qt::red); format.setUnderlineStyle(QTextCharFormat::WaveUnderline); format.setToolTip(d.message); collectRanges(begin, length, format); addDelayedUse(SemanticHighlighter::Use(line, column, length, addFormat(format))); }
void addMessages(QList<DiagnosticMessage> messages, const Document::Ptr &doc) { foreach (const DiagnosticMessage &d, messages) { int line = d.loc.startLine; int column = qMax(1U, d.loc.startColumn); int length = d.loc.length; int begin = d.loc.begin(); if (d.loc.length == 0) { QString source(doc->source()); int end = begin; if (begin == source.size() || source.at(begin) == QLatin1Char('\n') || source.at(begin) == QLatin1Char('\r')) { while (begin > end - column && !source.at(--begin).isSpace()) { } } else { while (end < source.size() && source.at(++end).isLetterOrNumber()) { } } column += begin - d.loc.begin(); length = end-begin; } const TextEditor::FontSettings &fontSettings = TextEditor::TextEditorSettings::instance()->fontSettings(); QTextCharFormat format; if (d.isWarning()) format = fontSettings.toTextCharFormat(TextEditor::C_WARNING); else format = fontSettings.toTextCharFormat(TextEditor::C_ERROR); format.setToolTip(d.message); collectRanges(begin, length, format); addDelayedUse(SemanticHighlighter::Use(line, column, length, addFormat(format))); }
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)); }