forked from qt-creator/qt-creator
		
	ClangCodeModel: Restrict opening non-project files to headers
We cannot tell clangd to opt out of indexing for certain files, so we
must prevent "foreign" sources from ever getting opened, or we will have
strange effects in the case of non-unique symbols.
Note that there are more (upstream) problems in this area, but this
patch limits the damage at least.
Amends 8ad7ab2d2a.
Fixes: QTCREATORBUG-28452
Change-Id: I131be699a35da8eacea6415c630e9012cc905a47
Reviewed-by: David Schulz <david.schulz@qt.io>
			
			
This commit is contained in:
		@@ -517,12 +517,14 @@ void ClangModelManagerSupport::updateLanguageClient(ProjectExplorer::Project *pr
 | 
			
		||||
                        && currentClient->project() == docProject) {
 | 
			
		||||
                    continue;
 | 
			
		||||
                }
 | 
			
		||||
                if (!docProject || docProject == project) {
 | 
			
		||||
                    if (currentClient)
 | 
			
		||||
                        currentClient->closeDocument(doc);
 | 
			
		||||
                    LanguageClientManager::openDocumentWithClient(doc, client);
 | 
			
		||||
                    hasDocuments = true;
 | 
			
		||||
                if (docProject != project
 | 
			
		||||
                        && (docProject || !ProjectFile::isHeader(doc->filePath()))) {
 | 
			
		||||
                    continue;
 | 
			
		||||
                }
 | 
			
		||||
                if (currentClient)
 | 
			
		||||
                    currentClient->closeDocument(doc);
 | 
			
		||||
                LanguageClientManager::openDocumentWithClient(doc, client);
 | 
			
		||||
                hasDocuments = true;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            for (auto it = m_queuedShadowDocuments.begin(); it != m_queuedShadowDocuments.end();) {
 | 
			
		||||
@@ -625,11 +627,13 @@ void ClangModelManagerSupport::claimNonProjectSources(ClangdClient *client)
 | 
			
		||||
        }
 | 
			
		||||
        if (!ClangdSettings::instance().sizeIsOkay(doc->filePath()))
 | 
			
		||||
            continue;
 | 
			
		||||
        if (!ProjectExplorer::SessionManager::projectForFile(doc->filePath())) {
 | 
			
		||||
            if (currentClient)
 | 
			
		||||
                currentClient->closeDocument(doc);
 | 
			
		||||
            LanguageClientManager::openDocumentWithClient(doc, client);
 | 
			
		||||
        }
 | 
			
		||||
        if (ProjectExplorer::SessionManager::projectForFile(doc->filePath()))
 | 
			
		||||
            continue;
 | 
			
		||||
        if (client->project() && !ProjectFile::isHeader(doc->filePath()))
 | 
			
		||||
            continue;
 | 
			
		||||
        if (currentClient)
 | 
			
		||||
            currentClient->closeDocument(doc);
 | 
			
		||||
        LanguageClientManager::openDocumentWithClient(doc, client);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -717,7 +721,7 @@ void ClangModelManagerSupport::onEditorOpened(Core::IEditor *editor)
 | 
			
		||||
            return;
 | 
			
		||||
        if (sessionModeEnabled())
 | 
			
		||||
            project = nullptr;
 | 
			
		||||
        else if (!project)
 | 
			
		||||
        else if (!project && ProjectFile::isHeader(document->filePath()))
 | 
			
		||||
            project = fallbackProject();
 | 
			
		||||
        if (ClangdClient * const client = clientForProject(project))
 | 
			
		||||
            LanguageClientManager::openDocumentWithClient(textDocument, client);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user