ui: update list indexed headers when editing the compilation database text box (issue #724)

This commit is contained in:
mlangkabel
2019-10-18 13:05:29 +02:00
committed by Eberhard Graether
parent f7262c805f
commit eb142cfb4e
9 changed files with 53 additions and 24 deletions
+4 -19
View File
@@ -10,23 +10,13 @@
#include "OrderedCache.h"
#include "ResourcePaths.h"
#include "utility.h"
#include "utilitySourceGroupCxx.h"
#include "utilityString.h"
std::shared_ptr<clang::tooling::JSONCompilationDatabase> IndexerCommandCxx::loadCDB(const FilePath& cdbPath)
std::vector<FilePath> IndexerCommandCxx::getSourceFilesFromCDB(const FilePath& cdbPath)
{
if (cdbPath.empty() || !cdbPath.exists())
{
return nullptr;
}
std::string error;
std::shared_ptr<clang::tooling::JSONCompilationDatabase> cdb = std::shared_ptr<clang::tooling::JSONCompilationDatabase>(
clang::tooling::JSONCompilationDatabase::loadFromFile(
utility::encodeToUtf8(cdbPath.wstr()),
error,
clang::tooling::JSONCommandLineSyntax::AutoDetect
)
);
std::shared_ptr<clang::tooling::JSONCompilationDatabase> cdb = utility::loadCDB(cdbPath, &error);
if (!error.empty())
{
@@ -35,12 +25,7 @@ std::shared_ptr<clang::tooling::JSONCompilationDatabase> IndexerCommandCxx::load
MessageStatus(message, true).dispatch();
}
return cdb;
}
std::vector<FilePath> IndexerCommandCxx::getSourceFilesFromCDB(const FilePath& cdbPath)
{
return getSourceFilesFromCDB(loadCDB(cdbPath), cdbPath);
return getSourceFilesFromCDB(cdb, cdbPath);
}
std::vector<FilePath> IndexerCommandCxx::getSourceFilesFromCDB(
@@ -17,7 +17,6 @@ class IndexerCommandCxx
: public IndexerCommand
{
public:
static std::shared_ptr<clang::tooling::JSONCompilationDatabase> loadCDB(const FilePath& cdbPath);
static std::vector<FilePath> getSourceFilesFromCDB(const FilePath& cdbPath);
static std::vector<FilePath> getSourceFilesFromCDB(
std::shared_ptr<clang::tooling::JSONCompilationDatabase> cdb, const FilePath& cdbPath);
@@ -9,6 +9,7 @@
struct ParseLocation;
struct ParseLocation;
class CanonicalFilePathCache;
class FilePath;
namespace clang
{
+3 -3
View File
@@ -47,7 +47,7 @@ std::set<FilePath> SourceGroupCxxCdb::filterToContainedFilePaths(const std::set<
std::set<FilePath> SourceGroupCxxCdb::getAllSourceFilePaths() const
{
return getAllSourceFilePaths(IndexerCommandCxx::loadCDB(m_settings->getCompilationDatabasePathExpandedAndAbsolute()));
return getAllSourceFilePaths(utility::loadCDB(m_settings->getCompilationDatabasePathExpandedAndAbsolute()));
}
std::set<FilePath> SourceGroupCxxCdb::getAllSourceFilePaths(std::shared_ptr<clang::tooling::JSONCompilationDatabase> cdb) const
@@ -85,7 +85,7 @@ std::shared_ptr<IndexerCommandProvider> SourceGroupCxxCdb::getIndexerCommandProv
std::shared_ptr<CxxIndexerCommandProvider> provider = std::make_shared<CxxIndexerCommandProvider>();
const FilePath cdbPath = m_settings->getCompilationDatabasePathExpandedAndAbsolute();
std::shared_ptr<clang::tooling::JSONCompilationDatabase> cdb = IndexerCommandCxx::loadCDB(cdbPath);
std::shared_ptr<clang::tooling::JSONCompilationDatabase> cdb = utility::loadCDB(cdbPath);
if (!cdb)
{
return provider;
@@ -161,7 +161,7 @@ std::shared_ptr<Task> SourceGroupCxxCdb::getPreIndexTask(
if (m_settings->getUseCompilerFlags())
{
const FilePath cdbPath = m_settings->getCompilationDatabasePathExpandedAndAbsolute();
std::shared_ptr<clang::tooling::JSONCompilationDatabase> cdb = IndexerCommandCxx::loadCDB(cdbPath);
std::shared_ptr<clang::tooling::JSONCompilationDatabase> cdb = utility::loadCDB(cdbPath);
if (cdb)
{
const std::set<FilePath> sourceFilePaths = getAllSourceFilePaths(cdb);
@@ -99,6 +99,30 @@ namespace utility
);
}
std::shared_ptr<clang::tooling::JSONCompilationDatabase> loadCDB(const FilePath& cdbPath, std::string* error)
{
if (cdbPath.empty() || !cdbPath.exists())
{
return std::shared_ptr<clang::tooling::JSONCompilationDatabase>();
}
std::string errorString;
std::shared_ptr<clang::tooling::JSONCompilationDatabase> cdb = std::shared_ptr<clang::tooling::JSONCompilationDatabase>(
clang::tooling::JSONCompilationDatabase::loadFromFile(
utility::encodeToUtf8(cdbPath.wstr()),
errorString,
clang::tooling::JSONCommandLineSyntax::AutoDetect
)
);
if (error && !errorString.empty())
{
*error = errorString;
}
return cdb;
}
bool containsIncludePchFlags(std::shared_ptr<clang::tooling::JSONCompilationDatabase> cdb)
{
for (const clang::tooling::CompileCommand& command : cdb->getAllCompileCommands())
@@ -12,6 +12,7 @@ namespace clang {
}
class DialogView;
class FilePath;
class SourceGroupSettingsWithCxxPchOptions;
class StorageProvider;
class Task;
@@ -24,6 +25,7 @@ namespace utility
std::shared_ptr<StorageProvider> storageProvider,
std::shared_ptr<DialogView> dialogView);
std::shared_ptr<clang::tooling::JSONCompilationDatabase> loadCDB(const FilePath& cdbPath, std::string* error = nullptr);
bool containsIncludePchFlags(std::shared_ptr<clang::tooling::JSONCompilationDatabase> cdb);
bool containsIncludePchFlag(const std::vector<std::string>& args);
std::vector<std::wstring> getWithRemoveIncludePchFlag(const std::vector<std::wstring>& args);
@@ -4,6 +4,7 @@
#include "SourceGroupCxxCdb.h"
#include "SourceGroupSettingsCxxCdb.h"
#include "utility.h"
#include "utilitySourceGroupCxx.h"
#include "utilityFile.h"
QtProjectWizardContentPathCDB::QtProjectWizardContentPathCDB(
@@ -37,6 +38,7 @@ void QtProjectWizardContentPathCDB::populate(QGridLayout* layout, int& row)
m_picker->setPickDirectory(false);
m_picker->setFileFilter("JSON Compilation Database (*.json)");
connect(m_picker, &QtLocationPicker::locationPicked, this, &QtProjectWizardContentPathCDB::pickedPath);
connect(m_picker, &QtLocationPicker::textChanged, this, &QtProjectWizardContentPathCDB::onPickerTextChanged);
QLabel* description = new QLabel(
"Sourcetrail will use all include paths and compiler flags from the Compilation Database and stay up-to-date "
@@ -112,6 +114,21 @@ void QtProjectWizardContentPathCDB::pickedPath()
m_window->loadContent();
}
void QtProjectWizardContentPathCDB::onPickerTextChanged(const QString& text)
{
const FilePath cdbPath = utility::getExpandedAndAbsolutePath(FilePath(text.toStdWString()), m_settings->getProjectDirectoryPath());
if (!cdbPath.empty() && cdbPath.exists() &&
cdbPath != m_settings->getCompilationDatabasePathExpandedAndAbsolute())
{
std::string error;
std::shared_ptr<clang::tooling::JSONCompilationDatabase> cdb = utility::loadCDB(cdbPath, &error);
if (cdb && error.empty())
{
pickedPath();
}
}
}
std::shared_ptr<SourceGroupSettings> QtProjectWizardContentPathCDB::getSourceGroupSettings()
{
return m_settings;
@@ -27,6 +27,7 @@ public:
private slots:
void pickedPath();
void onPickerTextChanged(const QString& text);
private:
std::shared_ptr<SourceGroupSettings> getSourceGroupSettings() override;
@@ -53,7 +53,7 @@ bool QtProjectWizardContentPathCxxPch::check()
if (std::shared_ptr<SourceGroupSettingsCxxCdb> cdbSettings = std::dynamic_pointer_cast<SourceGroupSettingsCxxCdb>(m_settings))
{
const FilePath cdbPath = cdbSettings->getCompilationDatabasePathExpandedAndAbsolute();
std::shared_ptr<clang::tooling::JSONCompilationDatabase> cdb = IndexerCommandCxx::loadCDB(cdbPath);
std::shared_ptr<clang::tooling::JSONCompilationDatabase> cdb = utility::loadCDB(cdbPath);
if (!cdb)
{
QMessageBox msgBox;