FileSearch: Get rid of FileSearchResult

Use SearchResultItem instead.
This change should reduce the remaining freeze described in
a9eb732ce6 even more.

Change-Id: I102b82ed5677360ccd9e425dd0bdd941d87116f0
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Jarek Kobus
2023-05-05 14:05:10 +02:00
parent 1d4228dfda
commit 936086745a
18 changed files with 289 additions and 294 deletions

View File

@@ -45,7 +45,7 @@ public:
class GitGrepRunner
{
using PromiseType = QPromise<FileSearchResultList>;
using PromiseType = QPromise<SearchResultItems>;
public:
GitGrepRunner(const TextEditor::FileFindParameters &parameters)
@@ -67,23 +67,23 @@ public:
QStringList regexpCapturedTexts;
};
void processLine(const QString &line, FileSearchResultList *resultList) const
void processLine(const QString &line, SearchResultItems *resultList) const
{
if (line.isEmpty())
return;
static const QLatin1String boldRed("\x1b[1;31m");
static const QLatin1String resetColor("\x1b[m");
FileSearchResult single;
SearchResultItem result;
const int lineSeparator = line.indexOf(QChar::Null);
QString filePath = line.left(lineSeparator);
if (!m_ref.isEmpty() && filePath.startsWith(m_ref))
filePath.remove(0, m_ref.length());
single.fileName = m_directory.pathAppended(filePath);
result.setFilePath(m_directory.pathAppended(filePath));
const int textSeparator = line.indexOf(QChar::Null, lineSeparator + 1);
single.lineNumber = line.mid(lineSeparator + 1, textSeparator - lineSeparator - 1).toInt();
const int lineNumber = line.mid(lineSeparator + 1, textSeparator - lineSeparator - 1).toInt();
QString text = line.mid(textSeparator + 1);
QRegularExpression regexp;
QVector<Match> matches;
QList<Match> matches;
if (m_parameters.flags & FindRegularExpression) {
const QRegularExpression::PatternOptions patternOptions =
(m_parameters.flags & FindCaseSensitively)
@@ -106,19 +106,18 @@ public:
matches.append(match);
text = text.left(matchStart) + matchText + text.mid(matchEnd + resetColor.size());
}
single.matchingLine = text;
result.setDisplayText(text);
for (const auto &match : std::as_const(matches)) {
single.matchStart = match.matchStart;
single.matchLength = match.matchLength;
single.regexpCapturedTexts = match.regexpCapturedTexts;
resultList->append(single);
result.setMainRange(lineNumber, match.matchStart, match.matchLength);
result.setUserData(match.regexpCapturedTexts);
resultList->append(result);
}
}
void read(PromiseType &fi, const QString &text)
{
FileSearchResultList resultList;
SearchResultItems resultList;
QString t = text;
QTextStream stream(&t);
while (!stream.atEnd() && !fi.isCanceled())
@@ -272,7 +271,7 @@ void GitGrep::writeSettings(QSettings *settings) const
settings->setValue(GitGrepRef, m_treeLineEdit->text());
}
QFuture<FileSearchResultList> GitGrep::executeSearch(const TextEditor::FileFindParameters &parameters,
QFuture<SearchResultItems> GitGrep::executeSearch(const TextEditor::FileFindParameters &parameters,
TextEditor::BaseFileFind * /*baseFileFind*/)
{
return Utils::asyncRun(GitGrepRunner(parameters));

View File

@@ -30,7 +30,7 @@ public:
QVariant parameters() const override;
void readSettings(QSettings *settings) override;
void writeSettings(QSettings *settings) const override;
QFuture<Utils::FileSearchResultList> executeSearch(
QFuture<Utils::SearchResultItems> executeSearch(
const TextEditor::FileFindParameters &parameters,
TextEditor::BaseFileFind *baseFileFind) override;
Core::IEditor *openEditor(const Utils::SearchResultItem &item,