forked from qt-creator/qt-creator
CppTools: Add UI for file size limit of indexer
Task-number: QTCREATORBUG-16712 Change-Id: I92db8cbcac9669cbd5e4ee5f7ef6f613797c753a Reviewed-by: David Schulz <david.schulz@qt.io> Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
@@ -25,11 +25,13 @@
|
||||
|
||||
#include "cpptoolsreuse.h"
|
||||
|
||||
#include "cppcodemodelsettings.h"
|
||||
#include "cpptoolsplugin.h"
|
||||
|
||||
#include <coreplugin/documentmanager.h>
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
#include <coreplugin/idocument.h>
|
||||
#include <coreplugin/messagemanager.h>
|
||||
#include <texteditor/convenience.h>
|
||||
|
||||
#include <cplusplus/Overview.h>
|
||||
@@ -255,29 +257,31 @@ QSharedPointer<CppCodeModelSettings> codeModelSettings()
|
||||
return CppTools::Internal::CppToolsPlugin::instance()->codeModelSettings();
|
||||
}
|
||||
|
||||
int fileSizeLimit()
|
||||
int indexerFileSizeLimitInMb()
|
||||
{
|
||||
static const QByteArray fileSizeLimitAsByteArray = qgetenv("QTC_CPP_FILE_SIZE_LIMIT_MB");
|
||||
static int fileSizeLimitAsInt = -1;
|
||||
const QSharedPointer<CppCodeModelSettings> settings = codeModelSettings();
|
||||
QTC_ASSERT(settings, return -1);
|
||||
|
||||
if (fileSizeLimitAsInt == -1) {
|
||||
bool ok;
|
||||
const int limit = fileSizeLimitAsByteArray.toInt(&ok);
|
||||
fileSizeLimitAsInt = ok && limit >= 0 ? limit : 0;
|
||||
}
|
||||
if (settings->skipIndexingBigFiles())
|
||||
return settings->indexerFileSizeLimitInMb();
|
||||
|
||||
return fileSizeLimitAsInt;
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool skipFileDueToSizeLimit(const QFileInfo &fileInfo, int limitInMB)
|
||||
bool fileSizeExceedsLimit(const QFileInfo &fileInfo, int sizeLimitInMb)
|
||||
{
|
||||
if (limitInMB == 0) // unlimited
|
||||
if (sizeLimitInMb <= 0)
|
||||
return false;
|
||||
|
||||
const int fileSizeInMB = fileInfo.size() / (1000 * 1000);
|
||||
if (fileSizeInMB > limitInMB) {
|
||||
qWarning() << "Files to process limited by QTC_CPP_FILE_SIZE_LIMIT_MB, skipping"
|
||||
<< fileInfo.absoluteFilePath();
|
||||
const qint64 fileSizeInMB = fileInfo.size() / (1000 * 1000);
|
||||
if (fileSizeInMB > sizeLimitInMb) {
|
||||
const QString absoluteFilePath = fileInfo.absoluteFilePath();
|
||||
const QString msg = QCoreApplication::translate(
|
||||
"CppIndexer",
|
||||
"C++ Indexer: Skipping file \"%1\" because it is too big.")
|
||||
.arg(absoluteFilePath);
|
||||
Core::MessageManager::write(msg, Core::MessageManager::Silent);
|
||||
qWarning().noquote() << msg;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user