Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/core/codedocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "project.h"
#include "querymatch.h"
#include "rangemark.h"
#include "settings.h"
#include "symbol.h"
#include "treesitter/predicates.h"
#include "utils/log.h"
Expand Down Expand Up @@ -755,6 +756,8 @@ int CodeDocument::revision() const
bool CodeDocument::checkClient() const
{
Q_ASSERT(textEdit());
if (!Settings::instance()->hasLsp())
return false;
if (!client()) {
spdlog::error("{}: CodeDocument {} has no LSP client - API not available", FUNCTION_NAME, fileName());
return false;
Expand Down
4 changes: 2 additions & 2 deletions src/core/settings.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
This file is part of Knut.

SPDX-FileCopyrightText: 2024 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
Expand Down Expand Up @@ -139,7 +139,7 @@ public slots:
void saveSettings();
void saveIfApplicable();
bool isUser() const;
void triggerLog(const Utils::LoadJsonStatus &loadJsonStatus, const QString &fileName, const QString &caller);
void triggerLog(const ::Utils::LoadJsonStatus &loadJsonStatus, const QString &fileName, const QString &caller);

inline static Settings *m_instance = nullptr;

Expand Down
43 changes: 23 additions & 20 deletions src/gui/textview.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
This file is part of Knut.

SPDX-FileCopyrightText: 2024 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
Expand All @@ -24,6 +24,7 @@
#include <QToolButton>
#include <QToolTip>
#include <QVBoxLayout>
#include <core/settings.h>

namespace Gui {

Expand Down Expand Up @@ -143,25 +144,27 @@ bool TextView::eventFilter(QObject *obj, QEvent *event)
if (event->type() == QEvent::Paint)
updateMarkRect();
if (event->type() == QEvent::ToolTip) {
if (const auto *codedocument = qobject_cast<Core::CodeDocument *>(m_document)) {
if (const auto *helpEvent = dynamic_cast<QHelpEvent *>(event)) {
auto cursor = codedocument->textEdit()->cursorForPosition(helpEvent->pos());

// Make the textEdit a guarded pointer, as it might have been destroyed once the hover
// callback returns.
QPointer<QPlainTextEdit> textEdit(codedocument->textEdit());
QPoint position(helpEvent->globalPos());

// Hover spams the log if it doesn't find anything.
// In our case, that's not a problem, so just disable the log.
Core::LoggerDisabler ld;

codedocument->hover(cursor.position(), [textEdit, position](const auto &hoverText) {
if (!textEdit.isNull() && textEdit->isVisible()) {
QToolTip::showText(position, hoverText, textEdit);
}
});
return true;
if (Core::Settings::instance()->hasLsp()) {
if (const auto *codedocument = qobject_cast<Core::CodeDocument *>(m_document)) {
if (const auto *helpEvent = dynamic_cast<QHelpEvent *>(event)) {
auto cursor = codedocument->textEdit()->cursorForPosition(helpEvent->pos());

// Make the textEdit a guarded pointer, as it might have been destroyed once the hover
// callback returns.
QPointer<QPlainTextEdit> textEdit(codedocument->textEdit());
QPoint position(helpEvent->globalPos());

// Hover spams the log if it doesn't find anything.
// In our case, that's not a problem, so just disable the log.
Core::LoggerDisabler ld;

codedocument->hover(cursor.position(), [textEdit, position](const auto &hoverText) {
if (!textEdit.isNull() && textEdit->isVisible()) {
QToolTip::showText(position, hoverText, textEdit);
}
});
return true;
}
}
}
}
Expand Down
Loading