Commit 363b5a68 authored by Waqar Ahmed's avatar Waqar Ahmed
Browse files

Fix LSPHover, honor markup kind

parent d8cf6287
Pipeline #147597 passed with stage
in 3 minutes and 38 seconds
......@@ -71,8 +71,10 @@ public:
}
// combine contents elements to one string
LSPMarkupKind kind = LSPMarkupKind::PlainText;
QString finalTooltip;
for (auto &element : info.contents) {
kind = element.kind;
if (!finalTooltip.isEmpty()) {
finalTooltip.append(QLatin1Char('\n'));
}
......@@ -81,7 +83,7 @@ public:
// make sure there is no selection, otherwise we interrupt
if (!v->selection()) {
LspTooltip::show(finalTooltip, v->mapToGlobal(v->cursorToCoordinate(position)), v, manual);
LspTooltip::show(finalTooltip, kind, v->mapToGlobal(v->cursorToCoordinate(position)), v, manual);
}
};
......
......@@ -510,24 +510,7 @@ static QList<LSPDocumentHighlight> parseDocumentHighlightList(const QJsonValue &
static LSPMarkupContent parseHoverContentElement(const QJsonValue &contents)
{
LSPMarkupContent result;
if (contents.isString()) {
result.value = contents.toString();
} else {
// should be object, pretend so
auto cont = contents.toObject();
auto text = cont.value(QStringLiteral("value")).toString();
if (text.isEmpty()) {
// nothing to lose, try markdown
result = parseMarkupContent(contents);
} else {
result.value = text;
}
}
if (result.value.length()) {
result.kind = LSPMarkupKind::PlainText;
}
return result;
return parseMarkupContent(contents);
}
static LSPHover parseHover(const QJsonValue &result)
......
......@@ -33,15 +33,19 @@ class Tooltip : public QTextBrowser
Q_OBJECT
public:
void setTooltipText(const QString &text)
void setTooltipText(const QString &text, LSPMarkupKind kind)
{
if (text.isEmpty())
return;
QString htext = text;
// we have to do this to handle soft line
htext.replace(QLatin1Char('\n'), QStringLiteral(" \n"));
setMarkdown(htext);
if (kind == LSPMarkupKind::PlainText) {
setPlainText(text);
} else {
QString htext = text;
htext.replace(QLatin1Char('\n'), QStringLiteral(" \n"));
setMarkdown(htext);
}
resizeTip(text);
}
......@@ -238,7 +242,7 @@ private:
bool m_manual;
};
void LspTooltip::show(const QString &text, QPoint pos, KTextEditor::View *v, bool manual)
void LspTooltip::show(const QString &text, LSPMarkupKind kind, QPoint pos, KTextEditor::View *v, bool manual)
{
if (text.isEmpty())
return;
......@@ -252,7 +256,7 @@ void LspTooltip::show(const QString &text, QPoint pos, KTextEditor::View *v, boo
tooltip = new Tooltip(v, manual);
tooltip->setView(v);
tooltip->setTooltipText(text);
tooltip->setTooltipText(text, kind);
tooltip->place(pos);
tooltip->show();
}
......
......@@ -6,6 +6,8 @@
#ifndef LSPTOOLTIP_H
#define LSPTOOLTIP_H
#include "lspclientprotocol.h"
#include <QPoint>
class QWidget;
......@@ -21,7 +23,7 @@ class LspTooltip
{
public:
// tooltip hidden after timeout msec (if > 0)
static void show(const QString &text, QPoint pos, KTextEditor::View *v, bool manual);
static void show(const QString &text, LSPMarkupKind kind, QPoint pos, KTextEditor::View *v, bool manual);
};
#endif // LSPTOOLTIP_H
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment