From 30a8e05a002b64c96857883d8a51dec2bbcfc373 Mon Sep 17 00:00:00 2001 From: Vikas Pachdha Date: Thu, 26 Jan 2017 13:59:09 +0100 Subject: [PATCH 1/2] iOS: Do not boot a simulator in Booted state It results into a simulator window with an error Change-Id: I47d55082bf248fc6558e995158b631d75adb8617 Reviewed-by: Eike Ziller --- src/plugins/ios/simulatorcontrol.cpp | 4 ++-- src/plugins/ios/simulatorcontrol.h | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/plugins/ios/simulatorcontrol.cpp b/src/plugins/ios/simulatorcontrol.cpp index 2f63892025d..a533152b431 100644 --- a/src/plugins/ios/simulatorcontrol.cpp +++ b/src/plugins/ios/simulatorcontrol.cpp @@ -397,8 +397,8 @@ void SimulatorControlPrivate::startSimulator(QFutureInterface Date: Wed, 27 Apr 2016 10:06:46 +0200 Subject: [PATCH 2/2] FindInFiles: Support Silver Searcher Change-Id: I6f0f55224f228fc1d0496c589cb71ede11d90ea5 Reviewed-by: Eike Ziller --- src/plugins/plugins.pro | 3 +- src/plugins/plugins.qbs | 1 + .../silversearcher/SilverSearcher.json.in | 19 ++ .../findinfilessilversearcher.cpp | 199 ++++++++++++++++++ .../findinfilessilversearcher.h | 66 ++++++ .../silversearcher/outputparser_test.cpp | 141 +++++++++++++ .../silversearcher/outputparser_test.h | 44 ++++ src/plugins/silversearcher/silversearcher.pro | 16 ++ src/plugins/silversearcher/silversearcher.qbs | 24 +++ .../silversearcher_dependencies.pri | 7 + .../silversearcheroutputparser.cpp | 128 +++++++++++ .../silversearcheroutputparser.h | 57 +++++ .../silversearcher/silversearcherplugin.cpp | 53 +++++ .../silversearcher/silversearcherplugin.h | 48 +++++ 14 files changed, 805 insertions(+), 1 deletion(-) create mode 100644 src/plugins/silversearcher/SilverSearcher.json.in create mode 100644 src/plugins/silversearcher/findinfilessilversearcher.cpp create mode 100644 src/plugins/silversearcher/findinfilessilversearcher.h create mode 100644 src/plugins/silversearcher/outputparser_test.cpp create mode 100644 src/plugins/silversearcher/outputparser_test.h create mode 100644 src/plugins/silversearcher/silversearcher.pro create mode 100644 src/plugins/silversearcher/silversearcher.qbs create mode 100644 src/plugins/silversearcher/silversearcher_dependencies.pri create mode 100644 src/plugins/silversearcher/silversearcheroutputparser.cpp create mode 100644 src/plugins/silversearcher/silversearcheroutputparser.h create mode 100644 src/plugins/silversearcher/silversearcherplugin.cpp create mode 100644 src/plugins/silversearcher/silversearcherplugin.h diff --git a/src/plugins/plugins.pro b/src/plugins/plugins.pro index 84da2998a69..c6a554fafaa 100644 --- a/src/plugins/plugins.pro +++ b/src/plugins/plugins.pro @@ -54,7 +54,8 @@ SUBDIRS = \ winrt \ updateinfo \ scxmleditor \ - welcome + welcome \ + silversearcher qtHaveModule(quick) { SUBDIRS += qmlprofiler diff --git a/src/plugins/plugins.qbs b/src/plugins/plugins.qbs index d7ae4f035f2..1b9bf695e19 100644 --- a/src/plugins/plugins.qbs +++ b/src/plugins/plugins.qbs @@ -57,6 +57,7 @@ Project { "remotelinux/remotelinux.qbs", "resourceeditor/resourceeditor.qbs", "scxmleditor/scxmleditor.qbs", + "silversearcher/silversearcher.qbs", "subversion/subversion.qbs", "tasklist/tasklist.qbs", "texteditor/texteditor.qbs", diff --git a/src/plugins/silversearcher/SilverSearcher.json.in b/src/plugins/silversearcher/SilverSearcher.json.in new file mode 100644 index 00000000000..d12092e3092 --- /dev/null +++ b/src/plugins/silversearcher/SilverSearcher.json.in @@ -0,0 +1,19 @@ +{ + \"Name\" : \"SilverSearcher\", + \"Version\" : \"$$QTCREATOR_VERSION\", + \"CompatVersion\" : \"$$QTCREATOR_COMPAT_VERSION\", + \"Experimental\" : true, + \"Vendor\" : \"Przemyslaw Gorszkowski\", + \"Copyright\" : \"(C) 2017 Przemyslaw Gorszkowski\", + \"License\" : [ \"Commercial Usage\", + \"\", + \"Licensees holding valid Qt Commercial licenses may use this plugin in accordance with the Qt Commercial License Agreement provided with the Software or, alternatively, in accordance with the terms contained in a written agreement between you and The Qt Company.\", + \"\", + \"GNU General Public License Usage\", + \"\", + \"Alternatively, this plugin may be used under the terms of the GNU General Public License version 3 as published by the Free Software Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT included in the packaging of this plugin. Please review the following information to ensure the GNU General Public License requirements will be met: https://www.gnu.org/licenses/gpl-3.0.html.\" + ], + \"Description\" : \"Adds possibility to use SilverSearcher tool as an alternative mechanism of 'find in files'\", + \"Url\" : \"http://www.qt.io\", + $$dependencyList +} diff --git a/src/plugins/silversearcher/findinfilessilversearcher.cpp b/src/plugins/silversearcher/findinfilessilversearcher.cpp new file mode 100644 index 00000000000..3d40de93490 --- /dev/null +++ b/src/plugins/silversearcher/findinfilessilversearcher.cpp @@ -0,0 +1,199 @@ +/**************************************************************************** +** +** Copyright (C) 2017 Przemyslaw Gorszkowski . +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +****************************************************************************/ + +#include "findinfilessilversearcher.h" + +#include +#include +#include +#include +#include +#include +#include + +#include "silversearcheroutputparser.h" + +#include +#include +#include + +using namespace Core; +using namespace TextEditor; +using namespace Utils; + +namespace { +const QLatin1String silverSearcherName("Silver Searcher"); + +using FutureInterfaceType = QFutureInterface; + +const QString metacharacters = "+()^$.{}[]|\\"; + +QString convertWildcardToRegex(const QString &wildcard) +{ + QString regex; + const int wildcardSize = wildcard.size(); + regex.append('^'); + for (int i = 0; i < wildcardSize; ++i) { + const QChar ch = wildcard[i]; + if (ch == '*') { + regex.append(".*"); + } else if (ch == '?') { + regex.append('.'); + } else if (metacharacters.indexOf(ch) != -1) { + regex.append('\\'); + regex.append(ch); + } else { + regex.append(ch); + } + } + regex.append('$'); + + return regex; +} + +bool isSilverSearcherAvailable() +{ + QProcess silverSearcherProcess; + silverSearcherProcess.start("ag", {"--version"}); + if (silverSearcherProcess.waitForFinished()) { + if (silverSearcherProcess.readAll().contains("ag version")) + return true; + } + + return false; +} + +void runSilverSeacher(FutureInterfaceType &fi, FileFindParameters parameters) +{ + ProgressTimer progress(fi, 5); + const QString directory = parameters.additionalParameters.toString(); + QStringList arguments = {"--parallel", "--ackmate"}; + + if (parameters.flags & FindCaseSensitively) + arguments << "-s"; + else + arguments << "-i"; + + if (parameters.flags & FindWholeWords) + arguments << "-w"; + + if (!(parameters.flags & FindRegularExpression)) + arguments << "-Q"; + + for (const QString &filter : parameters.exclusionFilters) + arguments << "--ignore" << filter; + + FileName path = FileName::fromUserInput(FileUtils::normalizePathName(directory)); + arguments << parameters.text << path.toString(); + + QString nameFiltersAsRegex; + for (const QString &filter : parameters.nameFilters) + nameFiltersAsRegex += QString("(%1)|").arg(convertWildcardToRegex(filter)); + nameFiltersAsRegex.remove(nameFiltersAsRegex.length() - 1, 1); + + arguments << "-G" << nameFiltersAsRegex; + + QProcess process; + process.start("ag", arguments); + if (process.waitForFinished()) { + typedef QList FileSearchResultList; + SilverSearcher::SilverSearcherOutputParser parser(process.readAll()); + FileSearchResultList items = parser.parse(); + if (!items.isEmpty()) + fi.reportResult(items); + } else { + fi.reportCanceled(); + } +} + +} // namespace + +namespace SilverSearcher { + +FindInFilesSilverSearcher::FindInFilesSilverSearcher() + : m_widget(0), + m_path("ag"), + m_toolName("SilverSearcher") +{ + m_widget = new QWidget; + FindInFiles *findInFiles = FindInFiles::instance(); + QTC_ASSERT(findInFiles, return); + findInFiles->addSearchEngine(this); + + setEnabled(isSilverSearcherAvailable()); + if (!isEnabled()) { + auto layout = new QHBoxLayout(m_widget); + layout->setMargin(0); + QLabel *label = new QLabel(tr("SilverSearcher is not available on system")); + label->setStyleSheet("QLabel { color : red; }"); + layout->addWidget(label); + } +} + +FindInFilesSilverSearcher::~FindInFilesSilverSearcher() +{ +} + +QVariant FindInFilesSilverSearcher::parameters() const +{ + return QVariant(); +} + +QString FindInFilesSilverSearcher::title() const +{ + return silverSearcherName; +} + +QString FindInFilesSilverSearcher::toolTip() const +{ + return QString(); +} + +QWidget *FindInFilesSilverSearcher::widget() const +{ + return m_widget; +} + +void FindInFilesSilverSearcher::writeSettings(QSettings * /*settings*/) const +{ +} + +QFuture FindInFilesSilverSearcher::executeSearch( + const FileFindParameters ¶meters, BaseFileFind * /*baseFileFind*/) +{ + return Utils::runAsync(runSilverSeacher, parameters); +} + +IEditor *FindInFilesSilverSearcher::openEditor(const SearchResultItem & /*item*/, + const FileFindParameters & /*parameters*/) +{ + return 0; +} + +void FindInFilesSilverSearcher::readSettings(QSettings */*settings*/) +{ +} + +} // namespace SilverSearcher diff --git a/src/plugins/silversearcher/findinfilessilversearcher.h b/src/plugins/silversearcher/findinfilessilversearcher.h new file mode 100644 index 00000000000..d290069cd5b --- /dev/null +++ b/src/plugins/silversearcher/findinfilessilversearcher.h @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2017 Przemyslaw Gorszkowski . +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +****************************************************************************/ + +#pragma once + +#include +#include + +#include + +#include + +namespace SilverSearcher { + +class FindInFilesSilverSearcher : public TextEditor::SearchEngine +{ + Q_OBJECT + +public: + FindInFilesSilverSearcher(); + ~FindInFilesSilverSearcher() override; + + // TextEditor::FileFindExtension + QString title() const override; + QString toolTip() const override; + QWidget *widget() const override; + QVariant parameters() const override; + void readSettings(QSettings *settings) override; + void writeSettings(QSettings *settings) const override; + QFuture executeSearch( + const TextEditor::FileFindParameters ¶meters, TextEditor::BaseFileFind *) override; + Core::IEditor *openEditor(const Core::SearchResultItem &item, + const TextEditor::FileFindParameters ¶meters) override; + +private: + QPointer m_currentFindSupport; + + Utils::FileName m_directorySetting; + QPointer m_widget; + QString m_path; + QString m_toolName; +}; + +} // namespace SilverSearcher diff --git a/src/plugins/silversearcher/outputparser_test.cpp b/src/plugins/silversearcher/outputparser_test.cpp new file mode 100644 index 00000000000..fb45d059410 --- /dev/null +++ b/src/plugins/silversearcher/outputparser_test.cpp @@ -0,0 +1,141 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +****************************************************************************/ + +#include "outputparser_test.h" +#include "silversearcheroutputparser.h" + +#include + +namespace SilverSearcher { +namespace Internal { + +void OutputParserTest::testNoResults() +{ + const char parserOutput[] = "\n"; + const QByteArray output(parserOutput); + SilverSearcher::SilverSearcherOutputParser ssop(output); + const QList items = ssop.parse(); + QCOMPARE(items.size(), 0); +} + +void OutputParserTest::testOneFileWithOneMatch() +{ + const char parserOutput[] = ":/file/path/to/filename.h\n" + "1;1 5:match\n"; + const QByteArray output(parserOutput); + SilverSearcher::SilverSearcherOutputParser ssop(output); + const QList items = ssop.parse(); + QCOMPARE(items.size(), 1); + QCOMPARE(items[0].fileName, QStringLiteral("/file/path/to/filename.h")); + QCOMPARE(items[0].lineNumber, 1); + QCOMPARE(items[0].matchingLine, QStringLiteral("match")); + QCOMPARE(items[0].matchStart, 1); + QCOMPARE(items[0].matchLength, 5); +} + +void OutputParserTest::testMultipleFilesWithOneMatch() +{ + const char parserOutput[] = ":/file/path/to/filename1.h\n" + "1;1 5:match\n" + "\n" + ":/file/path/to/filename2.h\n" + "2;2 5: match\n" + ; + const QByteArray output(parserOutput); + SilverSearcher::SilverSearcherOutputParser ssop(output); + const QList items = ssop.parse(); + QCOMPARE(items.size(), 2); + QCOMPARE(items[0].fileName, QStringLiteral("/file/path/to/filename1.h")); + QCOMPARE(items[0].lineNumber, 1); + QCOMPARE(items[0].matchingLine, QStringLiteral("match")); + QCOMPARE(items[0].matchStart, 1); + QCOMPARE(items[0].matchLength, 5); + + QCOMPARE(items[1].fileName, QStringLiteral("/file/path/to/filename2.h")); + QCOMPARE(items[1].lineNumber, 2); + QCOMPARE(items[1].matchingLine, QStringLiteral(" match")); + QCOMPARE(items[1].matchStart, 2); + QCOMPARE(items[1].matchLength, 5); +} + +void OutputParserTest::testOneFileWithMultipleMatches() +{ + const char parserOutput[] = ":/file/path/to/filename.h\n" + "1;1 5,7 5:match match\n"; + const QByteArray output(parserOutput); + SilverSearcher::SilverSearcherOutputParser ssop(output); + const QList items = ssop.parse(); + QCOMPARE(items.size(), 2); + QCOMPARE(items[0].fileName, QStringLiteral("/file/path/to/filename.h")); + QCOMPARE(items[0].lineNumber, 1); + QCOMPARE(items[0].matchingLine, QStringLiteral("match match")); + QCOMPARE(items[0].matchStart, 1); + QCOMPARE(items[0].matchLength, 5); + + QCOMPARE(items[1].fileName, QStringLiteral("/file/path/to/filename.h")); + QCOMPARE(items[1].lineNumber, 1); + QCOMPARE(items[1].matchingLine, QStringLiteral("match match")); + QCOMPARE(items[1].matchStart, 7); + QCOMPARE(items[1].matchLength, 5); +} + +void OutputParserTest::testMultipleFilesWithMultipleMatches() +{ + const char parserOutput[] = ":/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"; + const QByteArray output(parserOutput); + SilverSearcher::SilverSearcherOutputParser ssop(output); + const QList items = ssop.parse(); + QCOMPARE(items.size(), 4); + QCOMPARE(items[0].fileName, QStringLiteral("/file/path/to/filename1.h")); + QCOMPARE(items[0].lineNumber, 1); + QCOMPARE(items[0].matchingLine, QStringLiteral("match match")); + QCOMPARE(items[0].matchStart, 1); + QCOMPARE(items[0].matchLength, 5); + + QCOMPARE(items[1].fileName, QStringLiteral("/file/path/to/filename1.h")); + QCOMPARE(items[1].lineNumber, 1); + QCOMPARE(items[1].matchingLine, QStringLiteral("match match")); + QCOMPARE(items[1].matchStart, 7); + QCOMPARE(items[1].matchLength, 5); + + QCOMPARE(items[2].fileName, QStringLiteral("/file/path/to/filename2.h")); + QCOMPARE(items[2].lineNumber, 2); + QCOMPARE(items[2].matchingLine, QStringLiteral(" match match")); + QCOMPARE(items[2].matchStart, 2); + QCOMPARE(items[2].matchLength, 5); + + QCOMPARE(items[3].fileName, QStringLiteral("/file/path/to/filename2.h")); + QCOMPARE(items[3].lineNumber, 2); + QCOMPARE(items[3].matchingLine, QStringLiteral(" match match")); + QCOMPARE(items[3].matchStart, 8); + QCOMPARE(items[3].matchLength, 5); +} + +} // namespace Internal +} // namespace SilverSearcher diff --git a/src/plugins/silversearcher/outputparser_test.h b/src/plugins/silversearcher/outputparser_test.h new file mode 100644 index 00000000000..a54ea7ac866 --- /dev/null +++ b/src/plugins/silversearcher/outputparser_test.h @@ -0,0 +1,44 @@ +/**************************************************************************** +** +** Copyright (C) 2017 Przemyslaw Gorszkowski . +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +****************************************************************************/ + +#include + +namespace SilverSearcher { +namespace Internal { + +class OutputParserTest : public QObject +{ + Q_OBJECT + +private slots: + void testNoResults(); + void testOneFileWithOneMatch(); + void testMultipleFilesWithOneMatch(); + void testOneFileWithMultipleMatches(); + void testMultipleFilesWithMultipleMatches(); +}; + +} // namespace Internal +} // namespace SilverSearcher diff --git a/src/plugins/silversearcher/silversearcher.pro b/src/plugins/silversearcher/silversearcher.pro new file mode 100644 index 00000000000..d3fa01f59c4 --- /dev/null +++ b/src/plugins/silversearcher/silversearcher.pro @@ -0,0 +1,16 @@ +include(../../qtcreatorplugin.pri) + +SOURCES += \ + findinfilessilversearcher.cpp \ + silversearcheroutputparser.cpp \ + silversearcherplugin.cpp + +HEADERS += \ + findinfilessilversearcher.h \ + silversearcheroutputparser.h \ + silversearcherplugin.h + +equals(TEST, 1) { + SOURCES += outputparser_test.cpp + HEADERS += outputparser_test.h +} diff --git a/src/plugins/silversearcher/silversearcher.qbs b/src/plugins/silversearcher/silversearcher.qbs new file mode 100644 index 00000000000..f099858f6e3 --- /dev/null +++ b/src/plugins/silversearcher/silversearcher.qbs @@ -0,0 +1,24 @@ +import qbs 1.0 + +QtcPlugin { + name: "SilverSearcher" + + Depends { name: "Utils" } + Depends { name: "Core" } + Depends { name: "TextEditor" } + + files: [ + "findinfilessilversearcher.cpp", "findinfilessilversearcher.h", + "silversearcheroutputparser.cpp", "silversearcheroutputparser.h", + "silversearcherplugin.cpp", "silversearcherplugin.h", + ] + + Group { + name: "Tests" + condition: qtc.testsEnabled + files: [ + "outputparser_test.cpp", + "outputparser_test.h", + ] + } +} diff --git a/src/plugins/silversearcher/silversearcher_dependencies.pri b/src/plugins/silversearcher/silversearcher_dependencies.pri new file mode 100644 index 00000000000..3b5379d2013 --- /dev/null +++ b/src/plugins/silversearcher/silversearcher_dependencies.pri @@ -0,0 +1,7 @@ +QTC_PLUGIN_NAME = SilverSearcher +QTC_LIB_DEPENDS += \ + utils + +QTC_PLUGIN_DEPENDS += \ + coreplugin \ + texteditor diff --git a/src/plugins/silversearcher/silversearcheroutputparser.cpp b/src/plugins/silversearcher/silversearcheroutputparser.cpp new file mode 100644 index 00000000000..cbc82c5632f --- /dev/null +++ b/src/plugins/silversearcher/silversearcheroutputparser.cpp @@ -0,0 +1,128 @@ +/**************************************************************************** +** +** Copyright (C) 2017 Przemyslaw Gorszkowski . +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +****************************************************************************/ + +#include "silversearcheroutputparser.h" + +#include + +namespace SilverSearcher { + +SilverSearcherOutputParser::SilverSearcherOutputParser( + const QByteArray &output) + : output(output) + , outputSize(output.size()) +{ +} + +QList SilverSearcherOutputParser::parse() +{ + while (index < outputSize - 1) { + if (output[index] == '\n') { + ++index; + continue; + } + parseFilePath(); + while (output[index] != '\n') { + parseLineNumber(); + if (index >= outputSize - 1) + break; + int matches = parseMatches(); + if (index >= outputSize - 1) + break; + parseText(); + for (int i = 0; i < matches; ++i) + items[items.size() - i - 1].matchingLine = item.matchingLine; + } + } + + return items; +} + +bool SilverSearcherOutputParser::parseFilePath() +{ + int startIndex = ++index; + while (index < outputSize && output[index] != '\n') + ++index; + item.fileName = QString::fromUtf8(output.data() + startIndex, index - startIndex); + ++index; + return true; +} + +bool SilverSearcherOutputParser::parseLineNumber() +{ + int startIndex = index; + while (index < outputSize && output[++index] != ';') { } + + item.lineNumber = QString::fromUtf8(output.data() + startIndex, index - startIndex).toInt(); + ++index; + return true; +} + +bool SilverSearcherOutputParser::parseMatchIndex() +{ + int startIndex = index; + while (index < outputSize && output[++index] != ' ') { } + + item.matchStart = QString::fromUtf8(output.data() + startIndex, index - startIndex).toInt(); + ++index; + return true; +} + +bool SilverSearcherOutputParser::parseMatchLength() +{ + int startIndex = index; + while (index < outputSize && output[++index] != ':' && output[index] != ',') { } + + item.matchLength = QString::fromUtf8(output.data() + startIndex, index - startIndex).toInt(); + return true; +} + +int SilverSearcherOutputParser::parseMatches() +{ + int matches = 1; + while (index < outputSize && output[index] != ':') { + if (output[index] == ',') { + ++matches; + ++index; + } + parseMatchIndex(); + parseMatchLength(); + items << item; + } + + ++index; + return matches; +} + +bool SilverSearcherOutputParser::parseText() +{ + int startIndex = index; + while (index < outputSize && output[++index] != '\n') { } + item.matchingLine = QString::fromUtf8(output.data() + startIndex, index - startIndex); + ++index; + return true; +} + +} // namespace SilverSearcher diff --git a/src/plugins/silversearcher/silversearcheroutputparser.h b/src/plugins/silversearcher/silversearcheroutputparser.h new file mode 100644 index 00000000000..fd96253427a --- /dev/null +++ b/src/plugins/silversearcher/silversearcheroutputparser.h @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** Copyright (C) 2017 Przemyslaw Gorszkowski . +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +****************************************************************************/ + +#pragma once + +#include +#include + +#include +#include + +namespace SilverSearcher { + +class SilverSearcherOutputParser +{ +public: + SilverSearcherOutputParser(const QByteArray &output); + + QList parse(); +private: + int parseMatches(); + bool parseMatchLength(); + bool parseMatchIndex(); + bool parseLineNumber(); + bool parseFilePath(); + bool parseText(); + + QByteArray output; + int outputSize = 0; + int index = 0; + Utils::FileSearchResult item; + QList items; +}; + +} // namespace SilverSearcher diff --git a/src/plugins/silversearcher/silversearcherplugin.cpp b/src/plugins/silversearcher/silversearcherplugin.cpp new file mode 100644 index 00000000000..80b5b0edc77 --- /dev/null +++ b/src/plugins/silversearcher/silversearcherplugin.cpp @@ -0,0 +1,53 @@ +/**************************************************************************** +** +** Copyright (C) 2017 Przemyslaw Gorszkowski . +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +****************************************************************************/ + +#include "silversearcherplugin.h" +#include "findinfilessilversearcher.h" +#include "outputparser_test.h" + +namespace SilverSearcher { +namespace Internal { + +bool SilverSearcherPlugin::initialize(const QStringList &arguments, QString *errorString) +{ + Q_UNUSED(arguments) + Q_UNUSED(errorString) + + addAutoReleasedObject(new FindInFilesSilverSearcher); + + return true; +} + +void SilverSearcherPlugin::extensionsInitialized() +{ +} + +QList SilverSearcherPlugin::createTestObjects() const +{ + return {new OutputParserTest}; +} + +} // namespace Internal +} // namespace SilverSearcher diff --git a/src/plugins/silversearcher/silversearcherplugin.h b/src/plugins/silversearcher/silversearcherplugin.h new file mode 100644 index 00000000000..5c3df4ea682 --- /dev/null +++ b/src/plugins/silversearcher/silversearcherplugin.h @@ -0,0 +1,48 @@ +/**************************************************************************** +** +** Copyright (C) 2017 Przemyslaw Gorszkowski . +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +****************************************************************************/ + +#pragma once + +#include + +namespace SilverSearcher { +namespace Internal { + +class SilverSearcherPlugin : public ExtensionSystem::IPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "SilverSearcher.json") + +public: + bool initialize(const QStringList &arguments, QString *errorString); + void extensionsInitialized(); +#ifdef WITH_TESTS +private: + QList createTestObjects() const override; +#endif +}; + +} // namespace Internal +} // namespace SilverSearcher