diff --git a/src/plugins/haskell/haskellplugin.cpp b/src/plugins/haskell/haskellplugin.cpp index 84a86f7db48..1afa8cd175f 100644 --- a/src/plugins/haskell/haskellplugin.cpp +++ b/src/plugins/haskell/haskellplugin.cpp @@ -16,8 +16,11 @@ #include #include #include -#include + #include +#include +#include + #include #include diff --git a/src/plugins/haskell/haskellrunconfiguration.cpp b/src/plugins/haskell/haskellrunconfiguration.cpp index fec7f73e966..ef97ee4d4f0 100644 --- a/src/plugins/haskell/haskellrunconfiguration.cpp +++ b/src/plugins/haskell/haskellrunconfiguration.cpp @@ -4,19 +4,74 @@ #include "haskellrunconfiguration.h" #include "haskellconstants.h" -#include "haskellproject.h" #include "haskelltr.h" #include "haskellsettings.h" #include +#include +#include #include #include #include using namespace ProjectExplorer; +using namespace Utils; -namespace Haskell { -namespace Internal { +namespace Haskell::Internal { + +class HaskellRunConfiguration : public RunConfiguration +{ +public: + HaskellRunConfiguration(Target *target, Id id) + : RunConfiguration(target, id) + { + environment.setSupportForBuildEnvironment(target); + + executable.setSettingsKey("Haskell.Executable"); + executable.setLabelText(Tr::tr("Executable")); + + arguments.setMacroExpander(macroExpander()); + + workingDir.setMacroExpander(macroExpander()); + workingDir.setEnvironment(&environment); + workingDir.setDefaultWorkingDirectory(project()->projectDirectory()); + workingDir.setVisible(false); + + setUpdater([this] { executable.setValue(buildTargetInfo().buildKey); }); + + connect(target, &Target::buildSystemUpdated, this, &RunConfiguration::update); + update(); + } + +private: + ProjectExplorer::Runnable runnable() const final + { + const FilePath projectDirectory = project()->projectDirectory(); + Runnable r; + QStringList args; + if (BuildConfiguration *buildConfiguration = target()->activeBuildConfiguration()) { + args << "--work-dir" + << QDir(projectDirectory.toString()).relativeFilePath( + buildConfiguration->buildDirectory().toString()); + } + args << "exec" << executable(); + if (!arguments.arguments().isEmpty()) + args << "--" << arguments.arguments(); + + r.workingDirectory = projectDirectory; + r.environment = environment.environment(); + r.command = {r.environment.searchInPath(settings().stackPath().path()), args}; + return r; + } + + EnvironmentAspect environment{this}; + StringAspect executable{this}; + ArgumentsAspect arguments{this}; + WorkingDirectoryAspect workingDir{this}; + TerminalAspect terminal{this}; +}; + +// Factory HaskellRunConfigurationFactory::HaskellRunConfigurationFactory() { @@ -25,56 +80,4 @@ HaskellRunConfigurationFactory::HaskellRunConfigurationFactory() addSupportedTargetDeviceType(ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE); } -HaskellExecutableAspect::HaskellExecutableAspect() -{ - setSettingsKey("Haskell.Executable"); - setLabelText(Tr::tr("Executable")); -} - -HaskellRunConfiguration::HaskellRunConfiguration(Target *target, Utils::Id id) - : RunConfiguration(target, id) -{ - auto envAspect = addAspect(); - envAspect->setSupportForBuildEnvironment(target); - - addAspect(); - - auto argsAspect = addAspect(); - argsAspect->setMacroExpander(macroExpander()); - - auto workingDirAspect = addAspect(); - workingDirAspect->setMacroExpander(macroExpander()); - workingDirAspect->setEnvironment(envAspect); - workingDirAspect->setDefaultWorkingDirectory(target->project()->projectDirectory()); - workingDirAspect->setVisible(false); - - addAspect(); - - setUpdater([this] { aspect()->setValue(buildTargetInfo().buildKey); }); - connect(target, &Target::buildSystemUpdated, this, &RunConfiguration::update); - update(); -} - -Runnable HaskellRunConfiguration::runnable() const -{ - const Utils::FilePath projectDirectory = target()->project()->projectDirectory(); - Runnable r; - QStringList args; - if (BuildConfiguration *buildConfiguration = target()->activeBuildConfiguration()) { - args << "--work-dir" - << QDir(projectDirectory.toString()).relativeFilePath( - buildConfiguration->buildDirectory().toString()); - } - args << "exec" << aspect()->value(); - const QString arguments = aspect()->arguments(); - if (!arguments.isEmpty()) - args << "--" << arguments; - - r.workingDirectory = projectDirectory; - r.environment = aspect()->environment(); - r.command = {r.environment.searchInPath(settings().stackPath().path()), args}; - return r; -} - -} // namespace Internal -} // namespace Haskell +} // Haskell::Internal diff --git a/src/plugins/haskell/haskellrunconfiguration.h b/src/plugins/haskell/haskellrunconfiguration.h index c0c0423d2a0..579f8110a75 100644 --- a/src/plugins/haskell/haskellrunconfiguration.h +++ b/src/plugins/haskell/haskellrunconfiguration.h @@ -3,24 +3,9 @@ #pragma once -#include -#include -#include -#include +#include -namespace Haskell { -namespace Internal { - -class HaskellRunConfiguration : public ProjectExplorer::RunConfiguration -{ - Q_OBJECT - -public: - HaskellRunConfiguration(ProjectExplorer::Target *target, Utils::Id id); - -private: - ProjectExplorer::Runnable runnable() const final; -}; +namespace Haskell::Internal { class HaskellRunConfigurationFactory : public ProjectExplorer::RunConfigurationFactory { @@ -28,13 +13,4 @@ public: HaskellRunConfigurationFactory(); }; -class HaskellExecutableAspect : public Utils::StringAspect -{ - Q_OBJECT - -public: - HaskellExecutableAspect(); -}; - -} // namespace Internal -} // namespace Haskell +} // Haskell::Internal