CppTools: Use fallback project part if project is closed

...instead of sticking to the old one.

If a project is closed, the editor should reflect that. It also simplifies the code.

Change-Id: I9b8a94513d3b06a238cfc4ee60c11c0d0da3d93f
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Nikolai Kosjar
2017-01-19 11:08:13 +01:00
parent ec3dcfd6ad
commit 07f32ef57a
7 changed files with 44 additions and 47 deletions

View File

@@ -124,9 +124,8 @@ private:
ProjectPartInfo ProjectPartChooser::choose(
const QString &filePath,
const ProjectPart::Ptr &currentProjectPart,
const ProjectPartInfo &currentProjectPartInfo,
const ProjectPart::Ptr &manuallySetProjectPart,
bool stickToPreviousProjectPart,
const ProjectExplorer::Project *activeProject,
Language languagePreference,
bool projectHasChanged) const
@@ -138,15 +137,14 @@ ProjectPartInfo ProjectPartChooser::choose(
if (manuallySetProjectPart)
return {manuallySetProjectPart, ProjectPartInfo::NoHint};
ProjectPart::Ptr projectPart = currentProjectPart;
ProjectPart::Ptr projectPart = currentProjectPartInfo.projectPart;
ProjectPartInfo::Hint hint = ProjectPartInfo::NoHint;
QList<ProjectPart::Ptr> projectParts = m_projectPartsForFile(filePath);
if (projectParts.isEmpty()) {
if (projectPart && stickToPreviousProjectPart)
// File is not directly part of any project, but we got one before. We will re-use it,
// because re-calculating this can be expensive when the dependency table is big.
return {projectPart, ProjectPartInfo::NoHint};
if (projectPart && currentProjectPartInfo.hint == ProjectPartInfo::IsFallbackMatch)
// Avoid re-calculating the expensive dependency table for non-project files.
return {projectPart, ProjectPartInfo::IsFallbackMatch};
// Fall-back step 1: Get some parts through the dependency table:
projectParts = m_projectPartsFromDependenciesForFile(filePath);