CppEditor: Proliferate use of FilePath a bit

Change-Id: I7e314d73a427bf40c10f3ca6c4c5804e31482f88
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
hjk
2023-07-25 12:54:45 +02:00
parent cecf9c9136
commit 8423d2b5e5
7 changed files with 23 additions and 19 deletions

View File

@@ -3,29 +3,32 @@
#include "cppmodelmanagerbase.h" #include "cppmodelmanagerbase.h"
#include <utils/filepath.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
using namespace Utils;
namespace CPlusPlus::CppModelManagerBase { namespace CPlusPlus::CppModelManagerBase {
static bool (*setExtraDiagnosticsCallback) static bool (*setExtraDiagnosticsCallback)
(const QString &, const QString &, const QList<Document::DiagnosticMessage> &) = nullptr; (const FilePath &, const QString &, const QList<Document::DiagnosticMessage> &) = nullptr;
static CPlusPlus::Snapshot (*snapshotCallback)() = nullptr; static CPlusPlus::Snapshot (*snapshotCallback)() = nullptr;
bool trySetExtraDiagnostics(const QString &fileName, const QString &kind, bool trySetExtraDiagnostics(const FilePath &filePath, const QString &kind,
const QList<Document::DiagnosticMessage> &diagnostics) const QList<Document::DiagnosticMessage> &diagnostics)
{ {
if (!setExtraDiagnosticsCallback) if (!setExtraDiagnosticsCallback)
return false; return false;
return setExtraDiagnosticsCallback(fileName, kind, diagnostics); return setExtraDiagnosticsCallback(filePath, kind, diagnostics);
} }
bool setExtraDiagnostics(const QString &fileName, const QString &kind, bool setExtraDiagnostics(const FilePath &filePath, const QString &kind,
const QList<Document::DiagnosticMessage> &diagnostics) const QList<Document::DiagnosticMessage> &diagnostics)
{ {
QTC_ASSERT(setExtraDiagnosticsCallback, return false); QTC_ASSERT(setExtraDiagnosticsCallback, return false);
return setExtraDiagnosticsCallback(fileName, kind, diagnostics); return setExtraDiagnosticsCallback(filePath, kind, diagnostics);
} }
Snapshot snapshot() Snapshot snapshot()
@@ -42,7 +45,7 @@ bool hasSnapshots()
// Installation // Installation
void registerSetExtraDiagnosticsCallback( void registerSetExtraDiagnosticsCallback(
bool (*callback)(const QString &, const QString &, const QList<Document::DiagnosticMessage> &)) bool (*callback)(const FilePath &, const QString &, const QList<Document::DiagnosticMessage> &))
{ {
QTC_ASSERT(callback, return); QTC_ASSERT(callback, return);
QTC_CHECK(!setExtraDiagnosticsCallback); // bark when used twice QTC_CHECK(!setExtraDiagnosticsCallback); // bark when used twice

View File

@@ -5,13 +5,15 @@
#include <cplusplus/CppDocument.h> #include <cplusplus/CppDocument.h>
namespace Utils { class FilePath; }
namespace CPlusPlus::CppModelManagerBase { namespace CPlusPlus::CppModelManagerBase {
CPLUSPLUS_EXPORT bool trySetExtraDiagnostics CPLUSPLUS_EXPORT bool trySetExtraDiagnostics
(const QString &, const QString &, const QList<Document::DiagnosticMessage> &); (const Utils::FilePath &filePath, const QString &, const QList<Document::DiagnosticMessage> &);
CPLUSPLUS_EXPORT bool setSetExtraDiagnostics CPLUSPLUS_EXPORT bool setSetExtraDiagnostics
(const QString &, const QString &, const QList<Document::DiagnosticMessage> &); (const Utils::FilePath &, const QString &, const QList<Document::DiagnosticMessage> &);
CPLUSPLUS_EXPORT bool hasSnapshots(); CPLUSPLUS_EXPORT bool hasSnapshots();
@@ -23,6 +25,6 @@ CPLUSPLUS_EXPORT CPlusPlus::Snapshot snapshot();
CPLUSPLUS_EXPORT void registerSnapshotCallback(CPlusPlus::Snapshot (*)(void)); CPLUSPLUS_EXPORT void registerSnapshotCallback(CPlusPlus::Snapshot (*)(void));
CPLUSPLUS_EXPORT void registerSetExtraDiagnosticsCallback( CPLUSPLUS_EXPORT void registerSetExtraDiagnosticsCallback(
bool(*)(const QString &, const QString &, const QList<Document::DiagnosticMessage> &)); bool(*)(const Utils::FilePath &, const QString &, const QList<Document::DiagnosticMessage> &));
} // CPlusPlus::CppModelManagerBase } // CPlusPlus::CppModelManagerBase

View File

@@ -842,8 +842,7 @@ QStringList FindExportedCppTypes::operator()(const CPlusPlus::Document::Ptr &doc
FindExportsVisitor finder(document); FindExportsVisitor finder(document);
finder(); finder();
static const QString kindKey = QLatin1String("QmlJSTools.ExportedQmlTypesDiagnostic"); static const QString kindKey = QLatin1String("QmlJSTools.ExportedQmlTypesDiagnostic");
CppModelManagerBase::trySetExtraDiagnostics(document->filePath().toString(), kindKey, CppModelManagerBase::trySetExtraDiagnostics(document->filePath(), kindKey, finder.messages());
finder.messages());
// if nothing was found, done // if nothing was found, done
const QList<ContextProperty> contextPropertyDescriptions = finder.contextProperties(); const QList<ContextProperty> contextPropertyDescriptions = finder.contextProperties();

View File

@@ -479,9 +479,9 @@ bool CppEditorDocument::usesClangd() const
return CppModelManager::usesClangd(this); return CppModelManager::usesClangd(this);
} }
void CppEditorDocument::onDiagnosticsChanged(const QString &fileName, const QString &kind) void CppEditorDocument::onDiagnosticsChanged(const FilePath &fileName, const QString &kind)
{ {
if (FilePath::fromString(fileName) != filePath()) if (fileName != filePath())
return; return;
TextMarks removedMarks = marks(); TextMarks removedMarks = marks();

View File

@@ -76,7 +76,7 @@ private:
void onAboutToReload(); void onAboutToReload();
void onReloadFinished(); void onReloadFinished();
void onDiagnosticsChanged(const QString &fileName, const QString &kind); void onDiagnosticsChanged(const Utils::FilePath &fileName, const QString &kind);
void reparseWithPreferredParseContext(const QString &id); void reparseWithPreferredParseContext(const QString &id);

View File

@@ -2079,12 +2079,12 @@ QThreadPool *CppModelManager::sharedThreadPool()
return &d->m_threadPool; return &d->m_threadPool;
} }
bool CppModelManager::setExtraDiagnostics(const QString &fileName, bool CppModelManager::setExtraDiagnostics(const FilePath &filePath,
const QString &kind, const QString &kind,
const QList<Document::DiagnosticMessage> &diagnostics) const QList<Document::DiagnosticMessage> &diagnostics)
{ {
d->m_diagnosticMessages = diagnostics; d->m_diagnosticMessages = diagnostics;
emit m_instance->diagnosticsChanged(fileName, kind); emit m_instance->diagnosticsChanged(filePath, kind);
return true; return true;
} }

View File

@@ -95,7 +95,7 @@ public:
static QByteArray codeModelConfiguration(); static QByteArray codeModelConfiguration();
static CppLocatorData *locatorData(); static CppLocatorData *locatorData();
static bool setExtraDiagnostics(const QString &fileName, static bool setExtraDiagnostics(const Utils::FilePath &filePath,
const QString &kind, const QString &kind,
const QList<Document::DiagnosticMessage> &diagnostics); const QList<Document::DiagnosticMessage> &diagnostics);
@@ -268,7 +268,7 @@ signals:
void abstractEditorSupportRemoved(const QString &filePath); void abstractEditorSupportRemoved(const QString &filePath);
void fallbackProjectPartUpdated(); void fallbackProjectPartUpdated();
void diagnosticsChanged(const QString &fileName, const QString &kind); void diagnosticsChanged(const Utils::FilePath &filePath, const QString &kind);
public slots: public slots:
static void updateModifiedSourceFiles(); static void updateModifiedSourceFiles();