| 12 | namespace QodeAssist { |
| 13 | |
| 14 | void CompletionErrorHandler::showError( |
| 15 | TextEditor::TextEditorWidget *widget, |
| 16 | const QString &errorMessage, |
| 17 | int autoHideMs) |
| 18 | { |
| 19 | m_widget = widget; |
| 20 | m_errorMessage = errorMessage; |
| 21 | |
| 22 | if (m_widget) { |
| 23 | const QRect cursorRect = m_widget->cursorRect(m_widget->textCursor()); |
| 24 | m_errorPosition = m_widget->viewport()->mapToGlobal(cursorRect.topLeft()) |
| 25 | - Utils::ToolTip::offsetFromPosition(); |
| 26 | |
| 27 | identifyMatch(m_widget, m_widget->textCursor().position(), [this, autoHideMs](auto priority) { |
| 28 | if (priority != Priority_None) { |
| 29 | if (m_errorWidget) { |
| 30 | m_errorWidget->deleteLater(); |
| 31 | } |
| 32 | |
| 33 | m_errorWidget = new ErrorWidget(m_errorMessage, m_widget); |
| 34 | |
| 35 | const QRect cursorRect = m_widget->cursorRect(m_widget->textCursor()); |
| 36 | QPoint globalPos = m_widget->viewport()->mapToGlobal(cursorRect.topLeft()); |
| 37 | QPoint localPos = m_widget->mapFromGlobal(globalPos); |
| 38 | localPos.ry() -= m_errorWidget->height() + 5; |
| 39 | |
| 40 | if (localPos.y() < 0) { |
| 41 | localPos.ry() = cursorRect.bottom() + 5; |
| 42 | } |
| 43 | |
| 44 | m_errorWidget->move(localPos); |
| 45 | m_errorWidget->show(); |
| 46 | m_errorWidget->raise(); |
| 47 | |
| 48 | QObject::connect(m_errorWidget, &ErrorWidget::dismissed, m_errorWidget, [this]() { |
| 49 | hideError(); |
| 50 | }); |
| 51 | } |
| 52 | }); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | void CompletionErrorHandler::hideError() |
| 57 | { |
no test coverage detected