forked from qt-creator/qt-creator
		
	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:
		@@ -122,7 +122,7 @@ BaseEditorDocumentParser::Ptr BaseEditorDocumentParser::get(const QString &fileP
 | 
			
		||||
ProjectPartInfo BaseEditorDocumentParser::determineProjectPart(
 | 
			
		||||
        const QString &filePath,
 | 
			
		||||
        const Configuration &config,
 | 
			
		||||
        const State &state,
 | 
			
		||||
        const ProjectPartInfo ¤tProjectPartInfo,
 | 
			
		||||
        const ProjectExplorer::Project *activeProject,
 | 
			
		||||
        Language languagePreference,
 | 
			
		||||
        bool hasActiveProjectChanged)
 | 
			
		||||
@@ -143,9 +143,8 @@ ProjectPartInfo BaseEditorDocumentParser::determineProjectPart(
 | 
			
		||||
 | 
			
		||||
    const ProjectPartInfo chooserResult
 | 
			
		||||
            = chooser.choose(filePath,
 | 
			
		||||
                             state.projectPartInfo.projectPart,
 | 
			
		||||
                             currentProjectPartInfo,
 | 
			
		||||
                             config.manuallySetProjectPart,
 | 
			
		||||
                             config.stickToPreviousProjectPart,
 | 
			
		||||
                             activeProject,
 | 
			
		||||
                             languagePreference,
 | 
			
		||||
                             hasActiveProjectChanged);
 | 
			
		||||
 
 | 
			
		||||
@@ -47,7 +47,6 @@ public:
 | 
			
		||||
    static Ptr get(const QString &filePath);
 | 
			
		||||
 | 
			
		||||
    struct Configuration {
 | 
			
		||||
        bool stickToPreviousProjectPart = true;
 | 
			
		||||
        bool usePrecompiledHeaders = false;
 | 
			
		||||
        QByteArray editorDefines;
 | 
			
		||||
        ProjectPart::Ptr manuallySetProjectPart;
 | 
			
		||||
@@ -95,10 +94,9 @@ protected:
 | 
			
		||||
    State state() const;
 | 
			
		||||
    void setState(const State &state);
 | 
			
		||||
 | 
			
		||||
    static ProjectPartInfo determineProjectPart(
 | 
			
		||||
            const QString &filePath,
 | 
			
		||||
    static ProjectPartInfo determineProjectPart(const QString &filePath,
 | 
			
		||||
            const Configuration &config,
 | 
			
		||||
            const State &state,
 | 
			
		||||
            const ProjectPartInfo ¤tProjectPartInfo,
 | 
			
		||||
            const ProjectExplorer::Project *activeProject,
 | 
			
		||||
            Language languagePreference,
 | 
			
		||||
            bool hasActiveProjectChanged);
 | 
			
		||||
 
 | 
			
		||||
@@ -79,7 +79,7 @@ void BuiltinEditorDocumentParser::updateImpl(const QFutureInterface<void> &futur
 | 
			
		||||
 | 
			
		||||
    baseState.projectPartInfo = determineProjectPart(filePath(),
 | 
			
		||||
                                                    baseConfig,
 | 
			
		||||
                                                    baseState,
 | 
			
		||||
                                                    baseState.projectPartInfo,
 | 
			
		||||
                                                    updateParams.activeProject,
 | 
			
		||||
                                                    updateParams.languagePreference,
 | 
			
		||||
                                                    updateParams.hasActiveProjectChanged);
 | 
			
		||||
 
 | 
			
		||||
@@ -124,9 +124,8 @@ private:
 | 
			
		||||
 | 
			
		||||
ProjectPartInfo ProjectPartChooser::choose(
 | 
			
		||||
        const QString &filePath,
 | 
			
		||||
        const ProjectPart::Ptr ¤tProjectPart,
 | 
			
		||||
        const ProjectPartInfo ¤tProjectPartInfo,
 | 
			
		||||
        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);
 | 
			
		||||
 
 | 
			
		||||
@@ -50,9 +50,8 @@ public:
 | 
			
		||||
 | 
			
		||||
    ProjectPartInfo choose(
 | 
			
		||||
            const QString &filePath,
 | 
			
		||||
            const ProjectPart::Ptr ¤tProjectPart,
 | 
			
		||||
            const ProjectPartInfo ¤tProjectPartInfo,
 | 
			
		||||
            const ProjectPart::Ptr &manuallySetProjectPart,
 | 
			
		||||
            bool stickToPreviousProjectPart,
 | 
			
		||||
            const ProjectExplorer::Project *activeProject,
 | 
			
		||||
            Language languagePreference,
 | 
			
		||||
            bool projectHasChanged) const;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user