forked from qt-creator/qt-creator
cppeditor: Show hints for qmlRegister... diagnostics
This fixes passing the hints from FindExportedCppTypes to the actual cppeditor so they can be displayed to the user. Fixes: QTCREATORBUG-27243 Change-Id: Ibcb68296f044a9c6a96f40945d8a0e964be7f042 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -334,7 +334,7 @@ protected:
|
|||||||
_doc->fileName(),
|
_doc->fileName(),
|
||||||
line, column,
|
line, column,
|
||||||
QmlJS::FindExportedCppTypes::tr(
|
QmlJS::FindExportedCppTypes::tr(
|
||||||
"The module URI cannot be determined by static analysis. The type will be available\n"
|
"The module URI cannot be determined by static analysis. The type will not be available\n"
|
||||||
"globally in the QML editor. You can add a \"// @uri My.Module.Uri\" annotation to let\n"
|
"globally in the QML editor. You can add a \"// @uri My.Module.Uri\" annotation to let\n"
|
||||||
"the QML editor know about a likely URI."));
|
"the QML editor know about a likely URI."));
|
||||||
}
|
}
|
||||||
|
@@ -465,7 +465,8 @@ Import LinkPrivate::importNonFile(const Document::Ptr &doc, const ImportInfo &im
|
|||||||
"For Qbs projects, declare and set a qmlImportPaths property in your product "
|
"For Qbs projects, declare and set a qmlImportPaths property in your product "
|
||||||
"to add import paths.\n"
|
"to add import paths.\n"
|
||||||
"For qmlproject projects, use the importPaths property 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")
|
"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(), m_importPaths.join(QLatin1Char('\n'))));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -50,7 +50,9 @@
|
|||||||
#include <utils/minimizableinfobars.h>
|
#include <utils/minimizableinfobars.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
#include <utils/runextensions.h>
|
#include <utils/runextensions.h>
|
||||||
|
#include <utils/utilsicons.h>
|
||||||
|
|
||||||
|
#include <QApplication>
|
||||||
#include <QTextDocument>
|
#include <QTextDocument>
|
||||||
|
|
||||||
const char NO_PROJECT_CONFIGURATION[] = "NoProject";
|
const char NO_PROJECT_CONFIGURATION[] = "NoProject";
|
||||||
@@ -121,6 +123,9 @@ CppEditorDocument::CppEditorDocument()
|
|||||||
connect(this, &IDocument::filePathChanged,
|
connect(this, &IDocument::filePathChanged,
|
||||||
this, &CppEditorDocument::onFilePathChanged);
|
this, &CppEditorDocument::onFilePathChanged);
|
||||||
|
|
||||||
|
connect(mm(), &CppModelManager::diagnosticsChanged,
|
||||||
|
this, &CppEditorDocument::onDiagnosticsChanged);
|
||||||
|
|
||||||
connect(&m_parseContextModel, &ParseContextModel::preferredParseContextChanged,
|
connect(&m_parseContextModel, &ParseContextModel::preferredParseContextChanged,
|
||||||
this, &CppEditorDocument::reparseWithPreferredParseContext);
|
this, &CppEditorDocument::reparseWithPreferredParseContext);
|
||||||
|
|
||||||
@@ -483,5 +488,51 @@ bool CppEditorDocument::save(QString *errorString, const FilePath &filePath, boo
|
|||||||
return TextEditor::TextDocument::save(errorString, filePath, autoSave);
|
return TextEditor::TextDocument::save(errorString, filePath, autoSave);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CppEditorDocument::onDiagnosticsChanged(const QString &fileName, const QString &kind)
|
||||||
|
{
|
||||||
|
if (FilePath::fromString(fileName) != filePath())
|
||||||
|
return;
|
||||||
|
|
||||||
|
TextMarks removedMarks = marks();
|
||||||
|
|
||||||
|
const Utils::Id category = Utils::Id::fromString(kind);
|
||||||
|
|
||||||
|
for (const auto &diagnostic : mm()->diagnosticMessages()) {
|
||||||
|
if (FilePath::fromString(diagnostic.fileName()) == filePath()) {
|
||||||
|
auto it = std::find_if(std::begin(removedMarks),
|
||||||
|
std::end(removedMarks),
|
||||||
|
[&category, &diagnostic](TextMark *existing) {
|
||||||
|
return (diagnostic.line() == existing->lineNumber()
|
||||||
|
&& diagnostic.text() == existing->lineAnnotation()
|
||||||
|
&& category == existing->category());
|
||||||
|
});
|
||||||
|
|
||||||
|
if (it != std::end(removedMarks)) {
|
||||||
|
removedMarks.erase(it);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto mark = new TextMark(filePath(), diagnostic.line(), category);
|
||||||
|
mark->setLineAnnotation(diagnostic.text());
|
||||||
|
mark->setToolTip(diagnostic.text());
|
||||||
|
|
||||||
|
mark->setIcon(diagnostic.isWarning() ? Utils::Icons::CODEMODEL_WARNING.icon()
|
||||||
|
: Utils::Icons::CODEMODEL_ERROR.icon());
|
||||||
|
mark->setColor(diagnostic.isWarning() ? Utils::Theme::CodeModel_Warning_TextMarkColor
|
||||||
|
: Utils::Theme::CodeModel_Error_TextMarkColor);
|
||||||
|
mark->setPriority(diagnostic.isWarning() ? TextEditor::TextMark::NormalPriority
|
||||||
|
: TextEditor::TextMark::HighPriority);
|
||||||
|
addMark(mark);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto it = removedMarks.begin(); it != removedMarks.end(); ++it) {
|
||||||
|
if ((*it)->category() == category) {
|
||||||
|
removeMark(*it);
|
||||||
|
delete *it;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
} // namespace CppEditor
|
} // namespace CppEditor
|
||||||
|
@@ -94,6 +94,8 @@ private:
|
|||||||
|
|
||||||
void onAboutToReload();
|
void onAboutToReload();
|
||||||
void onReloadFinished();
|
void onReloadFinished();
|
||||||
|
void onDiagnosticsChanged(const QString &fileName, const QString &kind);
|
||||||
|
|
||||||
|
|
||||||
void reparseWithPreferredParseContext(const QString &id);
|
void reparseWithPreferredParseContext(const QString &id);
|
||||||
|
|
||||||
|
@@ -201,6 +201,8 @@ public:
|
|||||||
std::unique_ptr<Core::ILocatorFilter> m_functionsFilter;
|
std::unique_ptr<Core::ILocatorFilter> m_functionsFilter;
|
||||||
std::unique_ptr<Core::IFindFilter> m_symbolsFindFilter;
|
std::unique_ptr<Core::IFindFilter> m_symbolsFindFilter;
|
||||||
std::unique_ptr<Core::ILocatorFilter> m_currentDocumentFilter;
|
std::unique_ptr<Core::ILocatorFilter> m_currentDocumentFilter;
|
||||||
|
|
||||||
|
QList<Document::DiagnosticMessage> m_diagnosticMessages;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
@@ -1704,4 +1706,18 @@ QThreadPool *CppModelManager::sharedThreadPool()
|
|||||||
return &d->m_threadPool;
|
return &d->m_threadPool;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CppModelManager::setExtraDiagnostics(const QString &fileName,
|
||||||
|
const QString &kind,
|
||||||
|
const QList<Document::DiagnosticMessage> &diagnostics)
|
||||||
|
{
|
||||||
|
d->m_diagnosticMessages = diagnostics;
|
||||||
|
emit diagnosticsChanged(fileName, kind);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QList<Document::DiagnosticMessage> CppModelManager::diagnosticMessages()
|
||||||
|
{
|
||||||
|
return d->m_diagnosticMessages;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace CppEditor
|
} // namespace CppEditor
|
||||||
|
@@ -104,6 +104,12 @@ public:
|
|||||||
QByteArray codeModelConfiguration() const;
|
QByteArray codeModelConfiguration() const;
|
||||||
CppLocatorData *locatorData() const;
|
CppLocatorData *locatorData() const;
|
||||||
|
|
||||||
|
bool setExtraDiagnostics(const QString &fileName,
|
||||||
|
const QString &kind,
|
||||||
|
const QList<Document::DiagnosticMessage> &diagnostics) override;
|
||||||
|
|
||||||
|
const QList<Document::DiagnosticMessage> diagnosticMessages();
|
||||||
|
|
||||||
QList<ProjectInfo::ConstPtr> projectInfos() const;
|
QList<ProjectInfo::ConstPtr> projectInfos() const;
|
||||||
ProjectInfo::ConstPtr projectInfo(ProjectExplorer::Project *project) const;
|
ProjectInfo::ConstPtr projectInfo(ProjectExplorer::Project *project) const;
|
||||||
QFuture<void> updateProjectInfo(const ProjectInfo::ConstPtr &newProjectInfo,
|
QFuture<void> updateProjectInfo(const ProjectInfo::ConstPtr &newProjectInfo,
|
||||||
@@ -256,6 +262,8 @@ signals:
|
|||||||
void abstractEditorSupportRemoved(const QString &filePath);
|
void abstractEditorSupportRemoved(const QString &filePath);
|
||||||
void fallbackProjectPartUpdated();
|
void fallbackProjectPartUpdated();
|
||||||
|
|
||||||
|
void diagnosticsChanged(const QString &fileName, const QString &kind);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void updateModifiedSourceFiles();
|
void updateModifiedSourceFiles();
|
||||||
void GC();
|
void GC();
|
||||||
|
Reference in New Issue
Block a user