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