diff options
author | Eike Ziller <git@eikeziller.de> | 2017-07-02 15:33:25 +0200 |
---|---|---|
committer | Eike Ziller <git@eikeziller.de> | 2017-10-01 20:11:08 +0200 |
commit | 224815da1c03c2ad82900d1354590b8f678c672a (patch) | |
tree | 6a1255a4d8ba72f2d6121d805a6dd91483446059 /plugins/haskell/ghcmod.cpp | |
parent | d1c0bd6491e9ff5a2d9ce31d523901640eadbb66 (diff) |
Add options page for stack executable
Diffstat (limited to 'plugins/haskell/ghcmod.cpp')
-rw-r--r-- | plugins/haskell/ghcmod.cpp | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/plugins/haskell/ghcmod.cpp b/plugins/haskell/ghcmod.cpp index f51841b..4eabc1a 100644 --- a/plugins/haskell/ghcmod.cpp +++ b/plugins/haskell/ghcmod.cpp @@ -40,7 +40,6 @@ Q_LOGGING_CATEGORY(ghcModLog, "qtc.haskell.ghcmod") Q_LOGGING_CATEGORY(asyncGhcModLog, "qtc.haskell.ghcmod.async") // TODO do not hardcode -const char STACK_EXE[] = "/usr/local/bin/stack"; const int kTimeoutMS = 10 * 1000; using namespace Utils; @@ -48,6 +47,9 @@ using namespace Utils; namespace Haskell { namespace Internal { +FileName GhcMod::m_stackExecutable = Utils::FileName::fromString("stack"); +QMutex GhcMod::m_mutex; + GhcMod::GhcMod(const Utils::FileName &path) : m_path(path) { @@ -82,15 +84,22 @@ Utils::optional<QString> GhcMod::typeInfo(const FileName &filePath, int line, in bool GhcMod::ensureStarted() { + m_mutex.lock(); + const FileName plainStackExecutable = m_stackExecutable; + m_mutex.unlock(); + Environment env = Environment::systemEnvironment(); + const FileName stackExecutable = env.searchInPath(plainStackExecutable.toString()); + if (m_process && FileName::fromString(m_process->program()) != stackExecutable) + shutdown(); if (m_process) return true; log("starting"); - Environment env = Environment::systemEnvironment(); - env.prependOrSetPath(QFileInfo(STACK_EXE).absolutePath()); // for ghc-mod finding stack back + // for ghc-mod finding stack back: + env.prependOrSetPath(stackExecutable.toFileInfo().absolutePath()); m_process.reset(new QProcess); m_process->setWorkingDirectory(m_path.toString()); m_process->setEnvironment(env.toStringList()); - m_process->start(STACK_EXE, {"exec", "ghc-mod", "--", "legacy-interactive"}); + m_process->start(stackExecutable.toString(), {"exec", "ghc-mod", "--", "legacy-interactive"}); if (!m_process->waitForStarted(kTimeoutMS)) { log("failed to start"); return false; @@ -208,6 +217,12 @@ Utils::optional<QString> GhcMod::parseTypeInfo(const Utils::optional<QByteArray> return Utils::nullopt; } +void GhcMod::setStackExecutable(const FileName &filePath) +{ + QMutexLocker lock(&m_mutex); + m_stackExecutable = filePath; +} + AsyncGhcMod::AsyncGhcMod(const FileName &path) : m_ghcmod(path) { |