aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Ziller <eike.ziller@qt.io>2017-12-23 11:20:52 +0100
committerEike Ziller <eike.ziller@qt.io>2018-01-06 11:08:02 +0000
commita76efd4cac4592a9534717051c3bba801767d8b2 (patch)
treeb92854693ecce180abc84f73946f14fbcdbe1e61
parentf73e91128adeaca803e53b0f7af79075bf6ee4b1 (diff)
Show error in editor if stack cannot be run
With the option to open the configuration page. Change-Id: I4895e27648d5e161fd0c9b617723f7fdd6853248 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
-rw-r--r--plugins/haskell/haskellconstants.h1
-rw-r--r--plugins/haskell/haskelleditorwidget.cpp25
-rw-r--r--plugins/haskell/haskelleditorwidget.h3
-rw-r--r--plugins/haskell/haskellhoverhandler.cpp19
-rw-r--r--plugins/haskell/optionspage.cpp3
5 files changed, 48 insertions, 3 deletions
diff --git a/plugins/haskell/haskellconstants.h b/plugins/haskell/haskellconstants.h
index 1ec7113..f4c1bea 100644
--- a/plugins/haskell/haskellconstants.h
+++ b/plugins/haskell/haskellconstants.h
@@ -34,6 +34,7 @@ const char C_HASKELL_PROJECT_MIMETYPE[] = "text/x-haskell-project";
const char C_HASKELL_RUNCONFIG_ID_PREFIX[] = "Haskell.Run.";
const char C_HASKELL_PROJECT_ID[] = "Haskell.Project";
const char C_HASKELL_EXECUTABLE_KEY[] = "Haskell.Executable";
+const char OPTIONS_GENERAL[] = "Haskell.A.General";
} // namespace Haskell
} // namespace Constants
diff --git a/plugins/haskell/haskelleditorwidget.cpp b/plugins/haskell/haskelleditorwidget.cpp
index 8d052a9..6454d82 100644
--- a/plugins/haskell/haskelleditorwidget.cpp
+++ b/plugins/haskell/haskelleditorwidget.cpp
@@ -25,11 +25,16 @@
#include "haskelleditorwidget.h"
+#include "haskellconstants.h"
#include "haskelltokenizer.h"
+#include <coreplugin/icore.h>
+#include <coreplugin/infobar.h>
+#include <texteditor/textdocument.h>
#include <utils/textutils.h>
#include <QTextBlock>
+#include <QTimer>
using namespace TextEditor;
@@ -63,6 +68,26 @@ Utils::optional<Token> HaskellEditorWidget::symbolAt(QTextDocument *doc, int pos
return Utils::nullopt;
}
+void HaskellEditorWidget::showFailedToStartStackError(const QString &stackExecutable,
+ TextEditorWidget *widget)
+{
+ static const char id[] = "Haskell.FailedToStartStack";
+ Core::IDocument *document = widget->textDocument();
+ if (!document->infoBar()->containsInfo(id)) {
+ Core::InfoBarEntry info(
+ id,
+ tr("Failed to start Haskell Stack \"%1\". Make sure you have stack installed and configured in the options.")
+ .arg(stackExecutable));
+ info.setCustomButtonInfo(Core::ICore::msgShowOptionsDialog(), [document] {
+ QTimer::singleShot(0, Core::ICore::instance(), [document] {
+ document->infoBar()->removeInfo(id);
+ Core::ICore::showOptionsDialog(Constants::OPTIONS_GENERAL);
+ });
+ });
+ document->infoBar()->addInfo(info);
+ }
+}
+
Utils::Link HaskellEditorWidget::findLinkAt(const QTextCursor &cursor,
bool resolveTarget, bool inNextSplit)
{
diff --git a/plugins/haskell/haskelleditorwidget.h b/plugins/haskell/haskelleditorwidget.h
index 819e040..2421fc3 100644
--- a/plugins/haskell/haskelleditorwidget.h
+++ b/plugins/haskell/haskelleditorwidget.h
@@ -43,6 +43,9 @@ public:
static Utils::optional<Token> symbolAt(QTextDocument *doc, int position,
int *line, int *column);
+ static void showFailedToStartStackError(const QString &stackExecutable,
+ TextEditor::TextEditorWidget *widget);
+
protected:
Utils::Link findLinkAt(const QTextCursor &cursor, bool resolveTarget = true,
bool inNextSplit = false) override;
diff --git a/plugins/haskell/haskellhoverhandler.cpp b/plugins/haskell/haskellhoverhandler.cpp
index bb8472b..ffad6a9 100644
--- a/plugins/haskell/haskellhoverhandler.cpp
+++ b/plugins/haskell/haskellhoverhandler.cpp
@@ -86,7 +86,19 @@ void HaskellHoverHandler::identifyMatch(TextEditor::TextEditorWidget *editorWidg
}
}
-static void tryShowToolTip(const QPointer<QWidget> &widget, const QPoint &point,
+static void showError(const QPointer<TextEditor::TextEditorWidget> &widget,
+ const Error &typeError, const Error &infoError)
+{
+ if (typeError.type == Error::Type::FailedToStartStack
+ || infoError.type == Error::Type::FailedToStartStack) {
+ const QString stackExecutable = typeError.type == Error::Type::FailedToStartStack
+ ? typeError.details
+ : infoError.details;
+ HaskellEditorWidget::showFailedToStartStackError(stackExecutable, widget);
+ }
+}
+
+static void tryShowToolTip(const QPointer<TextEditor::TextEditorWidget> &widget, const QPoint &point,
QFuture<QStringOrError> typeFuture,
QFuture<SymbolInfoOrError> symbolFuture)
{
@@ -94,6 +106,9 @@ static void tryShowToolTip(const QPointer<QWidget> &widget, const QPoint &point,
&& symbolFuture.isResultReadyAt(0) && typeFuture.isResultReadyAt(0)) {
const QStringOrError typeOrError = typeFuture.result();
const SymbolInfoOrError infoOrError = symbolFuture.result();
+ if (const Error *typeError = Utils::get_if<Error>(&typeOrError))
+ if (const Error *infoError = Utils::get_if<Error>(&infoOrError))
+ showError(widget, *typeError, *infoError);
const QString *type = Utils::get_if<QString>(&typeOrError);
const SymbolInfo *info = Utils::get_if<SymbolInfo>(&infoOrError);
const QString typeString = !type || type->isEmpty()
@@ -115,7 +130,7 @@ void HaskellHoverHandler::operateTooltip(TextEditor::TextEditorWidget *editorWid
}
Utils::ToolTip::show(point, HaskellManager::trLookingUp(m_name), editorWidget);
- QPointer<QWidget> widget = editorWidget;
+ QPointer<TextEditor::TextEditorWidget> widget = editorWidget;
std::shared_ptr<AsyncGhcMod> ghcmod;
auto doc = qobject_cast<HaskellDocument *>(editorWidget->textDocument());
QTC_ASSERT(doc, return);
diff --git a/plugins/haskell/optionspage.cpp b/plugins/haskell/optionspage.cpp
index 88a5792..04cab79 100644
--- a/plugins/haskell/optionspage.cpp
+++ b/plugins/haskell/optionspage.cpp
@@ -25,6 +25,7 @@
#include "optionspage.h"
+#include "haskellconstants.h"
#include "haskellmanager.h"
#include <QGroupBox>
@@ -38,7 +39,7 @@ namespace Internal {
OptionsPage::OptionsPage()
{
- setId("A.General");
+ setId(Constants::OPTIONS_GENERAL);
setDisplayName(tr("General"));
setCategory("J.Z.Haskell");
setDisplayCategory(tr("Haskell"));