Commit 5dd1fba9 authored by Mark Nauwelaerts's avatar Mark Nauwelaerts
Browse files

lspclient: refactor search of diagnostics item for a position

parent 9f34bd8f
...@@ -1385,15 +1385,9 @@ public: ...@@ -1385,15 +1385,9 @@ public:
return nullptr; return nullptr;
} }
// select/scroll to diagnostics item for document and (optionally) line static QStandardItem *getItem(const QStandardItem *topItem, KTextEditor::Cursor pos, bool onlyLine)
bool syncDiagnostics(KTextEditor::Document *document, int line, bool allowTop, bool doShow)
{ {
if (!m_diagnosticsTree)
return false;
auto hint = QAbstractItemView::PositionAtTop;
QStandardItem *targetItem = nullptr; QStandardItem *targetItem = nullptr;
QStandardItem *topItem = getItem(*m_diagnosticsModel, document->url());
if (topItem) { if (topItem) {
int count = topItem->rowCount(); int count = topItem->rowCount();
// let's not run wild on a linear search in a flood of diagnostics // let's not run wild on a linear search in a flood of diagnostics
...@@ -1402,14 +1396,28 @@ public: ...@@ -1402,14 +1396,28 @@ public:
count = 0; count = 0;
for (int i = 0; i < count; ++i) { for (int i = 0; i < count; ++i) {
auto item = topItem->child(i); auto item = topItem->child(i);
int itemline = item->data(RangeData::RangeRole).value<LSPRange>().start().line(); auto range = item->data(RangeData::RangeRole).value<LSPRange>();
if (line == itemline && m_diagnosticsTree) { if ((onlyLine && pos.line() == range.start().line()) || (range.contains(pos))) {
targetItem = item; targetItem = item;
hint = QAbstractItemView::PositionAtCenter;
break; break;
} }
} }
} }
return targetItem;
}
// select/scroll to diagnostics item for document and (optionally) line
bool syncDiagnostics(KTextEditor::Document *document, int line, bool allowTop, bool doShow)
{
if (!m_diagnosticsTree)
return false;
auto hint = QAbstractItemView::PositionAtTop;
QStandardItem *topItem = getItem(*m_diagnosticsModel, document->url());
QStandardItem *targetItem = getItem(topItem, {line, 0}, true);
if (targetItem) {
hint = QAbstractItemView::PositionAtCenter;
}
if (!targetItem && allowTop) { if (!targetItem && allowTop) {
targetItem = topItem; targetItem = topItem;
} }
......
Markdown is supported
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