forked from qt-creator/qt-creator
Clang: Add refactoring project updater
The project parts are now first used by the pch manager and then notified by the pch manager to the refactoring plugin. Change-Id: I88074d8891cd0de9721497bbafee0deffc0b6339 Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
This commit is contained in:
@@ -21,7 +21,8 @@ HEADERS += \
|
||||
sourcelocations.h \
|
||||
symbolsfindfilterconfigwidget.h \
|
||||
symbolquery.h \
|
||||
qtcreatoreditormanager.h
|
||||
qtcreatoreditormanager.h \
|
||||
qtcreatorrefactoringprojectupdater.h
|
||||
|
||||
SOURCES += \
|
||||
clangrefactoringplugin.cpp \
|
||||
@@ -35,7 +36,8 @@ SOURCES += \
|
||||
qtcreatorsearchhandle.cpp \
|
||||
qtcreatorsymbolsfindfilter.cpp \
|
||||
symbolsfindfilterconfigwidget.cpp \
|
||||
qtcreatoreditormanager.cpp
|
||||
qtcreatoreditormanager.cpp \
|
||||
qtcreatorrefactoringprojectupdater.cpp
|
||||
|
||||
FORMS += \
|
||||
clangqueryprojectsfindfilter.ui
|
||||
|
||||
@@ -27,12 +27,13 @@
|
||||
#include "locatorfilter.h"
|
||||
#include "qtcreatorsymbolsfindfilter.h"
|
||||
#include "qtcreatoreditormanager.h"
|
||||
#include "qtcreatorrefactoringprojectupdater.h"
|
||||
#include "querysqlitestatementfactory.h"
|
||||
#include "sqlitedatabase.h"
|
||||
#include "sqlitereadstatement.h"
|
||||
#include "symbolquery.h"
|
||||
|
||||
#include <clangpchmanager/qtcreatorprojectupdater.h>
|
||||
#include <clangpchmanager/clangpchmanagerplugin.h>
|
||||
#include <clangsupport/refactoringdatabaseinitializer.h>
|
||||
|
||||
#include <cpptools/cppmodelmanager.h>
|
||||
@@ -72,7 +73,6 @@ std::unique_ptr<ClangRefactoringPluginData> ClangRefactoringPlugin::d;
|
||||
|
||||
class ClangRefactoringPluginData
|
||||
{
|
||||
using ProjectUpdater = ClangPchManager::QtCreatorProjectUpdater<ClangPchManager::ProjectUpdater>;
|
||||
public:
|
||||
using QuerySqliteReadStatementFactory = QuerySqliteStatementFactory<Sqlite::Database,
|
||||
Sqlite::ReadStatement>;
|
||||
@@ -90,7 +90,9 @@ public:
|
||||
QtCreatorClangQueryFindFilter qtCreatorfindFilter{connectionClient.serverProxy(),
|
||||
qtCreatorSearch,
|
||||
refactoringClient};
|
||||
ProjectUpdater projectUpdate{connectionClient.serverProxy(), filePathCache};
|
||||
QtCreatorRefactoringProjectUpdater projectUpdate{connectionClient.serverProxy(),
|
||||
ClangPchManager::ClangPchManagerPlugin::pchManagerClient(),
|
||||
filePathCache};
|
||||
};
|
||||
|
||||
ClangRefactoringPlugin::ClangRefactoringPlugin()
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2018 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "qtcreatorrefactoringprojectupdater.h"
|
||||
|
||||
#include <cpptools/abstracteditorsupport.h>
|
||||
#include <cpptools/cppmodelmanager.h>
|
||||
|
||||
namespace ClangRefactoring {
|
||||
|
||||
namespace {
|
||||
|
||||
CppTools::CppModelManager *cppModelManager()
|
||||
{
|
||||
return CppTools::CppModelManager::instance();
|
||||
}
|
||||
|
||||
std::vector<ClangBackEnd::V2::FileContainer> createGeneratedFiles()
|
||||
{
|
||||
auto abstractEditors = CppTools::CppModelManager::instance()->abstractEditorSupports();
|
||||
std::vector<ClangBackEnd::V2::FileContainer> generatedFiles;
|
||||
generatedFiles.reserve(std::size_t(abstractEditors.size()));
|
||||
|
||||
auto toFileContainer = [] (const CppTools::AbstractEditorSupport *abstractEditor) {
|
||||
return ClangBackEnd::V2::FileContainer(ClangBackEnd::FilePath(abstractEditor->fileName()),
|
||||
Utils::SmallString::fromQByteArray(abstractEditor->contents()),
|
||||
{});
|
||||
};
|
||||
|
||||
std::transform(abstractEditors.begin(),
|
||||
abstractEditors.end(),
|
||||
std::back_inserter(generatedFiles),
|
||||
toFileContainer);
|
||||
|
||||
std::sort(generatedFiles.begin(), generatedFiles.end());
|
||||
|
||||
return generatedFiles;
|
||||
}
|
||||
}
|
||||
|
||||
QtCreatorRefactoringProjectUpdater::QtCreatorRefactoringProjectUpdater(ClangBackEnd::ProjectManagementServerInterface &server,
|
||||
ClangPchManager::PchManagerClient &pchManagerClient,
|
||||
ClangBackEnd::FilePathCachingInterface &filePathCache)
|
||||
: RefactoringProjectUpdater(server, pchManagerClient, *cppModelManager(), filePathCache)
|
||||
{
|
||||
connectToCppModelManager();
|
||||
}
|
||||
|
||||
void QtCreatorRefactoringProjectUpdater::abstractEditorUpdated(const QString &filePath, const QByteArray &contents)
|
||||
{
|
||||
RefactoringProjectUpdater::updateGeneratedFiles({{ClangBackEnd::FilePath{filePath}, contents}});
|
||||
}
|
||||
|
||||
void QtCreatorRefactoringProjectUpdater::abstractEditorRemoved(const QString &filePath)
|
||||
{
|
||||
RefactoringProjectUpdater::removeGeneratedFiles({ClangBackEnd::FilePath{filePath}});
|
||||
}
|
||||
|
||||
void QtCreatorRefactoringProjectUpdater::connectToCppModelManager()
|
||||
{
|
||||
RefactoringProjectUpdater::updateGeneratedFiles(createGeneratedFiles());
|
||||
|
||||
QObject::connect(cppModelManager(),
|
||||
&CppTools::CppModelManager::abstractEditorSupportContentsUpdated,
|
||||
[&] (const QString &filePath, const QByteArray &contents) {
|
||||
abstractEditorUpdated(filePath, contents);
|
||||
});
|
||||
|
||||
QObject::connect(cppModelManager(),
|
||||
&CppTools::CppModelManager::abstractEditorSupportRemoved,
|
||||
[&] (const QString &filePath) {
|
||||
abstractEditorRemoved(filePath);
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace ClangRefactoring
|
||||
@@ -0,0 +1,45 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2018 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "refactoringprojectupdater.h"
|
||||
|
||||
namespace ClangRefactoring {
|
||||
|
||||
class QtCreatorRefactoringProjectUpdater final : public RefactoringProjectUpdater
|
||||
{
|
||||
public:
|
||||
QtCreatorRefactoringProjectUpdater(ClangBackEnd::ProjectManagementServerInterface &server,
|
||||
ClangPchManager::PchManagerClient &pchManagerClient,
|
||||
ClangBackEnd::FilePathCachingInterface &filePathCache);
|
||||
|
||||
private:
|
||||
void abstractEditorUpdated(const QString &filePath, const QByteArray &contents);
|
||||
void abstractEditorRemoved(const QString &filePath);
|
||||
void connectToCppModelManager();
|
||||
};
|
||||
|
||||
} // namespace ClangRefactoring
|
||||
@@ -25,14 +25,22 @@
|
||||
|
||||
#include "refactoringprojectupdater.h"
|
||||
|
||||
#include <cpptools/cppmodelmanager.h>
|
||||
|
||||
namespace ClangRefactoring {
|
||||
|
||||
RefactoringProjectUpdater::RefactoringProjectUpdater(ClangBackEnd::ProjectManagementServerInterface &server,
|
||||
RefactoringClient &,
|
||||
ClangBackEnd::FilePathCachingInterface &filePathCache)
|
||||
: ClangPchManager::ProjectUpdater(server, filePathCache)
|
||||
void RefactoringProjectUpdater::precompiledHeaderUpdated(const QString &projectPartId,
|
||||
const QString &,
|
||||
long long)
|
||||
{
|
||||
auto projectPart = m_cppModelManager.projectPartForId(projectPartId);
|
||||
if (projectPart)
|
||||
updateProjectParts({projectPart.data()});
|
||||
}
|
||||
|
||||
void RefactoringProjectUpdater::precompiledHeaderRemoved(const QString &projectPartId)
|
||||
{
|
||||
removeProjectParts({projectPartId});
|
||||
}
|
||||
|
||||
} // namespace ClangRefactoring
|
||||
|
||||
@@ -26,17 +26,34 @@
|
||||
#pragma once
|
||||
|
||||
#include <clangpchmanager/projectupdater.h>
|
||||
#include <clangpchmanager/pchmanagernotifierinterface.h>
|
||||
|
||||
#include <cpptools/cppmodelmanagerinterface.h>
|
||||
|
||||
namespace ClangRefactoring {
|
||||
|
||||
class RefactoringClient;
|
||||
|
||||
class RefactoringProjectUpdater : public ClangPchManager::ProjectUpdater
|
||||
class RefactoringProjectUpdater : public ClangPchManager::ProjectUpdater,
|
||||
public ClangPchManager::PchManagerNotifierInterface
|
||||
{
|
||||
public:
|
||||
RefactoringProjectUpdater(ClangBackEnd::ProjectManagementServerInterface &server,
|
||||
RefactoringClient &client,
|
||||
ClangBackEnd::FilePathCachingInterface &filePathCache);
|
||||
ClangPchManager::PchManagerClient &pchManagerClient,
|
||||
CppTools::CppModelManagerInterface &cppModelManager,
|
||||
ClangBackEnd::FilePathCachingInterface &filePathCache)
|
||||
: ClangPchManager::ProjectUpdater(server, filePathCache),
|
||||
ClangPchManager::PchManagerNotifierInterface(pchManagerClient),
|
||||
m_cppModelManager(cppModelManager)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void precompiledHeaderUpdated(const QString &projectPartId,
|
||||
const QString &pchFilePath,
|
||||
long long lastModified) override;
|
||||
void precompiledHeaderRemoved(const QString &projectPartId) override;
|
||||
|
||||
private:
|
||||
CppTools::CppModelManagerInterface &m_cppModelManager;
|
||||
};
|
||||
|
||||
} // namespace ClangRefactoring
|
||||
|
||||
Reference in New Issue
Block a user