2016-08-04 15:26:53 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** Copyright (C) 2016 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 "clangrefactoringplugin.h"
|
2018-04-09 13:30:30 +02:00
|
|
|
#include "locatorfilter.h"
|
2017-11-24 16:03:07 +01:00
|
|
|
#include "qtcreatorsymbolsfindfilter.h"
|
2018-04-09 13:30:30 +02:00
|
|
|
#include "qtcreatoreditormanager.h"
|
2018-09-06 11:57:36 +02:00
|
|
|
#include "qtcreatorrefactoringprojectupdater.h"
|
2017-09-19 15:38:20 +02:00
|
|
|
#include "querysqlitestatementfactory.h"
|
2017-11-24 16:03:07 +01:00
|
|
|
#include "sqlitedatabase.h"
|
|
|
|
|
#include "sqlitereadstatement.h"
|
|
|
|
|
#include "symbolquery.h"
|
2016-08-04 15:26:53 +02:00
|
|
|
|
2018-09-06 11:57:36 +02:00
|
|
|
#include <clangpchmanager/clangpchmanagerplugin.h>
|
2018-09-27 17:52:44 +02:00
|
|
|
#include <clangpchmanager/progressmanager.h>
|
2017-09-19 15:38:20 +02:00
|
|
|
#include <clangsupport/refactoringdatabaseinitializer.h>
|
2017-08-17 12:44:52 +02:00
|
|
|
|
2016-08-04 15:26:53 +02:00
|
|
|
#include <cpptools/cppmodelmanager.h>
|
|
|
|
|
|
|
|
|
|
#include <coreplugin/icore.h>
|
2018-09-27 17:52:44 +02:00
|
|
|
#include <coreplugin/progressmanager/progressmanager.h>
|
2016-11-15 15:38:12 +01:00
|
|
|
#include <extensionsystem/pluginmanager.h>
|
2018-04-09 13:30:30 +02:00
|
|
|
#include <cpptools/cpptoolsconstants.h>
|
2016-08-04 15:26:53 +02:00
|
|
|
|
2017-09-21 11:43:59 +02:00
|
|
|
#include <refactoringdatabaseinitializer.h>
|
|
|
|
|
#include <filepathcaching.h>
|
|
|
|
|
|
|
|
|
|
#include <sqlitedatabase.h>
|
2016-08-04 15:26:53 +02:00
|
|
|
#include <utils/hostosinfo.h>
|
|
|
|
|
|
2017-09-21 11:43:59 +02:00
|
|
|
#include <QDir>
|
2017-09-19 15:38:20 +02:00
|
|
|
#include <QApplication>
|
2017-09-21 11:43:59 +02:00
|
|
|
|
2018-03-28 17:55:14 +02:00
|
|
|
#include <chrono>
|
|
|
|
|
|
|
|
|
|
using namespace std::chrono_literals;
|
|
|
|
|
|
2016-08-04 15:26:53 +02:00
|
|
|
namespace ClangRefactoring {
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
QString backendProcessPath()
|
|
|
|
|
{
|
|
|
|
|
return Core::ICore::libexecPath()
|
|
|
|
|
+ QStringLiteral("/clangrefactoringbackend")
|
|
|
|
|
+ QStringLiteral(QTC_HOST_EXE_SUFFIX);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
|
2016-11-29 12:50:50 +01:00
|
|
|
std::unique_ptr<ClangRefactoringPluginData> ClangRefactoringPlugin::d;
|
|
|
|
|
|
|
|
|
|
class ClangRefactoringPluginData
|
|
|
|
|
{
|
|
|
|
|
public:
|
2017-10-24 13:45:07 +02:00
|
|
|
using QuerySqliteReadStatementFactory = QuerySqliteStatementFactory<Sqlite::Database,
|
|
|
|
|
Sqlite::ReadStatement>;
|
2019-02-20 17:26:36 +01:00
|
|
|
Sqlite::Database database{Utils::PathString{Core::ICore::cacheResourcePath()
|
|
|
|
|
+ "/symbol-experimental-v1.db"},
|
|
|
|
|
1000ms};
|
2017-09-21 11:43:59 +02:00
|
|
|
ClangBackEnd::RefactoringDatabaseInitializer<Sqlite::Database> databaseInitializer{database};
|
|
|
|
|
ClangBackEnd::FilePathCaching filePathCache{database};
|
2018-09-27 17:52:44 +02:00
|
|
|
ClangPchManager::ProgressManager progressManager{
|
|
|
|
|
[] (QFutureInterface<void> &promise) {
|
|
|
|
|
auto title = QCoreApplication::translate("ClangRefactoringProgressManager", "C++ Indexing");
|
|
|
|
|
Core::ProgressManager::addTask(promise.future(), title, "clang indexing", nullptr);}};
|
|
|
|
|
RefactoringClient refactoringClient{progressManager};
|
2018-04-09 13:30:30 +02:00
|
|
|
QtCreatorEditorManager editorManager{filePathCache};
|
2016-11-29 12:50:50 +01:00
|
|
|
ClangBackEnd::RefactoringConnectionClient connectionClient{&refactoringClient};
|
2017-10-24 13:45:07 +02:00
|
|
|
QuerySqliteReadStatementFactory statementFactory{database};
|
|
|
|
|
SymbolQuery<QuerySqliteReadStatementFactory> symbolQuery{statementFactory};
|
2017-09-19 15:38:20 +02:00
|
|
|
RefactoringEngine engine{connectionClient.serverProxy(), refactoringClient, filePathCache, symbolQuery};
|
2018-03-02 13:08:06 +01:00
|
|
|
QtCreatorSearch qtCreatorSearch;
|
2016-11-29 12:50:50 +01:00
|
|
|
QtCreatorClangQueryFindFilter qtCreatorfindFilter{connectionClient.serverProxy(),
|
|
|
|
|
qtCreatorSearch,
|
|
|
|
|
refactoringClient};
|
2018-09-06 11:57:36 +02:00
|
|
|
QtCreatorRefactoringProjectUpdater projectUpdate{connectionClient.serverProxy(),
|
|
|
|
|
ClangPchManager::ClangPchManagerPlugin::pchManagerClient(),
|
|
|
|
|
filePathCache};
|
2016-11-29 12:50:50 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
ClangRefactoringPlugin::ClangRefactoringPlugin()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ClangRefactoringPlugin::~ClangRefactoringPlugin()
|
|
|
|
|
{
|
|
|
|
|
}
|
2016-08-04 15:26:53 +02:00
|
|
|
|
2017-11-24 10:46:31 +01:00
|
|
|
static bool useClangFilters()
|
|
|
|
|
{
|
|
|
|
|
static bool use = qEnvironmentVariableIntValue("QTC_CLANG_LOCATORS");
|
|
|
|
|
return use;
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-07 12:44:30 +02:00
|
|
|
bool ClangRefactoringPlugin::initialize(const QStringList & /*arguments*/, QString * /*errorMessage*/)
|
2016-08-04 15:26:53 +02:00
|
|
|
{
|
2018-04-09 13:30:30 +02:00
|
|
|
d = std::make_unique<ClangRefactoringPluginData>();
|
2016-09-20 13:21:46 +02:00
|
|
|
|
2016-11-29 12:50:50 +01:00
|
|
|
d->refactoringClient.setRefactoringEngine(&d->engine);
|
2016-12-05 15:19:39 +01:00
|
|
|
d->refactoringClient.setRefactoringConnectionClient(&d->connectionClient);
|
2016-11-29 12:50:50 +01:00
|
|
|
ExtensionSystem::PluginManager::addObject(&d->qtCreatorfindFilter);
|
2016-08-04 15:26:53 +02:00
|
|
|
|
|
|
|
|
connectBackend();
|
|
|
|
|
startBackend();
|
|
|
|
|
|
2017-11-24 10:46:31 +01:00
|
|
|
CppTools::CppModelManager::addRefactoringEngine(
|
|
|
|
|
CppTools::RefactoringEngineType::ClangRefactoring, &refactoringEngine());
|
|
|
|
|
|
|
|
|
|
initializeFilters();
|
|
|
|
|
|
2016-08-04 15:26:53 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ClangRefactoringPlugin::extensionsInitialized()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-20 13:21:46 +02:00
|
|
|
ExtensionSystem::IPlugin::ShutdownFlag ClangRefactoringPlugin::aboutToShutdown()
|
|
|
|
|
{
|
2016-11-29 12:50:50 +01:00
|
|
|
ExtensionSystem::PluginManager::removeObject(&d->qtCreatorfindFilter);
|
2017-09-25 16:41:17 +02:00
|
|
|
CppTools::CppModelManager::removeRefactoringEngine(
|
|
|
|
|
CppTools::RefactoringEngineType::ClangRefactoring);
|
2016-12-05 15:19:39 +01:00
|
|
|
d->refactoringClient.setRefactoringConnectionClient(nullptr);
|
2016-11-29 12:50:50 +01:00
|
|
|
d->refactoringClient.setRefactoringEngine(nullptr);
|
2016-09-20 13:31:36 +02:00
|
|
|
|
2016-11-29 12:50:50 +01:00
|
|
|
d.reset();
|
2016-09-20 13:21:46 +02:00
|
|
|
|
|
|
|
|
return SynchronousShutdown;
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-04 15:26:53 +02:00
|
|
|
RefactoringEngine &ClangRefactoringPlugin::refactoringEngine()
|
|
|
|
|
{
|
2016-11-29 12:50:50 +01:00
|
|
|
return d->engine;
|
2016-08-04 15:26:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ClangRefactoringPlugin::startBackend()
|
|
|
|
|
{
|
2016-11-29 12:50:50 +01:00
|
|
|
d->connectionClient.setProcessPath(backendProcessPath());
|
2016-08-04 15:26:53 +02:00
|
|
|
|
2016-11-29 12:50:50 +01:00
|
|
|
d->connectionClient.startProcessAndConnectToServerAsynchronously();
|
2016-08-04 15:26:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ClangRefactoringPlugin::connectBackend()
|
|
|
|
|
{
|
2016-11-29 12:50:50 +01:00
|
|
|
connect(&d->connectionClient,
|
2016-08-04 15:26:53 +02:00
|
|
|
&ClangBackEnd::RefactoringConnectionClient::connectedToLocalSocket,
|
|
|
|
|
this,
|
|
|
|
|
&ClangRefactoringPlugin::backendIsConnected);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ClangRefactoringPlugin::backendIsConnected()
|
|
|
|
|
{
|
2017-09-25 16:41:17 +02:00
|
|
|
d->engine.setRefactoringEngineAvailable(true);
|
2016-08-04 15:26:53 +02:00
|
|
|
}
|
|
|
|
|
|
2017-11-24 10:46:31 +01:00
|
|
|
void ClangRefactoringPlugin::initializeFilters()
|
|
|
|
|
{
|
|
|
|
|
if (!useClangFilters())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
CppTools::CppModelManager *modelManager = CppTools::CppModelManager::instance();
|
2018-04-09 13:30:30 +02:00
|
|
|
modelManager->setClassesFilter(std::make_unique<LocatorFilter>(
|
|
|
|
|
d->symbolQuery,
|
|
|
|
|
d->editorManager,
|
|
|
|
|
ClangBackEnd::SymbolKinds{ClangBackEnd::SymbolKind::Record},
|
|
|
|
|
CppTools::Constants::CLASSES_FILTER_ID,
|
|
|
|
|
CppTools::Constants::CLASSES_FILTER_DISPLAY_NAME,
|
|
|
|
|
"c"));
|
|
|
|
|
modelManager->setFunctionsFilter(std::make_unique<LocatorFilter>(
|
|
|
|
|
d->symbolQuery,
|
|
|
|
|
d->editorManager,
|
|
|
|
|
ClangBackEnd::SymbolKinds{ClangBackEnd::SymbolKind::Function},
|
|
|
|
|
CppTools::Constants::FUNCTIONS_FILTER_ID,
|
|
|
|
|
CppTools::Constants::FUNCTIONS_FILTER_DISPLAY_NAME,
|
|
|
|
|
"m"));
|
|
|
|
|
modelManager->setLocatorFilter(std::make_unique<LocatorFilter>(
|
|
|
|
|
d->symbolQuery,
|
|
|
|
|
d->editorManager,
|
|
|
|
|
ClangBackEnd::SymbolKinds{ClangBackEnd::SymbolKind::Record,
|
|
|
|
|
ClangBackEnd::SymbolKind::Enumeration,
|
|
|
|
|
ClangBackEnd::SymbolKind::Function},
|
|
|
|
|
CppTools::Constants::LOCATOR_FILTER_ID,
|
|
|
|
|
CppTools::Constants::LOCATOR_FILTER_DISPLAY_NAME,
|
|
|
|
|
":"));
|
2017-11-24 10:46:31 +01:00
|
|
|
}
|
|
|
|
|
|
2016-08-04 15:26:53 +02:00
|
|
|
} // namespace ClangRefactoring
|