diff options
author | Eike Ziller <[email protected]> | 2020-03-02 16:30:18 +0100 |
---|---|---|
committer | Eike Ziller <[email protected]> | 2020-03-04 07:28:35 +0000 |
commit | edf6d1f89d2c78832253a60d48d7f0cf05bec89c (patch) | |
tree | be36b44396e9a60f251d0d65d8d39bca4ee64a3f /plugins/haskell/haskellmanager.cpp | |
parent | 8326e16c4ef1ae6bfa60b6495b6a1f5a8ec290f0 (diff) |
Add button for running GHCi to editor tool bar
Loading the file automatically in GHCi, so it is directly available for
investigation.
Change-Id: I221d02ef2e17de465244df3a8b6674d84ba52c6e
Reviewed-by: Eike Ziller <[email protected]>
Diffstat (limited to 'plugins/haskell/haskellmanager.cpp')
-rw-r--r-- | plugins/haskell/haskellmanager.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/plugins/haskell/haskellmanager.cpp b/plugins/haskell/haskellmanager.cpp index 9e18b51..5c9ab1d 100644 --- a/plugins/haskell/haskellmanager.cpp +++ b/plugins/haskell/haskellmanager.cpp @@ -25,7 +25,11 @@ #include "haskellmanager.h" +#include <coreplugin/messagemanager.h> +#include <utils/algorithm.h> +#include <utils/consoleprocess.h> #include <utils/hostosinfo.h> +#include <utils/mimetypes/mimedatabase.h> #include <QCoreApplication> #include <QDir> @@ -93,6 +97,25 @@ void HaskellManager::setStackExecutable(const FilePath &filePath) emit m_instance->stackExecutableChanged(m_d->stackExecutable); } +void HaskellManager::openGhci(const FilePath &haskellFile) +{ + const QList<MimeType> mimeTypes = mimeTypesForFileName(haskellFile.toString()); + const bool isHaskell = Utils::anyOf(mimeTypes, [](const MimeType &mt) { + return mt.inherits("text/x-haskell") || mt.inherits("text/x-literate-haskell"); + }); + const auto args = QStringList{"ghci"} + + (isHaskell ? QStringList{haskellFile.fileName()} : QStringList()); + auto p = new ConsoleProcess; + p->setCommand({stackExecutable(), args}); + p->setWorkingDirectory(haskellFile.toFileInfo().path()); + connect(p, &ConsoleProcess::processError, p, [p](const QString &errorString) { + Core::MessageManager::write(tr("Failed to run GHCi: \"%1\".").arg(errorString)); + p->deleteLater(); + }); + connect(p, &ConsoleProcess::stubStopped, p, &QObject::deleteLater); + p->start(); +} + void HaskellManager::readSettings(QSettings *settings) { m_d->stackExecutable = FilePath::fromString( |