forked from qt-creator/qt-creator
CppTools: Allow interpreting ambiguous headers as C headers
...instead of C++ headers. For the Clang Code Model this results in using "-x c-header" instead of "-x c++-header". This introduces a new option in Options > C++ > "Code Model" to configure this. Change-Id: I8a0ce8fa6155f5ef58743ebc7f1d0b500fbf6599 Reviewed-by: David Schulz <david.schulz@qt.io> Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
This commit is contained in:
@@ -43,6 +43,7 @@ void ClangEditorDocumentParser::updateImpl(const QFutureInterface<void> &,
|
|||||||
configuration(),
|
configuration(),
|
||||||
state_,
|
state_,
|
||||||
updateParams.activeProject,
|
updateParams.activeProject,
|
||||||
|
updateParams.languagePreference,
|
||||||
updateParams.hasActiveProjectChanged);
|
updateParams.hasActiveProjectChanged);
|
||||||
setState(state_);
|
setState(state_);
|
||||||
}
|
}
|
||||||
|
@@ -384,8 +384,17 @@ static CppTools::ProjectPart projectPartForLanguageOption(CppTools::ProjectPart
|
|||||||
static QStringList languageOptions(const QString &filePath, CppTools::ProjectPart *projectPart)
|
static QStringList languageOptions(const QString &filePath, CppTools::ProjectPart *projectPart)
|
||||||
{
|
{
|
||||||
const auto theProjectPart = projectPartForLanguageOption(projectPart);
|
const auto theProjectPart = projectPartForLanguageOption(projectPart);
|
||||||
|
|
||||||
|
// Determine file kind with respect to ambiguous headers.
|
||||||
|
CppTools::ProjectFile::Kind fileKind = CppTools::ProjectFile::classify(filePath);
|
||||||
|
if (fileKind == CppTools::ProjectFile::AmbiguousHeader) {
|
||||||
|
fileKind = theProjectPart.languageVersion <= CppTools::ProjectPart::LatestCVersion
|
||||||
|
? CppTools::ProjectFile::CHeader
|
||||||
|
: CppTools::ProjectFile::CXXHeader;
|
||||||
|
}
|
||||||
|
|
||||||
CppTools::CompilerOptionsBuilder builder(theProjectPart);
|
CppTools::CompilerOptionsBuilder builder(theProjectPart);
|
||||||
builder.addLanguageOption(CppTools::ProjectFile::classify(filePath));
|
builder.addLanguageOption(fileKind);
|
||||||
|
|
||||||
return builder.options();
|
return builder.options();
|
||||||
}
|
}
|
||||||
|
@@ -122,6 +122,7 @@ ProjectPart::Ptr BaseEditorDocumentParser::determineProjectPart(
|
|||||||
const Configuration &config,
|
const Configuration &config,
|
||||||
const State &state,
|
const State &state,
|
||||||
const ProjectExplorer::Project *activeProject,
|
const ProjectExplorer::Project *activeProject,
|
||||||
|
Language languagePreference,
|
||||||
bool hasActiveProjectChanged)
|
bool hasActiveProjectChanged)
|
||||||
{
|
{
|
||||||
Internal::ProjectPartChooser chooser;
|
Internal::ProjectPartChooser chooser;
|
||||||
@@ -141,6 +142,7 @@ ProjectPart::Ptr BaseEditorDocumentParser::determineProjectPart(
|
|||||||
config.manuallySetProjectPart,
|
config.manuallySetProjectPart,
|
||||||
config.stickToPreviousProjectPart,
|
config.stickToPreviousProjectPart,
|
||||||
activeProject,
|
activeProject,
|
||||||
|
languagePreference,
|
||||||
hasActiveProjectChanged);
|
hasActiveProjectChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "cpplanguage.h"
|
||||||
#include "cpptools_global.h"
|
#include "cpptools_global.h"
|
||||||
#include "cppworkingcopy.h"
|
#include "cppworkingcopy.h"
|
||||||
#include "projectpart.h"
|
#include "projectpart.h"
|
||||||
@@ -55,15 +56,18 @@ public:
|
|||||||
struct UpdateParams {
|
struct UpdateParams {
|
||||||
UpdateParams(const WorkingCopy &workingCopy,
|
UpdateParams(const WorkingCopy &workingCopy,
|
||||||
const ProjectExplorer::Project *activeProject,
|
const ProjectExplorer::Project *activeProject,
|
||||||
|
Language languagePreference,
|
||||||
bool hasActiveProjectChanged)
|
bool hasActiveProjectChanged)
|
||||||
: workingCopy(workingCopy)
|
: workingCopy(workingCopy)
|
||||||
, activeProject(activeProject)
|
, activeProject(activeProject)
|
||||||
|
, languagePreference(languagePreference)
|
||||||
, hasActiveProjectChanged(hasActiveProjectChanged)
|
, hasActiveProjectChanged(hasActiveProjectChanged)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
WorkingCopy workingCopy;
|
WorkingCopy workingCopy;
|
||||||
const ProjectExplorer::Project *activeProject = nullptr;
|
const ProjectExplorer::Project *activeProject = nullptr;
|
||||||
|
Language languagePreference = Language::Cxx;
|
||||||
bool hasActiveProjectChanged = false;
|
bool hasActiveProjectChanged = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -92,6 +96,7 @@ protected:
|
|||||||
const Configuration &config,
|
const Configuration &config,
|
||||||
const State &state,
|
const State &state,
|
||||||
const ProjectExplorer::Project *activeProject,
|
const ProjectExplorer::Project *activeProject,
|
||||||
|
Language languagePreference,
|
||||||
bool hasActiveProjectChanged);
|
bool hasActiveProjectChanged);
|
||||||
|
|
||||||
mutable QMutex m_stateAndConfigurationMutex;
|
mutable QMutex m_stateAndConfigurationMutex;
|
||||||
|
@@ -25,8 +25,11 @@
|
|||||||
|
|
||||||
#include "baseeditordocumentprocessor.h"
|
#include "baseeditordocumentprocessor.h"
|
||||||
|
|
||||||
|
#include "cppcodemodelsettings.h"
|
||||||
|
#include "cpplanguage.h"
|
||||||
#include "cppmodelmanager.h"
|
#include "cppmodelmanager.h"
|
||||||
#include "cpptoolsbridge.h"
|
#include "cpptoolsbridge.h"
|
||||||
|
#include "cpptoolsreuse.h"
|
||||||
#include "editordocumenthandle.h"
|
#include "editordocumenthandle.h"
|
||||||
|
|
||||||
#include <projectexplorer/session.h>
|
#include <projectexplorer/session.h>
|
||||||
@@ -55,8 +58,13 @@ BaseEditorDocumentProcessor::~BaseEditorDocumentProcessor()
|
|||||||
|
|
||||||
void BaseEditorDocumentProcessor::run(bool hasActiveProjectChanged)
|
void BaseEditorDocumentProcessor::run(bool hasActiveProjectChanged)
|
||||||
{
|
{
|
||||||
|
const Language languagePreference = codeModelSettings()->interpretAmbigiousHeadersAsCHeaders()
|
||||||
|
? Language::C
|
||||||
|
: Language::Cxx;
|
||||||
|
|
||||||
runImpl({CppModelManager::instance()->workingCopy(),
|
runImpl({CppModelManager::instance()->workingCopy(),
|
||||||
ProjectExplorer::SessionManager::startupProject(),
|
ProjectExplorer::SessionManager::startupProject(),
|
||||||
|
languagePreference,
|
||||||
hasActiveProjectChanged});
|
hasActiveProjectChanged});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -81,6 +81,7 @@ void BuiltinEditorDocumentParser::updateImpl(const QFutureInterface<void> &futur
|
|||||||
baseConfig,
|
baseConfig,
|
||||||
baseState,
|
baseState,
|
||||||
updateParams.activeProject,
|
updateParams.activeProject,
|
||||||
|
updateParams.languagePreference,
|
||||||
updateParams.hasActiveProjectChanged);
|
updateParams.hasActiveProjectChanged);
|
||||||
|
|
||||||
if (state.forceSnapshotInvalidation) {
|
if (state.forceSnapshotInvalidation) {
|
||||||
|
@@ -158,7 +158,8 @@ void indexFindErrors(QFutureInterface<void> &future, const ParseParams params)
|
|||||||
// Parse the file as precisely as possible
|
// Parse the file as precisely as possible
|
||||||
BuiltinEditorDocumentParser parser(file);
|
BuiltinEditorDocumentParser parser(file);
|
||||||
parser.setReleaseSourceAndAST(false);
|
parser.setReleaseSourceAndAST(false);
|
||||||
parser.update({CppModelManager::instance()->workingCopy(), nullptr, false});
|
parser.update({CppModelManager::instance()->workingCopy(), nullptr,
|
||||||
|
Language::Cxx, false});
|
||||||
CPlusPlus::Document::Ptr document = parser.document();
|
CPlusPlus::Document::Ptr document = parser.document();
|
||||||
QTC_ASSERT(document, return);
|
QTC_ASSERT(document, return);
|
||||||
|
|
||||||
|
@@ -58,6 +58,9 @@ static QString clangDiagnosticConfigsArrayOptionsKey()
|
|||||||
static QString pchUsageKey()
|
static QString pchUsageKey()
|
||||||
{ return QLatin1String(Constants::CPPTOOLS_MODEL_MANAGER_PCH_USAGE); }
|
{ return QLatin1String(Constants::CPPTOOLS_MODEL_MANAGER_PCH_USAGE); }
|
||||||
|
|
||||||
|
static QString interpretAmbiguousHeadersAsCHeadersKey()
|
||||||
|
{ return QLatin1String(Constants::CPPTOOLS_INTERPRET_AMBIGIUOUS_HEADERS_AS_C_HEADERS); }
|
||||||
|
|
||||||
static QString skipIndexingBigFilesKey()
|
static QString skipIndexingBigFilesKey()
|
||||||
{ return QLatin1String(Constants::CPPTOOLS_SKIP_INDEXING_BIG_FILES); }
|
{ return QLatin1String(Constants::CPPTOOLS_SKIP_INDEXING_BIG_FILES); }
|
||||||
|
|
||||||
@@ -88,6 +91,10 @@ void CppCodeModelSettings::fromSettings(QSettings *s)
|
|||||||
const QVariant pchUsageVariant = s->value(pchUsageKey(), initialPchUsage());
|
const QVariant pchUsageVariant = s->value(pchUsageKey(), initialPchUsage());
|
||||||
setPCHUsage(static_cast<PCHUsage>(pchUsageVariant.toInt()));
|
setPCHUsage(static_cast<PCHUsage>(pchUsageVariant.toInt()));
|
||||||
|
|
||||||
|
const QVariant interpretAmbiguousHeadersAsCHeaders
|
||||||
|
= s->value(interpretAmbiguousHeadersAsCHeadersKey(), false);
|
||||||
|
setInterpretAmbigiousHeadersAsCHeaders(interpretAmbiguousHeadersAsCHeaders.toBool());
|
||||||
|
|
||||||
const QVariant skipIndexingBigFiles = s->value(skipIndexingBigFilesKey(), true);
|
const QVariant skipIndexingBigFiles = s->value(skipIndexingBigFilesKey(), true);
|
||||||
setSkipIndexingBigFiles(skipIndexingBigFiles.toBool());
|
setSkipIndexingBigFiles(skipIndexingBigFiles.toBool());
|
||||||
|
|
||||||
@@ -116,6 +123,8 @@ void CppCodeModelSettings::toSettings(QSettings *s)
|
|||||||
|
|
||||||
s->setValue(clangDiagnosticConfigKey(), clangDiagnosticConfigId().toSetting());
|
s->setValue(clangDiagnosticConfigKey(), clangDiagnosticConfigId().toSetting());
|
||||||
s->setValue(pchUsageKey(), pchUsage());
|
s->setValue(pchUsageKey(), pchUsage());
|
||||||
|
|
||||||
|
s->setValue(interpretAmbiguousHeadersAsCHeadersKey(), interpretAmbigiousHeadersAsCHeaders());
|
||||||
s->setValue(skipIndexingBigFilesKey(), skipIndexingBigFiles());
|
s->setValue(skipIndexingBigFilesKey(), skipIndexingBigFiles());
|
||||||
s->setValue(indexerFileSizeLimitKey(), indexerFileSizeLimitInMb());
|
s->setValue(indexerFileSizeLimitKey(), indexerFileSizeLimitInMb());
|
||||||
|
|
||||||
@@ -166,6 +175,16 @@ void CppCodeModelSettings::emitChanged()
|
|||||||
emit changed();
|
emit changed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CppCodeModelSettings::interpretAmbigiousHeadersAsCHeaders() const
|
||||||
|
{
|
||||||
|
return m_interpretAmbigiousHeadersAsCHeaders;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CppCodeModelSettings::setInterpretAmbigiousHeadersAsCHeaders(bool yesno)
|
||||||
|
{
|
||||||
|
m_interpretAmbigiousHeadersAsCHeaders = yesno;
|
||||||
|
}
|
||||||
|
|
||||||
bool CppCodeModelSettings::skipIndexingBigFiles() const
|
bool CppCodeModelSettings::skipIndexingBigFiles() const
|
||||||
{
|
{
|
||||||
return m_skipIndexingBigFiles;
|
return m_skipIndexingBigFiles;
|
||||||
|
@@ -63,6 +63,9 @@ public:
|
|||||||
PCHUsage pchUsage() const;
|
PCHUsage pchUsage() const;
|
||||||
void setPCHUsage(PCHUsage pchUsage);
|
void setPCHUsage(PCHUsage pchUsage);
|
||||||
|
|
||||||
|
bool interpretAmbigiousHeadersAsCHeaders() const;
|
||||||
|
void setInterpretAmbigiousHeadersAsCHeaders(bool yesno);
|
||||||
|
|
||||||
bool skipIndexingBigFiles() const;
|
bool skipIndexingBigFiles() const;
|
||||||
void setSkipIndexingBigFiles(bool yesno);
|
void setSkipIndexingBigFiles(bool yesno);
|
||||||
|
|
||||||
@@ -78,6 +81,7 @@ signals:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
PCHUsage m_pchUsage = PchUse_None;
|
PCHUsage m_pchUsage = PchUse_None;
|
||||||
|
bool m_interpretAmbigiousHeadersAsCHeaders = false;
|
||||||
bool m_skipIndexingBigFiles = true;
|
bool m_skipIndexingBigFiles = true;
|
||||||
int m_indexerFileSizeLimitInMB = 5;
|
int m_indexerFileSizeLimitInMB = 5;
|
||||||
ClangDiagnosticConfigs m_clangCustomDiagnosticConfigs;
|
ClangDiagnosticConfigs m_clangCustomDiagnosticConfigs;
|
||||||
|
@@ -56,18 +56,16 @@ void CppCodeModelSettingsWidget::setSettings(const QSharedPointer<CppCodeModelSe
|
|||||||
{
|
{
|
||||||
m_settings = s;
|
m_settings = s;
|
||||||
|
|
||||||
|
setupGeneralWidgets();
|
||||||
setupClangCodeModelWidgets();
|
setupClangCodeModelWidgets();
|
||||||
setupPchCheckBox();
|
|
||||||
setupSkipIndexingFilesWidgets();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CppCodeModelSettingsWidget::applyToSettings() const
|
void CppCodeModelSettingsWidget::applyToSettings() const
|
||||||
{
|
{
|
||||||
bool changed = false;
|
bool changed = false;
|
||||||
|
|
||||||
|
changed |= applyGeneralWidgetsToSettings();
|
||||||
changed |= applyClangCodeModelWidgetsToSettings();
|
changed |= applyClangCodeModelWidgetsToSettings();
|
||||||
changed |= applyPchCheckBoxToSettings();
|
|
||||||
changed |= applySkipIndexingFilesWidgets();
|
|
||||||
|
|
||||||
if (changed)
|
if (changed)
|
||||||
m_settings->toSettings(Core::ICore::settings());
|
m_settings->toSettings(Core::ICore::settings());
|
||||||
@@ -88,16 +86,16 @@ void CppCodeModelSettingsWidget::setupClangCodeModelWidgets()
|
|||||||
m_ui->clangSettingsGroupBox->layout()->addWidget(m_clangDiagnosticConfigsWidget);
|
m_ui->clangSettingsGroupBox->layout()->addWidget(m_clangDiagnosticConfigsWidget);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CppCodeModelSettingsWidget::setupPchCheckBox() const
|
void CppCodeModelSettingsWidget::setupGeneralWidgets()
|
||||||
{
|
{
|
||||||
const bool ignorePch = m_settings->pchUsage() == CppCodeModelSettings::PchUse_None;
|
m_ui->interpretAmbiguousHeadersAsCHeaders->setChecked(
|
||||||
m_ui->ignorePCHCheckBox->setChecked(ignorePch);
|
m_settings->interpretAmbigiousHeadersAsCHeaders());
|
||||||
}
|
|
||||||
|
|
||||||
void CppCodeModelSettingsWidget::setupSkipIndexingFilesWidgets()
|
|
||||||
{
|
|
||||||
m_ui->skipIndexingBigFilesCheckBox->setChecked(m_settings->skipIndexingBigFiles());
|
m_ui->skipIndexingBigFilesCheckBox->setChecked(m_settings->skipIndexingBigFiles());
|
||||||
m_ui->bigFilesLimitSpinBox->setValue(m_settings->indexerFileSizeLimitInMb());
|
m_ui->bigFilesLimitSpinBox->setValue(m_settings->indexerFileSizeLimitInMb());
|
||||||
|
|
||||||
|
const bool ignorePch = m_settings->pchUsage() == CppCodeModelSettings::PchUse_None;
|
||||||
|
m_ui->ignorePCHCheckBox->setChecked(ignorePch);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CppCodeModelSettingsWidget::applyClangCodeModelWidgetsToSettings() const
|
bool CppCodeModelSettingsWidget::applyClangCodeModelWidgetsToSettings() const
|
||||||
@@ -122,39 +120,39 @@ bool CppCodeModelSettingsWidget::applyClangCodeModelWidgetsToSettings() const
|
|||||||
return settingsChanged;
|
return settingsChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CppCodeModelSettingsWidget::applyPchCheckBoxToSettings() const
|
bool CppCodeModelSettingsWidget::applyGeneralWidgetsToSettings() const
|
||||||
{
|
|
||||||
const bool newIgnorePch = m_ui->ignorePCHCheckBox->isChecked();
|
|
||||||
const bool previousIgnorePch = m_settings->pchUsage() == CppCodeModelSettings::PchUse_None;
|
|
||||||
|
|
||||||
if (newIgnorePch != previousIgnorePch) {
|
|
||||||
const CppCodeModelSettings::PCHUsage pchUsage = m_ui->ignorePCHCheckBox->isChecked()
|
|
||||||
? CppCodeModelSettings::PchUse_None
|
|
||||||
: CppCodeModelSettings::PchUse_BuildSystem;
|
|
||||||
m_settings->setPCHUsage(pchUsage);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CppCodeModelSettingsWidget::applySkipIndexingFilesWidgets() const
|
|
||||||
{
|
{
|
||||||
bool settingsChanged = false;
|
bool settingsChanged = false;
|
||||||
|
|
||||||
|
const bool newInterpretAmbiguousHeaderAsCHeaders
|
||||||
|
= m_ui->interpretAmbiguousHeadersAsCHeaders->isChecked();
|
||||||
|
if (m_settings->interpretAmbigiousHeadersAsCHeaders()
|
||||||
|
!= newInterpretAmbiguousHeaderAsCHeaders) {
|
||||||
|
m_settings->setInterpretAmbigiousHeadersAsCHeaders(newInterpretAmbiguousHeaderAsCHeaders);
|
||||||
|
settingsChanged = true;
|
||||||
|
}
|
||||||
|
|
||||||
const bool newSkipIndexingBigFiles = m_ui->skipIndexingBigFilesCheckBox->isChecked();
|
const bool newSkipIndexingBigFiles = m_ui->skipIndexingBigFilesCheckBox->isChecked();
|
||||||
if (m_settings->skipIndexingBigFiles() != newSkipIndexingBigFiles) {
|
if (m_settings->skipIndexingBigFiles() != newSkipIndexingBigFiles) {
|
||||||
m_settings->setSkipIndexingBigFiles(newSkipIndexingBigFiles);
|
m_settings->setSkipIndexingBigFiles(newSkipIndexingBigFiles);
|
||||||
settingsChanged = true;
|
settingsChanged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const int newFileSizeLimit = m_ui->bigFilesLimitSpinBox->value();
|
const int newFileSizeLimit = m_ui->bigFilesLimitSpinBox->value();
|
||||||
if (m_settings->indexerFileSizeLimitInMb() != newFileSizeLimit) {
|
if (m_settings->indexerFileSizeLimitInMb() != newFileSizeLimit) {
|
||||||
m_settings->setIndexerFileSizeLimitInMb(newFileSizeLimit);
|
m_settings->setIndexerFileSizeLimitInMb(newFileSizeLimit);
|
||||||
settingsChanged = true;
|
settingsChanged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const bool newIgnorePch = m_ui->ignorePCHCheckBox->isChecked();
|
||||||
|
const bool previousIgnorePch = m_settings->pchUsage() == CppCodeModelSettings::PchUse_None;
|
||||||
|
if (newIgnorePch != previousIgnorePch) {
|
||||||
|
const CppCodeModelSettings::PCHUsage pchUsage = m_ui->ignorePCHCheckBox->isChecked()
|
||||||
|
? CppCodeModelSettings::PchUse_None
|
||||||
|
: CppCodeModelSettings::PchUse_BuildSystem;
|
||||||
|
m_settings->setPCHUsage(pchUsage);
|
||||||
|
settingsChanged = true;
|
||||||
|
}
|
||||||
|
|
||||||
return settingsChanged;
|
return settingsChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -55,13 +55,11 @@ public:
|
|||||||
void applyToSettings() const;
|
void applyToSettings() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void setupGeneralWidgets();
|
||||||
void setupClangCodeModelWidgets();
|
void setupClangCodeModelWidgets();
|
||||||
void setupPchCheckBox() const;
|
|
||||||
void setupSkipIndexingFilesWidgets();
|
|
||||||
|
|
||||||
|
bool applyGeneralWidgetsToSettings() const;
|
||||||
bool applyClangCodeModelWidgetsToSettings() const;
|
bool applyClangCodeModelWidgetsToSettings() const;
|
||||||
bool applyPchCheckBoxToSettings() const;
|
|
||||||
bool applySkipIndexingFilesWidgets() const;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::CppCodeModelSettingsPage *m_ui;
|
Ui::CppCodeModelSettingsPage *m_ui;
|
||||||
|
@@ -14,37 +14,19 @@
|
|||||||
<string>Form</string>
|
<string>Form</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||||
<item>
|
|
||||||
<widget class="QLabel" name="clangCodeModelIsEnabledHint">
|
|
||||||
<property name="text">
|
|
||||||
<string><i>The Clang Code Model is enabled because the corresponding plugin is loaded.</i></string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QLabel" name="clangCodeModelIsDisabledHint">
|
|
||||||
<property name="text">
|
|
||||||
<string><i>The Clang Code Model is disabled because the corresponding plugin is not loaded.</i></string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QGroupBox" name="clangSettingsGroupBox">
|
|
||||||
<property name="title">
|
|
||||||
<string>Clang Code Model Warnings</string>
|
|
||||||
</property>
|
|
||||||
<property name="checkable">
|
|
||||||
<bool>false</bool>
|
|
||||||
</property>
|
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_3"/>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
<item>
|
||||||
<widget class="QGroupBox" name="anotherGroupBox">
|
<widget class="QGroupBox" name="anotherGroupBox">
|
||||||
<property name="title">
|
<property name="title">
|
||||||
<string>Files to Skip</string>
|
<string>General</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QCheckBox" name="interpretAmbiguousHeadersAsCHeaders">
|
||||||
|
<property name="text">
|
||||||
|
<string>Interpret ambiguous headers as C headers</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QCheckBox" name="ignorePCHCheckBox">
|
<widget class="QCheckBox" name="ignorePCHCheckBox">
|
||||||
<property name="toolTip">
|
<property name="toolTip">
|
||||||
@@ -101,6 +83,31 @@
|
|||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="clangCodeModelIsEnabledHint">
|
||||||
|
<property name="text">
|
||||||
|
<string><i>The Clang Code Model is enabled because the corresponding plugin is loaded.</i></string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="clangCodeModelIsDisabledHint">
|
||||||
|
<property name="text">
|
||||||
|
<string><i>The Clang Code Model is disabled because the corresponding plugin is not loaded.</i></string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QGroupBox" name="clangSettingsGroupBox">
|
||||||
|
<property name="title">
|
||||||
|
<string>Clang Code Model Warnings</string>
|
||||||
|
</property>
|
||||||
|
<property name="checkable">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout_3"/>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<spacer name="verticalSpacer">
|
<spacer name="verticalSpacer">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
|
@@ -2122,7 +2122,10 @@ void CppCompletionAssistInterface::getCppSpecifics() const
|
|||||||
m_gotCppSpecifics = true;
|
m_gotCppSpecifics = true;
|
||||||
|
|
||||||
if (m_parser) {
|
if (m_parser) {
|
||||||
m_parser->update({CppTools::CppModelManager::instance()->workingCopy(), nullptr, false});
|
m_parser->update({CppTools::CppModelManager::instance()->workingCopy(),
|
||||||
|
nullptr,
|
||||||
|
Language::Cxx,
|
||||||
|
false});
|
||||||
m_snapshot = m_parser->snapshot();
|
m_snapshot = m_parser->snapshot();
|
||||||
m_headerPaths = m_parser->headerPaths();
|
m_headerPaths = m_parser->headerPaths();
|
||||||
}
|
}
|
||||||
|
32
src/plugins/cpptools/cpplanguage.h
Normal file
32
src/plugins/cpptools/cpplanguage.h
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** 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
|
||||||
|
|
||||||
|
namespace CppTools {
|
||||||
|
|
||||||
|
enum class Language { C, Cxx };
|
||||||
|
|
||||||
|
} // namespace CppTools
|
@@ -877,7 +877,8 @@ void CppToolsPlugin::test_modelmanager_precompiled_headers()
|
|||||||
BaseEditorDocumentParser::Configuration config = parser->configuration();
|
BaseEditorDocumentParser::Configuration config = parser->configuration();
|
||||||
config.usePrecompiledHeaders = true;
|
config.usePrecompiledHeaders = true;
|
||||||
parser->setConfiguration(config);
|
parser->setConfiguration(config);
|
||||||
parser->update({CppModelManager::instance()->workingCopy(), nullptr, false});
|
parser->update({CppModelManager::instance()->workingCopy(), nullptr,
|
||||||
|
Language::Cxx, false});
|
||||||
|
|
||||||
// Check if defines from pch are considered
|
// Check if defines from pch are considered
|
||||||
Document::Ptr document = mm->document(fileName);
|
Document::Ptr document = mm->document(fileName);
|
||||||
@@ -955,7 +956,8 @@ void CppToolsPlugin::test_modelmanager_defines_per_editor()
|
|||||||
BaseEditorDocumentParser::Configuration config = parser->configuration();
|
BaseEditorDocumentParser::Configuration config = parser->configuration();
|
||||||
config.editorDefines = editorDefines.toUtf8();
|
config.editorDefines = editorDefines.toUtf8();
|
||||||
parser->setConfiguration(config);
|
parser->setConfiguration(config);
|
||||||
parser->update({CppModelManager::instance()->workingCopy(), nullptr, false});
|
parser->update({CppModelManager::instance()->workingCopy(), nullptr,
|
||||||
|
Language::Cxx, false});
|
||||||
|
|
||||||
Document::Ptr doc = mm->document(main1File);
|
Document::Ptr doc = mm->document(main1File);
|
||||||
QCOMPARE(nameOfFirstDeclaration(doc), firstDeclarationName);
|
QCOMPARE(nameOfFirstDeclaration(doc), firstDeclarationName);
|
||||||
|
@@ -31,25 +31,39 @@
|
|||||||
namespace CppTools {
|
namespace CppTools {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
static int priority(const ProjectPart &projectPart, const ProjectExplorer::Project *activeProject)
|
static bool isPreferredLanguage(const ProjectPart &projectPart, Language preference)
|
||||||
|
{
|
||||||
|
const bool isCProjectPart = projectPart.languageVersion <= ProjectPart::LatestCVersion;
|
||||||
|
return (preference == Language::C && isCProjectPart)
|
||||||
|
|| (preference == Language::Cxx && !isCProjectPart);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int priority(const ProjectPart &projectPart,
|
||||||
|
const ProjectExplorer::Project *activeProject,
|
||||||
|
Language languagePreference)
|
||||||
{
|
{
|
||||||
int thePriority = 0;
|
int thePriority = 0;
|
||||||
|
|
||||||
if (projectPart.project == activeProject)
|
if (projectPart.project == activeProject)
|
||||||
thePriority += 10;
|
thePriority += 100;
|
||||||
|
|
||||||
if (projectPart.selectedForBuilding)
|
if (projectPart.selectedForBuilding)
|
||||||
|
thePriority += 10;
|
||||||
|
|
||||||
|
if (isPreferredLanguage(projectPart, languagePreference))
|
||||||
thePriority += 1;
|
thePriority += 1;
|
||||||
|
|
||||||
return thePriority;
|
return thePriority;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ProjectPart::Ptr chooseFromMultiple(const QList<ProjectPart::Ptr> &projectParts,
|
static ProjectPart::Ptr chooseFromMultiple(const QList<ProjectPart::Ptr> &projectParts,
|
||||||
const ProjectExplorer::Project *activeProject)
|
const ProjectExplorer::Project *activeProject,
|
||||||
|
Language languagePreference)
|
||||||
{
|
{
|
||||||
QList<ProjectPart::Ptr> projectPartsPrioritized = projectParts;
|
QList<ProjectPart::Ptr> projectPartsPrioritized = projectParts;
|
||||||
const auto lessThan = [activeProject] (const ProjectPart::Ptr &p1, const ProjectPart::Ptr &p2) {
|
const auto lessThan = [&] (const ProjectPart::Ptr &p1, const ProjectPart::Ptr &p2) {
|
||||||
return priority(*p1, activeProject) > priority(*p2, activeProject);
|
return priority(*p1, activeProject, languagePreference)
|
||||||
|
> priority(*p2, activeProject, languagePreference);
|
||||||
};
|
};
|
||||||
std::stable_sort(projectPartsPrioritized.begin(), projectPartsPrioritized.end(), lessThan);
|
std::stable_sort(projectPartsPrioritized.begin(), projectPartsPrioritized.end(), lessThan);
|
||||||
|
|
||||||
@@ -61,6 +75,7 @@ ProjectPart::Ptr ProjectPartChooser::choose(const QString &filePath,
|
|||||||
const ProjectPart::Ptr &manuallySetProjectPart,
|
const ProjectPart::Ptr &manuallySetProjectPart,
|
||||||
bool stickToPreviousProjectPart,
|
bool stickToPreviousProjectPart,
|
||||||
const ProjectExplorer::Project *activeProject,
|
const ProjectExplorer::Project *activeProject,
|
||||||
|
Language languagePreference,
|
||||||
bool projectHasChanged) const
|
bool projectHasChanged) const
|
||||||
{
|
{
|
||||||
QTC_CHECK(m_projectPartsForFile);
|
QTC_CHECK(m_projectPartsForFile);
|
||||||
@@ -85,10 +100,10 @@ ProjectPart::Ptr ProjectPartChooser::choose(const QString &filePath,
|
|||||||
// Fall-back step 2: Use fall-back part from the model manager:
|
// Fall-back step 2: Use fall-back part from the model manager:
|
||||||
projectPart = m_fallbackProjectPart();
|
projectPart = m_fallbackProjectPart();
|
||||||
else
|
else
|
||||||
projectPart = chooseFromMultiple(projectParts, activeProject);
|
projectPart = chooseFromMultiple(projectParts, activeProject, languagePreference);
|
||||||
} else {
|
} else {
|
||||||
if (projectHasChanged || !projectParts.contains(projectPart))
|
if (projectHasChanged || !projectParts.contains(projectPart))
|
||||||
projectPart = chooseFromMultiple(projectParts, activeProject);
|
projectPart = chooseFromMultiple(projectParts, activeProject, languagePreference);
|
||||||
}
|
}
|
||||||
|
|
||||||
return projectPart;
|
return projectPart;
|
||||||
|
@@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "cpplanguage.h"
|
||||||
#include "projectpart.h"
|
#include "projectpart.h"
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
@@ -52,6 +53,7 @@ public:
|
|||||||
const ProjectPart::Ptr &manuallySetProjectPart,
|
const ProjectPart::Ptr &manuallySetProjectPart,
|
||||||
bool stickToPreviousProjectPart,
|
bool stickToPreviousProjectPart,
|
||||||
const ProjectExplorer::Project *activeProject,
|
const ProjectExplorer::Project *activeProject,
|
||||||
|
Language languagePreference,
|
||||||
bool projectHasChanged) const;
|
bool projectHasChanged) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@@ -34,6 +34,7 @@ HEADERS += \
|
|||||||
cppfunctionsfilter.h \
|
cppfunctionsfilter.h \
|
||||||
cppincludesfilter.h \
|
cppincludesfilter.h \
|
||||||
cppindexingsupport.h \
|
cppindexingsupport.h \
|
||||||
|
cpplanguage.h \
|
||||||
cpplocalsymbols.h \
|
cpplocalsymbols.h \
|
||||||
cpplocatordata.h \
|
cpplocatordata.h \
|
||||||
cpplocatorfilter.h \
|
cpplocatorfilter.h \
|
||||||
|
@@ -61,6 +61,7 @@ Project {
|
|||||||
"cppfunctionsfilter.cpp", "cppfunctionsfilter.h",
|
"cppfunctionsfilter.cpp", "cppfunctionsfilter.h",
|
||||||
"cppincludesfilter.cpp", "cppincludesfilter.h",
|
"cppincludesfilter.cpp", "cppincludesfilter.h",
|
||||||
"cppindexingsupport.cpp", "cppindexingsupport.h",
|
"cppindexingsupport.cpp", "cppindexingsupport.h",
|
||||||
|
"cpplanguage.h",
|
||||||
"cpplocalsymbols.cpp", "cpplocalsymbols.h",
|
"cpplocalsymbols.cpp", "cpplocalsymbols.h",
|
||||||
"cpplocatordata.cpp", "cpplocatordata.h",
|
"cpplocatordata.cpp", "cpplocatordata.h",
|
||||||
"cpplocatorfilter.cpp", "cpplocatorfilter.h",
|
"cpplocatorfilter.cpp", "cpplocatorfilter.h",
|
||||||
|
@@ -51,10 +51,13 @@ enum { lowerCaseFilesDefault = 1 };
|
|||||||
const char CPPTOOLS_SORT_EDITOR_DOCUMENT_OUTLINE[] = "SortedMethodOverview";
|
const char CPPTOOLS_SORT_EDITOR_DOCUMENT_OUTLINE[] = "SortedMethodOverview";
|
||||||
const char CPPTOOLS_SHOW_INFO_BAR_FOR_HEADER_ERRORS[] = "ShowInfoBarForHeaderErrors";
|
const char CPPTOOLS_SHOW_INFO_BAR_FOR_HEADER_ERRORS[] = "ShowInfoBarForHeaderErrors";
|
||||||
const char CPPTOOLS_MODEL_MANAGER_PCH_USAGE[] = "PCHUsage";
|
const char CPPTOOLS_MODEL_MANAGER_PCH_USAGE[] = "PCHUsage";
|
||||||
|
const char CPPTOOLS_INTERPRET_AMBIGIUOUS_HEADERS_AS_C_HEADERS[]
|
||||||
|
= "InterpretAmbiguousHeadersAsCHeaders";
|
||||||
const char CPPTOOLS_SKIP_INDEXING_BIG_FILES[] = "SkipIndexingBigFiles";
|
const char CPPTOOLS_SKIP_INDEXING_BIG_FILES[] = "SkipIndexingBigFiles";
|
||||||
const char CPPTOOLS_INDEXER_FILE_SIZE_LIMIT[] = "IndexerFileSizeLimit";
|
const char CPPTOOLS_INDEXER_FILE_SIZE_LIMIT[] = "IndexerFileSizeLimit";
|
||||||
|
|
||||||
const char CPP_CLANG_BUILTIN_CONFIG_ID_EVERYTHING_WITH_EXCEPTIONS[] = "Builtin.EverythingWithExceptions";
|
const char CPP_CLANG_BUILTIN_CONFIG_ID_EVERYTHING_WITH_EXCEPTIONS[]
|
||||||
|
= "Builtin.EverythingWithExceptions";
|
||||||
|
|
||||||
const char CPP_CODE_STYLE_SETTINGS_ID[] = "A.Cpp.Code Style";
|
const char CPP_CODE_STYLE_SETTINGS_ID[] = "A.Cpp.Code Style";
|
||||||
const char CPP_CODE_STYLE_SETTINGS_NAME[] = QT_TRANSLATE_NOOP("CppTools", "Code Style");
|
const char CPP_CODE_STYLE_SETTINGS_NAME[] = QT_TRANSLATE_NOOP("CppTools", "Code Style");
|
||||||
|
@@ -25,11 +25,13 @@
|
|||||||
|
|
||||||
#include "googletest.h"
|
#include "googletest.h"
|
||||||
|
|
||||||
|
#include <cpptools/cpplanguage.h>
|
||||||
#include <cpptools/cppprojectpartchooser.h>
|
#include <cpptools/cppprojectpartchooser.h>
|
||||||
#include <cpptools/projectpart.h>
|
#include <cpptools/projectpart.h>
|
||||||
|
|
||||||
using CppTools::Internal::ProjectPartChooser;
|
using CppTools::Internal::ProjectPartChooser;
|
||||||
using CppTools::ProjectPart;
|
using CppTools::ProjectPart;
|
||||||
|
using CppTools::Language;
|
||||||
|
|
||||||
using testing::Eq;
|
using testing::Eq;
|
||||||
|
|
||||||
@@ -42,6 +44,7 @@ protected:
|
|||||||
const ProjectPart::Ptr choose() const;
|
const ProjectPart::Ptr choose() const;
|
||||||
|
|
||||||
static QList<ProjectPart::Ptr> createProjectPartsWithDifferentProjects();
|
static QList<ProjectPart::Ptr> createProjectPartsWithDifferentProjects();
|
||||||
|
static QList<ProjectPart::Ptr> createCAndCxxProjectParts();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QString filePath;
|
QString filePath;
|
||||||
@@ -50,6 +53,7 @@ protected:
|
|||||||
bool stickToPreviousProjectPart = false;
|
bool stickToPreviousProjectPart = false;
|
||||||
const ProjectExplorer::Project *activeProject = nullptr;
|
const ProjectExplorer::Project *activeProject = nullptr;
|
||||||
bool projectHasChanged = false;
|
bool projectHasChanged = false;
|
||||||
|
Language languagePreference = Language::Cxx;
|
||||||
::ProjectPartChooser chooser;
|
::ProjectPartChooser chooser;
|
||||||
|
|
||||||
QList<ProjectPart::Ptr> projectPartsForFile;
|
QList<ProjectPart::Ptr> projectPartsForFile;
|
||||||
@@ -130,6 +134,28 @@ TEST_F(ProjectPartChooser, ForMultipleCheckIfActiveProjectChanged)
|
|||||||
ASSERT_THAT(chosen, Eq(secondProjectPart));
|
ASSERT_THAT(chosen, Eq(secondProjectPart));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(ProjectPartChooser, ForMultipleAndAmbigiousHeaderPreferCProjectPart)
|
||||||
|
{
|
||||||
|
languagePreference = Language::C;
|
||||||
|
projectPartsForFile = createCAndCxxProjectParts();
|
||||||
|
const ProjectPart::Ptr cProjectPart = projectPartsForFile.at(0);
|
||||||
|
|
||||||
|
const ProjectPart::Ptr chosen = choose();
|
||||||
|
|
||||||
|
ASSERT_THAT(chosen, Eq(cProjectPart));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(ProjectPartChooser, ForMultipleAndAmbigiousHeaderPreferCxxProjectPart)
|
||||||
|
{
|
||||||
|
languagePreference = Language::Cxx;
|
||||||
|
projectPartsForFile = createCAndCxxProjectParts();
|
||||||
|
const ProjectPart::Ptr cxxProjectPart = projectPartsForFile.at(1);
|
||||||
|
|
||||||
|
const ProjectPart::Ptr chosen = choose();
|
||||||
|
|
||||||
|
ASSERT_THAT(chosen, Eq(cxxProjectPart));
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(ProjectPartChooser, IfProjectIsGoneStickToPrevious) // Built-in Code Model
|
TEST_F(ProjectPartChooser, IfProjectIsGoneStickToPrevious) // Built-in Code Model
|
||||||
{
|
{
|
||||||
stickToPreviousProjectPart = true;
|
stickToPreviousProjectPart = true;
|
||||||
@@ -198,6 +224,7 @@ const ProjectPart::Ptr ProjectPartChooser::choose() const
|
|||||||
manuallySetProjectPart,
|
manuallySetProjectPart,
|
||||||
stickToPreviousProjectPart,
|
stickToPreviousProjectPart,
|
||||||
activeProject,
|
activeProject,
|
||||||
|
languagePreference,
|
||||||
projectHasChanged);
|
projectHasChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -215,4 +242,21 @@ QList<ProjectPart::Ptr> ProjectPartChooser::createProjectPartsWithDifferentProje
|
|||||||
return projectParts;
|
return projectParts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList<ProjectPart::Ptr> ProjectPartChooser::createCAndCxxProjectParts()
|
||||||
|
{
|
||||||
|
QList<ProjectPart::Ptr> projectParts;
|
||||||
|
|
||||||
|
// Create project part for C
|
||||||
|
const ProjectPart::Ptr cprojectpart{new ProjectPart};
|
||||||
|
cprojectpart->languageVersion = ProjectPart::C11;
|
||||||
|
projectParts.append(cprojectpart);
|
||||||
|
|
||||||
|
// Create project part for CXX
|
||||||
|
const ProjectPart::Ptr cxxprojectpart{new ProjectPart};
|
||||||
|
cxxprojectpart->languageVersion = ProjectPart::CXX98;
|
||||||
|
projectParts.append(cxxprojectpart);
|
||||||
|
|
||||||
|
return projectParts;
|
||||||
|
}
|
||||||
|
|
||||||
} // anonymous namespace
|
} // anonymous namespace
|
||||||
|
Reference in New Issue
Block a user