forked from qt-creator/qt-creator
CppTools: Fix using updated project part
1. Open a project consisting of two subprojects referencing the same source file. 2. Open the source file. 3. Click '#' in the editor toolbar and select the second project (part). 4. Update the project file, e.g. add a define ==> Editor does not reflect the added define This is due to comparing project part pointers. Fix by using the project part id that remains stable across project manager updates. Change-Id: Ifd1a113e55ebe2ecf036cd7caafdbfd6e4cdf415 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -37,7 +37,7 @@ void ClangEditorDocumentParser::updateImpl(const QFutureInterface<void> &,
|
||||
{
|
||||
State state_ = state();
|
||||
state_.projectPartInfo = determineProjectPart(filePath(),
|
||||
configuration(),
|
||||
configuration().preferredProjectPartId,
|
||||
state_.projectPartInfo,
|
||||
updateParams.activeProject,
|
||||
updateParams.languagePreference,
|
||||
|
||||
@@ -278,7 +278,7 @@ void CppEditorDocument::setPreprocessorSettings(const CppTools::ProjectPart::Ptr
|
||||
if (parser->projectPartInfo().projectPart != projectPart
|
||||
|| parser->configuration().editorDefines != defines) {
|
||||
CppTools::BaseEditorDocumentParser::Configuration config = parser->configuration();
|
||||
config.manuallySetProjectPart = projectPart;
|
||||
config.preferredProjectPartId = projectPart->id();
|
||||
config.editorDefines = defines;
|
||||
parser->setConfiguration(config);
|
||||
|
||||
|
||||
@@ -121,15 +121,13 @@ BaseEditorDocumentParser::Ptr BaseEditorDocumentParser::get(const QString &fileP
|
||||
|
||||
ProjectPartInfo BaseEditorDocumentParser::determineProjectPart(
|
||||
const QString &filePath,
|
||||
const Configuration &config,
|
||||
const QString &preferredProjectPartId,
|
||||
const ProjectPartInfo ¤tProjectPartInfo,
|
||||
const ProjectExplorer::Project *activeProject,
|
||||
Language languagePreference,
|
||||
bool hasActiveProjectChanged)
|
||||
{
|
||||
using Internal::ProjectPartChooser;
|
||||
|
||||
ProjectPartChooser chooser;
|
||||
Internal::ProjectPartChooser chooser;
|
||||
chooser.setFallbackProjectPart([](){
|
||||
return CppModelManager::instance()->fallbackProjectPart();
|
||||
});
|
||||
@@ -144,7 +142,7 @@ ProjectPartInfo BaseEditorDocumentParser::determineProjectPart(
|
||||
const ProjectPartInfo chooserResult
|
||||
= chooser.choose(filePath,
|
||||
currentProjectPartInfo,
|
||||
config.manuallySetProjectPart,
|
||||
preferredProjectPartId,
|
||||
activeProject,
|
||||
languagePreference,
|
||||
hasActiveProjectChanged);
|
||||
|
||||
@@ -49,7 +49,7 @@ public:
|
||||
struct Configuration {
|
||||
bool usePrecompiledHeaders = false;
|
||||
QByteArray editorDefines;
|
||||
ProjectPart::Ptr manuallySetProjectPart;
|
||||
QString preferredProjectPartId;
|
||||
};
|
||||
|
||||
struct UpdateParams {
|
||||
@@ -95,7 +95,7 @@ protected:
|
||||
void setState(const State &state);
|
||||
|
||||
static ProjectPartInfo determineProjectPart(const QString &filePath,
|
||||
const Configuration &config,
|
||||
const QString &preferredProjectPartId,
|
||||
const ProjectPartInfo ¤tProjectPartInfo,
|
||||
const ProjectExplorer::Project *activeProject,
|
||||
Language languagePreference,
|
||||
|
||||
@@ -78,7 +78,7 @@ void BuiltinEditorDocumentParser::updateImpl(const QFutureInterface<void> &futur
|
||||
LanguageFeatures features = LanguageFeatures::defaultFeatures();
|
||||
|
||||
baseState.projectPartInfo = determineProjectPart(filePath(),
|
||||
baseConfig,
|
||||
baseConfig.preferredProjectPartId,
|
||||
baseState.projectPartInfo,
|
||||
updateParams.activeProject,
|
||||
updateParams.languagePreference,
|
||||
|
||||
@@ -44,9 +44,11 @@ public:
|
||||
};
|
||||
|
||||
ProjectPartPrioritizer(const QList<ProjectPart::Ptr> &projectParts,
|
||||
const QString &preferredProjectPartId,
|
||||
const ProjectExplorer::Project *activeProject,
|
||||
Language languagePreference)
|
||||
: m_projectParts(projectParts)
|
||||
, m_preferredProjectPartId(preferredProjectPartId)
|
||||
, m_activeProject(activeProject)
|
||||
, m_languagePreference(languagePreference)
|
||||
{
|
||||
@@ -93,6 +95,9 @@ private:
|
||||
{
|
||||
int thePriority = 0;
|
||||
|
||||
if (!m_preferredProjectPartId.isEmpty() && projectPart.id() == m_preferredProjectPartId)
|
||||
thePriority += 1000;
|
||||
|
||||
if (projectPart.project == m_activeProject)
|
||||
thePriority += 100;
|
||||
|
||||
@@ -114,6 +119,7 @@ private:
|
||||
|
||||
private:
|
||||
const QList<ProjectPart::Ptr> m_projectParts;
|
||||
const QString m_preferredProjectPartId;
|
||||
const ProjectExplorer::Project *m_activeProject = nullptr;
|
||||
Language m_languagePreference = Language::Cxx;
|
||||
|
||||
@@ -122,10 +128,9 @@ private:
|
||||
bool m_isAmbiguous = false;
|
||||
};
|
||||
|
||||
ProjectPartInfo ProjectPartChooser::choose(
|
||||
const QString &filePath,
|
||||
ProjectPartInfo ProjectPartChooser::choose(const QString &filePath,
|
||||
const ProjectPartInfo ¤tProjectPartInfo,
|
||||
const ProjectPart::Ptr &manuallySetProjectPart,
|
||||
const QString &preferredProjectPartId,
|
||||
const ProjectExplorer::Project *activeProject,
|
||||
Language languagePreference,
|
||||
bool projectHasChanged) const
|
||||
@@ -134,9 +139,6 @@ ProjectPartInfo ProjectPartChooser::choose(
|
||||
QTC_CHECK(m_projectPartsFromDependenciesForFile);
|
||||
QTC_CHECK(m_fallbackProjectPart);
|
||||
|
||||
if (manuallySetProjectPart)
|
||||
return {manuallySetProjectPart, ProjectPartInfo::NoHint};
|
||||
|
||||
ProjectPart::Ptr projectPart = currentProjectPartInfo.projectPart;
|
||||
ProjectPartInfo::Hint hint = ProjectPartInfo::NoHint;
|
||||
|
||||
@@ -153,12 +155,18 @@ ProjectPartInfo ProjectPartChooser::choose(
|
||||
projectPart = m_fallbackProjectPart();
|
||||
hint = ProjectPartInfo::IsFallbackMatch;
|
||||
} else {
|
||||
ProjectPartPrioritizer prioritizer(projectParts, activeProject, languagePreference);
|
||||
ProjectPartPrioritizer prioritizer(projectParts,
|
||||
preferredProjectPartId,
|
||||
activeProject,
|
||||
languagePreference);
|
||||
projectPart = prioritizer.projectPart();
|
||||
}
|
||||
} else {
|
||||
if (projectHasChanged || !projectParts.contains(projectPart)) {
|
||||
ProjectPartPrioritizer prioritizer(projectParts, activeProject, languagePreference);
|
||||
ProjectPartPrioritizer prioritizer(projectParts,
|
||||
preferredProjectPartId,
|
||||
activeProject,
|
||||
languagePreference);
|
||||
projectPart = prioritizer.projectPart();
|
||||
hint = prioritizer.isAmbiguous()
|
||||
? ProjectPartInfo::IsAmbiguousMatch
|
||||
|
||||
@@ -51,7 +51,7 @@ public:
|
||||
ProjectPartInfo choose(
|
||||
const QString &filePath,
|
||||
const ProjectPartInfo ¤tProjectPartInfo,
|
||||
const ProjectPart::Ptr &manuallySetProjectPart,
|
||||
const QString &preferredProjectPartId,
|
||||
const ProjectExplorer::Project *activeProject,
|
||||
Language languagePreference,
|
||||
bool projectHasChanged) const;
|
||||
|
||||
@@ -51,7 +51,7 @@ protected:
|
||||
QString filePath;
|
||||
ProjectPartInfo currentProjectPartInfo{ProjectPart::Ptr(new ProjectPart),
|
||||
ProjectPartInfo::NoHint};
|
||||
ProjectPart::Ptr manuallySetProjectPart;
|
||||
QString preferredProjectPartId;
|
||||
const ProjectExplorer::Project *activeProject = nullptr;
|
||||
bool projectHasChanged = false;
|
||||
Language languagePreference = Language::Cxx;
|
||||
@@ -64,11 +64,14 @@ protected:
|
||||
|
||||
TEST_F(ProjectPartChooser, ChooseManuallySet)
|
||||
{
|
||||
manuallySetProjectPart.reset(new ProjectPart);
|
||||
ProjectPart::Ptr p1(new ProjectPart);
|
||||
ProjectPart::Ptr p2(new ProjectPart);
|
||||
p2->projectFile = preferredProjectPartId = "someId";
|
||||
projectPartsForFile += {p1, p2};
|
||||
|
||||
const ProjectPart::Ptr chosen = choose().projectPart;
|
||||
|
||||
ASSERT_THAT(chosen, Eq(manuallySetProjectPart));
|
||||
ASSERT_THAT(chosen, Eq(p2));
|
||||
}
|
||||
|
||||
TEST_F(ProjectPartChooser, ForMultipleChoosePrevious)
|
||||
@@ -249,7 +252,7 @@ const ProjectPartInfo ProjectPartChooser::choose() const
|
||||
{
|
||||
return chooser.choose(filePath,
|
||||
currentProjectPartInfo,
|
||||
manuallySetProjectPart,
|
||||
preferredProjectPartId,
|
||||
activeProject,
|
||||
languagePreference,
|
||||
projectHasChanged);
|
||||
|
||||
Reference in New Issue
Block a user