Commit 420bc697 authored by Nikolai Kosjar's avatar Nikolai Kosjar

CppTools: Use project part ids instead of file paths

File paths are not unique since e.g. each qbs group in a file is mapped
to a project part.

Change-Id: I7df3f224dd23046b869f2588b8a34eb26cfc0b1a
Reviewed-by: default avatarMarco Bubke <marco.bubke@theqtcompany.com>
parent 95c90dcd
......@@ -310,8 +310,7 @@ static ClangBackEnd::ProjectPartContainer toProjectPartContainer(
const CppTools::ProjectPart::Ptr &projectPart)
{
const QStringList arguments = projectPartCommandLine(projectPart);
return ClangBackEnd::ProjectPartContainer(projectPart->projectFile,
Utf8StringVector(arguments));
return ClangBackEnd::ProjectPartContainer(projectPart->id(), Utf8StringVector(arguments));
}
static QVector<ClangBackEnd::ProjectPartContainer> toProjectPartContainers(
......@@ -339,13 +338,13 @@ void IpcCommunicator::updateUnsavedFileFromCppEditorDocument(const QString &file
void IpcCommunicator::updateUnsavedFile(const QString &filePath, const QByteArray &contents)
{
const QString projectFilePath = Utils::projectFilePathForFile(filePath);
const QString projectPartId = Utils::projectPartIdForFile(filePath);
const bool hasUnsavedContent = true;
// TODO: Send new only if changed
registerFilesForCodeCompletion({
ClangBackEnd::FileContainer(filePath,
projectFilePath,
projectPartId,
Utf8String::fromByteArray(contents),
hasUnsavedContent)
});
......@@ -432,12 +431,12 @@ void IpcCommunicator::registerProjectPartsForCodeCompletion(
m_ipcSender->registerProjectPartsForCodeCompletion(command);
}
void IpcCommunicator::unregisterProjectPartsForCodeCompletion(const QStringList &filePaths)
void IpcCommunicator::unregisterProjectPartsForCodeCompletion(const QStringList &projectPartIds)
{
if (m_sendMode == IgnoreSendRequests)
return;
const UnregisterProjectPartsForCodeCompletionCommand command((Utf8StringVector(filePaths)));
const UnregisterProjectPartsForCodeCompletionCommand command((Utf8StringVector(projectPartIds)));
qCDebug(log) << ">>>" << command;
m_ipcSender->unregisterProjectPartsForCodeCompletion(command);
}
......
......@@ -112,7 +112,7 @@ public:
void registerFilesForCodeCompletion(const FileContainers &fileContainers);
void unregisterFilesForCodeCompletion(const FileContainers &fileContainers);
void registerProjectPartsForCodeCompletion(const ProjectPartContainers &projectPartContainers);
void unregisterProjectPartsForCodeCompletion(const QStringList &filePaths);
void unregisterProjectPartsForCodeCompletion(const QStringList &projectPartIds);
void completeCode(ClangCompletionAssistProcessor *assistProcessor, const QString &filePath,
quint32 line,
quint32 column,
......
......@@ -302,7 +302,7 @@ static QByteArray modifyInput(QTextDocument *doc, int endOfExpression) {
IAssistProposal *ClangCompletionAssistProcessor::startCompletionHelper()
{
sendFileContent(Utils::projectFilePathForFile(m_interface->fileName()), QByteArray()); // TODO: Remoe
sendFileContent(Utils::projectPartIdForFile(m_interface->fileName()), QByteArray()); // TODO: Remove
ClangCompletionContextAnalyzer analyzer(m_interface.data(), m_interface->languageFeatures());
analyzer.analyze();
......@@ -648,7 +648,7 @@ void ClangCompletionAssistProcessor::addCompletionItem(const QString &text,
m_completions.append(item);
}
void ClangCompletionAssistProcessor::sendFileContent(const QString &projectFilePath,
void ClangCompletionAssistProcessor::sendFileContent(const QString &projectPartId,
const QByteArray &modifiedFileContent)
{
const QString filePath = m_interface->fileName();
......@@ -660,7 +660,7 @@ void ClangCompletionAssistProcessor::sendFileContent(const QString &projectFileP
IpcCommunicator &ipcCommunicator = m_interface->ipcCommunicator();
ipcCommunicator.registerFilesForCodeCompletion(
{ClangBackEnd::FileContainer(filePath,
projectFilePath,
projectPartId,
Utf8String::fromByteArray(unsavedContent),
hasUnsavedContent)});
}
......@@ -673,9 +673,9 @@ void ClangCompletionAssistProcessor::sendCompletionRequest(int position,
++column;
const QString filePath = m_interface->fileName();
const QString projectFilePath = Utils::projectFilePathForFile(filePath);
sendFileContent(projectFilePath, modifiedFileContent);
m_interface->ipcCommunicator().completeCode(this, filePath, line, column, projectFilePath);
const QString projectPartId = Utils::projectPartIdForFile(filePath);
sendFileContent(projectPartId, modifiedFileContent);
m_interface->ipcCommunicator().completeCode(this, filePath, line, column, projectPartId);
}
TextEditor::IAssistProposal *ClangCompletionAssistProcessor::createProposal() const
......
......@@ -81,7 +81,7 @@ private:
int order = 0,
const QVariant &data = QVariant());
void sendFileContent(const QString &projectFilePath, const QByteArray &modifiedFileContent);
void sendFileContent(const QString &projectPartId, const QByteArray &modifiedFileContent);
void sendCompletionRequest(int position, const QByteArray &modifiedFileContent);
void onCompletionsAvailable(const CodeCompletions &completions);
......
......@@ -132,13 +132,13 @@ ClangEditorDocumentProcessor::~ClangEditorDocumentProcessor()
const CppTools::ProjectPart::Ptr projectPart = m_parser.projectPart();
QTC_ASSERT(projectPart, return);
QString projectFilePath;
QString projectPartId;
if (Utils::isProjectPartValid(projectPart))
projectFilePath = projectPart->projectFile; // OK, Project Part is still loaded
projectPartId = projectPart->id(); // OK, Project Part is still loaded
QTC_ASSERT(m_modelManagerSupport, return);
m_modelManagerSupport->ipcCommunicator().unregisterFilesForCodeCompletion(
{ClangBackEnd::FileContainer(filePath(), projectFilePath)});
{ClangBackEnd::FileContainer(filePath(), projectPartId)});
}
void ClangEditorDocumentProcessor::run()
......
......@@ -159,9 +159,9 @@ void ModelManagerSupportClang::onAbstractEditorSupportRemoved(const QString &fil
{
QTC_ASSERT(!filePath.isEmpty(), return);
if (!cppModelManager()->cppEditorDocument(filePath)) {
const QString projectFilePath = Utils::projectFilePathForFile(filePath);
const QString projectPartId = Utils::projectPartIdForFile(filePath);
m_ipcCommunicator.unregisterFilesForCodeCompletion(
{ClangBackEnd::FileContainer(filePath, projectFilePath)});
{ClangBackEnd::FileContainer(filePath, projectPartId)});
}
}
......@@ -173,9 +173,9 @@ void ModelManagerSupportClang::onProjectPartsUpdated(ProjectExplorer::Project *p
m_ipcCommunicator.registerProjectsParts(projectInfo.projectParts());
}
void ModelManagerSupportClang::onProjectPartsRemoved(const QStringList &projectFiles)
void ModelManagerSupportClang::onProjectPartsRemoved(const QStringList &projectPartIds)
{
m_ipcCommunicator.unregisterProjectPartsForCodeCompletion(projectFiles);
m_ipcCommunicator.unregisterProjectPartsForCodeCompletion(projectPartIds);
}
#ifdef QT_TESTLIB_LIB
......
......@@ -73,7 +73,7 @@ private:
void onAbstractEditorSupportRemoved(const QString &filePath);
void onProjectPartsUpdated(ProjectExplorer::Project *project);
void onProjectPartsRemoved(const QStringList &projectFiles);
void onProjectPartsRemoved(const QStringList &projectPartIds);
IpcCommunicator m_ipcCommunicator;
ClangCompletionAssistProvider m_completionAssistProvider;
......
......@@ -218,16 +218,16 @@ ProjectPart::Ptr projectPartForFile(const QString &filePath)
bool isProjectPartValid(const ProjectPart::Ptr projectPart)
{
if (projectPart)
return CppModelManager::instance()->projectPartForProjectFile(projectPart->projectFile);
return CppModelManager::instance()->projectPartForId(projectPart->id());
return false;
}
QString projectFilePathForFile(const QString &filePath)
QString projectPartIdForFile(const QString &filePath)
{
const ProjectPart::Ptr projectPart = projectPartForFile(filePath);
if (isProjectPartValid(projectPart))
return projectPart->projectFile; // OK, Project Part is still loaded
return projectPart->id(); // OK, Project Part is still loaded
return QString();
}
......
......@@ -55,7 +55,7 @@ QStringList createPCHInclusionOptions(const QString &pchFile);
CppTools::ProjectPart::Ptr projectPartForFile(const QString &filePath);
bool isProjectPartValid(const CppTools::ProjectPart::Ptr projectPart);
QString projectFilePathForFile(const QString &filePath);
QString projectPartIdForFile(const QString &filePath);
} // namespace Utils
} // namespace Clang
......
......@@ -1048,7 +1048,7 @@ void ClangCodeCompletionTest::testUpdateBackendAfterRestart()
QVERIFY(compare(LogOutput(spy.senderLog),
LogOutput(
"RegisterProjectPartsForCodeCompletionCommand\n"
" ProjectPartContainer id: qt-widgets-app.pro\n"
" ProjectPartContainer id: qt-widgets-app.pro qt-widgets-app\n"
"RegisterTranslationUnitForCodeCompletionCommand\n"
" Path: myheader.h ProjectPart: \n"
"RegisterTranslationUnitForCodeCompletionCommand\n"
......@@ -1069,7 +1069,7 @@ void ClangCodeCompletionTest::testUpdateBackendAfterRestart()
"RegisterProjectPartsForCodeCompletionCommand\n"
" ProjectPartContainer id: \n"
"RegisterProjectPartsForCodeCompletionCommand\n"
" ProjectPartContainer id: qt-widgets-app.pro\n"
" ProjectPartContainer id: qt-widgets-app.pro qt-widgets-app\n"
"RegisterTranslationUnitForCodeCompletionCommand\n"
" Path: myheader.h ProjectPart: \n"
"RegisterTranslationUnitForCodeCompletionCommand\n"
......
......@@ -254,13 +254,13 @@ void CppEditorDocument::updatePreprocessorSettings()
return;
const QString prefix = QLatin1String(Constants::CPP_PREPROCESSOR_PROJECT_PREFIX);
const QString &projectFile = ProjectExplorer::SessionManager::value(
const QString &projectPartId = ProjectExplorer::SessionManager::value(
prefix + filePath().toString()).toString();
const QString directivesKey = projectFile + QLatin1Char(',') + filePath().toString();
const QString directivesKey = projectPartId + QLatin1Char(',') + filePath().toString();
const QByteArray additionalDirectives = ProjectExplorer::SessionManager::value(
directivesKey).toString().toUtf8();
setPreprocessorSettings(mm()->projectPartForProjectFile(projectFile), additionalDirectives);
setPreprocessorSettings(mm()->projectPartForId(projectPartId), additionalDirectives);
}
void CppEditorDocument::setPreprocessorSettings(const CppTools::ProjectPart::Ptr &projectPart,
......
......@@ -70,7 +70,7 @@ CppPreProcessorDialog::CppPreProcessorDialog(QWidget *parent, const QString &fil
ProjectPartAddition addition;
addition.projectPart = projectPart;
addition.additionalDirectives = ProjectExplorer::SessionManager::value(
projectPart->projectFile + QLatin1Char(',') + m_filePath).toString();
projectPart->id() + QLatin1Char(',') + m_filePath).toString();
if (projectPart->id() == projectPartIdToUse)
currentIndex = m_ui->projectComboBox->count() - 1;
m_partAdditions << addition;
......@@ -96,16 +96,16 @@ int CppPreProcessorDialog::exec()
ProjectExplorer::SessionManager::setValue(
QLatin1String(Constants::CPP_PREPROCESSOR_PROJECT_PREFIX) + m_filePath,
m_partAdditions[m_ui->projectComboBox->currentIndex()].projectPart->projectFile);
m_partAdditions[m_ui->projectComboBox->currentIndex()].projectPart->id());
foreach (ProjectPartAddition partAddition, m_partAdditions) {
const QString &previousDirectives = ProjectExplorer::SessionManager::value(
partAddition.projectPart->projectFile
partAddition.projectPart->id()
+ QLatin1Char(',')
+ m_filePath).toString();
if (previousDirectives != partAddition.additionalDirectives) {
ProjectExplorer::SessionManager::setValue(
partAddition.projectPart->projectFile + QLatin1Char(',') + m_filePath,
partAddition.projectPart->id() + QLatin1Char(',') + m_filePath,
partAddition.additionalDirectives);
}
}
......
......@@ -491,7 +491,7 @@ void Dumper::dumpProjectInfos( const QList<ProjectInfo> &projectInfos)
}
if (!part->projectConfigFile.isEmpty())
m_out << i3 << "Project Config File: " << part->projectConfigFile << "\n";
m_out << i2 << "Project Part \"" << part->projectFile << "\"{{{3\n";
m_out << i2 << "Project Part \"" << part->id() << "\"{{{3\n";
m_out << i3 << "Project Part Name : " << part->displayName << "\n";
m_out << i3 << "Project Name : " << projectName << "\n";
m_out << i3 << "Project File : " << projectFilePath << "\n";
......
......@@ -137,7 +137,7 @@ public:
mutable QMutex m_projectMutex;
QMap<ProjectExplorer::Project *, ProjectInfo> m_projectToProjectsInfo;
QMap<Utils::FileName, QList<ProjectPart::Ptr> > m_fileToProjectParts;
QMap<QString, ProjectPart::Ptr> m_projectFileToProjectPart;
QMap<QString, ProjectPart::Ptr> m_projectPartIdToProjectProjectPart;
// The members below are cached/(re)calculated from the projects and/or their project parts
bool m_dirty;
QStringList m_projectFiles;
......@@ -710,12 +710,12 @@ void CppModelManager::removeFilesFromSnapshot(const QSet<QString> &filesToRemove
d->m_snapshot.remove(i.next());
}
static QStringList projectFilePaths(const QSet<ProjectPart::Ptr> &projectParts)
static QStringList projectPartIds(const QSet<ProjectPart::Ptr> &projectParts)
{
QStringList result;
QSetIterator<ProjectPart::Ptr> it(projectParts);
while (it.hasNext())
result << it.next()->projectFile;
result << it.next()->id();
return result;
}
......@@ -752,7 +752,7 @@ public:
{
QSet<ProjectPart::Ptr> removed = m_old.projectParts().toSet();
removed.subtract(m_new.projectParts().toSet());
return projectFilePaths(removed);
return projectPartIds(removed);
}
/// Returns a list of common files that have a changed timestamp.
......@@ -781,13 +781,13 @@ private:
};
/// Make sure that m_projectMutex is locked when calling this.
void CppModelManager::recalculateFileToProjectParts()
void CppModelManager::recalculateProjectPartMappings()
{
d->m_projectFileToProjectPart.clear();
d->m_projectPartIdToProjectProjectPart.clear();
d->m_fileToProjectParts.clear();
foreach (const ProjectInfo &projectInfo, d->m_projectToProjectsInfo) {
foreach (const ProjectPart::Ptr &projectPart, projectInfo.projectParts()) {
d->m_projectFileToProjectPart[projectPart->projectFile] = projectPart;
d->m_projectPartIdToProjectProjectPart[projectPart->id()] = projectPart;
foreach (const ProjectFile &cxxFile, projectPart->files)
d->m_fileToProjectParts[Utils::FileName::fromString(cxxFile.path)].append(
projectPart);
......@@ -883,7 +883,7 @@ QFuture<void> CppModelManager::updateProjectInfo(const ProjectInfo &newProjectIn
// Update Project/ProjectInfo and File/ProjectPart table
d->m_projectToProjectsInfo.insert(project, newProjectInfo);
recalculateFileToProjectParts();
recalculateProjectPartMappings();
} // Mutex scope
......@@ -908,9 +908,9 @@ QFuture<void> CppModelManager::updateProjectInfo(const ProjectInfo &newProjectIn
return updateSourceFiles(filesToReindex, ForcedProgressNotification);
}
ProjectPart::Ptr CppModelManager::projectPartForProjectFile(const QString &projectFile) const
ProjectPart::Ptr CppModelManager::projectPartForId(const QString &projectPartId) const
{
return d->m_projectFileToProjectPart.value(projectFile);
return d->m_projectPartIdToProjectProjectPart.value(projectPartId);
}
QList<ProjectPart::Ptr> CppModelManager::projectPart(const Utils::FileName &fileName) const
......@@ -981,17 +981,17 @@ void CppModelManager::delayedGC()
d->m_delayedGcTimer.start(500);
}
static QStringList pathsOfAllProjectParts(const ProjectInfo &projectInfo)
static QStringList idsOfAllProjectParts(const ProjectInfo &projectInfo)
{
QStringList projectPaths;
foreach (const ProjectPart::Ptr &part, projectInfo.projectParts())
projectPaths << part->projectFile;
projectPaths << part->id();
return projectPaths;
}
void CppModelManager::onAboutToRemoveProject(ProjectExplorer::Project *project)
{
QStringList projectFilePaths;
QStringList projectPartIds;
{
QMutexLocker locker(&d->m_projectMutex);
......@@ -999,14 +999,14 @@ void CppModelManager::onAboutToRemoveProject(ProjectExplorer::Project *project)
// Save paths
const ProjectInfo projectInfo = d->m_projectToProjectsInfo.value(project, ProjectInfo());
projectFilePaths = pathsOfAllProjectParts(projectInfo);
projectPartIds = idsOfAllProjectParts(projectInfo);
d->m_projectToProjectsInfo.remove(project);
recalculateFileToProjectParts();
recalculateProjectPartMappings();
}
if (!projectFilePaths.isEmpty())
emit projectPartsRemoved(projectFilePaths);
if (!projectPartIds.isEmpty())
emit projectPartsRemoved(projectPartIds);
delayedGC();
}
......@@ -1085,7 +1085,7 @@ void CppModelManager::onAboutToUnloadSession()
do {
QMutexLocker locker(&d->m_projectMutex);
d->m_projectToProjectsInfo.clear();
recalculateFileToProjectParts();
recalculateProjectPartMappings();
d->m_dirty = true;
} while (0);
}
......
......@@ -94,7 +94,7 @@ public:
QFuture<void> updateProjectInfo(const ProjectInfo &newProjectInfo);
/// \return The project part with the given project file
ProjectPart::Ptr projectPartForProjectFile(const QString &projectFile) const;
ProjectPart::Ptr projectPartForId(const QString &projectPartId) const;
/// \return All project parts that mention the given file name as one of the sources/headers.
QList<ProjectPart::Ptr> projectPart(const Utils::FileName &fileName) const;
QList<ProjectPart::Ptr> projectPart(const QString &fileName) const
......@@ -170,7 +170,7 @@ signals:
void sourceFilesRefreshed(const QSet<QString> &files);
void projectPartsUpdated(ProjectExplorer::Project *project);
void projectPartsRemoved(const QStringList &projectFiles);
void projectPartsRemoved(const QStringList &projectPartIds);
void globalSnapshotChanged();
......@@ -198,7 +198,7 @@ private slots:
private:
void delayedGC();
void recalculateFileToProjectParts();
void recalculateProjectPartMappings();
void updateCppEditorDocuments() const;
void replaceSnapshot(const CPlusPlus::Snapshot &newSnapshot);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment