logic: Hide non-fatal errors in unindexed files
* added database field indexed to error to tell if the error occured within an indexed file * added checkbox to Preferences for showing them
This commit is contained in:
@@ -8,12 +8,12 @@ struct ErrorCountInfo
|
||||
, fatal(0)
|
||||
{}
|
||||
|
||||
ErrorCountInfo(int total, size_t fatal)
|
||||
ErrorCountInfo(size_t total, size_t fatal)
|
||||
: total(total)
|
||||
, fatal(fatal)
|
||||
{}
|
||||
|
||||
int total;
|
||||
size_t total;
|
||||
size_t fatal;
|
||||
};
|
||||
|
||||
|
||||
@@ -138,11 +138,12 @@ void IntermediateStorage::addCommentLocation(Id fileNodeId, uint startLine, uint
|
||||
));
|
||||
}
|
||||
|
||||
void IntermediateStorage::addError(const std::string& message, bool fatal, const std::string& filePath, uint startLine, uint startCol)
|
||||
void IntermediateStorage::addError(const std::string& message, bool fatal, bool indexed, const std::string& filePath, uint startLine, uint startCol)
|
||||
{
|
||||
m_errors.push_back(StorageError(
|
||||
message,
|
||||
fatal,
|
||||
indexed,
|
||||
filePath,
|
||||
startLine,
|
||||
startCol
|
||||
|
||||
@@ -21,7 +21,7 @@ public:
|
||||
virtual void addSourceLocation(Id elementId, Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol, int type);
|
||||
virtual void addComponentAccess(Id edgeId , int type);
|
||||
virtual void addCommentLocation(Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol);
|
||||
virtual void addError(const std::string& message, bool fatal, const std::string& filePath, uint startLine, uint startCol);
|
||||
virtual void addError(const std::string& message, bool fatal, bool indexed, const std::string& filePath, uint startLine, uint startCol);
|
||||
|
||||
virtual void forEachFile(std::function<void(const Id /*id*/, const StorageFile& /*data*/)> callback) const;
|
||||
virtual void forEachNode(std::function<void(const Id /*id*/, const StorageNode& /*data*/)> callback) const;
|
||||
|
||||
@@ -136,11 +136,12 @@ void PersistentStorage::addCommentLocation(Id fileNodeId, uint startLine, uint s
|
||||
}
|
||||
|
||||
void PersistentStorage::addError(
|
||||
const std::string& message, bool fatal, const std::string& filePath, uint startLine, uint startCol)
|
||||
const std::string& message, bool fatal, bool indexed, const std::string& filePath, uint startLine, uint startCol)
|
||||
{
|
||||
m_sqliteStorage.addError(
|
||||
message,
|
||||
fatal,
|
||||
indexed,
|
||||
filePath,
|
||||
startLine,
|
||||
startCol
|
||||
@@ -224,14 +225,12 @@ void PersistentStorage::finishInjection()
|
||||
m_sqliteStorage.commitTransaction();
|
||||
|
||||
ErrorCountInfo errorCount = getErrorCount();
|
||||
if (m_preInjectionErrorCount != -1 &&
|
||||
m_preInjectionErrorCount != errorCount.total)
|
||||
if (m_preInjectionErrorCount != errorCount.total)
|
||||
{
|
||||
MessageShowErrors msg(errorCount);
|
||||
msg.setSendAsTask(false);
|
||||
msg.dispatchImmediately();
|
||||
}
|
||||
m_preInjectionErrorCount = -1;
|
||||
}
|
||||
|
||||
FilePath PersistentStorage::getDbFilePath() const
|
||||
@@ -988,14 +987,19 @@ std::shared_ptr<TokenLocationCollection> PersistentStorage::getErrorTokenLocatio
|
||||
|
||||
std::shared_ptr<TokenLocationCollection> errorCollection = std::make_shared<TokenLocationCollection>();
|
||||
|
||||
bool showExternalNonFatalErrors = ApplicationSettings::getInstance()->getShowExternalNonFatalErrors();
|
||||
|
||||
std::vector<StorageError> storageErrors = m_sqliteStorage.getAllErrors();
|
||||
for (size_t i = 0; i < storageErrors.size(); i++)
|
||||
{
|
||||
const StorageError& error = storageErrors[i];
|
||||
errorCollection->addTokenLocation(
|
||||
i, i, error.filePath, error.lineNumber, error.columnNumber, error.lineNumber, error.columnNumber
|
||||
)->setType(LOCATION_ERROR);
|
||||
errors->push_back(ErrorInfo(error.message, error.filePath, i, error.fatal));
|
||||
if (error.fatal || error.indexed || showExternalNonFatalErrors)
|
||||
{
|
||||
errorCollection->addTokenLocation(
|
||||
i, i, error.filePath, error.lineNumber, error.columnNumber, error.lineNumber, error.columnNumber
|
||||
)->setType(LOCATION_ERROR);
|
||||
errors->push_back(ErrorInfo(error.message, error.filePath, i, error.fatal));
|
||||
}
|
||||
}
|
||||
|
||||
return errorCollection;
|
||||
@@ -1048,7 +1052,25 @@ std::vector<FileInfo> PersistentStorage::getFileInfosForFilePaths(const std::vec
|
||||
|
||||
ErrorCountInfo PersistentStorage::getErrorCount() const
|
||||
{
|
||||
return ErrorCountInfo(m_sqliteStorage.getAllErrors().size(), m_sqliteStorage.getFatalErrors().size());
|
||||
bool showExternalNonFatalErrors = ApplicationSettings::getInstance()->getShowExternalNonFatalErrors();
|
||||
|
||||
ErrorCountInfo info;
|
||||
|
||||
std::vector<StorageError> storageErrors = m_sqliteStorage.getAllErrors();
|
||||
for (const StorageError& error : storageErrors)
|
||||
{
|
||||
if (error.fatal || error.indexed || showExternalNonFatalErrors)
|
||||
{
|
||||
info.total++;
|
||||
}
|
||||
|
||||
if (error.fatal)
|
||||
{
|
||||
info.fatal++;
|
||||
}
|
||||
}
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
StorageStats PersistentStorage::getStorageStats() const
|
||||
|
||||
@@ -34,7 +34,7 @@ public:
|
||||
virtual void addSourceLocation(Id elementId, Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol, int type);
|
||||
virtual void addComponentAccess(Id edgeId , int type);
|
||||
virtual void addCommentLocation(Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol);
|
||||
virtual void addError(const std::string& message, bool fatal, const std::string& filePath, uint startLine, uint startCol);
|
||||
virtual void addError(const std::string& message, bool fatal, bool indexed, const std::string& filePath, uint startLine, uint startCol);
|
||||
|
||||
virtual void forEachFile(std::function<void(const Id /*id*/, const StorageFile& /*data*/)> callback) const;
|
||||
virtual void forEachNode(std::function<void(const Id /*id*/, const StorageNode& /*data*/)> callback) const;
|
||||
@@ -139,7 +139,7 @@ private:
|
||||
|
||||
void log(std::string type, std::string str, const ParseLocation& location) const;
|
||||
|
||||
int m_preInjectionErrorCount;
|
||||
size_t m_preInjectionErrorCount;
|
||||
|
||||
SearchIndex m_commandIndex;
|
||||
SearchIndex m_elementIndex;
|
||||
|
||||
@@ -200,7 +200,7 @@ Id SqliteStorage::addCommentLocation(Id fileNodeId, uint startLine, uint startCo
|
||||
return m_database.lastRowId();
|
||||
}
|
||||
|
||||
Id SqliteStorage::addError(const std::string& message, bool fatal, const std::string& filePath, uint lineNumber, uint columnNumber)
|
||||
Id SqliteStorage::addError(const std::string& message, bool fatal, bool indexed, const std::string& filePath, uint lineNumber, uint columnNumber)
|
||||
{
|
||||
std::string sanitizedMessage = utility::replace((fatal ? "Fatal: " : "Error: ") + message, "'", "''");
|
||||
|
||||
@@ -226,8 +226,8 @@ Id SqliteStorage::addError(const std::string& message, bool fatal, const std::st
|
||||
stmt.finalize();
|
||||
|
||||
stmt = m_database.compileStatement((
|
||||
"INSERT INTO error(message, fatal, file_path, line_number, column_number) "
|
||||
"VALUES (?, " + std::to_string(fatal) + ", '" + filePath +
|
||||
"INSERT INTO error(message, fatal, indexed, file_path, line_number, column_number) "
|
||||
"VALUES (?, " + std::to_string(fatal) + ", " + std::to_string(indexed) + ", '" + filePath +
|
||||
"', " + std::to_string(lineNumber) + ", " + std::to_string(columnNumber) + ");"
|
||||
).c_str());
|
||||
|
||||
@@ -550,11 +550,6 @@ std::vector<StorageCommentLocation> SqliteStorage::getCommentLocationsInFile(con
|
||||
return getAll<StorageCommentLocation>("WHERE file_node_id == " + std::to_string(fileNodeId));
|
||||
}
|
||||
|
||||
std::vector<StorageError> SqliteStorage::getFatalErrors() const
|
||||
{
|
||||
return getAll<StorageError>("WHERE fatal == 1");
|
||||
}
|
||||
|
||||
std::vector<StorageFile> SqliteStorage::getAllFiles() const
|
||||
{
|
||||
return getAll<StorageFile>("");
|
||||
@@ -752,6 +747,7 @@ void SqliteStorage::setupTables()
|
||||
"id INTEGER NOT NULL, "
|
||||
"message TEXT, "
|
||||
"fatal INTEGER NOT NULL, "
|
||||
"indexed INTEGER NOT NULL, "
|
||||
"file_path TEXT, "
|
||||
"line_number INTEGER, "
|
||||
"column_number INTEGER, "
|
||||
@@ -990,7 +986,7 @@ template <>
|
||||
std::vector<StorageError> SqliteStorage::getAll<StorageError>(const std::string& query) const
|
||||
{
|
||||
CppSQLite3Query q = m_database.execQuery((
|
||||
"SELECT message, fatal, file_path, line_number, column_number FROM error " + query + ";"
|
||||
"SELECT message, fatal, indexed, file_path, line_number, column_number FROM error " + query + ";"
|
||||
).c_str());
|
||||
|
||||
std::vector<StorageError> errors;
|
||||
@@ -998,13 +994,14 @@ std::vector<StorageError> SqliteStorage::getAll<StorageError>(const std::string&
|
||||
{
|
||||
const std::string message = q.getStringField(0, "");
|
||||
const bool fatal = q.getIntField(1, 0);
|
||||
const std::string filePath = q.getStringField(2, "");
|
||||
const int lineNumber = q.getIntField(3, -1);
|
||||
const int columnNumber = q.getIntField(4, -1);
|
||||
const bool indexed = q.getIntField(2, 0);
|
||||
const std::string filePath = q.getStringField(3, "");
|
||||
const int lineNumber = q.getIntField(4, -1);
|
||||
const int columnNumber = q.getIntField(5, -1);
|
||||
|
||||
if (lineNumber != -1 && columnNumber != -1)
|
||||
{
|
||||
errors.push_back(StorageError(message, fatal, filePath, lineNumber, columnNumber));
|
||||
errors.push_back(StorageError(message, fatal, indexed, filePath, lineNumber, columnNumber));
|
||||
}
|
||||
|
||||
q.nextRow();
|
||||
|
||||
@@ -44,7 +44,7 @@ public:
|
||||
Id addSourceLocation(Id elementId, Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol, int type);
|
||||
Id addComponentAccess(Id memberEdgeId, int type);
|
||||
Id addCommentLocation(Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol);
|
||||
Id addError(const std::string& message, bool fatal, const std::string& filePath, uint lineNumber, uint columnNumber);
|
||||
Id addError(const std::string& message, bool fatal, bool indexed, const std::string& filePath, uint lineNumber, uint columnNumber);
|
||||
|
||||
void removeElement(Id id);
|
||||
void removeElements(const std::vector<Id>& ids);
|
||||
@@ -101,7 +101,6 @@ public:
|
||||
std::vector<ParseLocation> getFullTextSearch(const std::string& searchTerm) const;
|
||||
|
||||
std::vector<StorageCommentLocation> getCommentLocationsInFile(const FilePath& filePath) const;
|
||||
std::vector<StorageError> getFatalErrors() const;
|
||||
|
||||
std::vector<StorageFile> getAllFiles() const;
|
||||
std::vector<StorageNode> getAllNodes() const;
|
||||
|
||||
@@ -170,6 +170,7 @@ void Storage::inject(Storage* injected)
|
||||
addError(
|
||||
injectedData.message,
|
||||
injectedData.fatal,
|
||||
injectedData.indexed,
|
||||
injectedData.filePath,
|
||||
injectedData.lineNumber,
|
||||
injectedData.columnNumber
|
||||
|
||||
@@ -21,7 +21,7 @@ public:
|
||||
virtual void addSourceLocation(Id elementId, Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol, int type) = 0;
|
||||
virtual void addComponentAccess(Id edgeId , int type) = 0;
|
||||
virtual void addCommentLocation(Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol) = 0;
|
||||
virtual void addError(const std::string& message, bool fatal, const std::string& filePath, uint startLine, uint startCol) = 0;
|
||||
virtual void addError(const std::string& message, bool fatal, bool indexed, const std::string& filePath, uint startLine, uint startCol) = 0;
|
||||
|
||||
virtual void forEachFile(std::function<void(const Id /*id*/, const StorageFile& /*data*/)> callback) const = 0;
|
||||
virtual void forEachNode(std::function<void(const Id /*id*/, const StorageNode& /*data*/)> callback) const = 0;
|
||||
|
||||
@@ -171,14 +171,16 @@ struct StorageError
|
||||
StorageError()
|
||||
: message("")
|
||||
, fatal(0)
|
||||
, indexed(0)
|
||||
, filePath("")
|
||||
, lineNumber(-1)
|
||||
, columnNumber(-1)
|
||||
{}
|
||||
|
||||
StorageError(const std::string& message, bool fatal, const std::string& filePath, uint lineNumber, uint columnNumber)
|
||||
StorageError(const std::string& message, bool fatal, bool indexed, const std::string& filePath, uint lineNumber, uint columnNumber)
|
||||
: message(message)
|
||||
, fatal(fatal)
|
||||
, indexed(indexed)
|
||||
, filePath(filePath)
|
||||
, lineNumber(lineNumber)
|
||||
, columnNumber(columnNumber)
|
||||
@@ -186,6 +188,7 @@ struct StorageError
|
||||
|
||||
std::string message;
|
||||
bool fatal;
|
||||
bool indexed;
|
||||
std::string filePath;
|
||||
uint lineNumber;
|
||||
uint columnNumber;
|
||||
|
||||
@@ -21,7 +21,9 @@ public:
|
||||
std::vector<FilePath> systemHeaderSearchPaths;
|
||||
std::vector<FilePath> frameworkSearchPaths;
|
||||
std::vector<std::string> compilerFlags;
|
||||
|
||||
bool logErrors;
|
||||
|
||||
std::string language;
|
||||
std::string languageStandard;
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ public:
|
||||
virtual void startParsingFile() = 0;
|
||||
virtual void finishParsingFile() = 0;
|
||||
|
||||
virtual void onError(const ParseLocation& location, const std::string& message, bool fatal) = 0;
|
||||
virtual void onError(const ParseLocation& location, const std::string& message, bool fatal, bool indexed) = 0;
|
||||
|
||||
virtual void onTypedefParsed(
|
||||
const ParseLocation& location, const NameHierarchy& typedefName, AccessType access, bool isImplicit) = 0;
|
||||
|
||||
@@ -34,7 +34,7 @@ void ParserClientImpl::finishParsingFile()
|
||||
{
|
||||
}
|
||||
|
||||
void ParserClientImpl::onError(const ParseLocation& location, const std::string& message, bool fatal)
|
||||
void ParserClientImpl::onError(const ParseLocation& location, const std::string& message, bool fatal, bool indexed)
|
||||
{
|
||||
log(std::string(fatal ? "FATAL: " : "ERROR: "), message, location);
|
||||
|
||||
@@ -43,7 +43,7 @@ void ParserClientImpl::onError(const ParseLocation& location, const std::string&
|
||||
return;
|
||||
}
|
||||
|
||||
addError(message, fatal, location);
|
||||
addError(message, fatal, indexed, location);
|
||||
}
|
||||
|
||||
void ParserClientImpl::onTypedefParsed(
|
||||
@@ -576,14 +576,14 @@ void ParserClientImpl::addCommentLocation(const ParseLocation& location)
|
||||
);
|
||||
}
|
||||
|
||||
void ParserClientImpl::addError(const std::string& message, bool fatal, const ParseLocation& location)
|
||||
void ParserClientImpl::addError(const std::string& message, bool fatal, bool indexed, const ParseLocation& location)
|
||||
{
|
||||
if (!m_storage)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
m_storage->addError(message, fatal, location.filePath.str(), location.startLineNumber, location.startColumnNumber);
|
||||
m_storage->addError(message, fatal, indexed, location.filePath.str(), location.startLineNumber, location.startColumnNumber);
|
||||
}
|
||||
|
||||
void ParserClientImpl::log(std::string type, std::string str, const ParseLocation& location) const
|
||||
|
||||
@@ -21,7 +21,7 @@ public:
|
||||
virtual void startParsingFile();
|
||||
virtual void finishParsingFile();
|
||||
|
||||
virtual void onError(const ParseLocation& location, const std::string& message, bool fatal);
|
||||
virtual void onError(const ParseLocation& location, const std::string& message, bool fatal, bool indexed);
|
||||
|
||||
virtual void onTypedefParsed(
|
||||
const ParseLocation& location, const NameHierarchy& typedefName, AccessType access, bool isImplicit);
|
||||
@@ -97,7 +97,7 @@ private:
|
||||
void addSourceLocation(Id elementId, const ParseLocation& location, int type);
|
||||
void addComponentAccess(Id nodeId , int type);
|
||||
void addCommentLocation(const ParseLocation& location);
|
||||
void addError(const std::string& message, bool fatal, const ParseLocation& location);
|
||||
void addError(const std::string& message, bool fatal, bool indexed, const ParseLocation& location);
|
||||
|
||||
void log(std::string type, std::string str, const ParseLocation& location) const;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user