forked from qt-creator/qt-creator
Merge remote-tracking branch 'origin/4.2'
Change-Id: I259a402bc896fc2e359cc96b7510453ac9a9a552
This commit is contained in:
@@ -83,18 +83,32 @@ using namespace ClangCodeModel::Internal;
|
||||
using namespace ClangBackEnd;
|
||||
using namespace TextEditor;
|
||||
|
||||
namespace {
|
||||
|
||||
QString backendProcessPath()
|
||||
static QString backendProcessPath()
|
||||
{
|
||||
return Core::ICore::libexecPath()
|
||||
+ QStringLiteral("/clangbackend")
|
||||
+ QStringLiteral(QTC_HOST_EXE_SUFFIX);
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
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()
|
||||
: m_printAliveMessage(printAliveMessage())
|
||||
{
|
||||
}
|
||||
|
||||
@@ -143,7 +157,8 @@ bool IpcReceiver::isExpectingCodeCompletedMessage() const
|
||||
|
||||
void IpcReceiver::alive()
|
||||
{
|
||||
qCDebug(log) << "<<< AliveMessage";
|
||||
if (m_printAliveMessage)
|
||||
qCDebug(log) << "<<< AliveMessage";
|
||||
QTC_ASSERT(m_aliveHandler, return);
|
||||
m_aliveHandler();
|
||||
}
|
||||
@@ -505,8 +520,11 @@ void IpcCommunicator::registerCurrentCodeModelUiHeaders()
|
||||
using namespace CppTools;
|
||||
|
||||
const auto editorSupports = CppModelManager::instance()->abstractEditorSupports();
|
||||
foreach (const AbstractEditorSupport *es, editorSupports)
|
||||
updateUnsavedFile(es->fileName(), es->contents(), es->revision());
|
||||
foreach (const AbstractEditorSupport *es, editorSupports) {
|
||||
const QString mappedPath
|
||||
= ModelManagerSupportClang::instance()->dummyUiHeaderOnDiskPath(es->fileName());
|
||||
updateUnsavedFile(mappedPath, es->contents(), es->revision());
|
||||
}
|
||||
}
|
||||
|
||||
void IpcCommunicator::registerProjectsParts(const QList<CppTools::ProjectPart::Ptr> projectParts)
|
||||
@@ -517,43 +535,21 @@ void IpcCommunicator::registerProjectsParts(const QList<CppTools::ProjectPart::P
|
||||
|
||||
void IpcCommunicator::updateTranslationUnitFromCppEditorDocument(const QString &filePath)
|
||||
{
|
||||
const auto document = CppTools::CppModelManager::instance()->cppEditorDocument(filePath);
|
||||
const CppTools::CppEditorDocumentHandle *document = ClangCodeModel::Utils::cppDocument(filePath);
|
||||
|
||||
updateTranslationUnit(filePath, document->contents(), document->revision());
|
||||
}
|
||||
|
||||
void IpcCommunicator::updateUnsavedFileFromCppEditorDocument(const QString &filePath)
|
||||
{
|
||||
const auto document = CppTools::CppModelManager::instance()->cppEditorDocument(filePath);
|
||||
const CppTools::CppEditorDocumentHandle *document = ClangCodeModel::Utils::cppDocument(filePath);
|
||||
|
||||
updateUnsavedFile(filePath, document->contents(), document->revision());
|
||||
}
|
||||
|
||||
namespace {
|
||||
CppTools::CppEditorDocumentHandle *cppDocument(const QString &filePath)
|
||||
{
|
||||
return CppTools::CppModelManager::instance()->cppEditorDocument(filePath);
|
||||
}
|
||||
|
||||
bool documentHasChanged(const QString &filePath,
|
||||
uint revision)
|
||||
{
|
||||
auto *document = cppDocument(filePath);
|
||||
|
||||
if (document)
|
||||
return document->sendTracker().shouldSendRevision(revision);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void setLastSentDocumentRevision(const QString &filePath,
|
||||
uint revision)
|
||||
{
|
||||
auto *document = cppDocument(filePath);
|
||||
|
||||
if (document)
|
||||
document->sendTracker().setLastSentRevision(int(revision));
|
||||
}
|
||||
}
|
||||
|
||||
void IpcCommunicator::updateTranslationUnit(const QString &filePath,
|
||||
@@ -581,6 +577,20 @@ void IpcCommunicator::updateUnsavedFile(const QString &filePath, const QByteArra
|
||||
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())) {
|
||||
@@ -610,9 +620,7 @@ void IpcCommunicator::updateTranslationUnitWithRevisionCheck(Core::IDocument *do
|
||||
|
||||
void IpcCommunicator::updateChangeContentStartPosition(const QString &filePath, int position)
|
||||
{
|
||||
auto *document = cppDocument(filePath);
|
||||
|
||||
if (document)
|
||||
if (CppTools::CppEditorDocumentHandle *document = ClangCodeModel::Utils::cppDocument(filePath))
|
||||
document->sendTracker().applyContentChange(position);
|
||||
}
|
||||
|
||||
|
||||
@@ -85,6 +85,7 @@ private:
|
||||
private:
|
||||
AliveHandler m_aliveHandler;
|
||||
QHash<quint64, ClangCompletionAssistProcessor *> m_assistProcessorsTable;
|
||||
const bool m_printAliveMessage = false;
|
||||
};
|
||||
|
||||
class IpcSenderInterface
|
||||
|
||||
@@ -30,6 +30,7 @@ SOURCES += \
|
||||
clangprojectsettings.cpp \
|
||||
clangprojectsettingswidget.cpp \
|
||||
clangtextmark.cpp \
|
||||
clanguiheaderondiskmanager.cpp \
|
||||
clangutils.cpp
|
||||
|
||||
HEADERS += \
|
||||
@@ -61,6 +62,7 @@ HEADERS += \
|
||||
clangprojectsettings.h \
|
||||
clangprojectsettingswidget.h \
|
||||
clangtextmark.h \
|
||||
clanguiheaderondiskmanager.h \
|
||||
clangutils.h
|
||||
|
||||
FORMS += clangprojectsettingswidget.ui
|
||||
|
||||
@@ -87,6 +87,8 @@ QtcPlugin {
|
||||
"clangprojectsettingswidget.ui",
|
||||
"clangtextmark.cpp",
|
||||
"clangtextmark.h",
|
||||
"clanguiheaderondiskmanager.cpp",
|
||||
"clanguiheaderondiskmanager.h",
|
||||
"clangutils.cpp",
|
||||
"clangutils.h",
|
||||
]
|
||||
|
||||
@@ -519,15 +519,10 @@ void ClangCompletionAssistProcessor::sendFileContent(const QByteArray &customFil
|
||||
uint(m_interface->textDocument()->revision())}});
|
||||
}
|
||||
namespace {
|
||||
CppTools::CppEditorDocumentHandle *cppDocument(const QString &filePath)
|
||||
{
|
||||
return CppTools::CppModelManager::instance()->cppEditorDocument(filePath);
|
||||
}
|
||||
|
||||
bool shouldSendDocumentForCompletion(const QString &filePath,
|
||||
int completionPosition)
|
||||
{
|
||||
auto *document = cppDocument(filePath);
|
||||
CppTools::CppEditorDocumentHandle *document = ClangCodeModel::Utils::cppDocument(filePath);
|
||||
|
||||
if (document) {
|
||||
auto &sendTracker = document->sendTracker();
|
||||
@@ -541,7 +536,7 @@ bool shouldSendDocumentForCompletion(const QString &filePath,
|
||||
bool shouldSendCodeCompletion(const QString &filePath,
|
||||
int completionPosition)
|
||||
{
|
||||
auto *document = cppDocument(filePath);
|
||||
CppTools::CppEditorDocumentHandle *document = ClangCodeModel::Utils::cppDocument(filePath);
|
||||
|
||||
if (document) {
|
||||
auto &sendTracker = document->sendTracker();
|
||||
@@ -553,7 +548,7 @@ bool shouldSendCodeCompletion(const QString &filePath,
|
||||
|
||||
void setLastDocumentRevision(const QString &filePath)
|
||||
{
|
||||
auto *document = cppDocument(filePath);
|
||||
CppTools::CppEditorDocumentHandle *document = ClangCodeModel::Utils::cppDocument(filePath);
|
||||
|
||||
if (document)
|
||||
document->sendTracker().setLastSentRevision(int(document->revision()));
|
||||
@@ -562,7 +557,7 @@ void setLastDocumentRevision(const QString &filePath)
|
||||
void setLastCompletionPosition(const QString &filePath,
|
||||
int completionPosition)
|
||||
{
|
||||
auto *document = cppDocument(filePath);
|
||||
CppTools::CppEditorDocumentHandle *document = ClangCodeModel::Utils::cppDocument(filePath);
|
||||
|
||||
if (document)
|
||||
document->sendTracker().setLastCompletionPosition(completionPosition);
|
||||
|
||||
@@ -346,7 +346,12 @@ void ClangDiagnosticManager::addClangTextMarks(
|
||||
const QVector<ClangBackEnd::DiagnosticContainer> &diagnostics)
|
||||
{
|
||||
for (const ClangBackEnd::DiagnosticContainer &diagnostic : diagnostics) {
|
||||
auto textMark = new ClangTextMark(filePath(), diagnostic);
|
||||
const auto onMarkRemoved = [this](const ClangTextMark *mark) {
|
||||
const auto it = std::remove(m_clangTextMarks.begin(), m_clangTextMarks.end(), mark);
|
||||
m_clangTextMarks.erase(it, m_clangTextMarks.end());
|
||||
delete mark;
|
||||
};
|
||||
auto textMark = new ClangTextMark(filePath(), diagnostic, onMarkRemoved);
|
||||
m_clangTextMarks.push_back(textMark);
|
||||
m_textDocument->addMark(textMark);
|
||||
}
|
||||
|
||||
@@ -44,6 +44,7 @@
|
||||
#include <cpptools/cpptoolsbridge.h>
|
||||
#include <cpptools/cpptoolsreuse.h>
|
||||
#include <cpptools/cppworkingcopy.h>
|
||||
#include <cpptools/editordocumenthandle.h>
|
||||
|
||||
#include <texteditor/convenience.h>
|
||||
#include <texteditor/fontsettings.h>
|
||||
@@ -325,6 +326,10 @@ void ClangEditorDocumentProcessor::registerTranslationUnitForEditor(CppTools::Pr
|
||||
m_ipcCommunicator.unregisterTranslationUnitsForEditor({fileContainerWithArguments()});
|
||||
m_ipcCommunicator.registerTranslationUnitsForEditor({fileContainerWithArguments(projectPart)});
|
||||
}
|
||||
} else if (revision() != 1) {
|
||||
// E.g. a refactoring action opened the document and modified it immediately.
|
||||
m_ipcCommunicator.registerTranslationUnitsForEditor({{fileContainerWithArgumentsAndDocumentContent(projectPart)}});
|
||||
ClangCodeModel::Utils::setLastSentDocumentRevision(filePath(), revision());
|
||||
} else {
|
||||
m_ipcCommunicator.registerTranslationUnitsForEditor({{fileContainerWithArguments(projectPart)}});
|
||||
}
|
||||
@@ -438,6 +443,20 @@ ClangEditorDocumentProcessor::fileContainerWithArguments(CppTools::ProjectPart *
|
||||
return {filePath(), projectPartId, Utf8StringVector(theFileArguments), revision()};
|
||||
}
|
||||
|
||||
ClangBackEnd::FileContainer
|
||||
ClangEditorDocumentProcessor::fileContainerWithArgumentsAndDocumentContent(
|
||||
CppTools::ProjectPart *projectPart) const
|
||||
{
|
||||
const QStringList theFileArguments = fileArguments(filePath(), projectPart);
|
||||
|
||||
return ClangBackEnd::FileContainer(filePath(),
|
||||
projectPart->id(),
|
||||
Utf8StringVector(theFileArguments),
|
||||
textDocument()->toPlainText(),
|
||||
true,
|
||||
revision());
|
||||
}
|
||||
|
||||
ClangBackEnd::FileContainer
|
||||
ClangEditorDocumentProcessor::fileContainerWithDocumentContent(const QString &projectpartId) const
|
||||
{
|
||||
|
||||
@@ -100,6 +100,8 @@ private:
|
||||
HeaderErrorDiagnosticWidgetCreator creatorForHeaderErrorDiagnosticWidget(
|
||||
const ClangBackEnd::DiagnosticContainer &firstHeaderErrorDiagnostic);
|
||||
ClangBackEnd::FileContainer fileContainerWithArguments(CppTools::ProjectPart *projectPart) const;
|
||||
ClangBackEnd::FileContainer fileContainerWithArgumentsAndDocumentContent(
|
||||
CppTools::ProjectPart *projectPart) const;
|
||||
ClangBackEnd::FileContainer fileContainerWithDocumentContent(const QString &projectpartId) const;
|
||||
|
||||
private:
|
||||
|
||||
@@ -50,7 +50,7 @@
|
||||
using namespace ClangCodeModel;
|
||||
using namespace ClangCodeModel::Internal;
|
||||
|
||||
static ModelManagerSupportClang *m_instance_forTestsOnly = 0;
|
||||
static ModelManagerSupportClang *m_instance = 0;
|
||||
|
||||
static CppTools::CppModelManager *cppModelManager()
|
||||
{
|
||||
@@ -60,8 +60,8 @@ static CppTools::CppModelManager *cppModelManager()
|
||||
ModelManagerSupportClang::ModelManagerSupportClang()
|
||||
: m_completionAssistProvider(m_ipcCommunicator)
|
||||
{
|
||||
QTC_CHECK(!m_instance_forTestsOnly);
|
||||
m_instance_forTestsOnly = this;
|
||||
QTC_CHECK(!m_instance);
|
||||
m_instance = this;
|
||||
|
||||
Core::EditorManager *editorManager = Core::EditorManager::instance();
|
||||
connect(editorManager, &Core::EditorManager::editorOpened,
|
||||
@@ -88,7 +88,7 @@ ModelManagerSupportClang::ModelManagerSupportClang()
|
||||
|
||||
ModelManagerSupportClang::~ModelManagerSupportClang()
|
||||
{
|
||||
m_instance_forTestsOnly = 0;
|
||||
m_instance = 0;
|
||||
}
|
||||
|
||||
CppTools::CppCompletionAssistProvider *ModelManagerSupportClang::completionAssistProvider()
|
||||
@@ -244,15 +244,19 @@ void ModelManagerSupportClang::onAbstractEditorSupportContentsUpdated(const QStr
|
||||
const QByteArray &content)
|
||||
{
|
||||
QTC_ASSERT(!filePath.isEmpty(), return);
|
||||
m_ipcCommunicator.updateUnsavedFile(filePath, content, 0);
|
||||
|
||||
const QString mappedPath = m_uiHeaderOnDiskManager.createIfNeeded(filePath);
|
||||
m_ipcCommunicator.updateUnsavedFile(mappedPath, content, 0);
|
||||
}
|
||||
|
||||
void ModelManagerSupportClang::onAbstractEditorSupportRemoved(const QString &filePath)
|
||||
{
|
||||
QTC_ASSERT(!filePath.isEmpty(), return);
|
||||
|
||||
if (!cppModelManager()->cppEditorDocument(filePath)) {
|
||||
const QString mappedPath = m_uiHeaderOnDiskManager.remove(filePath);
|
||||
const QString projectPartId = Utils::projectPartIdForFile(filePath);
|
||||
m_ipcCommunicator.unregisterUnsavedFilesForEditor({{filePath, projectPartId}});
|
||||
m_ipcCommunicator.unregisterUnsavedFilesForEditor({{mappedPath, projectPartId}});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -347,18 +351,26 @@ void ModelManagerSupportClang::unregisterTranslationUnitsWithProjectParts(
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef QT_TESTLIB_LIB
|
||||
ModelManagerSupportClang *ModelManagerSupportClang::instance_forTestsOnly()
|
||||
ModelManagerSupportClang *ModelManagerSupportClang::instance()
|
||||
{
|
||||
return m_instance_forTestsOnly;
|
||||
return m_instance;
|
||||
}
|
||||
#endif
|
||||
|
||||
IpcCommunicator &ModelManagerSupportClang::ipcCommunicator()
|
||||
{
|
||||
return m_ipcCommunicator;
|
||||
}
|
||||
|
||||
QString ModelManagerSupportClang::dummyUiHeaderOnDiskPath(const QString &filePath) const
|
||||
{
|
||||
return m_uiHeaderOnDiskManager.mapPath(filePath);
|
||||
}
|
||||
|
||||
QString ModelManagerSupportClang::dummyUiHeaderOnDiskDirPath() const
|
||||
{
|
||||
return m_uiHeaderOnDiskManager.directoryPath();
|
||||
}
|
||||
|
||||
QString ModelManagerSupportProviderClang::id() const
|
||||
{
|
||||
return QLatin1String(Constants::CLANG_MODELMANAGERSUPPORT_ID);
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "clangcompletionassistprovider.h"
|
||||
#include "clanguiheaderondiskmanager.h"
|
||||
|
||||
#include <cpptools/cppmodelmanagersupport.h>
|
||||
|
||||
@@ -58,10 +59,10 @@ public:
|
||||
TextEditor::TextDocument *baseTextDocument) override;
|
||||
|
||||
IpcCommunicator &ipcCommunicator();
|
||||
QString dummyUiHeaderOnDiskDirPath() const;
|
||||
QString dummyUiHeaderOnDiskPath(const QString &filePath) const;
|
||||
|
||||
#ifdef QT_TESTLIB_LIB
|
||||
static ModelManagerSupportClang *instance_forTestsOnly();
|
||||
#endif
|
||||
static ModelManagerSupportClang *instance();
|
||||
|
||||
private:
|
||||
void onEditorOpened(Core::IEditor *editor);
|
||||
@@ -96,6 +97,7 @@ private:
|
||||
void connectToWidgetsMarkContextMenuRequested(QWidget *editorWidget);
|
||||
|
||||
private:
|
||||
UiHeaderOnDiskManager m_uiHeaderOnDiskManager;
|
||||
IpcCommunicator m_ipcCommunicator;
|
||||
ClangCompletionAssistProvider m_completionAssistProvider;
|
||||
};
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include "clangdiagnostictooltipwidget.h"
|
||||
|
||||
#include <utils/icon.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/theme/theme.h>
|
||||
|
||||
#include <QLayout>
|
||||
@@ -60,9 +61,14 @@ Core::Id cartegoryForSeverity(ClangBackEnd::DiagnosticSeverity severity)
|
||||
} // anonymous namespace
|
||||
|
||||
|
||||
ClangTextMark::ClangTextMark(const QString &fileName, const ClangBackEnd::DiagnosticContainer &diagnostic)
|
||||
: TextEditor::TextMark(fileName, int(diagnostic.location().line()), cartegoryForSeverity(diagnostic.severity())),
|
||||
m_diagnostic(diagnostic)
|
||||
ClangTextMark::ClangTextMark(const QString &fileName,
|
||||
const ClangBackEnd::DiagnosticContainer &diagnostic,
|
||||
const RemovedFromEditorHandler &removedHandler)
|
||||
: TextEditor::TextMark(fileName,
|
||||
int(diagnostic.location().line()),
|
||||
cartegoryForSeverity(diagnostic.severity()))
|
||||
, m_diagnostic(diagnostic)
|
||||
, m_removedFromEditorHandler(removedHandler)
|
||||
{
|
||||
setPriority(TextEditor::TextMark::HighPriority);
|
||||
setIcon(diagnostic.severity());
|
||||
@@ -93,5 +99,11 @@ bool ClangTextMark::addToolTipContent(QLayout *target)
|
||||
return true;
|
||||
}
|
||||
|
||||
void ClangTextMark::removedFromEditor()
|
||||
{
|
||||
QTC_ASSERT(m_removedFromEditorHandler, return);
|
||||
m_removedFromEditorHandler(this);
|
||||
}
|
||||
|
||||
} // namespace ClangCodeModel
|
||||
|
||||
|
||||
@@ -30,18 +30,28 @@
|
||||
|
||||
#include <texteditor/textmark.h>
|
||||
|
||||
#include <functional>
|
||||
|
||||
namespace ClangCodeModel {
|
||||
|
||||
class ClangTextMark : public TextEditor::TextMark
|
||||
{
|
||||
public:
|
||||
ClangTextMark(const QString &fileName, const ClangBackEnd::DiagnosticContainer &diagnostic);
|
||||
using RemovedFromEditorHandler = std::function<void(ClangTextMark *)>;
|
||||
|
||||
ClangTextMark(const QString &fileName,
|
||||
const ClangBackEnd::DiagnosticContainer &diagnostic,
|
||||
const RemovedFromEditorHandler &removedHandler);
|
||||
|
||||
private:
|
||||
bool addToolTipContent(QLayout *target);
|
||||
void setIcon(ClangBackEnd::DiagnosticSeverity severity);
|
||||
|
||||
bool addToolTipContent(QLayout *target) override;
|
||||
void removedFromEditor() override;
|
||||
|
||||
private:
|
||||
ClangBackEnd::DiagnosticContainer m_diagnostic;
|
||||
RemovedFromEditorHandler m_removedFromEditorHandler;
|
||||
};
|
||||
|
||||
} // namespace ClangCodeModel
|
||||
|
||||
75
src/plugins/clangcodemodel/clanguiheaderondiskmanager.cpp
Normal file
75
src/plugins/clangcodemodel/clanguiheaderondiskmanager.cpp
Normal file
@@ -0,0 +1,75 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** 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 "clanguiheaderondiskmanager.h"
|
||||
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
namespace ClangCodeModel {
|
||||
namespace Internal {
|
||||
|
||||
UiHeaderOnDiskManager::UiHeaderOnDiskManager()
|
||||
: m_temporaryDir(QDir::tempPath() + QStringLiteral("/qtc-clang-uiheader-XXXXXX"))
|
||||
{
|
||||
QTC_CHECK(m_temporaryDir.isValid());
|
||||
}
|
||||
|
||||
QString UiHeaderOnDiskManager::createIfNeeded(const QString &filePath)
|
||||
{
|
||||
const QString mappedPath = mapPath(filePath);
|
||||
if (!QFileInfo::exists(mappedPath)) {
|
||||
const bool fileCreated = QFile(mappedPath).open(QFile::WriteOnly); // touch file
|
||||
QTC_CHECK(fileCreated);
|
||||
}
|
||||
|
||||
return mappedPath;
|
||||
}
|
||||
|
||||
QString UiHeaderOnDiskManager::remove(const QString &filePath)
|
||||
{
|
||||
const QString mappedPath = mapPath(filePath);
|
||||
if (QFileInfo::exists(mappedPath)) {
|
||||
const bool fileRemoved = QFile::remove(mappedPath);
|
||||
QTC_CHECK(fileRemoved);
|
||||
}
|
||||
|
||||
return mappedPath;
|
||||
}
|
||||
|
||||
QString UiHeaderOnDiskManager::directoryPath() const
|
||||
{
|
||||
return m_temporaryDir.path();
|
||||
}
|
||||
|
||||
QString UiHeaderOnDiskManager::mapPath(const QString &filePath) const
|
||||
{
|
||||
return directoryPath() + '/' + QFileInfo(filePath).fileName();
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace ClangCodeModel
|
||||
50
src/plugins/clangcodemodel/clanguiheaderondiskmanager.h
Normal file
50
src/plugins/clangcodemodel/clanguiheaderondiskmanager.h
Normal file
@@ -0,0 +1,50 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** 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.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QTemporaryDir>
|
||||
|
||||
namespace ClangCodeModel {
|
||||
namespace Internal {
|
||||
|
||||
// TODO: Remove once libclang supports unsaved files that do not exist.
|
||||
class UiHeaderOnDiskManager
|
||||
{
|
||||
public:
|
||||
UiHeaderOnDiskManager();
|
||||
|
||||
QString createIfNeeded(const QString &filePath);
|
||||
QString remove(const QString &filePath);
|
||||
|
||||
QString mapPath(const QString &filePath) const;
|
||||
QString directoryPath() const;
|
||||
|
||||
private:
|
||||
QTemporaryDir m_temporaryDir;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace ClangCodeModel
|
||||
@@ -26,12 +26,14 @@
|
||||
#include "clangutils.h"
|
||||
|
||||
#include "clangeditordocumentprocessor.h"
|
||||
#include "clangmodelmanagersupport.h"
|
||||
|
||||
#include <coreplugin/icore.h>
|
||||
#include <coreplugin/idocument.h>
|
||||
#include <cpptools/baseeditordocumentparser.h>
|
||||
#include <cpptools/compileroptionsbuilder.h>
|
||||
#include <cpptools/cppmodelmanager.h>
|
||||
#include <cpptools/editordocumenthandle.h>
|
||||
#include <cpptools/projectpart.h>
|
||||
#include <projectexplorer/projectexplorerconstants.h>
|
||||
#include <utils/qtcassert.h>
|
||||
@@ -103,6 +105,7 @@ public:
|
||||
optionsBuilder.addPredefinedMacrosAndHeaderPathsOptions();
|
||||
optionsBuilder.addWrappedQtHeadersIncludePath();
|
||||
optionsBuilder.addHeaderPathOptions();
|
||||
optionsBuilder.addDummyUiHeaderOnDiskIncludePath();
|
||||
optionsBuilder.addProjectConfigFileInclude();
|
||||
|
||||
optionsBuilder.addMsvcCompatibilityVersion();
|
||||
@@ -145,7 +148,7 @@ private:
|
||||
void addPredefinedMacrosAndHeaderPathsOptionsForNonMsvc()
|
||||
{
|
||||
static const QString resourceDir = getResourceDir();
|
||||
if (!resourceDir.isEmpty()) {
|
||||
if (QTC_GUARD(!resourceDir.isEmpty())) {
|
||||
add(QLatin1String("-nostdlibinc"));
|
||||
add(QLatin1String("-I") + QDir::toNativeSeparators(resourceDir));
|
||||
add(QLatin1String("-undef"));
|
||||
@@ -172,6 +175,13 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
void addDummyUiHeaderOnDiskIncludePath()
|
||||
{
|
||||
const QString path = ModelManagerSupportClang::instance()->dummyUiHeaderOnDiskDirPath();
|
||||
if (!path.isEmpty())
|
||||
add(includeDirOption() + QDir::toNativeSeparators(path));
|
||||
}
|
||||
|
||||
void addExtraOptions()
|
||||
{
|
||||
add(QLatin1String("-fmessage-length=0"));
|
||||
@@ -222,5 +232,16 @@ QString projectPartIdForFile(const QString &filePath)
|
||||
return QString();
|
||||
}
|
||||
|
||||
CppEditorDocumentHandle *cppDocument(const QString &filePath)
|
||||
{
|
||||
return CppTools::CppModelManager::instance()->cppEditorDocument(filePath);
|
||||
}
|
||||
|
||||
void setLastSentDocumentRevision(const QString &filePath, uint revision)
|
||||
{
|
||||
if (CppEditorDocumentHandle *document = cppDocument(filePath))
|
||||
document->sendTracker().setLastSentRevision(int(revision));
|
||||
}
|
||||
|
||||
} // namespace Utils
|
||||
} // namespace Clang
|
||||
|
||||
@@ -27,9 +27,16 @@
|
||||
|
||||
#include <cpptools/projectpart.h>
|
||||
|
||||
namespace CppTools {
|
||||
class CppEditorDocumentHandle;
|
||||
}
|
||||
|
||||
namespace ClangCodeModel {
|
||||
namespace Utils {
|
||||
|
||||
CppTools::CppEditorDocumentHandle *cppDocument(const QString &filePath);
|
||||
void setLastSentDocumentRevision(const QString &filePath, uint revision);
|
||||
|
||||
QStringList createClangOptions(const CppTools::ProjectPart::Ptr &pPart,
|
||||
CppTools::ProjectFile::Kind fileKind);
|
||||
QStringList createClangOptions(const CppTools::ProjectPart::Ptr &pPart,
|
||||
|
||||
@@ -250,13 +250,13 @@ class ChangeIpcSender
|
||||
public:
|
||||
ChangeIpcSender(IpcSenderInterface *ipcSender)
|
||||
{
|
||||
auto &ipc = ModelManagerSupportClang::instance_forTestsOnly()->ipcCommunicator();
|
||||
auto &ipc = ModelManagerSupportClang::instance()->ipcCommunicator();
|
||||
m_previousSender = ipc.setIpcSender(ipcSender);
|
||||
}
|
||||
|
||||
~ChangeIpcSender()
|
||||
{
|
||||
auto &ipc = ModelManagerSupportClang::instance_forTestsOnly()->ipcCommunicator();
|
||||
auto &ipc = ModelManagerSupportClang::instance()->ipcCommunicator();
|
||||
ipc.setIpcSender(m_previousSender);
|
||||
}
|
||||
|
||||
@@ -1210,7 +1210,7 @@ void ClangCodeCompletionTest::testUpdateBackendAfterRestart()
|
||||
spy.senderLog.clear();
|
||||
|
||||
// Kill backend process...
|
||||
auto &ipcCommunicator = ModelManagerSupportClang::instance_forTestsOnly()->ipcCommunicator();
|
||||
auto &ipcCommunicator = ModelManagerSupportClang::instance()->ipcCommunicator();
|
||||
ipcCommunicator.killBackendProcess();
|
||||
QSignalSpy waitForReinitializedBackend(&ipcCommunicator,
|
||||
SIGNAL(backendReinitialized()));
|
||||
|
||||
Reference in New Issue
Block a user