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(),
|
||||
state_,
|
||||
updateParams.activeProject,
|
||||
updateParams.languagePreference,
|
||||
updateParams.hasActiveProjectChanged);
|
||||
setState(state_);
|
||||
}
|
||||
|
@@ -384,8 +384,17 @@ static CppTools::ProjectPart projectPartForLanguageOption(CppTools::ProjectPart
|
||||
static QStringList languageOptions(const QString &filePath, CppTools::ProjectPart *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);
|
||||
builder.addLanguageOption(CppTools::ProjectFile::classify(filePath));
|
||||
builder.addLanguageOption(fileKind);
|
||||
|
||||
return builder.options();
|
||||
}
|
||||
|
@@ -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);
|
||||
}
|
||||
|
||||
|
@@ -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;
|
||||
|
@@ -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});
|
||||
}
|
||||
|
||||
|
@@ -81,6 +81,7 @@ void BuiltinEditorDocumentParser::updateImpl(const QFutureInterface<void> &futur
|
||||
baseConfig,
|
||||
baseState,
|
||||
updateParams.activeProject,
|
||||
updateParams.languagePreference,
|
||||
updateParams.hasActiveProjectChanged);
|
||||
|
||||
if (state.forceSnapshotInvalidation) {
|
||||
|
@@ -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);
|
||||
|
||||
|
@@ -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;
|
||||
|
@@ -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;
|
||||
|
@@ -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
|
||||
{
|
||||
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 CppCodeModelSettingsWidget::applyGeneralWidgetsToSettings() const
|
||||
{
|
||||
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();
|
||||
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;
|
||||
}
|
||||
|
||||
|
@@ -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;
|
||||
|
@@ -14,37 +14,19 @@
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<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>
|
||||
<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">
|
||||
@@ -101,6 +83,31 @@
|
||||
</layout>
|
||||
</widget>
|
||||
</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>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
|
@@ -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();
|
||||
}
|
||||
|
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();
|
||||
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);
|
||||
|
@@ -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;
|
||||
|
@@ -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:
|
||||
|
@@ -34,6 +34,7 @@ HEADERS += \
|
||||
cppfunctionsfilter.h \
|
||||
cppincludesfilter.h \
|
||||
cppindexingsupport.h \
|
||||
cpplanguage.h \
|
||||
cpplocalsymbols.h \
|
||||
cpplocatordata.h \
|
||||
cpplocatorfilter.h \
|
||||
|
@@ -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",
|
||||
|
@@ -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");
|
||||
|
@@ -25,11 +25,13 @@
|
||||
|
||||
#include "googletest.h"
|
||||
|
||||
#include <cpptools/cpplanguage.h>
|
||||
#include <cpptools/cppprojectpartchooser.h>
|
||||
#include <cpptools/projectpart.h>
|
||||
|
||||
using CppTools::Internal::ProjectPartChooser;
|
||||
using CppTools::ProjectPart;
|
||||
using CppTools::Language;
|
||||
|
||||
using testing::Eq;
|
||||
|
||||
@@ -42,6 +44,7 @@ protected:
|
||||
const ProjectPart::Ptr choose() const;
|
||||
|
||||
static QList<ProjectPart::Ptr> createProjectPartsWithDifferentProjects();
|
||||
static QList<ProjectPart::Ptr> createCAndCxxProjectParts();
|
||||
|
||||
protected:
|
||||
QString filePath;
|
||||
@@ -50,6 +53,7 @@ protected:
|
||||
bool stickToPreviousProjectPart = false;
|
||||
const ProjectExplorer::Project *activeProject = nullptr;
|
||||
bool projectHasChanged = false;
|
||||
Language languagePreference = Language::Cxx;
|
||||
::ProjectPartChooser chooser;
|
||||
|
||||
QList<ProjectPart::Ptr> projectPartsForFile;
|
||||
@@ -130,6 +134,28 @@ TEST_F(ProjectPartChooser, ForMultipleCheckIfActiveProjectChanged)
|
||||
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
|
||||
{
|
||||
stickToPreviousProjectPart = true;
|
||||
@@ -198,6 +224,7 @@ const ProjectPart::Ptr ProjectPartChooser::choose() const
|
||||
manuallySetProjectPart,
|
||||
stickToPreviousProjectPart,
|
||||
activeProject,
|
||||
languagePreference,
|
||||
projectHasChanged);
|
||||
}
|
||||
|
||||
@@ -215,4 +242,21 @@ QList<ProjectPart::Ptr> ProjectPartChooser::createProjectPartsWithDifferentProje
|
||||
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
|
||||
|
Reference in New Issue
Block a user