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: Marco Bubke <marco.bubke@theqtcompany.com>
This commit is contained in:
Nikolai Kosjar
2015-07-14 17:30:17 +02:00
parent 95c90dcd42
commit 420bc69739
15 changed files with 56 additions and 57 deletions

View File

@@ -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);
}

View File

@@ -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,

View File

@@ -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

View File

@@ -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);

View File

@@ -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()

View File

@@ -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

View File

@@ -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;

View File

@@ -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();
}

View File

@@ -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

View File

@@ -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"