forked from qt-creator/qt-creator
CppEditor: Make check for clangd more fine-grained
... in the quickfix factories. We want to be able to offer or not offer certain quickfixes based on the current clangd version. Change-Id: I7dca69ff990ab9f1a691785cd72e633f7882ae3d Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Christian Stenger <christian.stenger@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
@@ -428,9 +428,12 @@ void ClangModelManagerSupport::checkUnused(const Link &link, SearchResult *searc
|
||||
CppModelManager::Backend::Builtin)->checkUnused(link, search, callback);
|
||||
}
|
||||
|
||||
bool ClangModelManagerSupport::usesClangd(const TextEditor::TextDocument *document) const
|
||||
std::optional<QVersionNumber> ClangModelManagerSupport::usesClangd(
|
||||
const TextEditor::TextDocument *document) const
|
||||
{
|
||||
return clientForFile(document->filePath());
|
||||
if (const auto client = clientForFile(document->filePath()))
|
||||
return client->versionNumber();
|
||||
return {};
|
||||
}
|
||||
|
||||
BaseEditorDocumentProcessor *ClangModelManagerSupport::createEditorDocumentProcessor(
|
||||
|
||||
@@ -42,7 +42,7 @@ public:
|
||||
|
||||
CppEditor::BaseEditorDocumentProcessor *createEditorDocumentProcessor(
|
||||
TextEditor::TextDocument *baseTextDocument) override;
|
||||
bool usesClangd(const TextEditor::TextDocument *document) const override;
|
||||
std::optional<QVersionNumber> usesClangd(const TextEditor::TextDocument *document) const override;
|
||||
|
||||
static QList<LanguageClient::Client *> clientsForOpenProjects();
|
||||
static ClangdClient *clientForProject(const ProjectExplorer::Project *project);
|
||||
|
||||
@@ -475,7 +475,7 @@ bool CppEditorDocument::saveImpl(QString *errorString, const FilePath &filePath,
|
||||
|
||||
bool CppEditorDocument::usesClangd() const
|
||||
{
|
||||
return CppModelManager::usesClangd(this);
|
||||
return CppModelManager::usesClangd(this).has_value();
|
||||
}
|
||||
|
||||
void CppEditorDocument::onDiagnosticsChanged(const FilePath &fileName, const QString &kind)
|
||||
|
||||
@@ -1714,7 +1714,7 @@ bool CppModelManager::isCppEditor(IEditor *editor)
|
||||
return editor->context().contains(ProjectExplorer::Constants::CXX_LANGUAGE_ID);
|
||||
}
|
||||
|
||||
bool CppModelManager::usesClangd(const TextEditor::TextDocument *document)
|
||||
std::optional<QVersionNumber> CppModelManager::usesClangd(const TextEditor::TextDocument *document)
|
||||
{
|
||||
return d->m_activeModelManagerSupport->usesClangd(document);
|
||||
}
|
||||
|
||||
@@ -19,9 +19,11 @@
|
||||
#include <QFuture>
|
||||
#include <QObject>
|
||||
#include <QStringList>
|
||||
#include <QVersionNumber>
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <utility>
|
||||
|
||||
namespace Core {
|
||||
@@ -132,7 +134,7 @@ public:
|
||||
static void emitAbstractEditorSupportRemoved(const QString &filePath);
|
||||
|
||||
static bool isCppEditor(Core::IEditor *editor);
|
||||
static bool usesClangd(const TextEditor::TextDocument *document);
|
||||
static std::optional<QVersionNumber> usesClangd(const TextEditor::TextDocument *document);
|
||||
static bool isClangCodeModelActive();
|
||||
|
||||
static QSet<AbstractEditorSupport*> abstractEditorSupports();
|
||||
|
||||
@@ -9,7 +9,10 @@
|
||||
|
||||
#include <utils/link.h>
|
||||
|
||||
#include <QVersionNumber>
|
||||
|
||||
#include <functional>
|
||||
#include <optional>
|
||||
|
||||
namespace Core { class SearchResult; }
|
||||
namespace TextEditor {
|
||||
@@ -31,7 +34,10 @@ public:
|
||||
|
||||
virtual BaseEditorDocumentProcessor *createEditorDocumentProcessor(
|
||||
TextEditor::TextDocument *baseTextDocument) = 0;
|
||||
virtual bool usesClangd(const TextEditor::TextDocument *) const { return false; }
|
||||
virtual std::optional<QVersionNumber> usesClangd(const TextEditor::TextDocument *) const
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
virtual void followSymbol(const CursorInEditor &data,
|
||||
const Utils::LinkHandler &processLinkCallback,
|
||||
|
||||
@@ -8,6 +8,10 @@
|
||||
|
||||
#include <texteditor/quickfix.h>
|
||||
|
||||
#include <QVersionNumber>
|
||||
|
||||
#include <optional>
|
||||
|
||||
namespace CppEditor {
|
||||
namespace Internal {
|
||||
class CppQuickFixInterface;
|
||||
@@ -52,8 +56,8 @@ public:
|
||||
|
||||
static const QList<CppQuickFixFactory *> &cppQuickFixFactories();
|
||||
|
||||
bool hasClangdReplacement() const { return m_hasClangdReplacement; }
|
||||
void setHasClangdReplacement() { m_hasClangdReplacement = true; }
|
||||
std::optional<QVersionNumber> clangdReplacement() const { return m_clangdReplacement; }
|
||||
void setClangdReplacement(const QVersionNumber &version) { m_clangdReplacement = version; }
|
||||
|
||||
private:
|
||||
/*!
|
||||
@@ -63,7 +67,7 @@ private:
|
||||
virtual void doMatch(const Internal::CppQuickFixInterface &interface,
|
||||
QuickFixOperations &result) = 0;
|
||||
|
||||
bool m_hasClangdReplacement = false;
|
||||
std::optional<QVersionNumber> m_clangdReplacement;
|
||||
};
|
||||
|
||||
} // namespace CppEditor
|
||||
|
||||
@@ -191,7 +191,7 @@ QuickFixOperationTest::QuickFixOperationTest(const QList<TestDocumentPtr> &testD
|
||||
const QByteArray &clangFormatSettings)
|
||||
: BaseQuickFixTestCase(testDocuments, headerPaths, clangFormatSettings)
|
||||
{
|
||||
if (factory->hasClangdReplacement() && CppModelManager::isClangCodeModelActive())
|
||||
if (factory->clangdReplacement() && CppModelManager::isClangCodeModelActive())
|
||||
return;
|
||||
|
||||
QVERIFY(succeededSoFar());
|
||||
|
||||
@@ -104,9 +104,12 @@ CppQuickFixFactory::~CppQuickFixFactory()
|
||||
void CppQuickFixFactory::match(const Internal::CppQuickFixInterface &interface,
|
||||
QuickFixOperations &result)
|
||||
{
|
||||
if (m_hasClangdReplacement
|
||||
&& CppModelManager::usesClangd(interface.currentFile()->editor()->textDocument())) {
|
||||
return;
|
||||
if (m_clangdReplacement) {
|
||||
if (const auto clangdVersion = CppModelManager::usesClangd(
|
||||
interface.currentFile()->editor()->textDocument());
|
||||
clangdVersion && clangdVersion >= m_clangdReplacement) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
doMatch(interface, result);
|
||||
|
||||
@@ -338,7 +338,7 @@ public:
|
||||
class CompleteSwitchCaseStatement: public CppQuickFixFactory
|
||||
{
|
||||
public:
|
||||
CompleteSwitchCaseStatement() { setHasClangdReplacement(); }
|
||||
CompleteSwitchCaseStatement() { setClangdReplacement({12}); }
|
||||
|
||||
private:
|
||||
void doMatch(const CppQuickFixInterface &interface, QuickFixOperations &result) override;
|
||||
@@ -580,7 +580,7 @@ public:
|
||||
class RemoveUsingNamespace : public CppQuickFixFactory
|
||||
{
|
||||
public:
|
||||
RemoveUsingNamespace() { setHasClangdReplacement(); }
|
||||
RemoveUsingNamespace() { setClangdReplacement({10}); }
|
||||
|
||||
private:
|
||||
void doMatch(const CppQuickFixInterface &interface, TextEditor::QuickFixOperations &result) override;
|
||||
|
||||
@@ -747,7 +747,8 @@ void QtCreatorIntegration::handleSymbolRenameStage2(
|
||||
// In the case of clangd, this entails doing a "virtual rename" on the TextDocument,
|
||||
// as the LanguageClient cannot be forced into taking a document and assuming a different
|
||||
// file path.
|
||||
const bool usesClangd = CppEditor::CppModelManager::usesClangd(editorWidget->textDocument());
|
||||
const bool usesClangd
|
||||
= CppEditor::CppModelManager::usesClangd(editorWidget->textDocument()).has_value();
|
||||
if (usesClangd)
|
||||
editorWidget->textDocument()->setFilePath(uiHeader);
|
||||
editorWidget->textDocument()->setPlainText(QString::fromUtf8(virtualContent));
|
||||
|
||||
Reference in New Issue
Block a user