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:
@@ -32,6 +32,7 @@
|
||||
#include "cppsourceprocessor.h"
|
||||
#include "cpptoolsconstants.h"
|
||||
#include "cpptoolsplugin.h"
|
||||
#include "cpptoolsreuse.h"
|
||||
#include "searchsymbols.h"
|
||||
|
||||
#include <coreplugin/icore.h>
|
||||
@@ -59,6 +60,7 @@ public:
|
||||
ProjectPartHeaderPaths headerPaths;
|
||||
WorkingCopy workingCopy;
|
||||
QSet<QString> sourceFiles;
|
||||
int indexerFileSizeLimitInMb = -1;
|
||||
};
|
||||
|
||||
class WriteTaskFileForDiagnostics
|
||||
@@ -179,6 +181,7 @@ void indexFindErrors(QFutureInterface<void> &future, const ParseParams params)
|
||||
void index(QFutureInterface<void> &future, const ParseParams params)
|
||||
{
|
||||
QScopedPointer<CppSourceProcessor> sourceProcessor(CppModelManager::createSourceProcessor());
|
||||
sourceProcessor->setFileSizeLimitInMb(params.indexerFileSizeLimitInMb);
|
||||
sourceProcessor->setHeaderPaths(params.headerPaths);
|
||||
sourceProcessor->setWorkingCopy(params.workingCopy);
|
||||
|
||||
@@ -349,6 +352,7 @@ QFuture<void> BuiltinIndexingSupport::refreshSourceFiles(const QSet<QString> &so
|
||||
CppModelManager *mgr = CppModelManager::instance();
|
||||
|
||||
ParseParams params;
|
||||
params.indexerFileSizeLimitInMb = indexerFileSizeLimitInMb();
|
||||
params.headerPaths = mgr->headerPaths();
|
||||
params.workingCopy = mgr->workingCopy();
|
||||
params.sourceFiles = sourceFiles;
|
||||
|
||||
@@ -58,6 +58,12 @@ static QString clangDiagnosticConfigsArrayOptionsKey()
|
||||
static QString pchUsageKey()
|
||||
{ return QLatin1String(Constants::CPPTOOLS_MODEL_MANAGER_PCH_USAGE); }
|
||||
|
||||
static QString skipIndexingBigFilesKey()
|
||||
{ return QLatin1String(Constants::CPPTOOLS_SKIP_INDEXING_BIG_FILES); }
|
||||
|
||||
static QString indexerFileSizeLimitKey()
|
||||
{ return QLatin1String(Constants::CPPTOOLS_INDEXER_FILE_SIZE_LIMIT); }
|
||||
|
||||
void CppCodeModelSettings::fromSettings(QSettings *s)
|
||||
{
|
||||
s->beginGroup(QLatin1String(Constants::CPPTOOLS_SETTINGSGROUP));
|
||||
@@ -81,6 +87,13 @@ void CppCodeModelSettings::fromSettings(QSettings *s)
|
||||
|
||||
const QVariant pchUsageVariant = s->value(pchUsageKey(), initialPchUsage());
|
||||
setPCHUsage(static_cast<PCHUsage>(pchUsageVariant.toInt()));
|
||||
|
||||
const QVariant skipIndexingBigFiles = s->value(skipIndexingBigFilesKey(), true);
|
||||
setSkipIndexingBigFiles(skipIndexingBigFiles.toBool());
|
||||
|
||||
const QVariant indexerFileSizeLimit = s->value(indexerFileSizeLimitKey(), 5);
|
||||
setIndexerFileSizeLimitInMb(indexerFileSizeLimit.toInt());
|
||||
|
||||
s->endGroup();
|
||||
|
||||
emit changed();
|
||||
@@ -103,6 +116,8 @@ void CppCodeModelSettings::toSettings(QSettings *s)
|
||||
|
||||
s->setValue(clangDiagnosticConfigKey(), clangDiagnosticConfigId().toSetting());
|
||||
s->setValue(pchUsageKey(), pchUsage());
|
||||
s->setValue(skipIndexingBigFilesKey(), skipIndexingBigFiles());
|
||||
s->setValue(indexerFileSizeLimitKey(), indexerFileSizeLimitInMb());
|
||||
|
||||
s->endGroup();
|
||||
|
||||
@@ -150,3 +165,23 @@ void CppCodeModelSettings::emitChanged()
|
||||
{
|
||||
emit changed();
|
||||
}
|
||||
|
||||
bool CppCodeModelSettings::skipIndexingBigFiles() const
|
||||
{
|
||||
return m_skipIndexingBigFiles;
|
||||
}
|
||||
|
||||
void CppCodeModelSettings::setSkipIndexingBigFiles(bool yesno)
|
||||
{
|
||||
m_skipIndexingBigFiles = yesno;
|
||||
}
|
||||
|
||||
int CppCodeModelSettings::indexerFileSizeLimitInMb() const
|
||||
{
|
||||
return m_indexerFileSizeLimitInMB;
|
||||
}
|
||||
|
||||
void CppCodeModelSettings::setIndexerFileSizeLimitInMb(int sizeInMB)
|
||||
{
|
||||
m_indexerFileSizeLimitInMB = sizeInMB;
|
||||
}
|
||||
|
||||
@@ -63,6 +63,12 @@ public:
|
||||
PCHUsage pchUsage() const;
|
||||
void setPCHUsage(PCHUsage pchUsage);
|
||||
|
||||
bool skipIndexingBigFiles() const;
|
||||
void setSkipIndexingBigFiles(bool yesno);
|
||||
|
||||
int indexerFileSizeLimitInMb() const;
|
||||
void setIndexerFileSizeLimitInMb(int sizeInMB);
|
||||
|
||||
public: // for tests
|
||||
void emitChanged();
|
||||
|
||||
@@ -72,6 +78,8 @@ signals:
|
||||
|
||||
private:
|
||||
PCHUsage m_pchUsage = PchUse_None;
|
||||
bool m_skipIndexingBigFiles = true;
|
||||
int m_indexerFileSizeLimitInMB = 5;
|
||||
ClangDiagnosticConfigs m_clangCustomDiagnosticConfigs;
|
||||
Core::Id m_clangDiagnosticConfigId;
|
||||
};
|
||||
|
||||
@@ -58,6 +58,7 @@ void CppCodeModelSettingsWidget::setSettings(const QSharedPointer<CppCodeModelSe
|
||||
|
||||
setupClangCodeModelWidgets();
|
||||
setupPchCheckBox();
|
||||
setupSkipIndexingFilesWidgets();
|
||||
}
|
||||
|
||||
void CppCodeModelSettingsWidget::applyToSettings() const
|
||||
@@ -66,6 +67,7 @@ void CppCodeModelSettingsWidget::applyToSettings() const
|
||||
|
||||
changed |= applyClangCodeModelWidgetsToSettings();
|
||||
changed |= applyPchCheckBoxToSettings();
|
||||
changed |= applySkipIndexingFilesWidgets();
|
||||
|
||||
if (changed)
|
||||
m_settings->toSettings(Core::ICore::settings());
|
||||
@@ -92,6 +94,12 @@ void CppCodeModelSettingsWidget::setupPchCheckBox() const
|
||||
m_ui->ignorePCHCheckBox->setChecked(ignorePch);
|
||||
}
|
||||
|
||||
void CppCodeModelSettingsWidget::setupSkipIndexingFilesWidgets()
|
||||
{
|
||||
m_ui->skipIndexingBigFilesCheckBox->setChecked(m_settings->skipIndexingBigFiles());
|
||||
m_ui->bigFilesLimitSpinBox->setValue(m_settings->indexerFileSizeLimitInMb());
|
||||
}
|
||||
|
||||
bool CppCodeModelSettingsWidget::applyClangCodeModelWidgetsToSettings() const
|
||||
{
|
||||
bool settingsChanged = false;
|
||||
@@ -131,6 +139,25 @@ bool CppCodeModelSettingsWidget::applyPchCheckBoxToSettings() const
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CppCodeModelSettingsWidget::applySkipIndexingFilesWidgets() const
|
||||
{
|
||||
bool settingsChanged = false;
|
||||
|
||||
const bool newSkipIndexingBigFiles = m_ui->skipIndexingBigFilesCheckBox->isChecked();
|
||||
if (m_settings->skipIndexingBigFiles() != newSkipIndexingBigFiles) {
|
||||
m_settings->setSkipIndexingBigFiles(newSkipIndexingBigFiles);
|
||||
settingsChanged = true;
|
||||
}
|
||||
|
||||
const int newFileSizeLimit = m_ui->bigFilesLimitSpinBox->value();
|
||||
if (m_settings->indexerFileSizeLimitInMb() != newFileSizeLimit) {
|
||||
m_settings->setIndexerFileSizeLimitInMb(newFileSizeLimit);
|
||||
settingsChanged = true;
|
||||
}
|
||||
|
||||
return settingsChanged;
|
||||
}
|
||||
|
||||
CppCodeModelSettingsPage::CppCodeModelSettingsPage(QSharedPointer<CppCodeModelSettings> &settings,
|
||||
QObject *parent)
|
||||
: Core::IOptionsPage(parent)
|
||||
|
||||
@@ -57,9 +57,11 @@ public:
|
||||
private:
|
||||
void setupClangCodeModelWidgets();
|
||||
void setupPchCheckBox() const;
|
||||
void setupSkipIndexingFilesWidgets();
|
||||
|
||||
bool applyClangCodeModelWidgetsToSettings() const;
|
||||
bool applyPchCheckBoxToSettings() const;
|
||||
bool applySkipIndexingFilesWidgets() const;
|
||||
|
||||
private:
|
||||
Ui::CppCodeModelSettingsPage *m_ui;
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
<item>
|
||||
<widget class="QGroupBox" name="anotherGroupBox">
|
||||
<property name="title">
|
||||
<string>Pre-compiled Headers</string>
|
||||
<string>Files to Skip</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
@@ -55,6 +55,49 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="skipIndexingBigFilesCheckBox">
|
||||
<property name="text">
|
||||
<string>Do not index files greater than</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSpinBox" name="bigFilesLimitSpinBox">
|
||||
<property name="suffix">
|
||||
<string>MB</string>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>500</number>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>5</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
|
||||
@@ -611,9 +611,9 @@ QByteArray CppModelManager::codeModelConfiguration() const
|
||||
return QByteArray::fromRawData(pp_configuration, qstrlen(pp_configuration));
|
||||
}
|
||||
|
||||
static QSet<QString> tooBigFilesRemoved(const QSet<QString> &files, int fileSizeLimit)
|
||||
static QSet<QString> tooBigFilesRemoved(const QSet<QString> &files, int fileSizeLimitInMb)
|
||||
{
|
||||
if (fileSizeLimit == 0)
|
||||
if (fileSizeLimitInMb <= 0)
|
||||
return files;
|
||||
|
||||
QSet<QString> result;
|
||||
@@ -623,7 +623,7 @@ static QSet<QString> tooBigFilesRemoved(const QSet<QString> &files, int fileSize
|
||||
while (i.hasNext()) {
|
||||
const QString filePath = i.next();
|
||||
fileInfo.setFile(filePath);
|
||||
if (skipFileDueToSizeLimit(fileInfo, fileSizeLimit))
|
||||
if (fileSizeExceedsLimit(fileInfo, fileSizeLimitInMb))
|
||||
continue;
|
||||
|
||||
result << filePath;
|
||||
@@ -638,7 +638,7 @@ QFuture<void> CppModelManager::updateSourceFiles(const QSet<QString> &sourceFile
|
||||
if (sourceFiles.isEmpty() || !d->m_indexerEnabled)
|
||||
return QFuture<void>();
|
||||
|
||||
const auto filteredFiles = tooBigFilesRemoved(sourceFiles, fileSizeLimit());
|
||||
const QSet<QString> filteredFiles = tooBigFilesRemoved(sourceFiles, indexerFileSizeLimitInMb());
|
||||
|
||||
if (d->m_indexingSupporter)
|
||||
d->m_indexingSupporter->refreshSourceFiles(filteredFiles, mode);
|
||||
|
||||
@@ -448,7 +448,7 @@ void CppSourceProcessor::sourceNeeded(unsigned line, const QString &fileName, In
|
||||
}
|
||||
|
||||
const QFileInfo info(absoluteFileName);
|
||||
if (skipFileDueToSizeLimit(info))
|
||||
if (fileSizeExceedsLimit(info, m_fileSizeLimitInMb))
|
||||
return; // TODO: Add diagnostic message
|
||||
|
||||
// Otherwise get file contents
|
||||
@@ -505,6 +505,11 @@ void CppSourceProcessor::sourceNeeded(unsigned line, const QString &fileName, In
|
||||
switchCurrentDocument(previousDocument);
|
||||
}
|
||||
|
||||
void CppSourceProcessor::setFileSizeLimitInMb(int fileSizeLimitInMb)
|
||||
{
|
||||
m_fileSizeLimitInMb = fileSizeLimitInMb;
|
||||
}
|
||||
|
||||
Document::Ptr CppSourceProcessor::switchCurrentDocument(Document::Ptr doc)
|
||||
{
|
||||
const Document::Ptr previousDoc = m_currentDoc;
|
||||
|
||||
@@ -65,6 +65,7 @@ public:
|
||||
void setWorkingCopy(const CppTools::WorkingCopy &workingCopy);
|
||||
void setHeaderPaths(const ProjectPartHeaderPaths &headerPaths);
|
||||
void setLanguageFeatures(CPlusPlus::LanguageFeatures languageFeatures);
|
||||
void setFileSizeLimitInMb(int fileSizeLimitInMb);
|
||||
void setTodo(const QSet<QString> &files);
|
||||
|
||||
void run(const QString &fileName, const QStringList &initialIncludes = QStringList());
|
||||
@@ -122,6 +123,7 @@ private:
|
||||
QSet<QString> m_todo;
|
||||
QSet<QString> m_processed;
|
||||
QHash<QString, QString> m_fileNameCache;
|
||||
int m_fileSizeLimitInMb = -1;
|
||||
QTextCodec *m_defaultCodec;
|
||||
};
|
||||
|
||||
|
||||
@@ -50,6 +50,8 @@ const char LOWERCASE_CPPFILES_KEY[] = "LowerCaseFiles";
|
||||
enum { lowerCaseFilesDefault = 1 };
|
||||
const char CPPTOOLS_SORT_EDITOR_DOCUMENT_OUTLINE[] = "SortedMethodOverview";
|
||||
const char CPPTOOLS_MODEL_MANAGER_PCH_USAGE[] = "PCHUsage";
|
||||
const char CPPTOOLS_SKIP_INDEXING_BIG_FILES[] = "SkipIndexingBigFiles";
|
||||
const char CPPTOOLS_INDEXER_FILE_SIZE_LIMIT[] = "IndexerFileSizeLimit";
|
||||
|
||||
const char CPP_CLANG_BUILTIN_CONFIG_ID_EVERYTHING_WITH_EXCEPTIONS[] = "Builtin.EverythingWithExceptions";
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -72,7 +72,7 @@ void CPPTOOLS_EXPORT switchHeaderSource();
|
||||
class CppCodeModelSettings;
|
||||
QSharedPointer<CppCodeModelSettings> CPPTOOLS_EXPORT codeModelSettings();
|
||||
|
||||
int fileSizeLimit();
|
||||
bool skipFileDueToSizeLimit(const QFileInfo &fileInfo, int limitInMB = fileSizeLimit());
|
||||
int indexerFileSizeLimitInMb();
|
||||
bool fileSizeExceedsLimit(const QFileInfo &fileInfo, int sizeLimitInMb);
|
||||
|
||||
} // CppTools
|
||||
|
||||
Reference in New Issue
Block a user