forked from qt-creator/qt-creator
CppEditor: Use FilePath in fileSizeExceedsLimit()
... and adapt caller side. Change-Id: Idd832101962dcdc8b24f96bebbdb77fd3e29ba7c Reviewed-by: Christian Kandeler <christian.kandeler@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
@@ -1238,7 +1238,6 @@ static QSet<QString> filteredFilesRemoved(const QSet<QString> &files, int fileSi
|
||||
return files;
|
||||
|
||||
QSet<QString> result;
|
||||
QFileInfo fileInfo;
|
||||
QList<QRegularExpression> regexes;
|
||||
const QStringList wildcards = ignorePattern.split('\n');
|
||||
|
||||
@@ -1246,19 +1245,19 @@ static QSet<QString> filteredFilesRemoved(const QSet<QString> &files, int fileSi
|
||||
regexes.append(QRegularExpression::fromWildcard(wildcard, Qt::CaseInsensitive,
|
||||
QRegularExpression::UnanchoredWildcardConversion));
|
||||
|
||||
for (const QString &filePath : files) {
|
||||
fileInfo.setFile(filePath);
|
||||
if (fileSizeLimitInMb > 0 && fileSizeExceedsLimit(fileInfo, fileSizeLimitInMb))
|
||||
for (const QString &file : files) {
|
||||
const FilePath filePath = FilePath::fromString(file);
|
||||
if (fileSizeLimitInMb > 0 && fileSizeExceedsLimit(filePath, fileSizeLimitInMb))
|
||||
continue;
|
||||
bool skip = false;
|
||||
if (ignoreFiles) {
|
||||
for (const QRegularExpression &rx: std::as_const(regexes)) {
|
||||
QRegularExpressionMatch match = rx.match(fileInfo.absoluteFilePath());
|
||||
QRegularExpressionMatch match = rx.match(filePath.absoluteFilePath().path());
|
||||
if (match.hasMatch()) {
|
||||
const QString msg = QCoreApplication::translate(
|
||||
"CppIndexer",
|
||||
"C++ Indexer: Skipping file \"%1\" because its path matches the ignore pattern.")
|
||||
.arg(filePath);
|
||||
.arg(filePath.displayName());
|
||||
QMetaObject::invokeMethod(Core::MessageManager::instance(),
|
||||
[msg]() { Core::MessageManager::writeSilently(msg); });
|
||||
skip = true;
|
||||
@@ -1268,7 +1267,7 @@ static QSet<QString> filteredFilesRemoved(const QSet<QString> &files, int fileSi
|
||||
}
|
||||
|
||||
if (!skip)
|
||||
result << filePath;
|
||||
result << filePath.toString();
|
||||
}
|
||||
|
||||
return result;
|
||||
|
@@ -422,8 +422,7 @@ void CppSourceProcessor::sourceNeeded(int line, const FilePath &filePath, Includ
|
||||
return;
|
||||
}
|
||||
|
||||
const QFileInfo info = absoluteFilePath.toFileInfo();
|
||||
if (fileSizeExceedsLimit(info, m_fileSizeLimitInMb))
|
||||
if (fileSizeExceedsLimit(absoluteFilePath, m_fileSizeLimitInMb))
|
||||
return; // TODO: Add diagnostic message
|
||||
|
||||
// Otherwise get file contents
|
||||
@@ -445,8 +444,8 @@ void CppSourceProcessor::sourceNeeded(int line, const FilePath &filePath, Includ
|
||||
Document::Include inc(include.toString(), include, 0, IncludeLocal);
|
||||
document->addIncludeFile(inc);
|
||||
}
|
||||
if (info.exists())
|
||||
document->setLastModified(info.lastModified());
|
||||
if (absoluteFilePath.exists())
|
||||
document->setLastModified(absoluteFilePath.lastModified());
|
||||
|
||||
const Document::Ptr previousDocument = switchCurrentDocument(document);
|
||||
const QByteArray preprocessedCode = m_preprocess.run(absoluteFilePath, contents);
|
||||
|
@@ -39,6 +39,7 @@
|
||||
#include <QTextDocument>
|
||||
|
||||
using namespace CPlusPlus;
|
||||
using namespace Utils;
|
||||
|
||||
namespace CppEditor {
|
||||
|
||||
@@ -336,18 +337,17 @@ int indexerFileSizeLimitInMb()
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool fileSizeExceedsLimit(const QFileInfo &fileInfo, int sizeLimitInMb)
|
||||
bool fileSizeExceedsLimit(const FilePath &filePath, int sizeLimitInMb)
|
||||
{
|
||||
if (sizeLimitInMb <= 0)
|
||||
return false;
|
||||
|
||||
const qint64 fileSizeInMB = fileInfo.size() / (1000 * 1000);
|
||||
const qint64 fileSizeInMB = filePath.fileSize() / (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);
|
||||
.arg(filePath.displayName());
|
||||
|
||||
QMetaObject::invokeMethod(Core::MessageManager::instance(),
|
||||
[msg]() { Core::MessageManager::writeSilently(msg); });
|
||||
|
@@ -16,12 +16,6 @@
|
||||
#include <cplusplus/CppDocument.h>
|
||||
#include <cplusplus/Token.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QChar;
|
||||
class QFileInfo;
|
||||
class QTextCursor;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
namespace CPlusPlus {
|
||||
class Macro;
|
||||
class Symbol;
|
||||
@@ -31,6 +25,7 @@ class LookupContext;
|
||||
namespace TextEditor { class AssistInterface; }
|
||||
|
||||
namespace CppEditor {
|
||||
|
||||
class CppRefactoringFile;
|
||||
class ProjectInfo;
|
||||
class CppCompletionAssistProcessor;
|
||||
@@ -75,7 +70,7 @@ bool CPPEDITOR_EXPORT preferLowerCaseFileNames();
|
||||
UsePrecompiledHeaders CPPEDITOR_EXPORT getPchUsage();
|
||||
|
||||
int indexerFileSizeLimitInMb();
|
||||
bool fileSizeExceedsLimit(const QFileInfo &fileInfo, int sizeLimitInMb);
|
||||
bool fileSizeExceedsLimit(const Utils::FilePath &filePath, int sizeLimitInMb);
|
||||
|
||||
ProjectExplorer::Project CPPEDITOR_EXPORT *projectForProjectInfo(const ProjectInfo &info);
|
||||
ProjectExplorer::Project CPPEDITOR_EXPORT *projectForProjectPart(const ProjectPart &part);
|
||||
|
Reference in New Issue
Block a user