Clang: Extract and rename backend classes

IpcCommunicator -> BackendCommunicator
IpcSender -> BackendSender
IpcReceiver -> BackendReceiver

Change-Id: I110ebe8d185db7ff47d2d5de9b786262520926d0
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
Nikolai Kosjar
2017-09-25 15:10:48 +02:00
parent 227acdea75
commit 917592970d
20 changed files with 1328 additions and 1101 deletions

View File

@@ -0,0 +1,581 @@
/****************************************************************************
**
** Copyright (C) 2017 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 "clangbackendcommunicator.h"
#include "clangbackendlogging.h"
#include "clangcompletionassistprocessor.h"
#include "clangmodelmanagersupport.h"
#include "clangutils.h"
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/icore.h>
#include <coreplugin/messagemanager.h>
#include <cpptools/abstracteditorsupport.h>
#include <cpptools/baseeditordocumentprocessor.h>
#include <cpptools/cppmodelmanager.h>
#include <cpptools/editordocumenthandle.h>
#include <cpptools/projectinfo.h>
#include <cpptools/cpptoolsbridge.h>
#include <texteditor/codeassist/functionhintproposal.h>
#include <texteditor/codeassist/iassistprocessor.h>
#include <texteditor/texteditor.h>
#include <clangsupport/filecontainer.h>
#include <clangsupport/clangcodemodelservermessages.h>
#include <utils/qtcassert.h>
#include <QDateTime>
#include <QDir>
#include <QTextBlock>
using namespace CPlusPlus;
using namespace ClangBackEnd;
using namespace TextEditor;
enum { backEndStartTimeOutInMs = 10000 };
static QString backendProcessPath()
{
return Core::ICore::libexecPath()
+ QStringLiteral("/clangbackend")
+ QStringLiteral(QTC_HOST_EXE_SUFFIX);
}
namespace ClangCodeModel {
namespace Internal {
class DummyBackendSender : public BackendSender
{
public:
DummyBackendSender() : BackendSender(nullptr) {}
void end() override {}
void registerTranslationUnitsForEditor(const RegisterTranslationUnitForEditorMessage &) override {}
void updateTranslationUnitsForEditor(const UpdateTranslationUnitsForEditorMessage &) override {}
void unregisterTranslationUnitsForEditor(const UnregisterTranslationUnitsForEditorMessage &) override {}
void registerProjectPartsForEditor(const RegisterProjectPartsForEditorMessage &) override {}
void unregisterProjectPartsForEditor(const UnregisterProjectPartsForEditorMessage &) override {}
void registerUnsavedFilesForEditor(const RegisterUnsavedFilesForEditorMessage &) override {}
void unregisterUnsavedFilesForEditor(const UnregisterUnsavedFilesForEditorMessage &) override {}
void completeCode(const CompleteCodeMessage &) override {}
void requestDocumentAnnotations(const RequestDocumentAnnotationsMessage &) override {}
void requestReferences(const RequestReferencesMessage &) override {}
void requestFollowSymbol(const RequestFollowSymbolMessage &) override {}
void updateVisibleTranslationUnits(const UpdateVisibleTranslationUnitsMessage &) override {}
};
BackendCommunicator::BackendCommunicator()
: m_connection(&m_receiver)
, m_sender(new DummyBackendSender())
{
m_backendStartTimeOut.setSingleShot(true);
connect(&m_backendStartTimeOut, &QTimer::timeout,
this, &BackendCommunicator::logStartTimeOut);
m_receiver.setAliveHandler([this]() { m_connection.resetProcessAliveTimer(); });
connect(Core::EditorManager::instance(), &Core::EditorManager::editorAboutToClose,
this, &BackendCommunicator::onEditorAboutToClose);
connect(Core::ICore::instance(), &Core::ICore::coreAboutToClose,
this, &BackendCommunicator::setupDummySender);
initializeBackend();
}
BackendCommunicator::~BackendCommunicator()
{
disconnect(&m_connection, 0, this, 0);
}
void BackendCommunicator::initializeBackend()
{
const QString clangBackEndProcessPath = backendProcessPath();
if (!QFileInfo(clangBackEndProcessPath).exists()) {
logExecutableDoesNotExist();
return;
}
qCDebug(ipcLog) << "Starting" << clangBackEndProcessPath;
m_connection.setProcessAliveTimerInterval(30 * 1000);
m_connection.setProcessPath(clangBackEndProcessPath);
connect(&m_connection, &ConnectionClient::connectedToLocalSocket,
this, &BackendCommunicator::onConnectedToBackend);
connect(&m_connection, &ConnectionClient::disconnectedFromLocalSocket,
this, &BackendCommunicator::setupDummySender);
m_connection.startProcessAndConnectToServerAsynchronously();
m_backendStartTimeOut.start(backEndStartTimeOutInMs);
}
static QStringList projectPartOptions(const CppTools::ProjectPart::Ptr &projectPart)
{
const QStringList options = ClangCodeModel::Utils::createClangOptions(projectPart,
CppTools::ProjectFile::Unsupported); // No language option
return options;
}
static ProjectPartContainer toProjectPartContainer(
const CppTools::ProjectPart::Ptr &projectPart)
{
const QStringList options = projectPartOptions(projectPart);
return ProjectPartContainer(projectPart->id(), Utf8StringVector(options));
}
static QVector<ProjectPartContainer> toProjectPartContainers(
const QVector<CppTools::ProjectPart::Ptr> projectParts)
{
QVector<ProjectPartContainer> projectPartContainers;
projectPartContainers.reserve(projectParts.size());
foreach (const CppTools::ProjectPart::Ptr &projectPart, projectParts)
projectPartContainers << toProjectPartContainer(projectPart);
return projectPartContainers;
}
void BackendCommunicator::registerFallbackProjectPart()
{
const auto projectPart = CppTools::CppModelManager::instance()->fallbackProjectPart();
const auto projectPartContainer = toProjectPartContainer(projectPart);
registerProjectPartsForEditor({projectPartContainer});
}
namespace {
Utf8String currentCppEditorDocumentFilePath()
{
Utf8String currentCppEditorDocumentFilePath;
const auto currentEditor = Core::EditorManager::currentEditor();
if (currentEditor && CppTools::CppModelManager::isCppEditor(currentEditor)) {
const auto currentDocument = currentEditor->document();
if (currentDocument)
currentCppEditorDocumentFilePath = currentDocument->filePath().toString();
}
return currentCppEditorDocumentFilePath;
}
void removeDuplicates(Utf8StringVector &visibleEditorDocumentsFilePaths)
{
std::sort(visibleEditorDocumentsFilePaths.begin(),
visibleEditorDocumentsFilePaths.end());
const auto end = std::unique(visibleEditorDocumentsFilePaths.begin(),
visibleEditorDocumentsFilePaths.end());
visibleEditorDocumentsFilePaths.erase(end,
visibleEditorDocumentsFilePaths.end());
}
void removeNonCppEditors(QList<Core::IEditor*> &visibleEditors)
{
const auto isNotCppEditor = [] (Core::IEditor *editor) {
return !CppTools::CppModelManager::isCppEditor(editor);
};
const auto end = std::remove_if(visibleEditors.begin(),
visibleEditors.end(),
isNotCppEditor);
visibleEditors.erase(end, visibleEditors.end());
}
Utf8StringVector visibleCppEditorDocumentsFilePaths()
{
auto visibleEditors = CppTools::CppToolsBridge::visibleEditors();
removeNonCppEditors(visibleEditors);
Utf8StringVector visibleCppEditorDocumentsFilePaths;
visibleCppEditorDocumentsFilePaths.reserve(visibleEditors.size());
const auto editorFilePaths = [] (Core::IEditor *editor) {
return Utf8String(editor->document()->filePath().toString());
};
std::transform(visibleEditors.begin(),
visibleEditors.end(),
std::back_inserter(visibleCppEditorDocumentsFilePaths),
editorFilePaths);
removeDuplicates(visibleCppEditorDocumentsFilePaths);
return visibleCppEditorDocumentsFilePaths;
}
}
void BackendCommunicator::updateTranslationUnitVisiblity()
{
updateTranslationUnitVisiblity(currentCppEditorDocumentFilePath(), visibleCppEditorDocumentsFilePaths());
}
bool BackendCommunicator::isNotWaitingForCompletion() const
{
return !m_receiver.isExpectingCodeCompletedMessage();
}
void BackendCommunicator::updateTranslationUnitVisiblity(const Utf8String &currentEditorFilePath,
const Utf8StringVector &visibleEditorsFilePaths)
{
const UpdateVisibleTranslationUnitsMessage message(currentEditorFilePath, visibleEditorsFilePaths);
m_sender->updateVisibleTranslationUnits(message);
}
void BackendCommunicator::registerCurrentProjectParts()
{
using namespace CppTools;
const QList<ProjectInfo> projectInfos = CppModelManager::instance()->projectInfos();
foreach (const ProjectInfo &projectInfo, projectInfos)
registerProjectsParts(projectInfo.projectParts());
}
void BackendCommunicator::restoreCppEditorDocuments()
{
resetCppEditorDocumentProcessors();
registerVisibleCppEditorDocumentAndMarkInvisibleDirty();
}
void BackendCommunicator::resetCppEditorDocumentProcessors()
{
using namespace CppTools;
const auto cppEditorDocuments = CppModelManager::instance()->cppEditorDocuments();
foreach (CppEditorDocumentHandle *cppEditorDocument, cppEditorDocuments)
cppEditorDocument->resetProcessor();
}
void BackendCommunicator::registerVisibleCppEditorDocumentAndMarkInvisibleDirty()
{
CppTools::CppModelManager::instance()->updateCppEditorDocuments();
}
void BackendCommunicator::registerCurrentCodeModelUiHeaders()
{
using namespace CppTools;
const auto editorSupports = CppModelManager::instance()->abstractEditorSupports();
foreach (const AbstractEditorSupport *es, editorSupports) {
const QString mappedPath
= ModelManagerSupportClang::instance()->dummyUiHeaderOnDiskPath(es->fileName());
updateUnsavedFile(mappedPath, es->contents(), es->revision());
}
}
void BackendCommunicator::registerProjectsParts(const QVector<CppTools::ProjectPart::Ptr> projectParts)
{
const auto projectPartContainers = toProjectPartContainers(projectParts);
registerProjectPartsForEditor(projectPartContainers);
}
void BackendCommunicator::updateTranslationUnitFromCppEditorDocument(const QString &filePath)
{
const CppTools::CppEditorDocumentHandle *document = ClangCodeModel::Utils::cppDocument(filePath);
updateTranslationUnit(filePath, document->contents(), document->revision());
}
void BackendCommunicator::updateUnsavedFileFromCppEditorDocument(const QString &filePath)
{
const CppTools::CppEditorDocumentHandle *document = ClangCodeModel::Utils::cppDocument(filePath);
updateUnsavedFile(filePath, document->contents(), document->revision());
}
void BackendCommunicator::updateTranslationUnit(const QString &filePath,
const QByteArray &contents,
uint documentRevision)
{
const bool hasUnsavedContent = true;
updateTranslationUnitsForEditor({{filePath,
Utf8String(),
Utf8String::fromByteArray(contents),
hasUnsavedContent,
documentRevision}});
}
void BackendCommunicator::updateUnsavedFile(const QString &filePath, const QByteArray &contents, uint documentRevision)
{
const bool hasUnsavedContent = true;
// TODO: Send new only if changed
registerUnsavedFilesForEditor({{filePath,
Utf8String(),
Utf8String::fromByteArray(contents),
hasUnsavedContent,
documentRevision}});
}
static bool documentHasChanged(const QString &filePath, uint revision)
{
if (CppTools::CppEditorDocumentHandle *document = ClangCodeModel::Utils::cppDocument(filePath))
return document->sendTracker().shouldSendRevision(revision);
return true;
}
static void setLastSentDocumentRevision(const QString &filePath, uint revision)
{
if (CppTools::CppEditorDocumentHandle *document = ClangCodeModel::Utils::cppDocument(filePath))
document->sendTracker().setLastSentRevision(int(revision));
}
void BackendCommunicator::updateTranslationUnitWithRevisionCheck(const FileContainer &fileContainer)
{
if (documentHasChanged(fileContainer.filePath(), fileContainer.documentRevision())) {
updateTranslationUnitsForEditor({fileContainer});
setLastSentDocumentRevision(fileContainer.filePath(),
fileContainer.documentRevision());
}
}
void BackendCommunicator::requestDocumentAnnotations(const FileContainer &fileContainer)
{
const RequestDocumentAnnotationsMessage message(fileContainer);
m_sender->requestDocumentAnnotations(message);
}
QFuture<CppTools::CursorInfo> BackendCommunicator::requestReferences(
const FileContainer &fileContainer,
quint32 line,
quint32 column,
QTextDocument *textDocument,
const CppTools::SemanticInfo::LocalUseMap &localUses)
{
const RequestReferencesMessage message(fileContainer, line, column);
m_sender->requestReferences(message);
return m_receiver.addExpectedReferencesMessage(message.ticketNumber(), textDocument,
localUses);
}
QFuture<CppTools::SymbolInfo> BackendCommunicator::requestFollowSymbol(
const FileContainer &curFileContainer,
const QVector<Utf8String> &dependentFiles,
quint32 line,
quint32 column)
{
const RequestFollowSymbolMessage message(curFileContainer,
dependentFiles,
line,
column);
m_sender->requestFollowSymbol(message);
return m_receiver.addExpectedRequestFollowSymbolMessage(message.ticketNumber());
}
void BackendCommunicator::updateTranslationUnitWithRevisionCheck(Core::IDocument *document)
{
const auto textDocument = qobject_cast<TextDocument*>(document);
const auto filePath = textDocument->filePath().toString();
const QString projectPartId = CppTools::CppToolsBridge::projectPartIdForFile(filePath);
updateTranslationUnitWithRevisionCheck(FileContainer(filePath,
projectPartId,
Utf8StringVector(),
textDocument->document()->revision()));
}
void BackendCommunicator::updateChangeContentStartPosition(const QString &filePath, int position)
{
if (CppTools::CppEditorDocumentHandle *document = ClangCodeModel::Utils::cppDocument(filePath))
document->sendTracker().applyContentChange(position);
}
void BackendCommunicator::updateTranslationUnitIfNotCurrentDocument(Core::IDocument *document)
{
QTC_ASSERT(document, return);
if (Core::EditorManager::currentDocument() != document)
updateTranslationUnit(document);
}
void BackendCommunicator::updateTranslationUnit(Core::IDocument *document)
{
updateTranslationUnitFromCppEditorDocument(document->filePath().toString());
}
void BackendCommunicator::updateUnsavedFile(Core::IDocument *document)
{
QTC_ASSERT(document, return);
updateUnsavedFileFromCppEditorDocument(document->filePath().toString());
}
void BackendCommunicator::onConnectedToBackend()
{
m_backendStartTimeOut.stop();
++m_connectedCount;
if (m_connectedCount > 1)
logRestartedDueToUnexpectedFinish();
m_receiver.reset();
m_sender.reset(new BackendSender(&m_connection));
initializeBackendWithCurrentData();
}
void BackendCommunicator::onEditorAboutToClose(Core::IEditor *editor)
{
if (auto *textEditor = qobject_cast<TextEditor::BaseTextEditor *>(editor))
m_receiver.deleteProcessorsOfEditorWidget(textEditor->editorWidget());
}
void BackendCommunicator::setupDummySender()
{
m_sender.reset(new DummyBackendSender);
}
void BackendCommunicator::logExecutableDoesNotExist()
{
const QString msg
= tr("Clang Code Model: Error: "
"The clangbackend executable \"%1\" does not exist.")
.arg(QDir::toNativeSeparators(backendProcessPath()));
logError(msg);
}
void BackendCommunicator::logStartTimeOut()
{
const QString msg
= tr("Clang Code Model: Error: "
"The clangbackend executable \"%1\" could not be started (timeout after %2ms).")
.arg(QDir::toNativeSeparators(backendProcessPath()))
.arg(backEndStartTimeOutInMs);
logError(msg);
}
void BackendCommunicator::logRestartedDueToUnexpectedFinish()
{
const QString msg
= tr("Clang Code Model: Error: "
"The clangbackend process has finished unexpectedly and was restarted.");
logError(msg);
}
void BackendCommunicator::logError(const QString &text)
{
const QString textWithTimestamp = QDateTime::currentDateTime().toString(Qt::ISODate)
+ ' ' + text;
Core::MessageManager::write(textWithTimestamp, Core::MessageManager::Flash);
qWarning("%s", qPrintable(textWithTimestamp));
}
void BackendCommunicator::initializeBackendWithCurrentData()
{
registerFallbackProjectPart();
registerCurrentProjectParts();
registerCurrentCodeModelUiHeaders();
restoreCppEditorDocuments();
updateTranslationUnitVisiblity();
emit backendReinitialized();
}
BackendSender *BackendCommunicator::setBackendSender(BackendSender *sender)
{
BackendSender *previousSender = m_sender.take();
m_sender.reset(sender);
return previousSender;
}
void BackendCommunicator::killBackendProcess()
{
m_connection.processForTestOnly()->kill();
}
void BackendCommunicator::registerTranslationUnitsForEditor(const FileContainers &fileContainers)
{
const RegisterTranslationUnitForEditorMessage message(fileContainers,
currentCppEditorDocumentFilePath(),
visibleCppEditorDocumentsFilePaths());
m_sender->registerTranslationUnitsForEditor(message);
}
void BackendCommunicator::updateTranslationUnitsForEditor(const FileContainers &fileContainers)
{
const UpdateTranslationUnitsForEditorMessage message(fileContainers);
m_sender->updateTranslationUnitsForEditor(message);
}
void BackendCommunicator::unregisterTranslationUnitsForEditor(const FileContainers &fileContainers)
{
const UnregisterTranslationUnitsForEditorMessage message(fileContainers);
m_sender->unregisterTranslationUnitsForEditor(message);
}
void BackendCommunicator::registerProjectPartsForEditor(
const ProjectPartContainers &projectPartContainers)
{
const RegisterProjectPartsForEditorMessage message(projectPartContainers);
m_sender->registerProjectPartsForEditor(message);
}
void BackendCommunicator::unregisterProjectPartsForEditor(const QStringList &projectPartIds)
{
const UnregisterProjectPartsForEditorMessage message((Utf8StringVector(projectPartIds)));
m_sender->unregisterProjectPartsForEditor(message);
}
void BackendCommunicator::registerUnsavedFilesForEditor(const FileContainers &fileContainers)
{
const RegisterUnsavedFilesForEditorMessage message(fileContainers);
m_sender->registerUnsavedFilesForEditor(message);
}
void BackendCommunicator::unregisterUnsavedFilesForEditor(const FileContainers &fileContainers)
{
const UnregisterUnsavedFilesForEditorMessage message(fileContainers);
m_sender->unregisterUnsavedFilesForEditor(message);
}
void BackendCommunicator::completeCode(ClangCompletionAssistProcessor *assistProcessor,
const QString &filePath,
quint32 line,
quint32 column,
const QString &projectFilePath,
qint32 funcNameStartLine,
qint32 funcNameStartColumn)
{
const CompleteCodeMessage message(filePath, line, column, projectFilePath, funcNameStartLine,
funcNameStartColumn);
m_sender->completeCode(message);
m_receiver.addExpectedCodeCompletedMessage(message.ticketNumber(), assistProcessor);
}
} // namespace Internal
} // namespace ClangCodeModel

View File

@@ -25,135 +25,42 @@
#pragma once #pragma once
#include "clangbackendreceiver.h"
#include "clangbackendsender.h"
#include <cpptools/projectpart.h> #include <cpptools/projectpart.h>
#include <cpptools/cppcursorinfo.h>
#include <cpptools/cppsymbolinfo.h>
#include <clangsupport/clangcodemodelconnectionclient.h> #include <clangsupport/clangcodemodelconnectionclient.h>
#include <clangsupport/filecontainer.h> #include <clangsupport/filecontainer.h>
#include <clangsupport/clangcodemodelclientinterface.h>
#include <clangsupport/projectpartcontainer.h> #include <clangsupport/projectpartcontainer.h>
#include <QFuture> #include <QFuture>
#include <QObject> #include <QObject>
#include <QPointer>
#include <QSharedPointer>
#include <QTextDocument>
#include <QVector> #include <QVector>
#include <QTimer>
#include <functional>
namespace Core { namespace Core {
class IEditor; class IEditor;
class IDocument; class IDocument;
} }
namespace ClangBackEnd {
class DocumentAnnotationsChangedMessage;
}
namespace TextEditor {
class TextEditorWidget;
class TextDocument;
}
namespace ClangCodeModel { namespace ClangCodeModel {
namespace Internal { namespace Internal {
class ModelManagerSupportClang;
class ClangCompletionAssistProcessor; class ClangCompletionAssistProcessor;
class IpcReceiver : public ClangBackEnd::ClangCodeModelClientInterface class BackendCommunicator : public QObject
{
public:
IpcReceiver();
~IpcReceiver();
using AliveHandler = std::function<void ()>;
void setAliveHandler(const AliveHandler &handler);
void addExpectedCodeCompletedMessage(quint64 ticket, ClangCompletionAssistProcessor *processor);
void deleteProcessorsOfEditorWidget(TextEditor::TextEditorWidget *textEditorWidget);
QFuture<CppTools::CursorInfo>
addExpectedReferencesMessage(quint64 ticket,
QTextDocument *textDocument,
const CppTools::SemanticInfo::LocalUseMap &localUses);
QFuture<CppTools::SymbolInfo> addExpectedRequestFollowSymbolMessage(quint64 ticket);
bool isExpectingCodeCompletedMessage() const;
void reset();
private:
void alive() override;
void echo(const ClangBackEnd::EchoMessage &message) override;
void codeCompleted(const ClangBackEnd::CodeCompletedMessage &message) override;
void documentAnnotationsChanged(const ClangBackEnd::DocumentAnnotationsChangedMessage &message) override;
void references(const ClangBackEnd::ReferencesMessage &message) override;
void followSymbol(const ClangBackEnd::FollowSymbolMessage &message) override;
private:
AliveHandler m_aliveHandler;
QHash<quint64, ClangCompletionAssistProcessor *> m_assistProcessorsTable;
struct ReferencesEntry {
ReferencesEntry() = default;
ReferencesEntry(QFutureInterface<CppTools::CursorInfo> futureInterface,
QTextDocument *textDocument,
const CppTools::SemanticInfo::LocalUseMap &localUses)
: futureInterface(futureInterface)
, textDocument(textDocument)
, localUses(localUses) {}
QFutureInterface<CppTools::CursorInfo> futureInterface;
QPointer<QTextDocument> textDocument;
CppTools::SemanticInfo::LocalUseMap localUses;
};
QHash<quint64, ReferencesEntry> m_referencesTable;
QHash<quint64, QFutureInterface<CppTools::SymbolInfo>> m_followTable;
};
class IpcSender : public ClangBackEnd::ClangCodeModelServerInterface
{
public:
IpcSender(ClangBackEnd::ClangCodeModelConnectionClient *connectionClient);
void end() override;
void registerTranslationUnitsForEditor(const ClangBackEnd::RegisterTranslationUnitForEditorMessage &message) override;
void updateTranslationUnitsForEditor(const ClangBackEnd::UpdateTranslationUnitsForEditorMessage &message) override;
void unregisterTranslationUnitsForEditor(const ClangBackEnd::UnregisterTranslationUnitsForEditorMessage &message) override;
void registerProjectPartsForEditor(const ClangBackEnd::RegisterProjectPartsForEditorMessage &message) override;
void unregisterProjectPartsForEditor(const ClangBackEnd::UnregisterProjectPartsForEditorMessage &message) override;
void registerUnsavedFilesForEditor(const ClangBackEnd::RegisterUnsavedFilesForEditorMessage &message) override;
void unregisterUnsavedFilesForEditor(const ClangBackEnd::UnregisterUnsavedFilesForEditorMessage &message) override;
void completeCode(const ClangBackEnd::CompleteCodeMessage &message) override;
void requestDocumentAnnotations(const ClangBackEnd::RequestDocumentAnnotationsMessage &message) override;
void requestReferences(const ClangBackEnd::RequestReferencesMessage &message) override;
void requestFollowSymbol(const ClangBackEnd::RequestFollowSymbolMessage &message) override;
void updateVisibleTranslationUnits(const ClangBackEnd::UpdateVisibleTranslationUnitsMessage &message) override;
private:
bool isConnected() const;
private:
ClangBackEnd::ClangCodeModelConnectionClient *m_connection = nullptr;
};
class IpcCommunicator : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
using Ptr = QSharedPointer<IpcCommunicator>;
using FileContainer = ClangBackEnd::FileContainer; using FileContainer = ClangBackEnd::FileContainer;
using FileContainers = QVector<ClangBackEnd::FileContainer>; using FileContainers = QVector<ClangBackEnd::FileContainer>;
using ProjectPartContainers = QVector<ClangBackEnd::ProjectPartContainer>; using ProjectPartContainers = QVector<ClangBackEnd::ProjectPartContainer>;
public: public:
IpcCommunicator(); BackendCommunicator();
~IpcCommunicator(); ~BackendCommunicator();
void registerTranslationUnitsForEditor(const FileContainers &fileContainers); void registerTranslationUnitsForEditor(const FileContainers &fileContainers);
void updateTranslationUnitsForEditor(const FileContainers &fileContainers); void updateTranslationUnitsForEditor(const FileContainers &fileContainers);
@@ -199,7 +106,7 @@ public:
bool isNotWaitingForCompletion() const; bool isNotWaitingForCompletion() const;
public: // for tests public: // for tests
IpcSender *setIpcSender(IpcSender *ipcSender); BackendSender *setBackendSender(BackendSender *sender);
void killBackendProcess(); void killBackendProcess();
signals: // for tests signals: // for tests
@@ -229,10 +136,10 @@ private:
const Utf8StringVector &visibleEditorsFilePaths); const Utf8StringVector &visibleEditorsFilePaths);
private: private:
IpcReceiver m_ipcReceiver; BackendReceiver m_receiver;
ClangBackEnd::ClangCodeModelConnectionClient m_connection; ClangBackEnd::ClangCodeModelConnectionClient m_connection;
QTimer m_backendStartTimeOut; QTimer m_backendStartTimeOut;
QScopedPointer<IpcSender> m_ipcSender; QScopedPointer<BackendSender> m_sender;
int m_connectedCount = 0; int m_connectedCount = 0;
}; };

View File

@@ -1,927 +0,0 @@
/****************************************************************************
**
** 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 "clangbackendipcintegration.h"
#include "clangcompletionassistprocessor.h"
#include "clangeditordocumentprocessor.h"
#include "clangmodelmanagersupport.h"
#include "clangutils.h"
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/icore.h>
#include <coreplugin/messagemanager.h>
#include <cpptools/abstracteditorsupport.h>
#include <cpptools/baseeditordocumentprocessor.h>
#include <cpptools/cppmodelmanager.h>
#include <cpptools/cpptoolsbridge.h>
#include <cpptools/editordocumenthandle.h>
#include <cpptools/projectinfo.h>
#include <texteditor/codeassist/functionhintproposal.h>
#include <texteditor/codeassist/iassistprocessor.h>
#include <texteditor/texteditor.h>
#include <utils/hostosinfo.h>
#include <utils/qtcassert.h>
#include <clangsupport/clangcodemodelservermessages.h>
#include <clangsupport/clangcodemodelclientmessages.h>
#include <clangsupport/filecontainer.h>
#include <cplusplus/Icons.h>
#include <QDateTime>
#include <QDir>
#include <QElapsedTimer>
#include <QLoggingCategory>
#include <QProcess>
#include <QTextBlock>
static Q_LOGGING_CATEGORY(log, "qtc.clangcodemodel.ipc")
using namespace CPlusPlus;
using namespace ClangCodeModel;
using namespace ClangCodeModel::Internal;
using namespace ClangBackEnd;
using namespace TextEditor;
static QString backendProcessPath()
{
return Core::ICore::libexecPath()
+ QStringLiteral("/clangbackend")
+ QStringLiteral(QTC_HOST_EXE_SUFFIX);
}
static bool printAliveMessageHelper()
{
const bool print = qEnvironmentVariableIntValue("QTC_CLANG_FORCE_VERBOSE_ALIVE");
if (!print) {
qCDebug(log) << "Hint: AliveMessage will not be printed. "
"Force it by setting QTC_CLANG_FORCE_VERBOSE_ALIVE=1.";
}
return print;
}
static bool printAliveMessage()
{
static bool print = log().isDebugEnabled() ? printAliveMessageHelper() : false;
return print;
}
IpcReceiver::IpcReceiver()
{
}
IpcReceiver::~IpcReceiver()
{
reset();
}
void IpcReceiver::setAliveHandler(const IpcReceiver::AliveHandler &handler)
{
m_aliveHandler = handler;
}
void IpcReceiver::addExpectedCodeCompletedMessage(
quint64 ticket,
ClangCompletionAssistProcessor *processor)
{
QTC_ASSERT(processor, return);
QTC_CHECK(!m_assistProcessorsTable.contains(ticket));
m_assistProcessorsTable.insert(ticket, processor);
}
void IpcReceiver::deleteProcessorsOfEditorWidget(TextEditor::TextEditorWidget *textEditorWidget)
{
QMutableHashIterator<quint64, ClangCompletionAssistProcessor *> it(m_assistProcessorsTable);
while (it.hasNext()) {
it.next();
ClangCompletionAssistProcessor *assistProcessor = it.value();
if (assistProcessor->textEditorWidget() == textEditorWidget) {
delete assistProcessor;
it.remove();
}
}
}
QFuture<CppTools::CursorInfo> IpcReceiver::addExpectedReferencesMessage(
quint64 ticket,
QTextDocument *textDocument,
const CppTools::SemanticInfo::LocalUseMap &localUses)
{
QTC_CHECK(textDocument);
QTC_CHECK(!m_referencesTable.contains(ticket));
QFutureInterface<CppTools::CursorInfo> futureInterface;
futureInterface.reportStarted();
const ReferencesEntry entry{futureInterface, textDocument, localUses};
m_referencesTable.insert(ticket, entry);
return futureInterface.future();
}
QFuture<CppTools::SymbolInfo> IpcReceiver::addExpectedRequestFollowSymbolMessage(quint64 ticket)
{
QTC_CHECK(!m_followTable.contains(ticket));
QFutureInterface<CppTools::SymbolInfo> futureInterface;
futureInterface.reportStarted();
m_followTable.insert(ticket, futureInterface);
return futureInterface.future();
}
bool IpcReceiver::isExpectingCodeCompletedMessage() const
{
return !m_assistProcessorsTable.isEmpty();
}
void IpcReceiver::reset()
{
// Clean up waiting assist processors
qDeleteAll(m_assistProcessorsTable.begin(), m_assistProcessorsTable.end());
m_assistProcessorsTable.clear();
// Clean up futures for references
for (ReferencesEntry &entry : m_referencesTable)
entry.futureInterface.cancel();
m_referencesTable.clear();
for (QFutureInterface<CppTools::SymbolInfo> &futureInterface : m_followTable)
futureInterface.cancel();
m_followTable.clear();
}
void IpcReceiver::alive()
{
if (printAliveMessage())
qCDebug(log) << "<<< AliveMessage";
QTC_ASSERT(m_aliveHandler, return);
m_aliveHandler();
}
void IpcReceiver::echo(const EchoMessage &message)
{
qCDebug(log) << "<<<" << message;
}
void IpcReceiver::codeCompleted(const CodeCompletedMessage &message)
{
qCDebug(log) << "<<< CodeCompletedMessage with" << message.codeCompletions().size() << "items";
const quint64 ticket = message.ticketNumber();
QScopedPointer<ClangCompletionAssistProcessor> processor(m_assistProcessorsTable.take(ticket));
if (processor) {
processor->handleAvailableCompletions(message.codeCompletions(),
message.neededCorrection());
}
}
void IpcReceiver::documentAnnotationsChanged(const DocumentAnnotationsChangedMessage &message)
{
qCDebug(log) << "<<< DocumentAnnotationsChangedMessage with"
<< message.diagnostics().size() << "diagnostics"
<< message.highlightingMarks().size() << "highlighting marks"
<< message.skippedPreprocessorRanges().size() << "skipped preprocessor ranges";
auto processor = ClangEditorDocumentProcessor::get(message.fileContainer().filePath());
if (processor) {
const QString projectPartId = message.fileContainer().projectPartId();
const QString filePath = message.fileContainer().filePath();
const QString documentProjectPartId = CppTools::CppToolsBridge::projectPartIdForFile(filePath);
if (projectPartId == documentProjectPartId) {
const quint32 documentRevision = message.fileContainer().documentRevision();
processor->updateCodeWarnings(message.diagnostics(),
message.firstHeaderErrorDiagnostic(),
documentRevision);
processor->updateHighlighting(message.highlightingMarks(),
message.skippedPreprocessorRanges(),
documentRevision);
}
}
}
static
CppTools::CursorInfo::Range toCursorInfoRange(const QTextDocument &textDocument,
const SourceRangeContainer &sourceRange)
{
const SourceLocationContainer start = sourceRange.start();
const SourceLocationContainer end = sourceRange.end();
const unsigned length = end.column() - start.column();
const QTextBlock block = textDocument.findBlockByNumber(static_cast<int>(start.line()) - 1);
const int shift = ClangCodeModel::Utils::extraUtf8CharsShift(block.text(),
static_cast<int>(start.column()));
const uint column = start.column() - static_cast<uint>(shift);
return CppTools::CursorInfo::Range(start.line(), column, length);
}
static
CppTools::CursorInfo toCursorInfo(const QTextDocument &textDocument,
const CppTools::SemanticInfo::LocalUseMap &localUses,
const ReferencesMessage &message)
{
CppTools::CursorInfo result;
const QVector<SourceRangeContainer> references = message.references();
result.areUseRangesForLocalVariable = message.isLocalVariable();
for (const SourceRangeContainer &reference : references)
result.useRanges.append(toCursorInfoRange(textDocument, reference));
result.useRanges.reserve(references.size());
result.localUses = localUses;
return result;
}
static
CppTools::SymbolInfo toSymbolInfo(const FollowSymbolMessage &message)
{
CppTools::SymbolInfo result;
const SourceRangeContainer &range = message.sourceRange();
const SourceLocationContainer start = range.start();
const SourceLocationContainer end = range.end();
result.startLine = static_cast<int>(start.line());
result.startColumn = static_cast<int>(start.column());
result.endLine = static_cast<int>(end.line());
result.endColumn = static_cast<int>(end.column());
result.fileName = start.filePath();
return result;
}
void IpcReceiver::references(const ReferencesMessage &message)
{
qCDebug(log) << "<<< ReferencesMessage with"
<< message.references().size() << "references";
const quint64 ticket = message.ticketNumber();
const ReferencesEntry entry = m_referencesTable.take(ticket);
QFutureInterface<CppTools::CursorInfo> futureInterface = entry.futureInterface;
QTC_CHECK(futureInterface != QFutureInterface<CppTools::CursorInfo>());
if (futureInterface.isCanceled())
return; // Editor document closed or a new request was issued making this result outdated.
QTC_ASSERT(entry.textDocument, return);
futureInterface.reportResult(toCursorInfo(*entry.textDocument, entry.localUses, message));
futureInterface.reportFinished();
}
void IpcReceiver::followSymbol(const ClangBackEnd::FollowSymbolMessage &message)
{
qCDebug(log) << "<<< FollowSymbolMessage with"
<< message.sourceRange() << "range";
const quint64 ticket = message.ticketNumber();
QFutureInterface<CppTools::SymbolInfo> futureInterface = m_followTable.take(ticket);
QTC_CHECK(futureInterface != QFutureInterface<CppTools::SymbolInfo>());
if (futureInterface.isCanceled())
return; // Editor document closed or a new request was issued making this result outdated.
futureInterface.reportResult(toSymbolInfo(message));
futureInterface.reportFinished();
}
IpcSender::IpcSender(ClangCodeModelConnectionClient *connectionClient)
: m_connection(connectionClient)
{}
void IpcSender::end()
{
QTC_CHECK(m_connection->isConnected());
qCDebug(log) << ">>>" << ClangBackEnd::EndMessage();
m_connection->sendEndMessage();
}
void IpcSender::registerTranslationUnitsForEditor(const RegisterTranslationUnitForEditorMessage &message)
{
QTC_CHECK(m_connection->isConnected());
qCDebug(log) << ">>>" << message;
m_connection->serverProxy().registerTranslationUnitsForEditor(message);
}
void IpcSender::updateTranslationUnitsForEditor(const UpdateTranslationUnitsForEditorMessage &message)
{
QTC_CHECK(m_connection->isConnected());
qCDebug(log) << ">>>" << message;
m_connection->serverProxy().updateTranslationUnitsForEditor(message);
}
void IpcSender::unregisterTranslationUnitsForEditor(const UnregisterTranslationUnitsForEditorMessage &message)
{
QTC_CHECK(m_connection->isConnected());
qCDebug(log) << ">>>" << message;
m_connection->serverProxy().unregisterTranslationUnitsForEditor(message);
}
void IpcSender::registerProjectPartsForEditor(const RegisterProjectPartsForEditorMessage &message)
{
QTC_CHECK(m_connection->isConnected());
qCDebug(log) << ">>>" << message;
m_connection->serverProxy().registerProjectPartsForEditor(message);
}
void IpcSender::unregisterProjectPartsForEditor(const UnregisterProjectPartsForEditorMessage &message)
{
QTC_CHECK(m_connection->isConnected());
qCDebug(log) << ">>>" << message;
m_connection->serverProxy().unregisterProjectPartsForEditor(message);
}
void IpcSender::registerUnsavedFilesForEditor(const RegisterUnsavedFilesForEditorMessage &message)
{
QTC_CHECK(m_connection->isConnected());
qCDebug(log) << ">>>" << message;
m_connection->serverProxy().registerUnsavedFilesForEditor(message);
}
void IpcSender::unregisterUnsavedFilesForEditor(const UnregisterUnsavedFilesForEditorMessage &message)
{
QTC_CHECK(m_connection->isConnected());
qCDebug(log) << ">>>" << message;
m_connection->serverProxy().unregisterUnsavedFilesForEditor(message);
}
void IpcSender::completeCode(const CompleteCodeMessage &message)
{
QTC_CHECK(m_connection->isConnected());
qCDebug(log) << ">>>" << message;
m_connection->serverProxy().completeCode(message);
}
void IpcSender::requestDocumentAnnotations(const RequestDocumentAnnotationsMessage &message)
{
QTC_CHECK(m_connection->isConnected());
qCDebug(log) << ">>>" << message;
m_connection->serverProxy().requestDocumentAnnotations(message);
}
void IpcSender::requestReferences(const RequestReferencesMessage &message)
{
QTC_CHECK(m_connection->isConnected());
qCDebug(log) << ">>>" << message;
m_connection->serverProxy().requestReferences(message);
}
void IpcSender::requestFollowSymbol(const RequestFollowSymbolMessage &message)
{
QTC_CHECK(m_connection->isConnected());
qCDebug(log) << ">>>" << message;
m_connection->serverProxy().requestFollowSymbol(message);
}
void IpcSender::updateVisibleTranslationUnits(const UpdateVisibleTranslationUnitsMessage &message)
{
QTC_CHECK(m_connection->isConnected());
qCDebug(log) << ">>>" << message;
m_connection->serverProxy().updateVisibleTranslationUnits(message);
}
bool IpcSender::isConnected() const
{
return m_connection && m_connection->isConnected();
}
class DummyIpcSender : public IpcSender
{
public:
DummyIpcSender() : IpcSender(nullptr) {}
void end() override {}
void registerTranslationUnitsForEditor(const ClangBackEnd::RegisterTranslationUnitForEditorMessage &) override {}
void updateTranslationUnitsForEditor(const ClangBackEnd::UpdateTranslationUnitsForEditorMessage &) override {}
void unregisterTranslationUnitsForEditor(const ClangBackEnd::UnregisterTranslationUnitsForEditorMessage &) override {}
void registerProjectPartsForEditor(const ClangBackEnd::RegisterProjectPartsForEditorMessage &) override {}
void unregisterProjectPartsForEditor(const ClangBackEnd::UnregisterProjectPartsForEditorMessage &) override {}
void registerUnsavedFilesForEditor(const ClangBackEnd::RegisterUnsavedFilesForEditorMessage &) override {}
void unregisterUnsavedFilesForEditor(const ClangBackEnd::UnregisterUnsavedFilesForEditorMessage &) override {}
void completeCode(const ClangBackEnd::CompleteCodeMessage &) override {}
void requestDocumentAnnotations(const ClangBackEnd::RequestDocumentAnnotationsMessage &) override {}
void requestReferences(const ClangBackEnd::RequestReferencesMessage &) override {}
void requestFollowSymbol(const RequestFollowSymbolMessage &) override {}
void updateVisibleTranslationUnits(const UpdateVisibleTranslationUnitsMessage &) override {}
};
enum { backEndStartTimeOutInMs = 10000 };
IpcCommunicator::IpcCommunicator()
: m_connection(&m_ipcReceiver)
, m_ipcSender(new DummyIpcSender())
{
m_backendStartTimeOut.setSingleShot(true);
connect(&m_backendStartTimeOut, &QTimer::timeout,
this, &IpcCommunicator::logStartTimeOut);
m_ipcReceiver.setAliveHandler([this]() { m_connection.resetProcessAliveTimer(); });
connect(Core::EditorManager::instance(), &Core::EditorManager::editorAboutToClose,
this, &IpcCommunicator::onEditorAboutToClose);
connect(Core::ICore::instance(), &Core::ICore::coreAboutToClose,
this, &IpcCommunicator::setupDummySender);
initializeBackend();
}
IpcCommunicator::~IpcCommunicator()
{
disconnect(&m_connection, 0, this, 0);
}
void IpcCommunicator::initializeBackend()
{
const QString clangBackEndProcessPath = backendProcessPath();
if (!QFileInfo(clangBackEndProcessPath).exists()) {
logExecutableDoesNotExist();
return;
}
qCDebug(log) << "Starting" << clangBackEndProcessPath;
m_connection.setProcessAliveTimerInterval(30 * 1000);
m_connection.setProcessPath(clangBackEndProcessPath);
connect(&m_connection, &ConnectionClient::connectedToLocalSocket,
this, &IpcCommunicator::onConnectedToBackend);
connect(&m_connection, &ConnectionClient::disconnectedFromLocalSocket,
this, &IpcCommunicator::setupDummySender);
m_connection.startProcessAndConnectToServerAsynchronously();
m_backendStartTimeOut.start(backEndStartTimeOutInMs);
}
static QStringList projectPartOptions(const CppTools::ProjectPart::Ptr &projectPart)
{
const QStringList options = ClangCodeModel::Utils::createClangOptions(projectPart,
CppTools::ProjectFile::Unsupported); // No language option
return options;
}
static ClangBackEnd::ProjectPartContainer toProjectPartContainer(
const CppTools::ProjectPart::Ptr &projectPart)
{
const QStringList options = projectPartOptions(projectPart);
return ClangBackEnd::ProjectPartContainer(projectPart->id(), Utf8StringVector(options));
}
static QVector<ClangBackEnd::ProjectPartContainer> toProjectPartContainers(
const QVector<CppTools::ProjectPart::Ptr> projectParts)
{
QVector<ClangBackEnd::ProjectPartContainer> projectPartContainers;
projectPartContainers.reserve(projectParts.size());
foreach (const CppTools::ProjectPart::Ptr &projectPart, projectParts)
projectPartContainers << toProjectPartContainer(projectPart);
return projectPartContainers;
}
void IpcCommunicator::registerFallbackProjectPart()
{
const auto projectPart = CppTools::CppModelManager::instance()->fallbackProjectPart();
const auto projectPartContainer = toProjectPartContainer(projectPart);
registerProjectPartsForEditor({projectPartContainer});
}
namespace {
Utf8String currentCppEditorDocumentFilePath()
{
Utf8String currentCppEditorDocumentFilePath;
const auto currentEditor = Core::EditorManager::currentEditor();
if (currentEditor && CppTools::CppModelManager::isCppEditor(currentEditor)) {
const auto currentDocument = currentEditor->document();
if (currentDocument)
currentCppEditorDocumentFilePath = currentDocument->filePath().toString();
}
return currentCppEditorDocumentFilePath;
}
void removeDuplicates(Utf8StringVector &visibleEditorDocumentsFilePaths)
{
std::sort(visibleEditorDocumentsFilePaths.begin(),
visibleEditorDocumentsFilePaths.end());
const auto end = std::unique(visibleEditorDocumentsFilePaths.begin(),
visibleEditorDocumentsFilePaths.end());
visibleEditorDocumentsFilePaths.erase(end,
visibleEditorDocumentsFilePaths.end());
}
void removeNonCppEditors(QList<Core::IEditor*> &visibleEditors)
{
const auto isNotCppEditor = [] (Core::IEditor *editor) {
return !CppTools::CppModelManager::isCppEditor(editor);
};
const auto end = std::remove_if(visibleEditors.begin(),
visibleEditors.end(),
isNotCppEditor);
visibleEditors.erase(end, visibleEditors.end());
}
Utf8StringVector visibleCppEditorDocumentsFilePaths()
{
auto visibleEditors = CppTools::CppToolsBridge::visibleEditors();
removeNonCppEditors(visibleEditors);
Utf8StringVector visibleCppEditorDocumentsFilePaths;
visibleCppEditorDocumentsFilePaths.reserve(visibleEditors.size());
const auto editorFilePaths = [] (Core::IEditor *editor) {
return Utf8String(editor->document()->filePath().toString());
};
std::transform(visibleEditors.begin(),
visibleEditors.end(),
std::back_inserter(visibleCppEditorDocumentsFilePaths),
editorFilePaths);
removeDuplicates(visibleCppEditorDocumentsFilePaths);
return visibleCppEditorDocumentsFilePaths;
}
}
void IpcCommunicator::updateTranslationUnitVisiblity()
{
updateTranslationUnitVisiblity(currentCppEditorDocumentFilePath(), visibleCppEditorDocumentsFilePaths());
}
bool IpcCommunicator::isNotWaitingForCompletion() const
{
return !m_ipcReceiver.isExpectingCodeCompletedMessage();
}
void IpcCommunicator::updateTranslationUnitVisiblity(const Utf8String &currentEditorFilePath,
const Utf8StringVector &visibleEditorsFilePaths)
{
const UpdateVisibleTranslationUnitsMessage message(currentEditorFilePath, visibleEditorsFilePaths);
m_ipcSender->updateVisibleTranslationUnits(message);
}
void IpcCommunicator::registerCurrentProjectParts()
{
using namespace CppTools;
const QList<ProjectInfo> projectInfos = CppModelManager::instance()->projectInfos();
foreach (const ProjectInfo &projectInfo, projectInfos)
registerProjectsParts(projectInfo.projectParts());
}
void IpcCommunicator::restoreCppEditorDocuments()
{
resetCppEditorDocumentProcessors();
registerVisibleCppEditorDocumentAndMarkInvisibleDirty();
}
void IpcCommunicator::resetCppEditorDocumentProcessors()
{
using namespace CppTools;
const auto cppEditorDocuments = CppModelManager::instance()->cppEditorDocuments();
foreach (CppEditorDocumentHandle *cppEditorDocument, cppEditorDocuments)
cppEditorDocument->resetProcessor();
}
void IpcCommunicator::registerVisibleCppEditorDocumentAndMarkInvisibleDirty()
{
CppTools::CppModelManager::instance()->updateCppEditorDocuments();
}
void IpcCommunicator::registerCurrentCodeModelUiHeaders()
{
using namespace CppTools;
const auto editorSupports = CppModelManager::instance()->abstractEditorSupports();
foreach (const AbstractEditorSupport *es, editorSupports) {
const QString mappedPath
= ModelManagerSupportClang::instance()->dummyUiHeaderOnDiskPath(es->fileName());
updateUnsavedFile(mappedPath, es->contents(), es->revision());
}
}
void IpcCommunicator::registerProjectsParts(const QVector<CppTools::ProjectPart::Ptr> projectParts)
{
const auto projectPartContainers = toProjectPartContainers(projectParts);
registerProjectPartsForEditor(projectPartContainers);
}
void IpcCommunicator::updateTranslationUnitFromCppEditorDocument(const QString &filePath)
{
const CppTools::CppEditorDocumentHandle *document = ClangCodeModel::Utils::cppDocument(filePath);
updateTranslationUnit(filePath, document->contents(), document->revision());
}
void IpcCommunicator::updateUnsavedFileFromCppEditorDocument(const QString &filePath)
{
const CppTools::CppEditorDocumentHandle *document = ClangCodeModel::Utils::cppDocument(filePath);
updateUnsavedFile(filePath, document->contents(), document->revision());
}
namespace {
}
void IpcCommunicator::updateTranslationUnit(const QString &filePath,
const QByteArray &contents,
uint documentRevision)
{
const bool hasUnsavedContent = true;
updateTranslationUnitsForEditor({{filePath,
Utf8String(),
Utf8String::fromByteArray(contents),
hasUnsavedContent,
documentRevision}});
}
void IpcCommunicator::updateUnsavedFile(const QString &filePath, const QByteArray &contents, uint documentRevision)
{
const bool hasUnsavedContent = true;
// TODO: Send new only if changed
registerUnsavedFilesForEditor({{filePath,
Utf8String(),
Utf8String::fromByteArray(contents),
hasUnsavedContent,
documentRevision}});
}
static bool documentHasChanged(const QString &filePath, uint revision)
{
if (CppTools::CppEditorDocumentHandle *document = ClangCodeModel::Utils::cppDocument(filePath))
return document->sendTracker().shouldSendRevision(revision);
return true;
}
static void setLastSentDocumentRevision(const QString &filePath, uint revision)
{
if (CppTools::CppEditorDocumentHandle *document = ClangCodeModel::Utils::cppDocument(filePath))
document->sendTracker().setLastSentRevision(int(revision));
}
void IpcCommunicator::updateTranslationUnitWithRevisionCheck(const FileContainer &fileContainer)
{
if (documentHasChanged(fileContainer.filePath(), fileContainer.documentRevision())) {
updateTranslationUnitsForEditor({fileContainer});
setLastSentDocumentRevision(fileContainer.filePath(),
fileContainer.documentRevision());
}
}
void IpcCommunicator::requestDocumentAnnotations(const FileContainer &fileContainer)
{
const RequestDocumentAnnotationsMessage message(fileContainer);
m_ipcSender->requestDocumentAnnotations(message);
}
QFuture<CppTools::CursorInfo> IpcCommunicator::requestReferences(
const FileContainer &fileContainer,
quint32 line,
quint32 column,
QTextDocument *textDocument,
const CppTools::SemanticInfo::LocalUseMap &localUses)
{
const RequestReferencesMessage message(fileContainer, line, column);
m_ipcSender->requestReferences(message);
return m_ipcReceiver.addExpectedReferencesMessage(message.ticketNumber(), textDocument,
localUses);
}
QFuture<CppTools::SymbolInfo> IpcCommunicator::requestFollowSymbol(
const FileContainer &curFileContainer,
const QVector<Utf8String> &dependentFiles,
quint32 line,
quint32 column)
{
const RequestFollowSymbolMessage message(curFileContainer,
dependentFiles,
line,
column);
m_ipcSender->requestFollowSymbol(message);
return m_ipcReceiver.addExpectedRequestFollowSymbolMessage(message.ticketNumber());
}
void IpcCommunicator::updateTranslationUnitWithRevisionCheck(Core::IDocument *document)
{
const auto textDocument = qobject_cast<TextDocument*>(document);
const auto filePath = textDocument->filePath().toString();
const QString projectPartId = CppTools::CppToolsBridge::projectPartIdForFile(filePath);
updateTranslationUnitWithRevisionCheck(FileContainer(filePath,
projectPartId,
Utf8StringVector(),
textDocument->document()->revision()));
}
void IpcCommunicator::updateChangeContentStartPosition(const QString &filePath, int position)
{
if (CppTools::CppEditorDocumentHandle *document = ClangCodeModel::Utils::cppDocument(filePath))
document->sendTracker().applyContentChange(position);
}
void IpcCommunicator::updateTranslationUnitIfNotCurrentDocument(Core::IDocument *document)
{
QTC_ASSERT(document, return);
if (Core::EditorManager::currentDocument() != document)
updateTranslationUnit(document);
}
void IpcCommunicator::updateTranslationUnit(Core::IDocument *document)
{
updateTranslationUnitFromCppEditorDocument(document->filePath().toString());
}
void IpcCommunicator::updateUnsavedFile(Core::IDocument *document)
{
QTC_ASSERT(document, return);
updateUnsavedFileFromCppEditorDocument(document->filePath().toString());
}
void IpcCommunicator::onConnectedToBackend()
{
m_backendStartTimeOut.stop();
++m_connectedCount;
if (m_connectedCount > 1)
logRestartedDueToUnexpectedFinish();
m_ipcReceiver.reset();
m_ipcSender.reset(new IpcSender(&m_connection));
initializeBackendWithCurrentData();
}
void IpcCommunicator::onEditorAboutToClose(Core::IEditor *editor)
{
if (auto *textEditor = qobject_cast<TextEditor::BaseTextEditor *>(editor))
m_ipcReceiver.deleteProcessorsOfEditorWidget(textEditor->editorWidget());
}
void IpcCommunicator::setupDummySender()
{
m_ipcSender.reset(new DummyIpcSender);
}
void IpcCommunicator::logExecutableDoesNotExist()
{
const QString msg
= tr("Clang Code Model: Error: "
"The clangbackend executable \"%1\" does not exist.")
.arg(QDir::toNativeSeparators(backendProcessPath()));
logError(msg);
}
void IpcCommunicator::logStartTimeOut()
{
const QString msg
= tr("Clang Code Model: Error: "
"The clangbackend executable \"%1\" could not be started (timeout after %2ms).")
.arg(QDir::toNativeSeparators(backendProcessPath()))
.arg(backEndStartTimeOutInMs);
logError(msg);
}
void IpcCommunicator::logRestartedDueToUnexpectedFinish()
{
const QString msg
= tr("Clang Code Model: Error: "
"The clangbackend process has finished unexpectedly and was restarted.");
logError(msg);
}
void IpcCommunicator::logError(const QString &text)
{
const QString textWithTimestamp = QDateTime::currentDateTime().toString(Qt::ISODate)
+ ' ' + text;
Core::MessageManager::write(textWithTimestamp, Core::MessageManager::Flash);
qWarning("%s", qPrintable(textWithTimestamp));
}
void IpcCommunicator::initializeBackendWithCurrentData()
{
registerFallbackProjectPart();
registerCurrentProjectParts();
registerCurrentCodeModelUiHeaders();
restoreCppEditorDocuments();
updateTranslationUnitVisiblity();
emit backendReinitialized();
}
IpcSender *IpcCommunicator::setIpcSender(IpcSender *ipcSender)
{
IpcSender *previousMessageSender = m_ipcSender.take();
m_ipcSender.reset(ipcSender);
return previousMessageSender;
}
void IpcCommunicator::killBackendProcess()
{
m_connection.processForTestOnly()->kill();
}
void IpcCommunicator::registerTranslationUnitsForEditor(const FileContainers &fileContainers)
{
const RegisterTranslationUnitForEditorMessage message(fileContainers,
currentCppEditorDocumentFilePath(),
visibleCppEditorDocumentsFilePaths());
m_ipcSender->registerTranslationUnitsForEditor(message);
}
void IpcCommunicator::updateTranslationUnitsForEditor(const IpcCommunicator::FileContainers &fileContainers)
{
const UpdateTranslationUnitsForEditorMessage message(fileContainers);
m_ipcSender->updateTranslationUnitsForEditor(message);
}
void IpcCommunicator::unregisterTranslationUnitsForEditor(const FileContainers &fileContainers)
{
const UnregisterTranslationUnitsForEditorMessage message(fileContainers);
m_ipcSender->unregisterTranslationUnitsForEditor(message);
}
void IpcCommunicator::registerProjectPartsForEditor(
const ProjectPartContainers &projectPartContainers)
{
const RegisterProjectPartsForEditorMessage message(projectPartContainers);
m_ipcSender->registerProjectPartsForEditor(message);
}
void IpcCommunicator::unregisterProjectPartsForEditor(const QStringList &projectPartIds)
{
const UnregisterProjectPartsForEditorMessage message((Utf8StringVector(projectPartIds)));
m_ipcSender->unregisterProjectPartsForEditor(message);
}
void IpcCommunicator::registerUnsavedFilesForEditor(const IpcCommunicator::FileContainers &fileContainers)
{
const RegisterUnsavedFilesForEditorMessage message(fileContainers);
m_ipcSender->registerUnsavedFilesForEditor(message);
}
void IpcCommunicator::unregisterUnsavedFilesForEditor(const IpcCommunicator::FileContainers &fileContainers)
{
const UnregisterUnsavedFilesForEditorMessage message(fileContainers);
m_ipcSender->unregisterUnsavedFilesForEditor(message);
}
void IpcCommunicator::completeCode(ClangCompletionAssistProcessor *assistProcessor,
const QString &filePath,
quint32 line,
quint32 column,
const QString &projectFilePath,
qint32 funcNameStartLine,
qint32 funcNameStartColumn)
{
const CompleteCodeMessage message(filePath, line, column, projectFilePath, funcNameStartLine,
funcNameStartColumn);
m_ipcSender->completeCode(message);
m_ipcReceiver.addExpectedCodeCompletedMessage(message.ticketNumber(), assistProcessor);
}

View File

@@ -0,0 +1,34 @@
/****************************************************************************
**
** Copyright (C) 2017 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 "clangbackendlogging.h"
namespace ClangCodeModel {
namespace Internal {
Q_LOGGING_CATEGORY(ipcLog, "qtc.clangcodemodel.ipc")
} // namespace Internal
} // namespace ClangCodeModel

View File

@@ -0,0 +1,35 @@
/****************************************************************************
**
** Copyright (C) 2017 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 <QLoggingCategory>
namespace ClangCodeModel { namespace Internal {
Q_DECLARE_LOGGING_CATEGORY(ipcLog)
} // namespace Internal
} // namespace ClangCodeModel

View File

@@ -0,0 +1,287 @@
/****************************************************************************
**
** Copyright (C) 2017 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 "clangbackendreceiver.h"
#include "clangbackendlogging.h"
#include "clangcompletionassistprocessor.h"
#include "clangeditordocumentprocessor.h"
#include <cpptools/cpptoolsbridge.h>
#include <clangsupport/clangcodemodelclientmessages.h>
#include <QLoggingCategory>
#include <QTextBlock>
#include <utils/qtcassert.h>
static Q_LOGGING_CATEGORY(log, "qtc.clangcodemodel.ipc")
using namespace ClangBackEnd;
namespace ClangCodeModel {
namespace Internal {
static bool printAliveMessageHelper()
{
const bool print = qEnvironmentVariableIntValue("QTC_CLANG_FORCE_VERBOSE_ALIVE");
if (!print) {
qCDebug(log) << "Hint: AliveMessage will not be printed. "
"Force it by setting QTC_CLANG_FORCE_VERBOSE_ALIVE=1.";
}
return print;
}
static bool printAliveMessage()
{
static bool print = log().isDebugEnabled() ? printAliveMessageHelper() : false;
return print;
}
BackendReceiver::BackendReceiver()
{
}
BackendReceiver::~BackendReceiver()
{
reset();
}
void BackendReceiver::setAliveHandler(const BackendReceiver::AliveHandler &handler)
{
m_aliveHandler = handler;
}
void BackendReceiver::addExpectedCodeCompletedMessage(
quint64 ticket,
ClangCompletionAssistProcessor *processor)
{
QTC_ASSERT(processor, return);
QTC_CHECK(!m_assistProcessorsTable.contains(ticket));
m_assistProcessorsTable.insert(ticket, processor);
}
void BackendReceiver::deleteProcessorsOfEditorWidget(TextEditor::TextEditorWidget *textEditorWidget)
{
QMutableHashIterator<quint64, ClangCompletionAssistProcessor *> it(m_assistProcessorsTable);
while (it.hasNext()) {
it.next();
ClangCompletionAssistProcessor *assistProcessor = it.value();
if (assistProcessor->textEditorWidget() == textEditorWidget) {
delete assistProcessor;
it.remove();
}
}
}
QFuture<CppTools::CursorInfo> BackendReceiver::addExpectedReferencesMessage(
quint64 ticket,
QTextDocument *textDocument,
const CppTools::SemanticInfo::LocalUseMap &localUses)
{
QTC_CHECK(textDocument);
QTC_CHECK(!m_referencesTable.contains(ticket));
QFutureInterface<CppTools::CursorInfo> futureInterface;
futureInterface.reportStarted();
const ReferencesEntry entry{futureInterface, textDocument, localUses};
m_referencesTable.insert(ticket, entry);
return futureInterface.future();
}
QFuture<CppTools::SymbolInfo> BackendReceiver::addExpectedRequestFollowSymbolMessage(quint64 ticket)
{
QTC_CHECK(!m_followTable.contains(ticket));
QFutureInterface<CppTools::SymbolInfo> futureInterface;
futureInterface.reportStarted();
m_followTable.insert(ticket, futureInterface);
return futureInterface.future();
}
bool BackendReceiver::isExpectingCodeCompletedMessage() const
{
return !m_assistProcessorsTable.isEmpty();
}
void BackendReceiver::reset()
{
// Clean up waiting assist processors
qDeleteAll(m_assistProcessorsTable.begin(), m_assistProcessorsTable.end());
m_assistProcessorsTable.clear();
// Clean up futures for references
for (ReferencesEntry &entry : m_referencesTable)
entry.futureInterface.cancel();
m_referencesTable.clear();
for (QFutureInterface<CppTools::SymbolInfo> &futureInterface : m_followTable)
futureInterface.cancel();
m_followTable.clear();
}
void BackendReceiver::alive()
{
if (printAliveMessage())
qCDebug(log) << "<<< AliveMessage";
QTC_ASSERT(m_aliveHandler, return);
m_aliveHandler();
}
void BackendReceiver::echo(const EchoMessage &message)
{
qCDebug(log) << "<<<" << message;
}
void BackendReceiver::codeCompleted(const CodeCompletedMessage &message)
{
qCDebug(log) << "<<< CodeCompletedMessage with" << message.codeCompletions().size() << "items";
const quint64 ticket = message.ticketNumber();
QScopedPointer<ClangCompletionAssistProcessor> processor(m_assistProcessorsTable.take(ticket));
if (processor) {
processor->handleAvailableCompletions(message.codeCompletions(),
message.neededCorrection());
}
}
void BackendReceiver::documentAnnotationsChanged(const DocumentAnnotationsChangedMessage &message)
{
qCDebug(log) << "<<< DocumentAnnotationsChangedMessage with"
<< message.diagnostics().size() << "diagnostics"
<< message.highlightingMarks().size() << "highlighting marks"
<< message.skippedPreprocessorRanges().size() << "skipped preprocessor ranges";
auto processor = ClangEditorDocumentProcessor::get(message.fileContainer().filePath());
if (processor) {
const QString projectPartId = message.fileContainer().projectPartId();
const QString filePath = message.fileContainer().filePath();
const QString documentProjectPartId = CppTools::CppToolsBridge::projectPartIdForFile(filePath);
if (projectPartId == documentProjectPartId) {
const quint32 documentRevision = message.fileContainer().documentRevision();
processor->updateCodeWarnings(message.diagnostics(),
message.firstHeaderErrorDiagnostic(),
documentRevision);
processor->updateHighlighting(message.highlightingMarks(),
message.skippedPreprocessorRanges(),
documentRevision);
}
}
}
static
CppTools::CursorInfo::Range toCursorInfoRange(const QTextDocument &textDocument,
const SourceRangeContainer &sourceRange)
{
const SourceLocationContainer start = sourceRange.start();
const SourceLocationContainer end = sourceRange.end();
const unsigned length = end.column() - start.column();
const QTextBlock block = textDocument.findBlockByNumber(static_cast<int>(start.line()) - 1);
const int shift = ClangCodeModel::Utils::extraUtf8CharsShift(block.text(),
static_cast<int>(start.column()));
const uint column = start.column() - static_cast<uint>(shift);
return CppTools::CursorInfo::Range(start.line(), column, length);
}
static
CppTools::CursorInfo toCursorInfo(const QTextDocument &textDocument,
const CppTools::SemanticInfo::LocalUseMap &localUses,
const ReferencesMessage &message)
{
CppTools::CursorInfo result;
const QVector<SourceRangeContainer> references = message.references();
result.areUseRangesForLocalVariable = message.isLocalVariable();
for (const SourceRangeContainer &reference : references)
result.useRanges.append(toCursorInfoRange(textDocument, reference));
result.useRanges.reserve(references.size());
result.localUses = localUses;
return result;
}
static
CppTools::SymbolInfo toSymbolInfo(const FollowSymbolMessage &message)
{
CppTools::SymbolInfo result;
const SourceRangeContainer &range = message.sourceRange();
const SourceLocationContainer start = range.start();
const SourceLocationContainer end = range.end();
result.startLine = static_cast<int>(start.line());
result.startColumn = static_cast<int>(start.column());
result.endLine = static_cast<int>(end.line());
result.endColumn = static_cast<int>(end.column());
result.fileName = start.filePath();
return result;
}
void BackendReceiver::references(const ReferencesMessage &message)
{
qCDebug(log) << "<<< ReferencesMessage with"
<< message.references().size() << "references";
const quint64 ticket = message.ticketNumber();
const ReferencesEntry entry = m_referencesTable.take(ticket);
QFutureInterface<CppTools::CursorInfo> futureInterface = entry.futureInterface;
QTC_CHECK(futureInterface != QFutureInterface<CppTools::CursorInfo>());
if (futureInterface.isCanceled())
return; // Editor document closed or a new request was issued making this result outdated.
QTC_ASSERT(entry.textDocument, return);
futureInterface.reportResult(toCursorInfo(*entry.textDocument, entry.localUses, message));
futureInterface.reportFinished();
}
void BackendReceiver::followSymbol(const ClangBackEnd::FollowSymbolMessage &message)
{
qCDebug(log) << "<<< FollowSymbolMessage with"
<< message.sourceRange() << "range";
const quint64 ticket = message.ticketNumber();
QFutureInterface<CppTools::SymbolInfo> futureInterface = m_followTable.take(ticket);
QTC_CHECK(futureInterface != QFutureInterface<CppTools::SymbolInfo>());
if (futureInterface.isCanceled())
return; // Editor document closed or a new request was issued making this result outdated.
futureInterface.reportResult(toSymbolInfo(message));
futureInterface.reportFinished();
}
} // namespace Internal
} // namespace ClangCodeModel

View File

@@ -0,0 +1,96 @@
/****************************************************************************
**
** Copyright (C) 2017 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 <cpptools/cppcursorinfo.h>
#include <cpptools/cppsymbolinfo.h>
#include <clangsupport/clangcodemodelclientinterface.h>
#include <QFuture>
#include <QPointer>
#include <QTextDocument>
namespace TextEditor { class TextEditorWidget; }
namespace ClangCodeModel {
namespace Internal {
class ClangCompletionAssistProcessor;
class BackendReceiver : public ClangBackEnd::ClangCodeModelClientInterface
{
public:
BackendReceiver();
~BackendReceiver() override;
using AliveHandler = std::function<void ()>;
void setAliveHandler(const AliveHandler &handler);
void addExpectedCodeCompletedMessage(quint64 ticket, ClangCompletionAssistProcessor *processor);
void deleteProcessorsOfEditorWidget(TextEditor::TextEditorWidget *textEditorWidget);
QFuture<CppTools::CursorInfo>
addExpectedReferencesMessage(quint64 ticket,
QTextDocument *textDocument,
const CppTools::SemanticInfo::LocalUseMap &localUses);
QFuture<CppTools::SymbolInfo> addExpectedRequestFollowSymbolMessage(quint64 ticket);
bool isExpectingCodeCompletedMessage() const;
void reset();
private:
void alive() override;
void echo(const ClangBackEnd::EchoMessage &message) override;
void codeCompleted(const ClangBackEnd::CodeCompletedMessage &message) override;
void documentAnnotationsChanged(const ClangBackEnd::DocumentAnnotationsChangedMessage &message) override;
void references(const ClangBackEnd::ReferencesMessage &message) override;
void followSymbol(const ClangBackEnd::FollowSymbolMessage &message) override;
private:
AliveHandler m_aliveHandler;
QHash<quint64, ClangCompletionAssistProcessor *> m_assistProcessorsTable;
struct ReferencesEntry {
ReferencesEntry() = default;
ReferencesEntry(QFutureInterface<CppTools::CursorInfo> futureInterface,
QTextDocument *textDocument,
const CppTools::SemanticInfo::LocalUseMap &localUses)
: futureInterface(futureInterface)
, textDocument(textDocument)
, localUses(localUses) {}
QFutureInterface<CppTools::CursorInfo> futureInterface;
QPointer<QTextDocument> textDocument;
CppTools::SemanticInfo::LocalUseMap localUses;
};
QHash<quint64, ReferencesEntry> m_referencesTable;
QHash<quint64, QFutureInterface<CppTools::SymbolInfo>> m_followTable;
};
} // namespace Internal
} // namespace ClangCodeModel

View File

@@ -0,0 +1,141 @@
/****************************************************************************
**
** Copyright (C) 2017 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 "clangbackendsender.h"
#include "clangbackendlogging.h"
#include <clangsupport/clangcodemodelconnectionclient.h>
#include <clangsupport/clangcodemodelservermessages.h>
#include <utils/qtcassert.h>
using namespace ClangBackEnd;
namespace ClangCodeModel {
namespace Internal {
BackendSender::BackendSender(ClangCodeModelConnectionClient *connectionClient)
: m_connection(connectionClient)
{}
void BackendSender::end()
{
QTC_CHECK(m_connection->isConnected());
qCDebug(ipcLog) << ">>>" << ClangBackEnd::EndMessage();
m_connection->sendEndMessage();
}
void BackendSender::registerTranslationUnitsForEditor(const RegisterTranslationUnitForEditorMessage &message)
{
QTC_CHECK(m_connection->isConnected());
qCDebug(ipcLog) << ">>>" << message;
m_connection->serverProxy().registerTranslationUnitsForEditor(message);
}
void BackendSender::updateTranslationUnitsForEditor(const UpdateTranslationUnitsForEditorMessage &message)
{
QTC_CHECK(m_connection->isConnected());
qCDebug(ipcLog) << ">>>" << message;
m_connection->serverProxy().updateTranslationUnitsForEditor(message);
}
void BackendSender::unregisterTranslationUnitsForEditor(const UnregisterTranslationUnitsForEditorMessage &message)
{
QTC_CHECK(m_connection->isConnected());
qCDebug(ipcLog) << ">>>" << message;
m_connection->serverProxy().unregisterTranslationUnitsForEditor(message);
}
void BackendSender::registerProjectPartsForEditor(const RegisterProjectPartsForEditorMessage &message)
{
QTC_CHECK(m_connection->isConnected());
qCDebug(ipcLog) << ">>>" << message;
m_connection->serverProxy().registerProjectPartsForEditor(message);
}
void BackendSender::unregisterProjectPartsForEditor(const UnregisterProjectPartsForEditorMessage &message)
{
QTC_CHECK(m_connection->isConnected());
qCDebug(ipcLog) << ">>>" << message;
m_connection->serverProxy().unregisterProjectPartsForEditor(message);
}
void BackendSender::registerUnsavedFilesForEditor(const RegisterUnsavedFilesForEditorMessage &message)
{
QTC_CHECK(m_connection->isConnected());
qCDebug(ipcLog) << ">>>" << message;
m_connection->serverProxy().registerUnsavedFilesForEditor(message);
}
void BackendSender::unregisterUnsavedFilesForEditor(const UnregisterUnsavedFilesForEditorMessage &message)
{
QTC_CHECK(m_connection->isConnected());
qCDebug(ipcLog) << ">>>" << message;
m_connection->serverProxy().unregisterUnsavedFilesForEditor(message);
}
void BackendSender::completeCode(const CompleteCodeMessage &message)
{
QTC_CHECK(m_connection->isConnected());
qCDebug(ipcLog) << ">>>" << message;
m_connection->serverProxy().completeCode(message);
}
void BackendSender::requestDocumentAnnotations(const RequestDocumentAnnotationsMessage &message)
{
QTC_CHECK(m_connection->isConnected());
qCDebug(ipcLog) << ">>>" << message;
m_connection->serverProxy().requestDocumentAnnotations(message);
}
void BackendSender::requestReferences(const RequestReferencesMessage &message)
{
QTC_CHECK(m_connection->isConnected());
qCDebug(ipcLog) << ">>>" << message;
m_connection->serverProxy().requestReferences(message);
}
void BackendSender::requestFollowSymbol(const RequestFollowSymbolMessage &message)
{
QTC_CHECK(m_connection->isConnected());
qCDebug(ipcLog) << ">>>" << message;
m_connection->serverProxy().requestFollowSymbol(message);
}
void BackendSender::updateVisibleTranslationUnits(const UpdateVisibleTranslationUnitsMessage &message)
{
QTC_CHECK(m_connection->isConnected());
qCDebug(ipcLog) << ">>>" << message;
m_connection->serverProxy().updateVisibleTranslationUnits(message);
}
bool BackendSender::isConnected() const
{
return m_connection && m_connection->isConnected();
}
} // namespace Internal
} // namespace ClangCodeModel

View File

@@ -0,0 +1,62 @@
/****************************************************************************
**
** Copyright (C) 2017 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 <clangsupport/clangcodemodelserverinterface.h>
namespace ClangBackEnd { class ClangCodeModelConnectionClient; }
namespace ClangCodeModel {
namespace Internal {
class BackendSender : public ClangBackEnd::ClangCodeModelServerInterface
{
public:
BackendSender(ClangBackEnd::ClangCodeModelConnectionClient *connectionClient);
void end() override;
void registerTranslationUnitsForEditor(const ClangBackEnd::RegisterTranslationUnitForEditorMessage &message) override;
void updateTranslationUnitsForEditor(const ClangBackEnd::UpdateTranslationUnitsForEditorMessage &message) override;
void unregisterTranslationUnitsForEditor(const ClangBackEnd::UnregisterTranslationUnitsForEditorMessage &message) override;
void registerProjectPartsForEditor(const ClangBackEnd::RegisterProjectPartsForEditorMessage &message) override;
void unregisterProjectPartsForEditor(const ClangBackEnd::UnregisterProjectPartsForEditorMessage &message) override;
void registerUnsavedFilesForEditor(const ClangBackEnd::RegisterUnsavedFilesForEditorMessage &message) override;
void unregisterUnsavedFilesForEditor(const ClangBackEnd::UnregisterUnsavedFilesForEditorMessage &message) override;
void completeCode(const ClangBackEnd::CompleteCodeMessage &message) override;
void requestDocumentAnnotations(const ClangBackEnd::RequestDocumentAnnotationsMessage &message) override;
void requestReferences(const ClangBackEnd::RequestReferencesMessage &message) override;
void requestFollowSymbol(const ClangBackEnd::RequestFollowSymbolMessage &message) override;
void updateVisibleTranslationUnits(const ClangBackEnd::UpdateVisibleTranslationUnitsMessage &message) override;
private:
bool isConnected() const;
private:
ClangBackEnd::ClangCodeModelConnectionClient *m_connection = nullptr;
};
} // namespace Internal
} // namespace ClangCodeModel

View File

@@ -9,7 +9,10 @@ SOURCES += \
clangassistproposal.cpp \ clangassistproposal.cpp \
clangassistproposalitem.cpp \ clangassistproposalitem.cpp \
clangassistproposalmodel.cpp \ clangassistproposalmodel.cpp \
clangbackendipcintegration.cpp \ clangbackendcommunicator.cpp \
clangbackendlogging.cpp \
clangbackendreceiver.cpp \
clangbackendsender.cpp \
clangcodemodelplugin.cpp \ clangcodemodelplugin.cpp \
clangcompletionassistinterface.cpp \ clangcompletionassistinterface.cpp \
clangcompletionassistprocessor.cpp \ clangcompletionassistprocessor.cpp \
@@ -40,7 +43,10 @@ HEADERS += \
clangassistproposal.h \ clangassistproposal.h \
clangassistproposalitem.h \ clangassistproposalitem.h \
clangassistproposalmodel.h \ clangassistproposalmodel.h \
clangbackendipcintegration.h \ clangbackendcommunicator.h \
clangbackendlogging.h \
clangbackendreceiver.h \
clangbackendsender.h \
clangcodemodelplugin.h \ clangcodemodelplugin.h \
clangcompletionassistinterface.h \ clangcompletionassistinterface.h \
clangcompletionassistprocessor.h \ clangcompletionassistprocessor.h \

View File

@@ -41,8 +41,14 @@ QtcPlugin {
"clangassistproposalitem.h", "clangassistproposalitem.h",
"clangassistproposalmodel.cpp", "clangassistproposalmodel.cpp",
"clangassistproposalmodel.h", "clangassistproposalmodel.h",
"clangbackendipcintegration.cpp", "clangbackendcommunicator.cpp",
"clangbackendipcintegration.h", "clangbackendcommunicator.h",
"clangbackendlogging.cpp",
"clangbackendlogging.h",
"clangbackendreceiver.cpp",
"clangbackendreceiver.h",
"clangbackendsender.cpp",
"clangbackendsender.h",
"clangcodemodelplugin.cpp", "clangcodemodelplugin.cpp",
"clangcodemodelplugin.h", "clangcodemodelplugin.h",
"clangcodemodel.qrc", "clangcodemodel.qrc",

View File

@@ -31,7 +31,7 @@ namespace ClangCodeModel {
namespace Internal { namespace Internal {
ClangCompletionAssistInterface::ClangCompletionAssistInterface( ClangCompletionAssistInterface::ClangCompletionAssistInterface(
IpcCommunicator &ipcCommunicator, BackendCommunicator &communicator,
const TextEditor::TextEditorWidget *textEditorWidget, const TextEditor::TextEditorWidget *textEditorWidget,
int position, int position,
const QString &fileName, const QString &fileName,
@@ -39,7 +39,7 @@ ClangCompletionAssistInterface::ClangCompletionAssistInterface(
const CppTools::ProjectPartHeaderPaths &headerPaths, const CppTools::ProjectPartHeaderPaths &headerPaths,
const CPlusPlus::LanguageFeatures &features) const CPlusPlus::LanguageFeatures &features)
: AssistInterface(textEditorWidget->document(), position, fileName, reason) : AssistInterface(textEditorWidget->document(), position, fileName, reason)
, m_ipcCommunicator(ipcCommunicator) , m_communicator(communicator)
, m_headerPaths(headerPaths) , m_headerPaths(headerPaths)
, m_languageFeatures(features) , m_languageFeatures(features)
, m_textEditorWidget(textEditorWidget) , m_textEditorWidget(textEditorWidget)
@@ -71,9 +71,9 @@ const TextEditor::TextEditorWidget *ClangCompletionAssistInterface::textEditorWi
return m_textEditorWidget; return m_textEditorWidget;
} }
IpcCommunicator &ClangCompletionAssistInterface::ipcCommunicator() const BackendCommunicator &ClangCompletionAssistInterface::communicator() const
{ {
return m_ipcCommunicator; return m_communicator;
} }
} // namespace Internal } // namespace Internal

View File

@@ -25,7 +25,7 @@
#pragma once #pragma once
#include "clangbackendipcintegration.h" #include "clangbackendcommunicator.h"
#include "clangutils.h" #include "clangutils.h"
#include <texteditor/codeassist/assistinterface.h> #include <texteditor/codeassist/assistinterface.h>
@@ -36,7 +36,7 @@ namespace Internal {
class ClangCompletionAssistInterface: public TextEditor::AssistInterface class ClangCompletionAssistInterface: public TextEditor::AssistInterface
{ {
public: public:
ClangCompletionAssistInterface(IpcCommunicator &ipcCommunicator, ClangCompletionAssistInterface(BackendCommunicator &communicator,
const TextEditor::TextEditorWidget *textEditorWidget, const TextEditor::TextEditorWidget *textEditorWidget,
int position, int position,
const QString &fileName, const QString &fileName,
@@ -44,7 +44,7 @@ public:
const CppTools::ProjectPartHeaderPaths &headerPaths, const CppTools::ProjectPartHeaderPaths &headerPaths,
const CPlusPlus::LanguageFeatures &features); const CPlusPlus::LanguageFeatures &features);
IpcCommunicator &ipcCommunicator() const; BackendCommunicator &communicator() const;
bool objcEnabled() const; bool objcEnabled() const;
const CppTools::ProjectPartHeaderPaths &headerPaths() const; const CppTools::ProjectPartHeaderPaths &headerPaths() const;
CPlusPlus::LanguageFeatures languageFeatures() const; CPlusPlus::LanguageFeatures languageFeatures() const;
@@ -53,7 +53,7 @@ public:
void setHeaderPaths(const CppTools::ProjectPartHeaderPaths &headerPaths); // For tests void setHeaderPaths(const CppTools::ProjectPartHeaderPaths &headerPaths); // For tests
private: private:
IpcCommunicator &m_ipcCommunicator; BackendCommunicator &m_communicator;
QStringList m_options; QStringList m_options;
CppTools::ProjectPartHeaderPaths m_headerPaths; CppTools::ProjectPartHeaderPaths m_headerPaths;
CPlusPlus::LanguageFeatures m_languageFeatures; CPlusPlus::LanguageFeatures m_languageFeatures;

View File

@@ -495,8 +495,8 @@ void ClangCompletionAssistProcessor::sendFileContent(const QByteArray &customFil
// TODO: Revert custom modification after the completions // TODO: Revert custom modification after the completions
const UnsavedFileContentInfo info = unsavedFileContent(customFileContent); const UnsavedFileContentInfo info = unsavedFileContent(customFileContent);
IpcCommunicator &ipcCommunicator = m_interface->ipcCommunicator(); BackendCommunicator &communicator = m_interface->communicator();
ipcCommunicator.updateTranslationUnitsForEditor({{m_interface->fileName(), communicator.updateTranslationUnitsForEditor({{m_interface->fileName(),
Utf8String(), Utf8String(),
Utf8String::fromByteArray(info.unsavedContent), Utf8String::fromByteArray(info.unsavedContent),
info.isDocumentModified, info.isDocumentModified,
@@ -568,10 +568,9 @@ bool ClangCompletionAssistProcessor::sendCompletionRequest(int position,
{ {
const QString filePath = m_interface->fileName(); const QString filePath = m_interface->fileName();
auto &ipcCommunicator = m_interface->ipcCommunicator(); auto &communicator = m_interface->communicator();
if (shouldSendCodeCompletion(filePath, position) if (shouldSendCodeCompletion(filePath, position) || communicator.isNotWaitingForCompletion()) {
|| ipcCommunicator.isNotWaitingForCompletion()) {
if (shouldSendDocumentForCompletion(filePath, position)) { if (shouldSendDocumentForCompletion(filePath, position)) {
sendFileContent(customFileContent); sendFileContent(customFileContent);
setLastDocumentRevision(filePath); setLastDocumentRevision(filePath);
@@ -580,7 +579,7 @@ bool ClangCompletionAssistProcessor::sendCompletionRequest(int position,
const Position cursorPosition = extractLineColumn(position); const Position cursorPosition = extractLineColumn(position);
const Position functionNameStart = extractLineColumn(functionNameStartPosition); const Position functionNameStart = extractLineColumn(functionNameStartPosition);
const QString projectPartId = CppTools::CppToolsBridge::projectPartIdForFile(filePath); const QString projectPartId = CppTools::CppToolsBridge::projectPartIdForFile(filePath);
ipcCommunicator.completeCode(this, filePath, uint(cursorPosition.line), communicator.completeCode(this, filePath, uint(cursorPosition.line),
uint(cursorPosition.column), projectPartId, uint(cursorPosition.column), projectPartId,
functionNameStart.line, functionNameStart.column); functionNameStart.line, functionNameStart.column);
setLastCompletionPosition(filePath, position); setLastCompletionPosition(filePath, position);

View File

@@ -43,8 +43,8 @@
namespace ClangCodeModel { namespace ClangCodeModel {
namespace Internal { namespace Internal {
ClangCompletionAssistProvider::ClangCompletionAssistProvider(IpcCommunicator &ipcCommunicator) ClangCompletionAssistProvider::ClangCompletionAssistProvider(BackendCommunicator &communicator)
: m_ipcCommunicator(ipcCommunicator) : m_communicator(communicator)
{ {
} }
@@ -67,7 +67,7 @@ TextEditor::AssistInterface *ClangCompletionAssistProvider::createAssistInterfac
{ {
const CppTools::ProjectPart::Ptr projectPart = Utils::projectPartForFileBasedOnProcessor(filePath); const CppTools::ProjectPart::Ptr projectPart = Utils::projectPartForFileBasedOnProcessor(filePath);
if (projectPart) { if (projectPart) {
return new ClangCompletionAssistInterface(m_ipcCommunicator, return new ClangCompletionAssistInterface(m_communicator,
textEditorWidget, textEditorWidget,
position, position,
filePath, filePath,

View File

@@ -25,7 +25,7 @@
#pragma once #pragma once
#include "clangbackendipcintegration.h" #include "clangbackendcommunicator.h"
#include <cpptools/cppcompletionassistprovider.h> #include <cpptools/cppcompletionassistprovider.h>
@@ -39,7 +39,7 @@ class ClangCompletionAssistProvider : public CppTools::CppCompletionAssistProvid
Q_OBJECT Q_OBJECT
public: public:
ClangCompletionAssistProvider(IpcCommunicator &ipcCommunicator); ClangCompletionAssistProvider(BackendCommunicator &communicator);
IAssistProvider::RunType runType() const override; IAssistProvider::RunType runType() const override;
@@ -52,7 +52,7 @@ public:
TextEditor::AssistReason reason) const override; TextEditor::AssistReason reason) const override;
private: private:
IpcCommunicator &m_ipcCommunicator; BackendCommunicator &m_communicator;
}; };
} // namespace Internal } // namespace Internal

View File

@@ -25,7 +25,7 @@
#include "clangeditordocumentprocessor.h" #include "clangeditordocumentprocessor.h"
#include "clangbackendipcintegration.h" #include "clangbackendcommunicator.h"
#include "clangdiagnostictooltipwidget.h" #include "clangdiagnostictooltipwidget.h"
#include "clangfixitoperation.h" #include "clangfixitoperation.h"
#include "clangfixitoperationsextractor.h" #include "clangfixitoperationsextractor.h"
@@ -67,12 +67,12 @@ namespace ClangCodeModel {
namespace Internal { namespace Internal {
ClangEditorDocumentProcessor::ClangEditorDocumentProcessor( ClangEditorDocumentProcessor::ClangEditorDocumentProcessor(
IpcCommunicator &ipcCommunicator, BackendCommunicator &communicator,
TextEditor::TextDocument *document) TextEditor::TextDocument *document)
: BaseEditorDocumentProcessor(document->document(), document->filePath().toString()) : BaseEditorDocumentProcessor(document->document(), document->filePath().toString())
, m_document(*document) , m_document(*document)
, m_diagnosticManager(document) , m_diagnosticManager(document)
, m_ipcCommunicator(ipcCommunicator) , m_communicator(communicator)
, m_parser(new ClangEditorDocumentParser(document->filePath().toString())) , m_parser(new ClangEditorDocumentParser(document->filePath().toString()))
, m_parserRevision(0) , m_parserRevision(0)
, m_semanticHighlighter(document) , m_semanticHighlighter(document)
@@ -102,7 +102,7 @@ ClangEditorDocumentProcessor::~ClangEditorDocumentProcessor()
m_parserWatcher.waitForFinished(); m_parserWatcher.waitForFinished();
if (m_projectPart) { if (m_projectPart) {
m_ipcCommunicator.unregisterTranslationUnitsForEditor( m_communicator.unregisterTranslationUnitsForEditor(
{ClangBackEnd::FileContainer(filePath(), m_projectPart->id())}); {ClangBackEnd::FileContainer(filePath(), m_projectPart->id())});
} }
} }
@@ -343,7 +343,7 @@ ClangEditorDocumentProcessor::cursorInfo(const CppTools::CursorInfoParams &param
const CppTools::SemanticInfo::LocalUseMap localUses const CppTools::SemanticInfo::LocalUseMap localUses
= CppTools::BuiltinCursorInfo::findLocalUses(params.semanticInfo.doc, line, column); = CppTools::BuiltinCursorInfo::findLocalUses(params.semanticInfo.doc, line, column);
return m_ipcCommunicator.requestReferences(simpleFileContainer(), return m_communicator.requestReferences(simpleFileContainer(),
static_cast<quint32>(line), static_cast<quint32>(line),
static_cast<quint32>(column), static_cast<quint32>(column),
textDocument(), textDocument(),
@@ -392,7 +392,7 @@ ClangEditorDocumentProcessor::requestFollowSymbol(int line, int column)
dependentFiles = prioritizeByBaseName(filePath(), fileDeps); dependentFiles = prioritizeByBaseName(filePath(), fileDeps);
} }
return m_ipcCommunicator.requestFollowSymbol(simpleFileContainer(), return m_communicator.requestFollowSymbol(simpleFileContainer(),
dependentFiles, dependentFiles,
static_cast<quint32>(line), static_cast<quint32>(line),
static_cast<quint32>(column)); static_cast<quint32>(column));
@@ -456,10 +456,10 @@ void ClangEditorDocumentProcessor::registerTranslationUnitForEditor(CppTools::Pr
if (m_projectPart) { if (m_projectPart) {
if (projectPart->id() == m_projectPart->id()) if (projectPart->id() == m_projectPart->id())
return; return;
m_ipcCommunicator.unregisterTranslationUnitsForEditor({fileContainerWithArguments()}); m_communicator.unregisterTranslationUnitsForEditor({fileContainerWithArguments()});
} }
m_ipcCommunicator.registerTranslationUnitsForEditor( m_communicator.registerTranslationUnitsForEditor(
{fileContainerWithArgumentsAndDocumentContent(projectPart)}); {fileContainerWithArgumentsAndDocumentContent(projectPart)});
ClangCodeModel::Utils::setLastSentDocumentRevision(filePath(), revision()); ClangCodeModel::Utils::setLastSentDocumentRevision(filePath(), revision());
} }
@@ -469,7 +469,7 @@ void ClangEditorDocumentProcessor::updateTranslationUnitIfProjectPartExists()
if (m_projectPart) { if (m_projectPart) {
const ClangBackEnd::FileContainer fileContainer = fileContainerWithDocumentContent(m_projectPart->id()); const ClangBackEnd::FileContainer fileContainer = fileContainerWithDocumentContent(m_projectPart->id());
m_ipcCommunicator.updateTranslationUnitWithRevisionCheck(fileContainer); m_communicator.updateTranslationUnitWithRevisionCheck(fileContainer);
} }
} }
@@ -477,7 +477,7 @@ void ClangEditorDocumentProcessor::requestDocumentAnnotations(const QString &pro
{ {
const auto fileContainer = fileContainerWithDocumentContent(projectpartId); const auto fileContainer = fileContainerWithDocumentContent(projectpartId);
m_ipcCommunicator.requestDocumentAnnotations(fileContainer); m_communicator.requestDocumentAnnotations(fileContainer);
} }
CppTools::BaseEditorDocumentProcessor::HeaderErrorDiagnosticWidgetCreator CppTools::BaseEditorDocumentProcessor::HeaderErrorDiagnosticWidgetCreator

View File

@@ -43,14 +43,14 @@ class FileContainer;
namespace ClangCodeModel { namespace ClangCodeModel {
namespace Internal { namespace Internal {
class IpcCommunicator; class BackendCommunicator;
class ClangEditorDocumentProcessor : public CppTools::BaseEditorDocumentProcessor class ClangEditorDocumentProcessor : public CppTools::BaseEditorDocumentProcessor
{ {
Q_OBJECT Q_OBJECT
public: public:
ClangEditorDocumentProcessor(IpcCommunicator &ipcCommunicator, ClangEditorDocumentProcessor(BackendCommunicator &communicator,
TextEditor::TextDocument *document); TextEditor::TextDocument *document);
~ClangEditorDocumentProcessor(); ~ClangEditorDocumentProcessor();
@@ -114,7 +114,7 @@ private:
private: private:
TextEditor::TextDocument &m_document; TextEditor::TextDocument &m_document;
ClangDiagnosticManager m_diagnosticManager; ClangDiagnosticManager m_diagnosticManager;
IpcCommunicator &m_ipcCommunicator; BackendCommunicator &m_communicator;
QSharedPointer<ClangEditorDocumentParser> m_parser; QSharedPointer<ClangEditorDocumentParser> m_parser;
CppTools::ProjectPart::Ptr m_projectPart; CppTools::ProjectPart::Ptr m_projectPart;
bool m_isProjectFile = false; bool m_isProjectFile = false;

View File

@@ -66,7 +66,7 @@ static CppTools::CppModelManager *cppModelManager()
} }
ModelManagerSupportClang::ModelManagerSupportClang() ModelManagerSupportClang::ModelManagerSupportClang()
: m_completionAssistProvider(m_ipcCommunicator) : m_completionAssistProvider(m_communicator)
{ {
QTC_CHECK(!m_instance); QTC_CHECK(!m_instance);
m_instance = this; m_instance = this;
@@ -96,7 +96,7 @@ ModelManagerSupportClang::ModelManagerSupportClang()
connect(modelManager, &CppTools::CppModelManager::projectPartsRemoved, connect(modelManager, &CppTools::CppModelManager::projectPartsRemoved,
this, &ModelManagerSupportClang::onProjectPartsRemoved); this, &ModelManagerSupportClang::onProjectPartsRemoved);
m_ipcCommunicator.registerFallbackProjectPart(); m_communicator.registerFallbackProjectPart();
} }
ModelManagerSupportClang::~ModelManagerSupportClang() ModelManagerSupportClang::~ModelManagerSupportClang()
@@ -117,12 +117,12 @@ CppTools::FollowSymbolInterface &ModelManagerSupportClang::followSymbolInterface
CppTools::BaseEditorDocumentProcessor *ModelManagerSupportClang::editorDocumentProcessor( CppTools::BaseEditorDocumentProcessor *ModelManagerSupportClang::editorDocumentProcessor(
TextEditor::TextDocument *baseTextDocument) TextEditor::TextDocument *baseTextDocument)
{ {
return new ClangEditorDocumentProcessor(m_ipcCommunicator, baseTextDocument); return new ClangEditorDocumentProcessor(m_communicator, baseTextDocument);
} }
void ModelManagerSupportClang::onCurrentEditorChanged(Core::IEditor *) void ModelManagerSupportClang::onCurrentEditorChanged(Core::IEditor *)
{ {
m_ipcCommunicator.updateTranslationUnitVisiblity(); m_communicator.updateTranslationUnitVisiblity();
} }
void ModelManagerSupportClang::connectTextDocumentToTranslationUnit(TextEditor::TextDocument *textDocument) void ModelManagerSupportClang::connectTextDocumentToTranslationUnit(TextEditor::TextDocument *textDocument)
@@ -195,7 +195,7 @@ void ModelManagerSupportClang::onEditorOpened(Core::IEditor *editor)
void ModelManagerSupportClang::onEditorClosed(const QList<Core::IEditor *> &) void ModelManagerSupportClang::onEditorClosed(const QList<Core::IEditor *> &)
{ {
m_ipcCommunicator.updateTranslationUnitVisiblity(); m_communicator.updateTranslationUnitVisiblity();
} }
void ModelManagerSupportClang::onCppDocumentAboutToReloadOnTranslationUnit() void ModelManagerSupportClang::onCppDocumentAboutToReloadOnTranslationUnit()
@@ -210,7 +210,7 @@ void ModelManagerSupportClang::onCppDocumentReloadFinishedOnTranslationUnit(bool
if (success) { if (success) {
TextEditor::TextDocument *textDocument = qobject_cast<TextEditor::TextDocument *>(sender()); TextEditor::TextDocument *textDocument = qobject_cast<TextEditor::TextDocument *>(sender());
connectToTextDocumentContentsChangedForTranslationUnit(textDocument); connectToTextDocumentContentsChangedForTranslationUnit(textDocument);
m_ipcCommunicator.updateTranslationUnitWithRevisionCheck(textDocument); m_communicator.updateTranslationUnitWithRevisionCheck(textDocument);
} }
} }
@@ -229,9 +229,9 @@ void ModelManagerSupportClang::onCppDocumentContentsChangedOnTranslationUnit(int
{ {
Core::IDocument *document = qobject_cast<Core::IDocument *>(sender()); Core::IDocument *document = qobject_cast<Core::IDocument *>(sender());
m_ipcCommunicator.updateChangeContentStartPosition(document->filePath().toString(), m_communicator.updateChangeContentStartPosition(document->filePath().toString(),
position); position);
m_ipcCommunicator.updateTranslationUnitIfNotCurrentDocument(document); m_communicator.updateTranslationUnitIfNotCurrentDocument(document);
clearDiagnosticFixIts(document->filePath().toString()); clearDiagnosticFixIts(document->filePath().toString());
} }
@@ -248,14 +248,14 @@ void ModelManagerSupportClang::onCppDocumentReloadFinishedOnUnsavedFile(bool suc
if (success) { if (success) {
TextEditor::TextDocument *textDocument = qobject_cast<TextEditor::TextDocument *>(sender()); TextEditor::TextDocument *textDocument = qobject_cast<TextEditor::TextDocument *>(sender());
connectToTextDocumentContentsChangedForUnsavedFile(textDocument); connectToTextDocumentContentsChangedForUnsavedFile(textDocument);
m_ipcCommunicator.updateUnsavedFile(textDocument); m_communicator.updateUnsavedFile(textDocument);
} }
} }
void ModelManagerSupportClang::onCppDocumentContentsChangedOnUnsavedFile() void ModelManagerSupportClang::onCppDocumentContentsChangedOnUnsavedFile()
{ {
Core::IDocument *document = qobject_cast<Core::IDocument *>(sender()); Core::IDocument *document = qobject_cast<Core::IDocument *>(sender());
m_ipcCommunicator.updateUnsavedFile(document); m_communicator.updateUnsavedFile(document);
} }
void ModelManagerSupportClang::onAbstractEditorSupportContentsUpdated(const QString &filePath, void ModelManagerSupportClang::onAbstractEditorSupportContentsUpdated(const QString &filePath,
@@ -264,7 +264,7 @@ void ModelManagerSupportClang::onAbstractEditorSupportContentsUpdated(const QStr
QTC_ASSERT(!filePath.isEmpty(), return); QTC_ASSERT(!filePath.isEmpty(), return);
const QString mappedPath = m_uiHeaderOnDiskManager.createIfNeeded(filePath); const QString mappedPath = m_uiHeaderOnDiskManager.createIfNeeded(filePath);
m_ipcCommunicator.updateUnsavedFile(mappedPath, content, 0); m_communicator.updateUnsavedFile(mappedPath, content, 0);
} }
void ModelManagerSupportClang::onAbstractEditorSupportRemoved(const QString &filePath) void ModelManagerSupportClang::onAbstractEditorSupportRemoved(const QString &filePath)
@@ -274,7 +274,7 @@ void ModelManagerSupportClang::onAbstractEditorSupportRemoved(const QString &fil
if (!cppModelManager()->cppEditorDocument(filePath)) { if (!cppModelManager()->cppEditorDocument(filePath)) {
const QString mappedPath = m_uiHeaderOnDiskManager.remove(filePath); const QString mappedPath = m_uiHeaderOnDiskManager.remove(filePath);
const QString projectPartId = Utils::projectPartIdForFile(filePath); const QString projectPartId = Utils::projectPartIdForFile(filePath);
m_ipcCommunicator.unregisterUnsavedFilesForEditor({{mappedPath, projectPartId}}); m_communicator.unregisterUnsavedFilesForEditor({{mappedPath, projectPartId}});
} }
} }
@@ -328,16 +328,16 @@ void ModelManagerSupportClang::onProjectPartsUpdated(ProjectExplorer::Project *p
const CppTools::ProjectInfo projectInfo = cppModelManager()->projectInfo(project); const CppTools::ProjectInfo projectInfo = cppModelManager()->projectInfo(project);
QTC_ASSERT(projectInfo.isValid(), return); QTC_ASSERT(projectInfo.isValid(), return);
m_ipcCommunicator.registerProjectsParts(projectInfo.projectParts()); m_communicator.registerProjectsParts(projectInfo.projectParts());
m_ipcCommunicator.registerFallbackProjectPart(); m_communicator.registerFallbackProjectPart();
} }
void ModelManagerSupportClang::onProjectPartsRemoved(const QStringList &projectPartIds) void ModelManagerSupportClang::onProjectPartsRemoved(const QStringList &projectPartIds)
{ {
if (!projectPartIds.isEmpty()) { if (!projectPartIds.isEmpty()) {
unregisterTranslationUnitsWithProjectParts(projectPartIds); unregisterTranslationUnitsWithProjectParts(projectPartIds);
m_ipcCommunicator.unregisterProjectPartsForEditor(projectPartIds); m_communicator.unregisterProjectPartsForEditor(projectPartIds);
m_ipcCommunicator.registerFallbackProjectPart(); m_communicator.registerFallbackProjectPart();
} }
} }
@@ -363,7 +363,7 @@ void ModelManagerSupportClang::unregisterTranslationUnitsWithProjectParts(
{ {
const auto processors = clangProcessorsWithProjectParts(projectPartIds); const auto processors = clangProcessorsWithProjectParts(projectPartIds);
foreach (ClangEditorDocumentProcessor *processor, processors) { foreach (ClangEditorDocumentProcessor *processor, processors) {
m_ipcCommunicator.unregisterTranslationUnitsForEditor({processor->fileContainerWithArguments()}); m_communicator.unregisterTranslationUnitsForEditor({processor->fileContainerWithArguments()});
processor->clearProjectPart(); processor->clearProjectPart();
processor->run(); processor->run();
} }
@@ -374,9 +374,9 @@ ModelManagerSupportClang *ModelManagerSupportClang::instance()
return m_instance; return m_instance;
} }
IpcCommunicator &ModelManagerSupportClang::ipcCommunicator() BackendCommunicator &ModelManagerSupportClang::communicator()
{ {
return m_ipcCommunicator; return m_communicator;
} }
QString ModelManagerSupportClang::dummyUiHeaderOnDiskPath(const QString &filePath) const QString ModelManagerSupportClang::dummyUiHeaderOnDiskPath(const QString &filePath) const

View File

@@ -62,7 +62,7 @@ public:
TextEditor::TextDocument *baseTextDocument) override; TextEditor::TextDocument *baseTextDocument) override;
CppTools::FollowSymbolInterface &followSymbolInterface() override; CppTools::FollowSymbolInterface &followSymbolInterface() override;
IpcCommunicator &ipcCommunicator(); BackendCommunicator &communicator();
QString dummyUiHeaderOnDiskDirPath() const; QString dummyUiHeaderOnDiskDirPath() const;
QString dummyUiHeaderOnDiskPath(const QString &filePath) const; QString dummyUiHeaderOnDiskPath(const QString &filePath) const;
@@ -102,7 +102,7 @@ private:
private: private:
UiHeaderOnDiskManager m_uiHeaderOnDiskManager; UiHeaderOnDiskManager m_uiHeaderOnDiskManager;
IpcCommunicator m_ipcCommunicator; BackendCommunicator m_communicator;
ClangCompletionAssistProvider m_completionAssistProvider; ClangCompletionAssistProvider m_completionAssistProvider;
std::unique_ptr<CppTools::FollowSymbolInterface> m_followSymbol; std::unique_ptr<CppTools::FollowSymbolInterface> m_followSymbol;
}; };