diff options
Diffstat (limited to 'src/plugins/cppeditor/cppmodelmanager.cpp')
-rw-r--r-- | src/plugins/cppeditor/cppmodelmanager.cpp | 57 |
1 files changed, 35 insertions, 22 deletions
diff --git a/src/plugins/cppeditor/cppmodelmanager.cpp b/src/plugins/cppeditor/cppmodelmanager.cpp index ac7fe32b91..6f2aebcca3 100644 --- a/src/plugins/cppeditor/cppmodelmanager.cpp +++ b/src/plugins/cppeditor/cppmodelmanager.cpp @@ -90,6 +90,7 @@ #include <QWriteLocker> #include <memory> +#include <unordered_map> #if defined(QTCREATOR_WITH_DUMP_AST) && defined(Q_CC_GNU) #define WITH_AST_DUMP @@ -1302,16 +1303,19 @@ CppLocatorData *CppModelManager::locatorData() return &d->m_locatorData; } -static QSet<QString> filteredFilesRemoved(const QSet<QString> &files, int fileSizeLimitInMb, - bool ignoreFiles, - const QString& ignorePattern) +static QSet<QString> filteredFilesRemoved(const QSet<QString> &files, + const CppCodeModelSettings &settings) { - if (fileSizeLimitInMb <= 0 && !ignoreFiles) + if (!settings.enableIndexing) + return {}; + + const int fileSizeLimitInMb = settings.effectiveIndexerFileSizeLimitInMb(); + if (fileSizeLimitInMb <= 0 && !settings.ignoreFiles) return files; QSet<QString> result; QList<QRegularExpression> regexes; - const QStringList wildcards = ignorePattern.split('\n'); + const QStringList wildcards = settings.ignorePattern.split('\n'); for (const QString &wildcard : wildcards) regexes.append(QRegularExpression::fromWildcard(wildcard, Qt::CaseInsensitive, @@ -1322,15 +1326,12 @@ static QSet<QString> filteredFilesRemoved(const QSet<QString> &files, int fileSi if (fileSizeLimitInMb > 0 && fileSizeExceedsLimit(filePath, fileSizeLimitInMb)) continue; bool skip = false; - if (ignoreFiles) { + if (settings.ignoreFiles) { for (const QRegularExpression &rx: std::as_const(regexes)) { QRegularExpressionMatch match = rx.match(filePath.absoluteFilePath().path()); if (match.hasMatch()) { - const QString msg = Tr::tr("C++ Indexer: Skipping file \"%1\" " - "because its path matches the ignore pattern.") - .arg(filePath.displayName()); - QMetaObject::invokeMethod(MessageManager::instance(), - [msg] { MessageManager::writeSilently(msg); }); + MessageManager::writeSilently(Tr::tr("C++ Indexer: Skipping file \"%1\" " + "because its path matches the ignore pattern.").arg(filePath.displayName())); skip = true; break; } @@ -1350,18 +1351,25 @@ QFuture<void> CppModelManager::updateSourceFiles(const QSet<FilePath> &sourceFil if (sourceFiles.isEmpty() || !d->m_indexerEnabled) return QFuture<void>(); - QHash<Project *, QSet<QString>> sourcesPerProject; // TODO: Work with QList from here on? + std::unordered_map<Project *, QSet<QString>> sourcesPerProject; for (const FilePath &fp : sourceFiles) sourcesPerProject[ProjectManager::projectForFile(fp)] << fp.toString(); - QSet<QString> filteredFiles; - for (auto it = sourcesPerProject.cbegin(); it != sourcesPerProject.cend(); ++it) { - const CppCodeModelSettings settings = CppCodeModelSettings::settingsForProject(it.key()); - filteredFiles.unite(filteredFilesRemoved(it.value(), - settings.effectiveIndexerFileSizeLimitInMb(), - settings.ignoreFiles, - settings.ignorePattern)); + std::vector<std::pair<QSet<QString>, CppCodeModelSettings>> sourcesAndSettings; + for (const auto &it : sourcesPerProject) { + sourcesAndSettings + .emplace_back(it.second, CppCodeModelSettings::settingsForProject(it.first)); } + const auto filteredFiles = [sourcesAndSettings = std::move(sourcesAndSettings)] { + QSet<QString> result; + for (const auto &it : sourcesAndSettings) + result.unite(filteredFilesRemoved(it.first, it.second)); + return result; + }; + + // "ReservedProgressNotification" should be shown if there is more than one source file. + if (sourceFiles.size() > 1) + mode = ForcedProgressNotification; return d->m_internalIndexingSupport->refreshSourceFiles(filteredFiles, mode); } @@ -1386,14 +1394,20 @@ ProjectInfo::ConstPtr CppModelManager::projectInfo(Project *project) void CppModelManager::removeProjectInfoFilesAndIncludesFromSnapshot(const ProjectInfo &projectInfo) { QMutexLocker snapshotLocker(&d->m_snapshotMutex); + QStringList removedFiles; for (const ProjectPart::ConstPtr &projectPart : projectInfo.projectParts()) { for (const ProjectFile &cxxFile : std::as_const(projectPart->files)) { const QSet<FilePath> filePaths = d->m_snapshot.allIncludesForDocument(cxxFile.path); - for (const FilePath &filePath : filePaths) + for (const FilePath &filePath : filePaths) { d->m_snapshot.remove(filePath); + removedFiles << filePath.toString(); + } d->m_snapshot.remove(cxxFile.path); + removedFiles << cxxFile.path.toString(); } } + + emit m_instance->aboutToRemoveFiles(removedFiles); } const QList<CppEditorDocumentHandle *> CppModelManager::cppEditorDocuments() @@ -1996,8 +2010,7 @@ void CppModelManager::renameIncludes(const QList<std::pair<FilePath, FilePath>> newString); } } - file->setChangeSet(changeSet); - file->apply(); + file->apply(changeSet); } } |