forked from qt-creator/qt-creator
Clang: Update symbol database if file has changed
The code in the symbol indexer is quite similar, but still different enough to prevent easy reuse of the function. Change-Id: I47907d90066da922eafe8ff3cce124ea47ea4a0a Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
This commit is contained in:
@@ -17,7 +17,8 @@ HEADERS += \
|
||||
$$PWD/symbolsvisitorbase.h \
|
||||
$$PWD/usedmacro.h \
|
||||
$$PWD/sourcedependency.h \
|
||||
$$PWD/filestatus.h
|
||||
$$PWD/filestatus.h \
|
||||
$$PWD/projectpartartefacts.h
|
||||
|
||||
!isEmpty(LIBTOOLING_LIBS) {
|
||||
SOURCES += \
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2017 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/smallstringvector.h>
|
||||
|
||||
#include <QJsonArray>
|
||||
#include <QJsonDocument>
|
||||
|
||||
namespace ClangBackEnd {
|
||||
|
||||
class ProjectPartArtefact
|
||||
{
|
||||
public:
|
||||
ProjectPartArtefact(Utils::SmallStringView compilerArgumentsText,
|
||||
Utils::SmallStringView macroNamesText,
|
||||
int projectPartId)
|
||||
: compilerArguments(toVector(compilerArgumentsText)),
|
||||
macroNames(toVector(macroNamesText)),
|
||||
projectPartId(projectPartId)
|
||||
{
|
||||
}
|
||||
|
||||
static
|
||||
Utils::SmallStringVector toVector(Utils::SmallStringView jsonText)
|
||||
{
|
||||
QJsonDocument document = QJsonDocument::fromJson(QByteArray::fromRawData(jsonText.data(),
|
||||
jsonText.size()));
|
||||
|
||||
return Utils::transform<Utils::SmallStringVector>(document.array(), [] (const QJsonValue &value) {
|
||||
return Utils::SmallString{value.toString()};
|
||||
});
|
||||
}
|
||||
|
||||
friend
|
||||
bool operator==(const ProjectPartArtefact &first, const ProjectPartArtefact &second)
|
||||
{
|
||||
return first.compilerArguments == second.compilerArguments
|
||||
&& first.macroNames == second.macroNames;
|
||||
}
|
||||
|
||||
public:
|
||||
Utils::SmallStringVector compilerArguments;
|
||||
Utils::SmallStringVector macroNames;
|
||||
int projectPartId = -1;
|
||||
};
|
||||
|
||||
using ProjectPartArtefacts = std::vector<ProjectPartArtefact>;
|
||||
}
|
||||
@@ -217,6 +217,10 @@ public:
|
||||
"DELETE FROM newSourceDependencies",
|
||||
database
|
||||
};
|
||||
ReadStatement getProjectPartCompilerArgumentsAndMacroNames{
|
||||
"SELECT compilerArguments, macroNames, projectPartId FROM projectParts WHERE projectPartId = (SELECT projectPartId FROM projectPartsSources WHERE sourceId = ?)",
|
||||
database
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace ClangBackEnd
|
||||
|
||||
@@ -85,7 +85,39 @@ void SymbolIndexer::pathsWithIdsChanged(const Utils::SmallStringVector &)
|
||||
|
||||
void SymbolIndexer::pathsChanged(const FilePathIds &filePathIds)
|
||||
{
|
||||
for (FilePathId filePathId : filePathIds)
|
||||
updateChangedPath(filePathId);
|
||||
}
|
||||
|
||||
void SymbolIndexer::updateChangedPath(FilePathId filePathId)
|
||||
{
|
||||
m_symbolsCollector.clear();
|
||||
|
||||
const Utils::optional<ProjectPartArtefact> optionalArtefact = m_symbolStorage.fetchProjectPartArtefact(filePathId);
|
||||
|
||||
if (optionalArtefact) {
|
||||
const ProjectPartArtefact &artefact = optionalArtefact.value();
|
||||
|
||||
m_symbolsCollector.addFiles({filePathId}, artefact.compilerArguments);
|
||||
|
||||
m_symbolsCollector.collectSymbols();
|
||||
|
||||
Sqlite::ImmediateTransaction transaction{m_transactionInterface};
|
||||
|
||||
m_symbolStorage.addSymbolsAndSourceLocations(m_symbolsCollector.symbols(),
|
||||
m_symbolsCollector.sourceLocations());
|
||||
|
||||
m_symbolStorage.updateProjectPartSources(artefact.projectPartId,
|
||||
m_symbolsCollector.sourceFiles());
|
||||
|
||||
m_symbolStorage.insertOrUpdateUsedMacros(m_symbolsCollector.usedMacros());
|
||||
|
||||
m_symbolStorage.insertFileStatuses(m_symbolsCollector.fileStatuses());
|
||||
|
||||
m_symbolStorage.insertOrUpdateSourceDependencies(m_symbolsCollector.sourceDependencies());
|
||||
|
||||
transaction.commit();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace ClangBackEnd
|
||||
|
||||
@@ -50,6 +50,7 @@ public:
|
||||
|
||||
void pathsWithIdsChanged(const Utils::SmallStringVector &ids) override;
|
||||
void pathsChanged(const FilePathIds &filePathIds) override;
|
||||
void updateChangedPath(FilePathId filePath);
|
||||
|
||||
private:
|
||||
SymbolsCollectorInterface &m_symbolsCollector;
|
||||
|
||||
@@ -83,6 +83,13 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
Utils::optional<ProjectPartArtefact> fetchProjectPartArtefact(FilePathId sourceId) const override
|
||||
{
|
||||
ReadStatement &statement = m_statementFactory.getProjectPartCompilerArgumentsAndMacroNames;
|
||||
|
||||
return statement.template value<ProjectPartArtefact, 3>(sourceId.filePathId);
|
||||
}
|
||||
|
||||
void insertOrUpdateUsedMacros(const UsedMacros &usedMacros) override
|
||||
{
|
||||
WriteStatement &insertStatement = m_statementFactory.insertIntoNewUsedMacrosStatement;
|
||||
@@ -112,6 +119,12 @@ public:
|
||||
ReadStatement &getProjectPartIdStatement = m_statementFactory.getProjectPartIdStatement;
|
||||
int projectPartId = getProjectPartIdStatement.template value<int>(projectPartName).value();
|
||||
|
||||
updateProjectPartSources(projectPartId, sourceFilePathIds);
|
||||
}
|
||||
|
||||
void updateProjectPartSources(int projectPartId,
|
||||
const FilePathIds &sourceFilePathIds) override
|
||||
{
|
||||
WriteStatement &deleteStatement = m_statementFactory.deleteAllProjectPartsSourcesWithProjectPartIdStatement;
|
||||
deleteStatement.write(projectPartId);
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
|
||||
#include "filestatus.h"
|
||||
#include "projectpartentry.h"
|
||||
#include "projectpartartefacts.h"
|
||||
#include "sourcelocationentry.h"
|
||||
#include "sourcedependency.h"
|
||||
#include "symbolentry.h"
|
||||
@@ -51,9 +52,12 @@ public:
|
||||
const Utils::SmallStringVector ¯oNames) = 0;
|
||||
virtual void updateProjectPartSources(Utils::SmallStringView projectPartName,
|
||||
const FilePathIds &sourceFilePathIds) = 0;
|
||||
virtual void updateProjectPartSources(int projectPartId,
|
||||
const FilePathIds &sourceFilePathIds) = 0;
|
||||
virtual void insertOrUpdateUsedMacros(const UsedMacros &usedMacros) = 0;
|
||||
virtual void insertFileStatuses(const FileStatuses &fileStatuses) = 0;
|
||||
virtual void insertOrUpdateSourceDependencies(const SourceDependencies &sourceDependencies) = 0;
|
||||
virtual Utils::optional<ProjectPartArtefact> fetchProjectPartArtefact(FilePathId sourceId) const = 0;
|
||||
};
|
||||
|
||||
} // namespace ClangBackEnd
|
||||
|
||||
Reference in New Issue
Block a user