2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
2022-12-21 10:12:09 +01:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2014-08-19 15:59:29 +02:00
|
|
|
|
|
|
|
|
#include "clangeditordocumentprocessor.h"
|
|
|
|
|
|
2018-01-22 16:31:05 +01:00
|
|
|
#include "clangmodelmanagersupport.h"
|
2014-08-19 15:59:29 +02:00
|
|
|
|
2021-08-30 10:58:08 +02:00
|
|
|
#include <cppeditor/builtincursorinfo.h>
|
2022-09-08 15:27:55 +02:00
|
|
|
#include <cppeditor/builtineditordocumentparser.h>
|
2021-08-30 10:58:08 +02:00
|
|
|
#include <cppeditor/clangdiagnosticconfigsmodel.h>
|
|
|
|
|
#include <cppeditor/compileroptionsbuilder.h>
|
|
|
|
|
#include <cppeditor/cppcodemodelsettings.h>
|
|
|
|
|
#include <cppeditor/cppmodelmanager.h>
|
|
|
|
|
#include <cppeditor/cpptoolsreuse.h>
|
|
|
|
|
#include <cppeditor/cppworkingcopy.h>
|
|
|
|
|
#include <cppeditor/editordocumenthandle.h>
|
2014-08-19 15:59:29 +02:00
|
|
|
|
2015-09-10 14:18:09 +02:00
|
|
|
#include <texteditor/fontsettings.h>
|
2015-08-31 16:28:26 +02:00
|
|
|
#include <texteditor/texteditor.h>
|
2015-09-10 14:18:09 +02:00
|
|
|
#include <texteditor/texteditorconstants.h>
|
|
|
|
|
#include <texteditor/texteditorsettings.h>
|
2015-08-31 16:28:26 +02:00
|
|
|
|
2014-08-19 15:59:29 +02:00
|
|
|
#include <cplusplus/CppDocument.h>
|
|
|
|
|
|
2018-10-19 10:20:27 +02:00
|
|
|
#include <utils/algorithm.h>
|
2017-09-21 12:35:24 +02:00
|
|
|
#include <utils/textutils.h>
|
2014-08-19 15:59:29 +02:00
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
|
2015-08-31 16:28:26 +02:00
|
|
|
#include <QTextBlock>
|
2016-10-04 16:23:42 +02:00
|
|
|
#include <QWidget>
|
2015-08-31 16:28:26 +02:00
|
|
|
|
2014-08-19 15:59:29 +02:00
|
|
|
namespace ClangCodeModel {
|
2015-05-08 15:48:17 +02:00
|
|
|
namespace Internal {
|
2014-08-19 15:59:29 +02:00
|
|
|
|
2022-04-28 17:15:39 +02:00
|
|
|
ClangEditorDocumentProcessor::ClangEditorDocumentProcessor(TextEditor::TextDocument *document)
|
2022-04-28 17:42:53 +02:00
|
|
|
: BuiltinEditorDocumentProcessor(document), m_document(*document)
|
2014-08-19 15:59:29 +02:00
|
|
|
{
|
2022-04-28 17:42:53 +02:00
|
|
|
connect(parser().data(), &CppEditor::BaseEditorDocumentParser::projectPartInfoUpdated,
|
2017-01-17 15:27:31 +01:00
|
|
|
this, &BaseEditorDocumentProcessor::projectPartInfoUpdated);
|
2022-09-08 15:27:55 +02:00
|
|
|
connect(static_cast<CppEditor::BuiltinEditorDocumentParser *>(parser().data()),
|
|
|
|
|
&CppEditor::BuiltinEditorDocumentParser::finished,
|
|
|
|
|
this, [this] {
|
2022-11-21 16:48:50 +01:00
|
|
|
emit parserConfigChanged(filePath(), parserConfig());
|
2022-09-08 15:27:55 +02:00
|
|
|
});
|
2022-04-28 17:42:53 +02:00
|
|
|
setSemanticHighlightingChecker([this] {
|
2022-08-01 18:07:41 +02:00
|
|
|
return !ClangModelManagerSupport::clientForFile(m_document.filePath());
|
2022-04-28 12:10:53 +02:00
|
|
|
});
|
2014-08-19 15:59:29 +02:00
|
|
|
}
|
|
|
|
|
|
2015-06-19 14:43:41 +02:00
|
|
|
void ClangEditorDocumentProcessor::semanticRehighlight()
|
|
|
|
|
{
|
2020-07-15 16:11:26 +02:00
|
|
|
const auto matchesEditor = [this](const Core::IEditor *editor) {
|
|
|
|
|
return editor->document()->filePath() == m_document.filePath();
|
|
|
|
|
};
|
|
|
|
|
if (!Utils::contains(Core::EditorManager::visibleEditors(), matchesEditor))
|
|
|
|
|
return;
|
2022-08-01 18:07:41 +02:00
|
|
|
if (ClangModelManagerSupport::clientForFile(m_document.filePath()))
|
2021-06-09 09:47:26 +02:00
|
|
|
return;
|
2022-04-28 17:42:53 +02:00
|
|
|
BuiltinEditorDocumentProcessor::semanticRehighlight();
|
2014-08-19 15:59:29 +02:00
|
|
|
}
|
|
|
|
|
|
2015-09-28 15:15:25 +02:00
|
|
|
bool ClangEditorDocumentProcessor::hasProjectPart() const
|
|
|
|
|
{
|
2020-09-18 12:39:32 +02:00
|
|
|
return !m_projectPart.isNull();
|
2015-09-28 15:15:25 +02:00
|
|
|
}
|
|
|
|
|
|
2021-08-30 10:58:08 +02:00
|
|
|
CppEditor::ProjectPart::ConstPtr ClangEditorDocumentProcessor::projectPart() const
|
2015-07-14 19:01:32 +02:00
|
|
|
{
|
|
|
|
|
return m_projectPart;
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-18 12:19:46 +02:00
|
|
|
void ClangEditorDocumentProcessor::clearProjectPart()
|
|
|
|
|
{
|
|
|
|
|
m_projectPart.clear();
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-26 13:59:38 +02:00
|
|
|
::Utils::Id ClangEditorDocumentProcessor::diagnosticConfigId() const
|
2018-01-19 16:57:18 +01:00
|
|
|
{
|
|
|
|
|
return m_diagnosticConfigId;
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-18 15:05:46 +01:00
|
|
|
void ClangEditorDocumentProcessor::setParserConfig(
|
2021-08-30 10:58:08 +02:00
|
|
|
const CppEditor::BaseEditorDocumentParser::Configuration &config)
|
2017-01-18 15:05:46 +01:00
|
|
|
{
|
2022-04-28 17:42:53 +02:00
|
|
|
CppEditor::BuiltinEditorDocumentProcessor::setParserConfig(config);
|
2022-11-21 16:48:50 +01:00
|
|
|
emit parserConfigChanged(filePath(), config);
|
2022-02-08 11:49:37 +01:00
|
|
|
}
|
|
|
|
|
|
2022-04-28 17:42:53 +02:00
|
|
|
CppEditor::BaseEditorDocumentParser::Configuration ClangEditorDocumentProcessor::parserConfig()
|
2017-05-24 13:23:01 +02:00
|
|
|
{
|
2022-04-28 17:42:53 +02:00
|
|
|
return parser()->configuration();
|
2017-09-26 16:00:30 +02:00
|
|
|
}
|
|
|
|
|
|
2022-11-23 19:00:38 +01:00
|
|
|
ClangEditorDocumentProcessor *ClangEditorDocumentProcessor::get(const Utils::FilePath &filePath)
|
2015-07-14 19:01:32 +02:00
|
|
|
{
|
2021-09-02 12:15:59 +02:00
|
|
|
return qobject_cast<ClangEditorDocumentProcessor*>(
|
|
|
|
|
CppEditor::CppModelManager::cppEditorDocumentProcessor(filePath));
|
2015-07-14 19:01:32 +02:00
|
|
|
}
|
|
|
|
|
|
2015-05-08 15:48:17 +02:00
|
|
|
} // namespace Internal
|
2014-08-19 15:59:29 +02:00
|
|
|
} // namespace ClangCodeModel
|