Commit f89d3dca authored by Nikolai Kosjar's avatar Nikolai Kosjar

Clang: Activate code model automatically if plugin is loaded

This removes also the need to close editor documents.

Change-Id: I96c68105bceb37841053f3dbd8a264e059a02cb8
Reviewed-by: default avatarMarco Bubke <marco.bubke@theqtcompany.com>
parent 6dcdba92
......@@ -140,10 +140,6 @@
\li Restart \QC to be able to use the plugin.
\li Select \uicontrol Tools > \uicontrol Options >
\uicontrol {C++} > \uicontrol {Code Model},
and select \uicontrol {Use Clang Code Model}.
\li To process pre-compiled headers before processing any project files,
deselect the \uicontrol {Ignore pre-compiled headers} check box.
......
......@@ -60,9 +60,7 @@ bool ClangCodeModelPlugin::initialize(const QStringList &arguments, QString *err
Q_UNUSED(arguments)
Q_UNUSED(errorMessage)
// Register ModelManagerSupportProvider
auto cppModelManager = CppTools::CppModelManager::instance();
cppModelManager->setClangModelManagerSupportProvider(&m_modelManagerSupportProvider);
CppTools::CppModelManager::instance()->activateClangCodeModel(&m_modelManagerSupportProvider);
initializeTextMarks();
......
......@@ -39,7 +39,6 @@
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/editormanager/ieditor.h>
#include <coreplugin/icore.h>
#include <cpptools/cppcodemodelsettings.h>
#include <cpptools/cpptoolsreuse.h>
#include <cpptools/cpptoolstestcase.h>
#include <cpptools/modelmanagertesthelper.h>
......@@ -858,52 +857,6 @@ namespace ClangCodeModel {
namespace Internal {
namespace Tests {
typedef QSharedPointer<CppTools::CppCodeModelSettings> CppCodeModelSettingsPtr;
class ActivateClangModelManagerSupport
{
public:
ActivateClangModelManagerSupport(CppCodeModelSettingsPtr codeModelSettings);
~ActivateClangModelManagerSupport();
private:
ActivateClangModelManagerSupport();
CppCodeModelSettingsPtr m_codeModelSettings;
bool m_clangCodeModelWasUsedPreviously;
};
ActivateClangModelManagerSupport::ActivateClangModelManagerSupport(
CppCodeModelSettingsPtr codeModelSettings)
: m_codeModelSettings(codeModelSettings)
{
QTC_CHECK(m_codeModelSettings);
m_clangCodeModelWasUsedPreviously = m_codeModelSettings->useClangCodeModel();
m_codeModelSettings->setUseClangCodeModel(true);
m_codeModelSettings->emitChanged();
}
ActivateClangModelManagerSupport::~ActivateClangModelManagerSupport()
{
m_codeModelSettings->setUseClangCodeModel(m_clangCodeModelWasUsedPreviously);
m_codeModelSettings->emitChanged();
}
ClangCodeCompletionTest::ClangCodeCompletionTest()
{
}
ClangCodeCompletionTest::~ClangCodeCompletionTest()
{
}
void ClangCodeCompletionTest::initTestCase()
{
m_activater.reset(new ActivateClangModelManagerSupport(CppTools::codeModelSettings()));
}
void ClangCodeCompletionTest::testCompleteDoxygenKeywords()
{
ProjectLessCompletionTest t("doxygenKeywordsCompletion.cpp");
......
......@@ -43,13 +43,7 @@ class ClangCodeCompletionTest : public QObject
{
Q_OBJECT
public:
ClangCodeCompletionTest();
~ClangCodeCompletionTest();
private slots:
void initTestCase();
void testCompleteDoxygenKeywords();
void testCompletePreprocessorKeywords();
void testCompleteIncludeDirective();
......@@ -69,9 +63,6 @@ private slots:
void testCompleteAfterChangingIncludedAndNotOpenHeaderExternally();
void testUpdateBackendAfterRestart();
private:
QScopedPointer<ActivateClangModelManagerSupport> m_activater;
};
} // namespace Tests
......
......@@ -38,13 +38,11 @@ using namespace CppTools;
static QLatin1String cppHeaderMimeType(Constants::CPP_HEADER_MIMETYPE);
static QLatin1String cHeaderMimeType(Constants::C_HEADER_MIMETYPE);
static QLatin1String clangExtraOptionsKey(Constants::CPPTOOLS_EXTRA_CLANG_OPTIONS);
static QLatin1String useClangCodeModelKey(Constants::CPPTOOLS_USE_CLANG_CODE_MODEL);
void CppCodeModelSettings::fromSettings(QSettings *s)
{
s->beginGroup(QLatin1String(Constants::CPPTOOLS_SETTINGSGROUP));
setUseClangCodeModel(s->value(useClangCodeModelKey, false).toBool());
setExtraClangOptions(s->value(clangExtraOptionsKey, defaultExtraClangOptions()).toStringList());
QVariant v = s->value(QLatin1String(Constants::CPPTOOLS_MODEL_MANAGER_PCH_USAGE), PchUse_None);
......@@ -58,7 +56,6 @@ void CppCodeModelSettings::toSettings(QSettings *s)
{
s->beginGroup(QLatin1String(Constants::CPPTOOLS_SETTINGSGROUP));
s->setValue(useClangCodeModelKey, useClangCodeModel());
s->setValue(clangExtraOptionsKey, extraClangOptions());
s->setValue(QLatin1String(Constants::CPPTOOLS_MODEL_MANAGER_PCH_USAGE), pchUsage());
......@@ -67,16 +64,6 @@ void CppCodeModelSettings::toSettings(QSettings *s)
emit changed();
}
bool CppCodeModelSettings::useClangCodeModel() const
{
return m_useClangCodeModel;
}
void CppCodeModelSettings::setUseClangCodeModel(bool useClangCodeModel)
{
m_useClangCodeModel = useClangCodeModel;
}
QStringList CppCodeModelSettings::defaultExtraClangOptions()
{
return {
......
......@@ -57,9 +57,6 @@ public:
void toSettings(QSettings *s);
public:
bool useClangCodeModel() const;
void setUseClangCodeModel(bool useClangCodeModel);
static QStringList defaultExtraClangOptions();
QStringList extraClangOptions() const;
void setExtraClangOptions(const QStringList &extraClangOptions);
......@@ -74,8 +71,6 @@ signals:
void changed();
private:
bool m_isClangCodeModelAvailable = false;
bool m_useClangCodeModel = false;
QStringList m_extraClangOptions;
PCHUsage m_pchUsage = PchUse_None;
};
......
......@@ -80,14 +80,10 @@ void CppCodeModelSettingsWidget::applyToSettings() const
void CppCodeModelSettingsWidget::setupClangCodeModelWidgets() const
{
bool isClangActive = false;
const bool isClangAvailable = CppModelManager::instance()->isClangCodeModelAvailable();
if (isClangAvailable)
isClangActive = m_settings->useClangCodeModel();
const bool isClangActive = CppModelManager::instance()->isClangCodeModelActive();
m_ui->activateClangCodeModelPluginHint->setVisible(!isClangAvailable);
m_ui->clangSettingsGroupBox->setEnabled(isClangAvailable);
m_ui->clangSettingsGroupBox->setChecked(isClangActive);
m_ui->activateClangCodeModelPluginHint->setVisible(!isClangActive);
m_ui->clangSettingsGroupBox->setEnabled(isClangActive);
const QString extraClangOptions = m_settings->extraClangOptions().join(QLatin1Char('\n'));
m_ui->clangOptionsToAppendTextEdit->document()->setPlainText(extraClangOptions);
......@@ -103,13 +99,6 @@ bool CppCodeModelSettingsWidget::applyClangCodeModelWidgetsToSettings() const
{
bool settingsChanged = false;
const bool previouslyClangWasActive = m_settings->useClangCodeModel();
const bool nowClangIsActive = m_ui->clangSettingsGroupBox->isChecked();
if (nowClangIsActive != previouslyClangWasActive) {
m_settings->setUseClangCodeModel(nowClangIsActive);
settingsChanged = true;
}
const QStringList previousOptions = m_settings->extraClangOptions();
const QString newOptionsAsString = m_ui->clangOptionsToAppendTextEdit->document()->toPlainText();
const QStringList newOptions = newOptionsAsString.split(QLatin1Char('\n'),
......
......@@ -24,10 +24,10 @@
<item>
<widget class="QGroupBox" name="clangSettingsGroupBox">
<property name="title">
<string>Use Clang Code Model</string>
<string>Clang Code Model</string>
</property>
<property name="checkable">
<bool>true</bool>
<bool>false</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
......
......@@ -34,7 +34,6 @@
#include "baseeditordocumentprocessor.h"
#include "builtinindexingsupport.h"
#include "cppcodemodelinspectordumper.h"
#include "cppcodemodelsettings.h"
#include "cppfindreferences.h"
#include "cppindexingsupport.h"
#include "cppmodelmanagersupportinternal.h"
......@@ -152,7 +151,6 @@ public:
QSet<AbstractEditorSupport *> m_extraEditorSupports;
// Model Manager Supports for e.g. completion and highlighting
ModelManagerSupportProvider *m_clangModelManagerSupportProvider;
ModelManagerSupport::Ptr m_builtinModelManagerSupport;
ModelManagerSupport::Ptr m_activeModelManagerSupport;
......@@ -298,9 +296,8 @@ CppModelManager *CppModelManager::instance()
return m_instance;
}
void CppModelManager::initializeModelManagerSupports()
void CppModelManager::initializeBuiltinModelManagerSupport()
{
d->m_clangModelManagerSupportProvider = nullptr;
d->m_builtinModelManagerSupport
= ModelManagerSupportProviderInternal().createModelManagerSupport();
d->m_activeModelManagerSupport = d->m_builtinModelManagerSupport;
......@@ -348,12 +345,7 @@ CppModelManager::CppModelManager(QObject *parent)
qRegisterMetaType<QList<Document::DiagnosticMessage>>(
"QList<CPlusPlus::Document::DiagnosticMessage>");
QSharedPointer<CppCodeModelSettings> codeModelSettings
= CppToolsPlugin::instance()->codeModelSettings();
connect(codeModelSettings.data(), &CppCodeModelSettings::changed,
this, &CppModelManager::onCodeModelSettingsChanged);
initializeModelManagerSupports();
initializeBuiltinModelManagerSupport();
d->m_internalIndexingSupport = new BuiltinIndexingSupport;
}
......@@ -673,14 +665,6 @@ void CppModelManager::removeProjectInfoFilesAndIncludesFromSnapshot(const Projec
}
}
void CppModelManager::closeCppEditorDocuments()
{
QList<Core::IDocument *> cppDocumentsToClose;
foreach (CppEditorDocumentHandle *cppDocument, cppEditorDocuments())
cppDocumentsToClose << cppDocument->processor()->baseTextDocument();
QTC_CHECK(Core::EditorManager::closeDocuments(cppDocumentsToClose));
}
QList<CppEditorDocumentHandle *> CppModelManager::cppEditorDocuments() const
{
QMutexLocker locker(&d->m_cppEditorDocumentsMutex);
......@@ -947,15 +931,9 @@ bool CppModelManager::isCppEditor(Core::IEditor *editor)
return editor->context().contains(ProjectExplorer::Constants::LANG_CXX);
}
bool CppModelManager::isClangCodeModelAvailable() const
{
return d->m_clangModelManagerSupportProvider != nullptr;
}
bool CppModelManager::isClangCodeModelActive() const
{
return isClangCodeModelAvailable()
&& d->m_activeModelManagerSupport != d->m_builtinModelManagerSupport;
return d->m_activeModelManagerSupport != d->m_builtinModelManagerSupport;
}
void CppModelManager::emitDocumentUpdated(Document::Ptr doc)
......@@ -1039,27 +1017,6 @@ void CppModelManager::onCurrentEditorChanged(Core::IEditor *editor)
}
}
void CppModelManager::onCodeModelSettingsChanged()
{
const bool isClangActive = isClangCodeModelActive();
const QSharedPointer<CppCodeModelSettings> settings
= CppToolsPlugin::instance()->codeModelSettings();
ModelManagerSupport::Ptr newCodeModelSupport;
if (isClangCodeModelAvailable()) {
if (!isClangActive && settings->useClangCodeModel())
newCodeModelSupport = d->m_clangModelManagerSupportProvider->createModelManagerSupport();
else if (isClangActive && !settings->useClangCodeModel())
newCodeModelSupport = d->m_builtinModelManagerSupport;
}
if (newCodeModelSupport) {
closeCppEditorDocuments();
d->m_activeModelManagerSupport = newCodeModelSupport;
}
}
void CppModelManager::onAboutToLoadSession()
{
if (d->m_delayedGcTimer.isActive())
......@@ -1169,15 +1126,12 @@ void CppModelManager::finishedRefreshingSourceFiles(const QSet<QString> &files)
emit sourceFilesRefreshed(files);
}
void CppModelManager::setClangModelManagerSupportProvider(
void CppModelManager::activateClangCodeModel(
ModelManagerSupportProvider *modelManagerSupportProvider)
{
QTC_ASSERT(modelManagerSupportProvider, return);
QTC_CHECK(d->m_clangModelManagerSupportProvider == nullptr);
d->m_clangModelManagerSupportProvider = modelManagerSupportProvider;
onCodeModelSettingsChanged();
d->m_activeModelManagerSupport = modelManagerSupportProvider->createModelManagerSupport();
}
CppCompletionAssistProvider *CppModelManager::completionAssistProvider() const
......
......@@ -122,7 +122,6 @@ public:
void emitAbstractEditorSupportRemoved(const QString &filePath);
static bool isCppEditor(Core::IEditor *editor);
bool isClangCodeModelAvailable() const;
bool isClangCodeModelActive() const;
QSet<AbstractEditorSupport*> abstractEditorSupports() const;
......@@ -145,7 +144,7 @@ public:
void finishedRefreshingSourceFiles(const QSet<QString> &files);
void setClangModelManagerSupportProvider(ModelManagerSupportProvider *modelManagerSupportProvider);
void activateClangCodeModel(ModelManagerSupportProvider *modelManagerSupportProvider);
CppCompletionAssistProvider *completionAssistProvider() const;
BaseEditorDocumentProcessor *editorDocumentProcessor(
TextEditor::TextDocument *baseTextDocument) const;
......@@ -203,11 +202,10 @@ private slots:
void onAboutToRemoveProject(ProjectExplorer::Project *project);
void onSourceFilesRefreshed() const;
void onCurrentEditorChanged(Core::IEditor *editor);
void onCodeModelSettingsChanged();
void onCoreAboutToClose();
private:
void initializeModelManagerSupports();
void initializeBuiltinModelManagerSupport();
void delayedGC();
void recalculateProjectPartMappings();
......@@ -215,8 +213,6 @@ private:
void removeFilesFromSnapshot(const QSet<QString> &removedFiles);
void removeProjectInfoFilesAndIncludesFromSnapshot(const ProjectInfo &projectInfo);
void closeCppEditorDocuments();
WorkingCopy buildWorkingCopyList();
void ensureUpdated();
......
......@@ -55,7 +55,6 @@ enum { lowerCaseFilesDefault = 1 };
const char CPPTOOLS_SORT_EDITOR_DOCUMENT_OUTLINE[] = "SortedMethodOverview";
const char CPPTOOLS_MODEL_MANAGER_PCH_USAGE[] = "PCHUsage";
const char CPPTOOLS_EXTRA_CLANG_OPTIONS[] = "ExtraClangOptions";
const char CPPTOOLS_USE_CLANG_CODE_MODEL[] = "UseClangCodeModel";
const char CPP_CODE_STYLE_SETTINGS_ID[] = "A.Cpp.Code Style";
const char CPP_CODE_STYLE_SETTINGS_NAME[] = QT_TRANSLATE_NOOP("CppTools", "Code Style");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment