ui: store and display translation unit of recorded indexing errors

This commit is contained in:
mlangkabel
2018-07-02 13:00:41 +02:00
parent 6794b61fab
commit 7c09f3339b
17 changed files with 77 additions and 49 deletions
+1 -1
View File
@@ -144,7 +144,7 @@ void TaskBuildIndex::doExit(std::shared_ptr<Blackboard> blackboard)
is->addError(StorageErrorData(
L"The translation unit threw an exception during indexing. Please check if the source file "
"conforms to the specified language standard and all necessary options are defined within your project "
"setup.", path.wstr(), 1, 1, true, true
"setup.", path.wstr(), 1, 1, path.wstr(), true, true
));
LOG_INFO(L"crashed translation unit: " + path.wstr());
}
@@ -123,6 +123,7 @@ struct SharedStorageErrorData
const std::string& filePath,
uint lineNumber,
uint columnNumber,
const std::string& sourceFilePath,
bool fatal,
bool indexed,
SharedMemory::Allocator* allocator
@@ -131,6 +132,7 @@ struct SharedStorageErrorData
, filePath(filePath.c_str(), allocator)
, lineNumber(lineNumber)
, columnNumber(columnNumber)
, translationUnit(sourceFilePath.c_str(), allocator)
, fatal(fatal)
, indexed(indexed)
{}
@@ -141,6 +143,7 @@ struct SharedStorageErrorData
uint lineNumber;
uint columnNumber;
SharedMemory::String translationUnit;
bool fatal;
bool indexed;
};
@@ -152,6 +155,7 @@ inline SharedStorageErrorData toShared(const StorageErrorData& error, SharedMemo
utility::encodeToUtf8(error.filePath),
error.lineNumber,
error.columnNumber,
utility::encodeToUtf8(error.translationUnit),
error.fatal,
error.indexed, allocator
);
@@ -164,6 +168,7 @@ inline StorageErrorData fromShared(const SharedStorageErrorData& error)
utility::decodeFromUtf8(error.filePath.c_str()),
error.lineNumber,
error.columnNumber,
utility::decodeFromUtf8(error.translationUnit.c_str()),
error.fatal,
error.indexed
);
+2 -6
View File
@@ -75,14 +75,10 @@ ParserClient::ParserClient()
{
}
ParserClient::~ParserClient()
{
}
void ParserClient::recordError(
const ParseLocation& location, const std::wstring& message, bool fatal, bool indexed)
const ParseLocation& errorLocation, const std::wstring& message, bool fatal, bool indexed, const FilePath& translationUnit)
{
doRecordError(location, message, fatal, indexed);
doRecordError(errorLocation, message, fatal, indexed, translationUnit);
if (fatal)
{
+3 -3
View File
@@ -26,7 +26,7 @@ public:
const std::wstring& str, const ParseLocation& location, const ParseLocation& scopeLocation);
ParserClient();
virtual ~ParserClient();
virtual ~ParserClient() = default;
virtual Id recordSymbol(
const NameHierarchy& symbolName, SymbolKind symbolKind,
@@ -50,7 +50,7 @@ public:
const NameHierarchy& qualifierName, const ParseLocation& location) = 0;
void recordError(
const ParseLocation& location, const std::wstring& message, bool fatal, bool indexed);
const ParseLocation& errorLocation, const std::wstring& message, bool fatal, bool indexed, const FilePath& translationUnit);
virtual void recordLocalSymbol(const std::wstring& name, const ParseLocation& location) = 0;
virtual void recordFile(const FileInfo& fileInfo, bool indexed) = 0;
@@ -60,7 +60,7 @@ public:
protected:
virtual void doRecordError(
const ParseLocation& location, const std::wstring& message, bool fatal, bool indexed) = 0;
const ParseLocation& errorLocation, const std::wstring& message, bool fatal, bool indexed, const FilePath& translationUnit) = 0;
bool m_hasFatalErrors;
};
+4 -4
View File
@@ -91,11 +91,11 @@ void ParserClientImpl::recordComment(const ParseLocation& location)
}
void ParserClientImpl::doRecordError(
const ParseLocation& location, const std::wstring& message, bool fatal, bool indexed)
const ParseLocation& location, const std::wstring& message, bool fatal, bool indexed, const FilePath& translationUnit)
{
if (location.isValid())
{
addError(message, fatal, indexed, location);
addError(message, fatal, indexed, location, translationUnit);
}
}
@@ -331,7 +331,7 @@ void ParserClientImpl::addCommentLocation(const ParseLocation& location)
}
void ParserClientImpl::addError(
const std::wstring& message, bool fatal, bool indexed, const ParseLocation& location)
const std::wstring& message, bool fatal, bool indexed, const ParseLocation& location, const FilePath& translationUnit)
{
if (!m_storage)
{
@@ -339,6 +339,6 @@ void ParserClientImpl::addError(
}
m_storage->addError(StorageErrorData(
message, location.filePath.wstr(), location.startLineNumber, location.startColumnNumber, fatal, indexed
message, location.filePath.wstr(), location.startLineNumber, location.startColumnNumber, translationUnit.wstr(), fatal, indexed
));
}
+2 -2
View File
@@ -45,7 +45,7 @@ public:
private:
virtual void doRecordError(
const ParseLocation& location, const std::wstring& message, bool fatal, bool indexed) override;
const ParseLocation& location, const std::wstring& message, bool fatal, bool indexed, const FilePath& sourceFilePath) override;
NodeType symbolKindToNodeType(SymbolKind symbolType) const;
Edge::EdgeType referenceKindToEdgeType(ReferenceKind referenceKind) const;
@@ -61,7 +61,7 @@ private:
void addComponentAccess(Id nodeId , int type);
void addCommentLocation(const ParseLocation& location);
void addError(const std::wstring& message, bool fatal, bool indexed,
const ParseLocation& location);
const ParseLocation& location, const FilePath& sourceFilePath);
std::shared_ptr<IntermediateStorage> m_storage;
};
@@ -9,7 +9,7 @@
#include "data/location/SourceLocationCollection.h"
#include "data/location/SourceLocationFile.h"
const size_t SqliteIndexStorage::s_storageVersion = 16;
const size_t SqliteIndexStorage::s_storageVersion = 17;
SqliteIndexStorage::SqliteIndexStorage(const FilePath& dbFilePath)
: SqliteStorage(dbFilePath.getCanonical())
@@ -281,6 +281,7 @@ StorageError SqliteIndexStorage::addError(const StorageErrorData& data)
m_insertErrorStmt.bind(4, utility::encodeToUtf8(data.filePath).c_str());
m_insertErrorStmt.bind(5, int(data.lineNumber));
m_insertErrorStmt.bind(6, int(data.columnNumber));
m_insertErrorStmt.bind(7, utility::encodeToUtf8(data.translationUnit).c_str());
const bool success = executeStatement(m_insertErrorStmt);
if (success)
@@ -1056,6 +1057,7 @@ void SqliteIndexStorage::setupTables()
"file_path TEXT, "
"line_number INTEGER, "
"column_number INTEGER, "
"translation_unit TEXT, "
"PRIMARY KEY(id));"
);
}
@@ -1136,7 +1138,7 @@ void SqliteIndexStorage::setupPrecompiledStatements()
"LIMIT 1;"
);
m_insertErrorStmt = m_database.compileStatement(
"INSERT INTO error(message, fatal, indexed, file_path, line_number, column_number) VALUES(?, ?, ?, ?, ?, ?);"
"INSERT INTO error(message, fatal, indexed, file_path, line_number, column_number, translation_unit) VALUES(?, ?, ?, ?, ?, ?, ?);"
);
}
catch (CppSQLite3Exception& e)
@@ -1383,7 +1385,7 @@ template <>
std::vector<StorageError> SqliteIndexStorage::doGetAll<StorageError>(const std::string& query) const
{
CppSQLite3Query q = executeQuery(
"SELECT message, fatal, indexed, file_path, line_number, column_number FROM error " + query + ";"
"SELECT message, fatal, indexed, file_path, line_number, column_number, translation_unit FROM error " + query + ";"
);
std::vector<StorageError> errors;
@@ -1396,11 +1398,12 @@ std::vector<StorageError> SqliteIndexStorage::doGetAll<StorageError>(const std::
const std::string filePath = q.getStringField(3, "");
const int lineNumber = q.getIntField(4, -1);
const int columnNumber = q.getIntField(5, -1);
const std::string translationUnit = q.getStringField(6, "");
if (lineNumber != -1 && columnNumber != -1)
{
errors.push_back(StorageError(
id, utility::decodeFromUtf8(message), utility::decodeFromUtf8(filePath), lineNumber, columnNumber, fatal, indexed)
id, utility::decodeFromUtf8(message), utility::decodeFromUtf8(filePath), lineNumber, columnNumber, utility::decodeFromUtf8(translationUnit), fatal, indexed)
);
id++;
}
+6
View File
@@ -13,6 +13,7 @@ struct StorageErrorData
, filePath(L"")
, lineNumber(-1)
, columnNumber(-1)
, translationUnit(L"")
, fatal(0)
, indexed(0)
{}
@@ -22,6 +23,7 @@ struct StorageErrorData
const std::wstring& filePath,
uint lineNumber,
uint columnNumber,
const std::wstring& translationUnit,
bool fatal,
bool indexed
)
@@ -29,6 +31,7 @@ struct StorageErrorData
, filePath(filePath)
, lineNumber(lineNumber)
, columnNumber(columnNumber)
, translationUnit(translationUnit)
, fatal(fatal)
, indexed(indexed)
{}
@@ -39,6 +42,7 @@ struct StorageErrorData
uint lineNumber;
uint columnNumber;
std::wstring translationUnit;
bool fatal;
bool indexed;
};
@@ -61,6 +65,7 @@ struct StorageError: public StorageErrorData
const std::wstring& filePath,
uint lineNumber,
uint columnNumber,
const std::wstring& translationUnit,
bool fatal,
bool indexed
)
@@ -69,6 +74,7 @@ struct StorageError: public StorageErrorData
filePath,
lineNumber,
columnNumber,
translationUnit,
fatal,
indexed
)
@@ -16,12 +16,14 @@ CxxDiagnosticConsumer::CxxDiagnosticConsumer(
std::shared_ptr<ParserClient> client,
std::shared_ptr<FileRegister> fileRegister,
std::shared_ptr<CanonicalFilePathCache> canonicalFilePathCache,
const FilePath& sourceFilePath,
bool useLogging
)
: clang::TextDiagnosticPrinter(os, diags)
, m_client(client)
, m_register(fileRegister)
, m_canonicalFilePathCache(canonicalFilePathCache)
, m_sourceFilePath(sourceFilePath)
, m_isParsingFile(false)
, m_useLogging(useLogging)
{
@@ -34,6 +36,8 @@ void CxxDiagnosticConsumer::BeginSourceFile(const clang::LangOptions& langOption
clang::TextDiagnosticPrinter::BeginSourceFile(langOptions, preProcessor);
}
m_isParsingFile = true;
}
@@ -107,7 +111,8 @@ void CxxDiagnosticConsumer::HandleDiagnostic(clang::DiagnosticsEngine::Level lev
location,
utility::decodeFromUtf8(message),
level == clang::DiagnosticsEngine::Fatal,
m_register->hasFilePath(location.filePath)
m_register->hasFilePath(location.filePath),
m_sourceFilePath
);
}
}
@@ -2,6 +2,7 @@
#define CXX_DIAGNOSTIC_CONSUMER
#include "clang/Frontend/TextDiagnosticPrinter.h"
#include "utility/file/FilePath.h"
class CanonicalFilePathCache;
class FileRegister;
@@ -17,6 +18,7 @@ public:
std::shared_ptr<ParserClient> client,
std::shared_ptr<FileRegister> fileRegister,
std::shared_ptr<CanonicalFilePathCache> canonicalFilePathCache,
const FilePath& sourceFilePath,
bool useLogging = true
);
@@ -30,6 +32,7 @@ private:
std::shared_ptr<FileRegister> m_register;
std::shared_ptr<CanonicalFilePathCache> m_canonicalFilePathCache;
const FilePath m_sourceFilePath;
bool m_isParsingFile;
bool m_useLogging;
};
+5 -4
View File
@@ -110,7 +110,7 @@ void CxxParser::buildIndex(const std::wstring& fileName, std::shared_ptr<TextAcc
{
std::shared_ptr<CanonicalFilePathCache> canonicalFilePathCache = std::make_shared<CanonicalFilePathCache>();
std::shared_ptr<CxxDiagnosticConsumer> diagnostics = getDiagnostics(canonicalFilePathCache, false);
std::shared_ptr<CxxDiagnosticConsumer> diagnostics = getDiagnostics(FilePath(), canonicalFilePathCache, false);
ASTActionFactory actionFactory(m_client, m_fileRegister, canonicalFilePathCache);
std::vector<std::string> args = getCommandlineArgumentsEssential(compilerFlags, std::vector<FilePath>(), std::vector<FilePath>());
@@ -130,7 +130,7 @@ void CxxParser::runTool(clang::tooling::CompilationDatabase* compilationDatabase
std::shared_ptr<CanonicalFilePathCache> canonicalFilePathCache = std::make_shared<CanonicalFilePathCache>();
std::shared_ptr<CxxDiagnosticConsumer> diagnostics = getDiagnostics(canonicalFilePathCache, true);
std::shared_ptr<CxxDiagnosticConsumer> diagnostics = getDiagnostics(sourceFilePath, canonicalFilePathCache, true);
tool.setDiagnosticConsumer(diagnostics.get());
@@ -195,9 +195,10 @@ std::vector<std::string> CxxParser::getCommandlineArguments(std::shared_ptr<Inde
return args;
}
std::shared_ptr<CxxDiagnosticConsumer> CxxParser::getDiagnostics(std::shared_ptr<CanonicalFilePathCache> canonicalFilePathCache, bool logErrors) const
std::shared_ptr<CxxDiagnosticConsumer> CxxParser::getDiagnostics(const FilePath& sourceFilePath, std::shared_ptr<CanonicalFilePathCache> canonicalFilePathCache, bool logErrors) const
{
llvm::IntrusiveRefCntPtr<clang::DiagnosticOptions> options = new clang::DiagnosticOptions();
return std::make_shared<CxxDiagnosticConsumer>(
llvm::errs(), &*options, m_client, m_fileRegister, canonicalFilePathCache, logErrors);
llvm::errs(), &*options, m_client, m_fileRegister, canonicalFilePathCache, sourceFilePath, logErrors
);
}
+2 -1
View File
@@ -37,7 +37,8 @@ private:
const std::vector<FilePath>& frameworkSearchPaths) const;
std::vector<std::string> getCommandlineArguments(std::shared_ptr<IndexerCommandCxxEmpty> indexerCommand) const;
std::shared_ptr<CxxDiagnosticConsumer> getDiagnostics(std::shared_ptr<CanonicalFilePathCache> canonicalFilePathCache, bool logErrors) const;
std::shared_ptr<CxxDiagnosticConsumer> getDiagnostics(
const FilePath& sourceFilePath, std::shared_ptr<CanonicalFilePathCache> canonicalFilePathCache, bool logErrors) const;
friend class TaskParseCxx;
+22 -18
View File
@@ -86,14 +86,15 @@ void QtErrorView::initView()
// Setup Table Headers
m_model->setColumnCount(COLUMN_MAX + 1);
m_table->setColumnWidth(COLUMN::ID, 40);
m_table->setColumnWidth(COLUMN::TYPE, 80);
m_table->setColumnWidth(COLUMN::MESSAGE, 450);
m_table->setColumnWidth(COLUMN::FILE, 300);
m_table->setColumnWidth(COLUMN::LINE, 50);
m_table->setColumnWidth(Column::ID, 40);
m_table->setColumnWidth(Column::TYPE, 80);
m_table->setColumnWidth(Column::MESSAGE, 450);
m_table->setColumnWidth(Column::FILE, 300);
m_table->setColumnWidth(Column::LINE, 50);
m_table->setColumnWidth(Column::TRANSLATION_UNIT, 300);
QStringList headers;
headers << "ID" << "Type" << "Message" << "File" << "Line" << "Indexed";
headers << "ID" << "Type" << "Message" << "File" << "Line" << "Indexed" << "Translation Unit";
m_model->setHorizontalHeaderLabels(headers);
connect(m_table->selectionModel(), &QItemSelectionModel::currentRowChanged,
@@ -101,12 +102,12 @@ void QtErrorView::initView()
{
if (index.isValid() && !m_ignoreRowSelection)
{
if (m_model->item(index.row(), COLUMN::FILE) == nullptr)
if (m_model->item(index.row(), Column::FILE) == nullptr)
{
return;
}
Id errorId = m_model->item(index.row(), COLUMN::ID)->text().toUInt();
Id errorId = m_model->item(index.row(), Column::ID)->text().toUInt();
m_controllerProxy.executeAsTaskWithArgs(&ErrorController::showError, errorId);
}
@@ -263,7 +264,7 @@ void QtErrorView::setErrorId(Id errorId)
{
m_onQtThread([=]()
{
QList<QStandardItem*> items = m_model->findItems(QString::number(errorId), Qt::MatchExactly, COLUMN::ID);
QList<QStandardItem*> items = m_model->findItems(QString::number(errorId), Qt::MatchExactly, Column::ID);
if (items.size() == 1)
{
@@ -360,25 +361,28 @@ void QtErrorView::addErrorToTable(const ErrorInfo& error)
QStandardItem *item = new QStandardItem();
item->setData(QVariant(qlonglong(error.id)), Qt::DisplayRole);
m_model->setItem(rowNumber, COLUMN::ID, item);
m_model->setItem(rowNumber, Column::ID, item);
m_model->setItem(rowNumber, COLUMN::TYPE, new QStandardItem(error.fatal ? "FATAL" : "ERROR"));
m_model->setItem(rowNumber, Column::TYPE, new QStandardItem(error.fatal ? "FATAL" : "ERROR"));
if (error.fatal)
{
m_model->item(rowNumber, COLUMN::TYPE)->setForeground(QBrush(Qt::red));
m_model->item(rowNumber, Column::TYPE)->setForeground(QBrush(Qt::red));
}
m_model->item(rowNumber, COLUMN::TYPE)->setIcon(s_errorIcon);
m_model->item(rowNumber, Column::TYPE)->setIcon(s_errorIcon);
m_model->setItem(rowNumber, COLUMN::MESSAGE, new QStandardItem(QString::fromStdWString(error.message)));
m_model->setItem(rowNumber, Column::MESSAGE, new QStandardItem(QString::fromStdWString(error.message)));
m_model->setItem(rowNumber, COLUMN::FILE, new QStandardItem(QString::fromStdWString(error.filePath)));
m_model->item(rowNumber, COLUMN::FILE)->setToolTip(QString::fromStdWString(error.filePath));
m_model->setItem(rowNumber, Column::FILE, new QStandardItem(QString::fromStdWString(error.filePath)));
m_model->item(rowNumber, Column::FILE)->setToolTip(QString::fromStdWString(error.filePath));
item = new QStandardItem();
item->setData(QVariant(error.lineNumber), Qt::DisplayRole);
m_model->setItem(rowNumber, COLUMN::LINE, item);
m_model->setItem(rowNumber, Column::LINE, item);
m_model->setItem(rowNumber, COLUMN::INDEXED, new QStandardItem(error.indexed ? "yes" : "no"));
m_model->setItem(rowNumber, Column::INDEXED, new QStandardItem(error.indexed ? "yes" : "no"));
m_model->setItem(rowNumber, Column::TRANSLATION_UNIT, new QStandardItem(QString::fromStdWString(error.translationUnit)));
m_model->item(rowNumber, Column::TRANSLATION_UNIT)->setToolTip(QString::fromStdWString(error.translationUnit));
}
QCheckBox* QtErrorView::createFilterCheckbox(const QString& name, bool checked, QBoxLayout* layout)
+4 -2
View File
@@ -48,14 +48,16 @@ private slots:
void errorFilterChanged(int i = 0);
private:
enum COLUMN {
enum Column
{
ID = 0,
TYPE = 1,
MESSAGE = 2,
FILE = 3,
LINE = 4,
INDEXED = 5,
COLUMN_MAX = INDEXED
TRANSLATION_UNIT = 6,
COLUMN_MAX = TRANSLATION_UNIT
};
void setStyleSheet() const;
+2 -1
View File
@@ -265,6 +265,7 @@ void JavaParser::doRecordError(
ParseLocation(m_currentFilePath, beginLine, beginColumn, endLine, endColumn),
utility::decodeFromUtf8(m_javaEnvironment->toStdString(jMessage)),
fatal,
indexed
indexed,
FilePath()
);
}
+1 -1
View File
@@ -97,7 +97,7 @@ public:
private:
virtual void doRecordError(const ParseLocation& location, const std::wstring& message,
bool fatal, bool indexed) override
bool fatal, bool indexed, const FilePath& translationUnit) override
{
recordLine(L"ERROR: " + addLocationSuffix(message + L" [" + location.filePath.fileName(), location) + L"]\n");
}
+2 -1
View File
@@ -166,7 +166,8 @@ private:
const ParseLocation& location,
const std::wstring& message,
bool fatal,
bool indexed) override
bool indexed,
const FilePath& translationUnit) override
{
if (location.isValid())
{