summaryrefslogtreecommitdiff
path: root/src/plugins/cpptools
diff options
context:
space:
mode:
authorNikolai Kosjar <nikolai.kosjar@qt.io>2017-01-12 18:01:12 +0100
committerNikolai Kosjar <nikolai.kosjar@qt.io>2017-01-16 10:17:50 +0000
commite4e65726614fa4e3ee02f25db755d959850441ea (patch)
treea76a4aab899eb313f25f0da8a1f3e89ede71b67b /src/plugins/cpptools
parent4416eecc024e155438c7ed6399182dbff143bd0d (diff)
downloadqt-creator-e4e65726614fa4e3ee02f25db755d959850441ea.tar.gz
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>
Diffstat (limited to 'src/plugins/cpptools')
-rw-r--r--src/plugins/cpptools/baseeditordocumentparser.cpp2
-rw-r--r--src/plugins/cpptools/baseeditordocumentparser.h5
-rw-r--r--src/plugins/cpptools/baseeditordocumentprocessor.cpp8
-rw-r--r--src/plugins/cpptools/builtineditordocumentparser.cpp1
-rw-r--r--src/plugins/cpptools/builtinindexingsupport.cpp3
-rw-r--r--src/plugins/cpptools/cppcodemodelsettings.cpp19
-rw-r--r--src/plugins/cpptools/cppcodemodelsettings.h4
-rw-r--r--src/plugins/cpptools/cppcodemodelsettingspage.cpp54
-rw-r--r--src/plugins/cpptools/cppcodemodelsettingspage.h6
-rw-r--r--src/plugins/cpptools/cppcodemodelsettingspage.ui59
-rw-r--r--src/plugins/cpptools/cppcompletionassist.cpp5
-rw-r--r--src/plugins/cpptools/cpplanguage.h32
-rw-r--r--src/plugins/cpptools/cppmodelmanager_test.cpp6
-rw-r--r--src/plugins/cpptools/cppprojectpartchooser.cpp29
-rw-r--r--src/plugins/cpptools/cppprojectpartchooser.h2
-rw-r--r--src/plugins/cpptools/cpptools.pro1
-rw-r--r--src/plugins/cpptools/cpptools.qbs1
-rw-r--r--src/plugins/cpptools/cpptoolsconstants.h5
18 files changed, 172 insertions, 70 deletions
diff --git a/src/plugins/cpptools/baseeditordocumentparser.cpp b/src/plugins/cpptools/baseeditordocumentparser.cpp
index f346e05415..ca4d16e564 100644
--- a/src/plugins/cpptools/baseeditordocumentparser.cpp
+++ b/src/plugins/cpptools/baseeditordocumentparser.cpp
@@ -122,6 +122,7 @@ ProjectPart::Ptr BaseEditorDocumentParser::determineProjectPart(
const Configuration &config,
const State &state,
const ProjectExplorer::Project *activeProject,
+ Language languagePreference,
bool hasActiveProjectChanged)
{
Internal::ProjectPartChooser chooser;
@@ -141,6 +142,7 @@ ProjectPart::Ptr BaseEditorDocumentParser::determineProjectPart(
config.manuallySetProjectPart,
config.stickToPreviousProjectPart,
activeProject,
+ languagePreference,
hasActiveProjectChanged);
}
diff --git a/src/plugins/cpptools/baseeditordocumentparser.h b/src/plugins/cpptools/baseeditordocumentparser.h
index 11f76fa67d..92f919e96d 100644
--- a/src/plugins/cpptools/baseeditordocumentparser.h
+++ b/src/plugins/cpptools/baseeditordocumentparser.h
@@ -25,6 +25,7 @@
#pragma once
+#include "cpplanguage.h"
#include "cpptools_global.h"
#include "cppworkingcopy.h"
#include "projectpart.h"
@@ -55,15 +56,18 @@ public:
struct UpdateParams {
UpdateParams(const WorkingCopy &workingCopy,
const ProjectExplorer::Project *activeProject,
+ Language languagePreference,
bool hasActiveProjectChanged)
: workingCopy(workingCopy)
, activeProject(activeProject)
+ , languagePreference(languagePreference)
, hasActiveProjectChanged(hasActiveProjectChanged)
{
}
WorkingCopy workingCopy;
const ProjectExplorer::Project *activeProject = nullptr;
+ Language languagePreference = Language::Cxx;
bool hasActiveProjectChanged = false;
};
@@ -92,6 +96,7 @@ protected:
const Configuration &config,
const State &state,
const ProjectExplorer::Project *activeProject,
+ Language languagePreference,
bool hasActiveProjectChanged);
mutable QMutex m_stateAndConfigurationMutex;
diff --git a/src/plugins/cpptools/baseeditordocumentprocessor.cpp b/src/plugins/cpptools/baseeditordocumentprocessor.cpp
index bf68bc1c4e..b656c5798a 100644
--- a/src/plugins/cpptools/baseeditordocumentprocessor.cpp
+++ b/src/plugins/cpptools/baseeditordocumentprocessor.cpp
@@ -25,8 +25,11 @@
#include "baseeditordocumentprocessor.h"
+#include "cppcodemodelsettings.h"
+#include "cpplanguage.h"
#include "cppmodelmanager.h"
#include "cpptoolsbridge.h"
+#include "cpptoolsreuse.h"
#include "editordocumenthandle.h"
#include <projectexplorer/session.h>
@@ -55,8 +58,13 @@ BaseEditorDocumentProcessor::~BaseEditorDocumentProcessor()
void BaseEditorDocumentProcessor::run(bool hasActiveProjectChanged)
{
+ const Language languagePreference = codeModelSettings()->interpretAmbigiousHeadersAsCHeaders()
+ ? Language::C
+ : Language::Cxx;
+
runImpl({CppModelManager::instance()->workingCopy(),
ProjectExplorer::SessionManager::startupProject(),
+ languagePreference,
hasActiveProjectChanged});
}
diff --git a/src/plugins/cpptools/builtineditordocumentparser.cpp b/src/plugins/cpptools/builtineditordocumentparser.cpp
index 77700e2cdf..5243e2a76b 100644
--- a/src/plugins/cpptools/builtineditordocumentparser.cpp
+++ b/src/plugins/cpptools/builtineditordocumentparser.cpp
@@ -81,6 +81,7 @@ void BuiltinEditorDocumentParser::updateImpl(const QFutureInterface<void> &futur
baseConfig,
baseState,
updateParams.activeProject,
+ updateParams.languagePreference,
updateParams.hasActiveProjectChanged);
if (state.forceSnapshotInvalidation) {
diff --git a/src/plugins/cpptools/builtinindexingsupport.cpp b/src/plugins/cpptools/builtinindexingsupport.cpp
index c4360f5fd7..6d3eac843b 100644
--- a/src/plugins/cpptools/builtinindexingsupport.cpp
+++ b/src/plugins/cpptools/builtinindexingsupport.cpp
@@ -158,7 +158,8 @@ void indexFindErrors(QFutureInterface<void> &future, const ParseParams params)
// Parse the file as precisely as possible
BuiltinEditorDocumentParser parser(file);
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();
QTC_ASSERT(document, return);
diff --git a/src/plugins/cpptools/cppcodemodelsettings.cpp b/src/plugins/cpptools/cppcodemodelsettings.cpp
index 43d8e5f812..a129fa61da 100644
--- a/src/plugins/cpptools/cppcodemodelsettings.cpp
+++ b/src/plugins/cpptools/cppcodemodelsettings.cpp
@@ -58,6 +58,9 @@ static QString clangDiagnosticConfigsArrayOptionsKey()
static QString pchUsageKey()
{ return QLatin1String(Constants::CPPTOOLS_MODEL_MANAGER_PCH_USAGE); }
+static QString interpretAmbiguousHeadersAsCHeadersKey()
+{ return QLatin1String(Constants::CPPTOOLS_INTERPRET_AMBIGIUOUS_HEADERS_AS_C_HEADERS); }
+
static QString skipIndexingBigFilesKey()
{ return QLatin1String(Constants::CPPTOOLS_SKIP_INDEXING_BIG_FILES); }
@@ -88,6 +91,10 @@ void CppCodeModelSettings::fromSettings(QSettings *s)
const QVariant pchUsageVariant = s->value(pchUsageKey(), initialPchUsage());
setPCHUsage(static_cast<PCHUsage>(pchUsageVariant.toInt()));
+ const QVariant interpretAmbiguousHeadersAsCHeaders
+ = s->value(interpretAmbiguousHeadersAsCHeadersKey(), false);
+ setInterpretAmbigiousHeadersAsCHeaders(interpretAmbiguousHeadersAsCHeaders.toBool());
+
const QVariant skipIndexingBigFiles = s->value(skipIndexingBigFilesKey(), true);
setSkipIndexingBigFiles(skipIndexingBigFiles.toBool());
@@ -116,6 +123,8 @@ void CppCodeModelSettings::toSettings(QSettings *s)
s->setValue(clangDiagnosticConfigKey(), clangDiagnosticConfigId().toSetting());
s->setValue(pchUsageKey(), pchUsage());
+
+ s->setValue(interpretAmbiguousHeadersAsCHeadersKey(), interpretAmbigiousHeadersAsCHeaders());
s->setValue(skipIndexingBigFilesKey(), skipIndexingBigFiles());
s->setValue(indexerFileSizeLimitKey(), indexerFileSizeLimitInMb());
@@ -166,6 +175,16 @@ void CppCodeModelSettings::emitChanged()
emit changed();
}
+bool CppCodeModelSettings::interpretAmbigiousHeadersAsCHeaders() const
+{
+ return m_interpretAmbigiousHeadersAsCHeaders;
+}
+
+void CppCodeModelSettings::setInterpretAmbigiousHeadersAsCHeaders(bool yesno)
+{
+ m_interpretAmbigiousHeadersAsCHeaders = yesno;
+}
+
bool CppCodeModelSettings::skipIndexingBigFiles() const
{
return m_skipIndexingBigFiles;
diff --git a/src/plugins/cpptools/cppcodemodelsettings.h b/src/plugins/cpptools/cppcodemodelsettings.h
index c57ee8bbc4..4c6404e506 100644
--- a/src/plugins/cpptools/cppcodemodelsettings.h
+++ b/src/plugins/cpptools/cppcodemodelsettings.h
@@ -63,6 +63,9 @@ public:
PCHUsage pchUsage() const;
void setPCHUsage(PCHUsage pchUsage);
+ bool interpretAmbigiousHeadersAsCHeaders() const;
+ void setInterpretAmbigiousHeadersAsCHeaders(bool yesno);
+
bool skipIndexingBigFiles() const;
void setSkipIndexingBigFiles(bool yesno);
@@ -78,6 +81,7 @@ signals:
private:
PCHUsage m_pchUsage = PchUse_None;
+ bool m_interpretAmbigiousHeadersAsCHeaders = false;
bool m_skipIndexingBigFiles = true;
int m_indexerFileSizeLimitInMB = 5;
ClangDiagnosticConfigs m_clangCustomDiagnosticConfigs;
diff --git a/src/plugins/cpptools/cppcodemodelsettingspage.cpp b/src/plugins/cpptools/cppcodemodelsettingspage.cpp
index e1792ed0b7..e6af115aed 100644
--- a/src/plugins/cpptools/cppcodemodelsettingspage.cpp
+++ b/src/plugins/cpptools/cppcodemodelsettingspage.cpp
@@ -56,18 +56,16 @@ void CppCodeModelSettingsWidget::setSettings(const QSharedPointer<CppCodeModelSe
{
m_settings = s;
+ setupGeneralWidgets();
setupClangCodeModelWidgets();
- setupPchCheckBox();
- setupSkipIndexingFilesWidgets();
}
void CppCodeModelSettingsWidget::applyToSettings() const
{
bool changed = false;
+ changed |= applyGeneralWidgetsToSettings();
changed |= applyClangCodeModelWidgetsToSettings();
- changed |= applyPchCheckBoxToSettings();
- changed |= applySkipIndexingFilesWidgets();
if (changed)
m_settings->toSettings(Core::ICore::settings());
@@ -88,16 +86,16 @@ void CppCodeModelSettingsWidget::setupClangCodeModelWidgets()
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->ignorePCHCheckBox->setChecked(ignorePch);
-}
+ m_ui->interpretAmbiguousHeadersAsCHeaders->setChecked(
+ m_settings->interpretAmbigiousHeadersAsCHeaders());
-void CppCodeModelSettingsWidget::setupSkipIndexingFilesWidgets()
-{
m_ui->skipIndexingBigFilesCheckBox->setChecked(m_settings->skipIndexingBigFiles());
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
@@ -122,39 +120,39 @@ bool CppCodeModelSettingsWidget::applyClangCodeModelWidgetsToSettings() const
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);
+ bool settingsChanged = false;
- return true;
+ const bool newInterpretAmbiguousHeaderAsCHeaders
+ = m_ui->interpretAmbiguousHeadersAsCHeaders->isChecked();
+ if (m_settings->interpretAmbigiousHeadersAsCHeaders()
+ != newInterpretAmbiguousHeaderAsCHeaders) {
+ m_settings->setInterpretAmbigiousHeadersAsCHeaders(newInterpretAmbiguousHeaderAsCHeaders);
+ settingsChanged = true;
}
- return false;
-}
-
-bool CppCodeModelSettingsWidget::applySkipIndexingFilesWidgets() const
-{
- bool settingsChanged = false;
-
const bool newSkipIndexingBigFiles = m_ui->skipIndexingBigFilesCheckBox->isChecked();
if (m_settings->skipIndexingBigFiles() != newSkipIndexingBigFiles) {
m_settings->setSkipIndexingBigFiles(newSkipIndexingBigFiles);
settingsChanged = true;
}
-
const int newFileSizeLimit = m_ui->bigFilesLimitSpinBox->value();
if (m_settings->indexerFileSizeLimitInMb() != newFileSizeLimit) {
m_settings->setIndexerFileSizeLimitInMb(newFileSizeLimit);
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;
}
diff --git a/src/plugins/cpptools/cppcodemodelsettingspage.h b/src/plugins/cpptools/cppcodemodelsettingspage.h
index fc249d4285..21911763a1 100644
--- a/src/plugins/cpptools/cppcodemodelsettingspage.h
+++ b/src/plugins/cpptools/cppcodemodelsettingspage.h
@@ -55,13 +55,11 @@ public:
void applyToSettings() const;
private:
+ void setupGeneralWidgets();
void setupClangCodeModelWidgets();
- void setupPchCheckBox() const;
- void setupSkipIndexingFilesWidgets();
+ bool applyGeneralWidgetsToSettings() const;
bool applyClangCodeModelWidgetsToSettings() const;
- bool applyPchCheckBoxToSettings() const;
- bool applySkipIndexingFilesWidgets() const;
private:
Ui::CppCodeModelSettingsPage *m_ui;
diff --git a/src/plugins/cpptools/cppcodemodelsettingspage.ui b/src/plugins/cpptools/cppcodemodelsettingspage.ui
index 34a946854b..025b91dba9 100644
--- a/src/plugins/cpptools/cppcodemodelsettingspage.ui
+++ b/src/plugins/cpptools/cppcodemodelsettingspage.ui
@@ -15,37 +15,19 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
- <widget class="QLabel" name="clangCodeModelIsEnabledHint">
- <property name="text">
- <string>&lt;i&gt;The Clang Code Model is enabled because the corresponding plugin is loaded.&lt;/i&gt;</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QLabel" name="clangCodeModelIsDisabledHint">
- <property name="text">
- <string>&lt;i&gt;The Clang Code Model is disabled because the corresponding plugin is not loaded.&lt;/i&gt;</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>
<widget class="QGroupBox" name="anotherGroupBox">
<property name="title">
- <string>Files to Skip</string>
+ <string>General</string>
</property>
<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>
<widget class="QCheckBox" name="ignorePCHCheckBox">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;When pre-compiled headers are not ignored, the parsing for code completion and semantic highlighting will process the pre-compiled header before processing any file.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
@@ -102,6 +84,31 @@
</widget>
</item>
<item>
+ <widget class="QLabel" name="clangCodeModelIsEnabledHint">
+ <property name="text">
+ <string>&lt;i&gt;The Clang Code Model is enabled because the corresponding plugin is loaded.&lt;/i&gt;</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="clangCodeModelIsDisabledHint">
+ <property name="text">
+ <string>&lt;i&gt;The Clang Code Model is disabled because the corresponding plugin is not loaded.&lt;/i&gt;</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>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
diff --git a/src/plugins/cpptools/cppcompletionassist.cpp b/src/plugins/cpptools/cppcompletionassist.cpp
index 73800a094d..30b1a0d9dc 100644
--- a/src/plugins/cpptools/cppcompletionassist.cpp
+++ b/src/plugins/cpptools/cppcompletionassist.cpp
@@ -2122,7 +2122,10 @@ void CppCompletionAssistInterface::getCppSpecifics() const
m_gotCppSpecifics = true;
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_headerPaths = m_parser->headerPaths();
}
diff --git a/src/plugins/cpptools/cpplanguage.h b/src/plugins/cpptools/cpplanguage.h
new file mode 100644
index 0000000000..2a84641d4d
--- /dev/null
+++ b/src/plugins/cpptools/cpplanguage.h
@@ -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
diff --git a/src/plugins/cpptools/cppmodelmanager_test.cpp b/src/plugins/cpptools/cppmodelmanager_test.cpp
index d5f0b2fc09..4db38959c3 100644
--- a/src/plugins/cpptools/cppmodelmanager_test.cpp
+++ b/src/plugins/cpptools/cppmodelmanager_test.cpp
@@ -877,7 +877,8 @@ void CppToolsPlugin::test_modelmanager_precompiled_headers()
BaseEditorDocumentParser::Configuration config = parser->configuration();
config.usePrecompiledHeaders = true;
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
Document::Ptr document = mm->document(fileName);
@@ -955,7 +956,8 @@ void CppToolsPlugin::test_modelmanager_defines_per_editor()
BaseEditorDocumentParser::Configuration config = parser->configuration();
config.editorDefines = editorDefines.toUtf8();
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);
QCOMPARE(nameOfFirstDeclaration(doc), firstDeclarationName);
diff --git a/src/plugins/cpptools/cppprojectpartchooser.cpp b/src/plugins/cpptools/cppprojectpartchooser.cpp
index 19c40c5fe0..5f7d3de137 100644
--- a/src/plugins/cpptools/cppprojectpartchooser.cpp
+++ b/src/plugins/cpptools/cppprojectpartchooser.cpp
@@ -31,25 +31,39 @@
namespace CppTools {
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;
if (projectPart.project == activeProject)
- thePriority += 10;
+ thePriority += 100;
if (projectPart.selectedForBuilding)
+ thePriority += 10;
+
+ if (isPreferredLanguage(projectPart, languagePreference))
thePriority += 1;
return thePriority;
}
static ProjectPart::Ptr chooseFromMultiple(const QList<ProjectPart::Ptr> &projectParts,
- const ProjectExplorer::Project *activeProject)
+ const ProjectExplorer::Project *activeProject,
+ Language languagePreference)
{
QList<ProjectPart::Ptr> projectPartsPrioritized = projectParts;
- const auto lessThan = [activeProject] (const ProjectPart::Ptr &p1, const ProjectPart::Ptr &p2) {
- return priority(*p1, activeProject) > priority(*p2, activeProject);
+ const auto lessThan = [&] (const ProjectPart::Ptr &p1, const ProjectPart::Ptr &p2) {
+ return priority(*p1, activeProject, languagePreference)
+ > priority(*p2, activeProject, languagePreference);
};
std::stable_sort(projectPartsPrioritized.begin(), projectPartsPrioritized.end(), lessThan);
@@ -61,6 +75,7 @@ ProjectPart::Ptr ProjectPartChooser::choose(const QString &filePath,
const ProjectPart::Ptr &manuallySetProjectPart,
bool stickToPreviousProjectPart,
const ProjectExplorer::Project *activeProject,
+ Language languagePreference,
bool projectHasChanged) const
{
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:
projectPart = m_fallbackProjectPart();
else
- projectPart = chooseFromMultiple(projectParts, activeProject);
+ projectPart = chooseFromMultiple(projectParts, activeProject, languagePreference);
} else {
if (projectHasChanged || !projectParts.contains(projectPart))
- projectPart = chooseFromMultiple(projectParts, activeProject);
+ projectPart = chooseFromMultiple(projectParts, activeProject, languagePreference);
}
return projectPart;
diff --git a/src/plugins/cpptools/cppprojectpartchooser.h b/src/plugins/cpptools/cppprojectpartchooser.h
index 1ad6da10af..e0a8581c34 100644
--- a/src/plugins/cpptools/cppprojectpartchooser.h
+++ b/src/plugins/cpptools/cppprojectpartchooser.h
@@ -25,6 +25,7 @@
#pragma once
+#include "cpplanguage.h"
#include "projectpart.h"
#include <functional>
@@ -52,6 +53,7 @@ public:
const ProjectPart::Ptr &manuallySetProjectPart,
bool stickToPreviousProjectPart,
const ProjectExplorer::Project *activeProject,
+ Language languagePreference,
bool projectHasChanged) const;
private:
diff --git a/src/plugins/cpptools/cpptools.pro b/src/plugins/cpptools/cpptools.pro
index 00611dbca1..9b3b064b77 100644
--- a/src/plugins/cpptools/cpptools.pro
+++ b/src/plugins/cpptools/cpptools.pro
@@ -34,6 +34,7 @@ HEADERS += \
cppfunctionsfilter.h \
cppincludesfilter.h \
cppindexingsupport.h \
+ cpplanguage.h \
cpplocalsymbols.h \
cpplocatordata.h \
cpplocatorfilter.h \
diff --git a/src/plugins/cpptools/cpptools.qbs b/src/plugins/cpptools/cpptools.qbs
index 53ff39b5e9..f7047ed28d 100644
--- a/src/plugins/cpptools/cpptools.qbs
+++ b/src/plugins/cpptools/cpptools.qbs
@@ -61,6 +61,7 @@ Project {
"cppfunctionsfilter.cpp", "cppfunctionsfilter.h",
"cppincludesfilter.cpp", "cppincludesfilter.h",
"cppindexingsupport.cpp", "cppindexingsupport.h",
+ "cpplanguage.h",
"cpplocalsymbols.cpp", "cpplocalsymbols.h",
"cpplocatordata.cpp", "cpplocatordata.h",
"cpplocatorfilter.cpp", "cpplocatorfilter.h",
diff --git a/src/plugins/cpptools/cpptoolsconstants.h b/src/plugins/cpptools/cpptoolsconstants.h
index 11a5f1a1ab..18192317ce 100644
--- a/src/plugins/cpptools/cpptoolsconstants.h
+++ b/src/plugins/cpptools/cpptoolsconstants.h
@@ -51,10 +51,13 @@ enum { lowerCaseFilesDefault = 1 };
const char CPPTOOLS_SORT_EDITOR_DOCUMENT_OUTLINE[] = "SortedMethodOverview";
const char CPPTOOLS_SHOW_INFO_BAR_FOR_HEADER_ERRORS[] = "ShowInfoBarForHeaderErrors";
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_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_NAME[] = QT_TRANSLATE_NOOP("CppTools", "Code Style");