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"
|
2017-11-24 16:03:07 +01:00
|
|
|
#include "qtcreatorclassesfilter.h"
|
|
|
|
|
#include "qtcreatorfunctionsfilter.h"
|
|
|
|
|
#include "qtcreatorincludesfilter.h"
|
|
|
|
|
#include "qtcreatorlocatorfilter.h"
|
|
|
|
|
#include "qtcreatorsymbolsfindfilter.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
|
|
|
|
2017-08-17 12:44:52 +02:00
|
|
|
#include <clangpchmanager/qtcreatorprojectupdater.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>
|
2016-11-15 15:38:12 +01:00
|
|
|
#include <coreplugin/find/searchresultwindow.h>
|
|
|
|
|
#include <extensionsystem/pluginmanager.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
|
|
|
|
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
|
|
|
|
|
{
|
2017-10-26 11:28:49 +02:00
|
|
|
using ProjectUpdater = ClangPchManager::QtCreatorProjectUpdater<ClangPchManager::ProjectUpdater>;
|
2016-11-29 12:50:50 +01:00
|
|
|
public:
|
2017-10-24 13:45:07 +02:00
|
|
|
using QuerySqliteReadStatementFactory = QuerySqliteStatementFactory<Sqlite::Database,
|
|
|
|
|
Sqlite::ReadStatement>;
|
2017-09-19 15:38:20 +02:00
|
|
|
|
2017-11-27 16:42:59 +01:00
|
|
|
Sqlite::Database database{Utils::PathString{Core::ICore::userResourcePath() + "/symbol-experimental-v1.db"}};
|
2017-09-21 11:43:59 +02:00
|
|
|
ClangBackEnd::RefactoringDatabaseInitializer<Sqlite::Database> databaseInitializer{database};
|
|
|
|
|
ClangBackEnd::FilePathCaching filePathCache{database};
|
2016-11-29 12:50:50 +01:00
|
|
|
RefactoringClient refactoringClient;
|
|
|
|
|
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};
|
|
|
|
|
|
2016-11-29 12:50:50 +01:00
|
|
|
QtCreatorSearch qtCreatorSearch{*Core::SearchResultWindow::instance()};
|
|
|
|
|
QtCreatorClangQueryFindFilter qtCreatorfindFilter{connectionClient.serverProxy(),
|
|
|
|
|
qtCreatorSearch,
|
|
|
|
|
refactoringClient};
|
2017-10-26 11:28:49 +02:00
|
|
|
ProjectUpdater projectUpdate{connectionClient.serverProxy()};
|
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
|
|
|
{
|
2016-11-29 12:50:50 +01:00
|
|
|
d.reset(new 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();
|
2017-11-24 16:03:07 +01:00
|
|
|
modelManager->setLocatorFilter(std::make_unique<QtcreatorLocatorFilter>(d->symbolQuery));
|
|
|
|
|
modelManager->setClassesFilter(std::make_unique<QtcreatorClassesFilter>());
|
|
|
|
|
modelManager->setIncludesFilter(std::make_unique<QtcreatorIncludesFilter>());
|
|
|
|
|
modelManager->setFunctionsFilter(std::make_unique<QtcreatorFunctionsFilter>());
|
|
|
|
|
modelManager->setSymbolsFindFilter(std::make_unique<QtcreatorSymbolsFindFilter>());
|
2017-11-24 10:46:31 +01:00
|
|
|
}
|
|
|
|
|
|
2016-08-04 15:26:53 +02:00
|
|
|
} // namespace ClangRefactoring
|