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 "refactoringengine.h"
|
|
|
|
|
|
2016-11-15 15:38:12 +01:00
|
|
|
#include "projectpartutilities.h"
|
|
|
|
|
|
2016-08-04 15:26:53 +02:00
|
|
|
|
|
|
|
|
#include <refactoringserverinterface.h>
|
|
|
|
|
#include <requestsourcelocationforrenamingmessage.h>
|
|
|
|
|
|
2016-12-14 14:56:17 +01:00
|
|
|
#include <cpptools/clangcompileroptionsbuilder.h>
|
2016-11-02 12:21:54 +03:00
|
|
|
#include <cpptools/cpptoolsreuse.h>
|
|
|
|
|
|
2017-08-03 14:13:42 +02:00
|
|
|
#include <texteditor/textdocument.h>
|
|
|
|
|
|
2016-08-04 15:26:53 +02:00
|
|
|
#include <QTextCursor>
|
|
|
|
|
#include <QTextDocument>
|
|
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
|
|
namespace ClangRefactoring {
|
|
|
|
|
|
|
|
|
|
using ClangBackEnd::RequestSourceLocationsForRenamingMessage;
|
|
|
|
|
|
|
|
|
|
RefactoringEngine::RefactoringEngine(ClangBackEnd::RefactoringServerInterface &server,
|
|
|
|
|
ClangBackEnd::RefactoringClientInterface &client)
|
|
|
|
|
: server(server),
|
|
|
|
|
client(client)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-03 14:13:42 +02:00
|
|
|
void RefactoringEngine::startLocalRenaming(const CppTools::CursorInEditor &data,
|
2016-08-04 15:26:53 +02:00
|
|
|
CppTools::ProjectPart *projectPart,
|
|
|
|
|
RenameCallback &&renameSymbolsCallback)
|
|
|
|
|
{
|
2016-12-14 14:56:17 +01:00
|
|
|
using CppTools::ClangCompilerOptionsBuilder;
|
|
|
|
|
|
2016-11-15 15:38:12 +01:00
|
|
|
setUsable(false);
|
2016-08-04 15:26:53 +02:00
|
|
|
|
|
|
|
|
client.setLocalRenamingCallback(std::move(renameSymbolsCallback));
|
|
|
|
|
|
2017-08-03 14:13:42 +02:00
|
|
|
QString filePath = data.filePath().toString();
|
|
|
|
|
QTextCursor textCursor = data.cursor();
|
2017-09-11 14:08:00 +02:00
|
|
|
ClangCompilerOptionsBuilder clangCOBuilder{*projectPart, CLANG_VERSION, CLANG_RESOURCE_DIR};
|
|
|
|
|
Utils::SmallStringVector commandLine{clangCOBuilder.build(
|
2017-08-03 14:13:42 +02:00
|
|
|
fileKindInProjectPart(projectPart, filePath),
|
2017-09-11 14:08:00 +02:00
|
|
|
CppTools::getPchUsage())};
|
2016-08-04 15:26:53 +02:00
|
|
|
|
2017-08-03 14:13:42 +02:00
|
|
|
commandLine.push_back(filePath);
|
2016-08-04 15:26:53 +02:00
|
|
|
|
2017-08-03 14:13:42 +02:00
|
|
|
RequestSourceLocationsForRenamingMessage message(ClangBackEnd::FilePath(filePath),
|
2016-08-04 15:26:53 +02:00
|
|
|
uint(textCursor.blockNumber() + 1),
|
|
|
|
|
uint(textCursor.positionInBlock() + 1),
|
|
|
|
|
textCursor.document()->toPlainText(),
|
|
|
|
|
std::move(commandLine),
|
2017-08-03 14:13:42 +02:00
|
|
|
textCursor.document()->revision());
|
2016-08-04 15:26:53 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
server.requestSourceLocationsForRenamingMessage(std::move(message));
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-04 10:18:41 +02:00
|
|
|
void RefactoringEngine::startGlobalRenaming(const CppTools::CursorInEditor &)
|
|
|
|
|
{
|
|
|
|
|
// TODO: implement
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-04 15:26:53 +02:00
|
|
|
bool RefactoringEngine::isUsable() const
|
|
|
|
|
{
|
2016-11-15 15:38:12 +01:00
|
|
|
return server.isUsable();
|
2016-08-04 15:26:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RefactoringEngine::setUsable(bool isUsable)
|
|
|
|
|
{
|
2016-11-15 15:38:12 +01:00
|
|
|
server.setUsable(isUsable);
|
2016-08-04 15:26:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace ClangRefactoring
|