aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/silversearcher
diff options
context:
space:
mode:
authorJarek Kobus <jaroslaw.kobus@qt.io>2023-05-05 14:05:10 +0200
committerJarek Kobus <jaroslaw.kobus@qt.io>2023-05-09 11:03:48 +0000
commit936086745ab826932f6559cc51f49ba20718f56a (patch)
tree5acc6d4a5043b8c1ff6e5f80465db5d1f08403f8 /src/plugins/silversearcher
parent1d4228dfda8137920523c242c17e59451bcb937b (diff)
FileSearch: Get rid of FileSearchResult
Use SearchResultItem instead. This change should reduce the remaining freeze described in a9eb732ce6763e22badd92fc8523cebe84b09a84 even more. Change-Id: I102b82ed5677360ccd9e425dd0bdd941d87116f0 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Diffstat (limited to 'src/plugins/silversearcher')
-rw-r--r--src/plugins/silversearcher/findinfilessilversearcher.cpp6
-rw-r--r--src/plugins/silversearcher/findinfilessilversearcher.h2
-rw-r--r--src/plugins/silversearcher/outputparser_test.cpp64
-rw-r--r--src/plugins/silversearcher/silversearcheroutputparser.cpp42
-rw-r--r--src/plugins/silversearcher/silversearcheroutputparser.h14
5 files changed, 70 insertions, 58 deletions
diff --git a/src/plugins/silversearcher/findinfilessilversearcher.cpp b/src/plugins/silversearcher/findinfilessilversearcher.cpp
index 9ac9702a6e4..b6759aeaeff 100644
--- a/src/plugins/silversearcher/findinfilessilversearcher.cpp
+++ b/src/plugins/silversearcher/findinfilessilversearcher.cpp
@@ -73,7 +73,7 @@ bool isSilverSearcherAvailable()
return false;
}
-void runSilverSeacher(QPromise<FileSearchResultList> &promise, FileFindParameters parameters)
+void runSilverSeacher(QPromise<SearchResultItems> &promise, FileFindParameters parameters)
{
const FilePath directory = FilePath::fromUserInput(parameters.additionalParameters.toString());
QStringList arguments = {"--parallel", "--ackmate"};
@@ -120,7 +120,7 @@ void runSilverSeacher(QPromise<FileSearchResultList> &promise, FileFindParameter
regexp.setPatternOptions(patternOptions);
}
SilverSearcher::SilverSearcherOutputParser parser(process.cleanedStdOut(), regexp);
- FileSearchResultList items = parser.parse();
+ const SearchResultItems items = parser.parse();
if (!items.isEmpty())
promise.addResult(items);
} else {
@@ -189,7 +189,7 @@ void FindInFilesSilverSearcher::writeSettings(QSettings *settings) const
settings->setValue(SearchOptionsString, m_searchOptionsLineEdit->text());
}
-QFuture<FileSearchResultList> FindInFilesSilverSearcher::executeSearch(
+QFuture<SearchResultItems> FindInFilesSilverSearcher::executeSearch(
const FileFindParameters &parameters, BaseFileFind * /*baseFileFind*/)
{
return Utils::asyncRun(runSilverSeacher, parameters);
diff --git a/src/plugins/silversearcher/findinfilessilversearcher.h b/src/plugins/silversearcher/findinfilessilversearcher.h
index af59e3d4b79..85b35192b8e 100644
--- a/src/plugins/silversearcher/findinfilessilversearcher.h
+++ b/src/plugins/silversearcher/findinfilessilversearcher.h
@@ -31,7 +31,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 *) override;
Core::IEditor *openEditor(const Utils::SearchResultItem &item,
const TextEditor::FileFindParameters &parameters) override;
diff --git a/src/plugins/silversearcher/outputparser_test.cpp b/src/plugins/silversearcher/outputparser_test.cpp
index a9185b31568..cdc587ce702 100644
--- a/src/plugins/silversearcher/outputparser_test.cpp
+++ b/src/plugins/silversearcher/outputparser_test.cpp
@@ -11,47 +11,57 @@ using namespace Utils;
namespace SilverSearcher {
namespace Internal {
+SearchResultItem searchResult(const FilePath &fileName, const QString &matchingLine,
+ int lineNumber, int matchStart, int matchLength)
+{
+ SearchResultItem result;
+ result.setFilePath(fileName);
+ result.setLineText(matchingLine);
+ result.setMainRange(lineNumber, matchStart, matchLength);
+ return result;
+}
+
void OutputParserTest::test_data()
{
QTest::addColumn<QString>("parserOutput");
- QTest::addColumn<FileSearchResultList>("results");
+ QTest::addColumn<SearchResultItems>("results");
- QTest::addRow("nothing") << QString("\n") << FileSearchResultList();
+ QTest::addRow("nothing") << QString("\n") << SearchResultItems();
QTest::addRow("oneFileOneMatch")
- << QString(":/file/path/to/filename.h\n"
- "1;1 5:match\n")
- << FileSearchResultList({{"/file/path/to/filename.h", 1, "match", 1, 5, {}}});
+ << QString(":/file/path/to/filename.h\n"
+ "1;1 5:match\n")
+ << SearchResultItems{searchResult("/file/path/to/filename.h", "match", 1, 1, 5)};
QTest::addRow("multipleFilesWithOneMatch")
- << QString(":/file/path/to/filename1.h\n"
- "1;1 5:match\n"
- "\n"
- ":/file/path/to/filename2.h\n"
- "2;2 5: match\n")
- << FileSearchResultList({{"/file/path/to/filename1.h", 1, "match", 1, 5, {}},
- {"/file/path/to/filename2.h", 2, " match", 2, 5, {}}});
+ << QString(":/file/path/to/filename1.h\n"
+ "1;1 5:match\n"
+ "\n"
+ ":/file/path/to/filename2.h\n"
+ "2;2 5: match\n")
+ << SearchResultItems{searchResult("/file/path/to/filename1.h", "match", 1, 1, 5),
+ searchResult("/file/path/to/filename2.h", " match", 2, 2, 5)};
QTest::addRow("oneFileMultipleMatches")
- << QString(":/file/path/to/filename.h\n"
- "1;1 5,7 5:match match\n")
- << FileSearchResultList({{"/file/path/to/filename.h", 1, "match match", 1, 5, {}},
- {"/file/path/to/filename.h", 1, "match match", 7, 5, {}}});
+ << QString(":/file/path/to/filename.h\n"
+ "1;1 5,7 5:match match\n")
+ << SearchResultItems{searchResult("/file/path/to/filename.h", "match match", 1, 1, 5),
+ searchResult("/file/path/to/filename.h", "match match", 1, 7, 5)};
QTest::addRow("multipleFilesWithMultipleMatches")
- << QString(":/file/path/to/filename1.h\n"
- "1;1 5,7 5:match match\n"
- "\n"
- ":/file/path/to/filename2.h\n"
- "2;2 5,8 5: match match\n")
- << FileSearchResultList({{"/file/path/to/filename1.h", 1, "match match", 1, 5, {}},
- {"/file/path/to/filename1.h", 1, "match match", 7, 5, {}},
- {"/file/path/to/filename2.h", 2, " match match", 2, 5, {}},
- {"/file/path/to/filename2.h", 2, " match match", 8, 5, {}}});
+ << QString(":/file/path/to/filename1.h\n"
+ "1;1 5,7 5:match match\n"
+ "\n"
+ ":/file/path/to/filename2.h\n"
+ "2;2 5,8 5: match match\n")
+ << SearchResultItems{searchResult("/file/path/to/filename1.h", "match match", 1, 1, 5),
+ searchResult("/file/path/to/filename1.h", "match match", 1, 7, 5),
+ searchResult("/file/path/to/filename2.h", " match match", 2, 2, 5),
+ searchResult("/file/path/to/filename2.h", " match match", 2, 8, 5)};
}
void OutputParserTest::test()
{
QFETCH(QString, parserOutput);
- QFETCH(FileSearchResultList, results);
+ QFETCH(SearchResultItems, results);
SilverSearcher::SilverSearcherOutputParser ssop(parserOutput);
- const FileSearchResultList items = ssop.parse();
+ const SearchResultItems items = ssop.parse();
QCOMPARE(items, results);
}
diff --git a/src/plugins/silversearcher/silversearcheroutputparser.cpp b/src/plugins/silversearcher/silversearcheroutputparser.cpp
index 9088310c3fc..20ce2473425 100644
--- a/src/plugins/silversearcher/silversearcheroutputparser.cpp
+++ b/src/plugins/silversearcher/silversearcheroutputparser.cpp
@@ -16,7 +16,7 @@ SilverSearcherOutputParser::SilverSearcherOutputParser(
hasRegexp = !regexp.pattern().isEmpty();
}
-Utils::FileSearchResultList SilverSearcherOutputParser::parse()
+Utils::SearchResultItems SilverSearcherOutputParser::parse()
{
while (index < outputSize - 1) {
if (output[index] == '\n') {
@@ -25,15 +25,15 @@ Utils::FileSearchResultList SilverSearcherOutputParser::parse()
}
parseFilePath();
while (index < outputSize && output[index] != '\n') {
- parseLineNumber();
+ const int lineNumber = parseLineNumber();
if (index >= outputSize - 1)
break;
- int matches = parseMatches();
+ int matches = parseMatches(lineNumber);
if (index >= outputSize - 1)
break;
parseText();
for (int i = 0; i < matches; ++i)
- items[items.size() - i - 1].matchingLine = item.matchingLine;
+ items[items.size() - i - 1].setDisplayText(item.lineText());
}
}
@@ -45,41 +45,41 @@ bool SilverSearcherOutputParser::parseFilePath()
int startIndex = ++index;
while (index < outputSize && output[index] != '\n')
++index;
- item.fileName = Utils::FilePath::fromString(QString(output.data() + startIndex, index - startIndex));
+ item.setFilePath(Utils::FilePath::fromString(QString(output.data() + startIndex,
+ index - startIndex)));
++index;
return true;
}
-bool SilverSearcherOutputParser::parseLineNumber()
+int SilverSearcherOutputParser::parseLineNumber()
{
int startIndex = index;
while (index < outputSize && output[++index] != ';') { }
- item.lineNumber = QString(output.data() + startIndex, index - startIndex).toInt();
+ const int lineNumber = QString(output.data() + startIndex, index - startIndex).toInt();
++index;
- return true;
+ return lineNumber;
}
-bool SilverSearcherOutputParser::parseMatchIndex()
+int SilverSearcherOutputParser::parseMatchIndex()
{
int startIndex = index;
while (index < outputSize && output[++index] != ' ') { }
- item.matchStart = QString(output.data() + startIndex, index - startIndex).toInt();
+ const int lineStart = QString(output.data() + startIndex, index - startIndex).toInt();
++index;
- return true;
+ return lineStart;
}
-bool SilverSearcherOutputParser::parseMatchLength()
+int SilverSearcherOutputParser::parseMatchLength()
{
int startIndex = index;
while (index < outputSize && output[++index] != ':' && output[index] != ',') { }
- item.matchLength = QString(output.data() + startIndex, index - startIndex).toInt();
- return true;
+ return QString(output.data() + startIndex, index - startIndex).toInt();
}
-int SilverSearcherOutputParser::parseMatches()
+int SilverSearcherOutputParser::parseMatches(int lineNumber)
{
int matches = 1;
const int colon = output.indexOf(':', index);
@@ -94,11 +94,12 @@ int SilverSearcherOutputParser::parseMatches()
++matches;
++index;
}
- parseMatchIndex();
- parseMatchLength();
+ const int lineStart = parseMatchIndex();
+ const int lineLength = parseMatchLength();
+ item.setMainRange(lineNumber, lineStart, lineLength);
if (hasRegexp) {
- const QString part = QString(text.mid(item.matchStart, item.matchLength));
- item.regexpCapturedTexts = regexp.match(part).capturedTexts();
+ const QString part = QString(text.mid(lineStart, lineLength));
+ item.setUserData(regexp.match(part).capturedTexts());
}
items << item;
}
@@ -111,7 +112,8 @@ bool SilverSearcherOutputParser::parseText()
{
int startIndex = index;
while (index < outputSize && output[++index] != '\n') { }
- item.matchingLine = QString(output.data() + startIndex, index - startIndex);
+
+ item.setLineText(QString(output.data() + startIndex, index - startIndex));
++index;
return true;
}
diff --git a/src/plugins/silversearcher/silversearcheroutputparser.h b/src/plugins/silversearcher/silversearcheroutputparser.h
index 187e463938c..a4b34a6051f 100644
--- a/src/plugins/silversearcher/silversearcheroutputparser.h
+++ b/src/plugins/silversearcher/silversearcheroutputparser.h
@@ -16,13 +16,13 @@ class SilverSearcherOutputParser
public:
SilverSearcherOutputParser(const QString &output, const QRegularExpression &regexp = {});
- Utils::FileSearchResultList parse();
+ Utils::SearchResultItems parse();
private:
- int parseMatches();
- bool parseMatchLength();
- bool parseMatchIndex();
- bool parseLineNumber();
+ int parseMatches(int lineNumber);
+ int parseMatchLength();
+ int parseMatchIndex();
+ int parseLineNumber();
bool parseFilePath();
bool parseText();
@@ -31,8 +31,8 @@ private:
bool hasRegexp = false;
int outputSize = 0;
int index = 0;
- Utils::FileSearchResult item;
- Utils::FileSearchResultList items;
+ Utils::SearchResultItem item;
+ Utils::SearchResultItems items;
};
} // namespace SilverSearcher