forked from qt-creator/qt-creator
Clang: Add fileContainer getter
File containers were generates in many places. To reduce the noise this getters are introduced. Change-Id: I059745c27ac2dd0515bc23b3438d6d264ba071d7 Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
This commit is contained in:
@@ -214,6 +214,11 @@ TextEditor::QuickFixOperations ClangEditorDocumentProcessor::extraRefactoringOpe
|
||||
return extractor.extract(assistInterface.fileName(), currentLine(assistInterface));
|
||||
}
|
||||
|
||||
ClangBackEnd::FileContainer ClangEditorDocumentProcessor::fileContainer() const
|
||||
{
|
||||
return fileContainer(m_projectPart.data());
|
||||
}
|
||||
|
||||
ClangEditorDocumentProcessor *ClangEditorDocumentProcessor::get(const QString &filePath)
|
||||
{
|
||||
return qobject_cast<ClangEditorDocumentProcessor *>(BaseEditorDocumentProcessor::get(filePath));
|
||||
@@ -230,8 +235,8 @@ void ClangEditorDocumentProcessor::updateProjectPartAndTranslationUnitForEditor(
|
||||
const CppTools::ProjectPart::Ptr projectPart = m_parser->projectPart();
|
||||
|
||||
if (isProjectPartLoadedOrIsFallback(projectPart)) {
|
||||
updateTranslationUnitForEditor(*projectPart.data());
|
||||
requestDiagnostics(*projectPart.data());
|
||||
updateTranslationUnitForEditor(projectPart.data());
|
||||
requestDiagnostics(projectPart.data());
|
||||
|
||||
m_projectPart = projectPart;
|
||||
}
|
||||
@@ -252,41 +257,27 @@ void ClangEditorDocumentProcessor::onParserFinished()
|
||||
updateProjectPartAndTranslationUnitForEditor();
|
||||
}
|
||||
|
||||
void ClangEditorDocumentProcessor::updateTranslationUnitForEditor(CppTools::ProjectPart &projectPart)
|
||||
void ClangEditorDocumentProcessor::updateTranslationUnitForEditor(CppTools::ProjectPart *projectPart)
|
||||
{
|
||||
QTC_ASSERT(m_modelManagerSupport, return);
|
||||
IpcCommunicator &ipcCommunicator = m_modelManagerSupport->ipcCommunicator();
|
||||
|
||||
if (m_projectPart) {
|
||||
if (projectPart.id() != m_projectPart->id()) {
|
||||
auto container1 = ClangBackEnd::FileContainer(filePath(),
|
||||
m_projectPart->id(),
|
||||
revision());
|
||||
ipcCommunicator.unregisterTranslationUnitsForEditor({container1});
|
||||
|
||||
auto container2 = ClangBackEnd::FileContainer(filePath(),
|
||||
projectPart.id(),
|
||||
revision());
|
||||
ipcCommunicator.registerTranslationUnitsForEditor({container2});
|
||||
if (projectPart->id() != m_projectPart->id()) {
|
||||
ipcCommunicator.unregisterTranslationUnitsForEditor({fileContainer()});
|
||||
ipcCommunicator.registerTranslationUnitsForEditor({fileContainer(projectPart)});
|
||||
}
|
||||
} else {
|
||||
auto container = ClangBackEnd::FileContainer(filePath(),
|
||||
projectPart.id(),
|
||||
revision());
|
||||
ipcCommunicator.registerTranslationUnitsForEditor({container});
|
||||
ipcCommunicator.registerTranslationUnitsForEditor({{fileContainer(projectPart)}});
|
||||
}
|
||||
}
|
||||
|
||||
void ClangEditorDocumentProcessor::requestDiagnostics(CppTools::ProjectPart &projectPart)
|
||||
void ClangEditorDocumentProcessor::requestDiagnostics(CppTools::ProjectPart *projectPart)
|
||||
{
|
||||
if (!m_projectPart || projectPart.id() != m_projectPart->id()) {
|
||||
if (!m_projectPart || projectPart->id() != m_projectPart->id()) {
|
||||
IpcCommunicator &ipcCommunicator = m_modelManagerSupport->ipcCommunicator();
|
||||
|
||||
ipcCommunicator.requestDiagnostics({filePath(),
|
||||
projectPart.id(),
|
||||
Utf8String(),
|
||||
false,
|
||||
revision()});
|
||||
ipcCommunicator.requestDiagnostics({fileContainer(projectPart)});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -303,5 +294,14 @@ void ClangEditorDocumentProcessor::requestDiagnostics()
|
||||
}
|
||||
}
|
||||
|
||||
ClangBackEnd::FileContainer
|
||||
ClangEditorDocumentProcessor::fileContainer(CppTools::ProjectPart *projectPart) const
|
||||
{
|
||||
if (projectPart)
|
||||
return {filePath(), projectPart->id(), revision()};
|
||||
|
||||
return {filePath(), Utf8String(), revision()};
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace ClangCodeModel
|
||||
|
@@ -43,6 +43,7 @@
|
||||
|
||||
namespace ClangBackEnd {
|
||||
class DiagnosticContainer;
|
||||
class FileContainer;
|
||||
}
|
||||
|
||||
namespace ClangCodeModel {
|
||||
@@ -78,6 +79,8 @@ public:
|
||||
TextEditor::QuickFixOperations
|
||||
extraRefactoringOperations(const TextEditor::AssistInterface &assistInterface) override;
|
||||
|
||||
ClangBackEnd::FileContainer fileContainer() const;
|
||||
|
||||
public:
|
||||
static ClangEditorDocumentProcessor *get(const QString &filePath);
|
||||
|
||||
@@ -86,9 +89,10 @@ private slots:
|
||||
|
||||
private:
|
||||
void updateProjectPartAndTranslationUnitForEditor();
|
||||
void updateTranslationUnitForEditor(CppTools::ProjectPart &projectPart);
|
||||
void requestDiagnostics(CppTools::ProjectPart &projectPart);
|
||||
void updateTranslationUnitForEditor(CppTools::ProjectPart *projectPart);
|
||||
void requestDiagnostics(CppTools::ProjectPart *projectPart);
|
||||
void requestDiagnostics();
|
||||
ClangBackEnd::FileContainer fileContainer(CppTools::ProjectPart *projectPart) const;
|
||||
|
||||
private:
|
||||
ClangDiagnosticManager m_diagnosticManager;
|
||||
|
@@ -294,23 +294,12 @@ clangProcessorsWithProjectParts(const QStringList &projectPartIds)
|
||||
return result;
|
||||
}
|
||||
|
||||
static QVector<ClangBackEnd::FileContainer>
|
||||
processorToFileContainer(ClangEditorDocumentProcessor *processor)
|
||||
{
|
||||
QTC_ASSERT(processor, return QVector<ClangBackEnd::FileContainer>());
|
||||
|
||||
const QString filePath = processor->baseTextDocument()->filePath().toString();
|
||||
const QString projectPartId = processor->projectPart()->id();
|
||||
|
||||
return {ClangBackEnd::FileContainer(filePath, projectPartId)};
|
||||
}
|
||||
|
||||
void ModelManagerSupportClang::unregisterTranslationUnitsWithProjectParts(
|
||||
const QStringList &projectPartIds)
|
||||
{
|
||||
const auto processors = clangProcessorsWithProjectParts(projectPartIds);
|
||||
foreach (ClangEditorDocumentProcessor *processor, processors) {
|
||||
m_ipcCommunicator.unregisterTranslationUnitsForEditor(processorToFileContainer(processor));
|
||||
m_ipcCommunicator.unregisterTranslationUnitsForEditor({processor->fileContainer()});
|
||||
processor->clearProjectPart();
|
||||
processor->run();
|
||||
}
|
||||
|
Reference in New Issue
Block a user