aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/haskell/haskellhoverhandler.cpp
diff options
context:
space:
mode:
authorEike Ziller <git@eikeziller.de>2017-09-25 11:57:34 +0200
committerEike Ziller <git@eikeziller.de>2017-10-01 20:11:08 +0200
commit3f1f50c44847a0e76a95507c9566a35dfe809a78 (patch)
treeb9bc03a93a0743d7f7b5568f3e0c04b74c30b08e /plugins/haskell/haskellhoverhandler.cpp
parent233678df4307588d6c748fbf4463674fd4a58268 (diff)
Support "Follow Symbol Under Cursor"
Diffstat (limited to 'plugins/haskell/haskellhoverhandler.cpp')
-rw-r--r--plugins/haskell/haskellhoverhandler.cpp38
1 files changed, 12 insertions, 26 deletions
diff --git a/plugins/haskell/haskellhoverhandler.cpp b/plugins/haskell/haskellhoverhandler.cpp
index 5e03e32..f418170 100644
--- a/plugins/haskell/haskellhoverhandler.cpp
+++ b/plugins/haskell/haskellhoverhandler.cpp
@@ -26,6 +26,8 @@
#include "haskellhoverhandler.h"
#include "haskelldocument.h"
+#include "haskelleditorwidget.h"
+#include "haskellmanager.h"
#include "haskelltokenizer.h"
#include <texteditor/textdocument.h>
@@ -35,11 +37,6 @@
#include <utils/synchronousprocess.h>
#include <utils/tooltip/tooltip.h>
-#include <QTextBlock>
-#include <QTextDocument>
-
-#include <functional>
-
using namespace Utils;
static QString toCode(const QString &s)
@@ -77,27 +74,16 @@ void HaskellHoverHandler::identifyMatch(TextEditor::TextEditorWidget *editorWidg
{
cancel();
m_name.clear();
- editorWidget->convertPosition(pos, &m_line, &m_col);
- if (m_line < 0 || m_col < 0)
- return;
- QTextBlock block = editorWidget->document()->findBlockByNumber(m_line - 1);
- if (block.text().isEmpty())
- return;
- m_filePath = editorWidget->textDocument()->filePath();
- const int startState = block.previous().isValid() ? block.previous().userState() : -1;
- const Tokens tokens = HaskellTokenizer::tokenize(block.text(), startState);
- const Token token = tokens.tokenAtColumn(m_col);
- if (token.isValid()
- && (token.type == TokenType::Variable
- || token.type == TokenType::Operator
- || token.type == TokenType::Constructor
- || token.type == TokenType::OperatorConstructor)) {
- m_name = token.text.toString();
- }
- if (m_name.isEmpty())
- setPriority(-1);
- else
+ m_filePath.clear();
+ const Utils::optional<Token> token = HaskellEditorWidget::symbolAt(editorWidget->document(),
+ pos, &m_line, &m_col);
+ if (token) {
+ m_filePath = editorWidget->textDocument()->filePath();
+ m_name = token->text.toString();
setPriority(Priority_Tooltip);
+ } else {
+ setPriority(-1);
+ }
}
static void tryShowToolTip(const QPointer<QWidget> &widget, const QPoint &point,
@@ -125,7 +111,7 @@ void HaskellHoverHandler::operateTooltip(TextEditor::TextEditorWidget *editorWid
Utils::ToolTip::hide();
return;
}
- Utils::ToolTip::show(point, tr("Looking up \"%1\"").arg(m_name), editorWidget);
+ Utils::ToolTip::show(point, HaskellManager::trLookingUp(m_name), editorWidget);
QPointer<QWidget> widget = editorWidget;
std::shared_ptr<AsyncGhcMod> ghcmod;