Skip to content

Commit 6dd73ac

Browse files
Nicolas Arnaud-Cormosnarnaud
authored andcommitted
fix: Fix crash without LSP enabled
Crash was happening during edition or hover.
1 parent 16cf8b4 commit 6dd73ac

File tree

3 files changed

+28
-22
lines changed

3 files changed

+28
-22
lines changed

src/core/codedocument.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "project.h"
1717
#include "querymatch.h"
1818
#include "rangemark.h"
19+
#include "settings.h"
1920
#include "symbol.h"
2021
#include "treesitter/predicates.h"
2122
#include "utils/log.h"
@@ -755,6 +756,8 @@ int CodeDocument::revision() const
755756
bool CodeDocument::checkClient() const
756757
{
757758
Q_ASSERT(textEdit());
759+
if (!Settings::instance()->hasLsp())
760+
return false;
758761
if (!client()) {
759762
spdlog::error("{}: CodeDocument {} has no LSP client - API not available", FUNCTION_NAME, fileName());
760763
return false;

src/core/settings.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
This file is part of Knut.
33
44
SPDX-FileCopyrightText: 2024 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]>
@@ -139,7 +139,7 @@ public slots:
139139
void saveSettings();
140140
void saveIfApplicable();
141141
bool isUser() const;
142-
void triggerLog(const Utils::LoadJsonStatus &loadJsonStatus, const QString &fileName, const QString &caller);
142+
void triggerLog(const ::Utils::LoadJsonStatus &loadJsonStatus, const QString &fileName, const QString &caller);
143143

144144
inline static Settings *m_instance = nullptr;
145145

src/gui/textview.cpp

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
This file is part of Knut.
33
44
SPDX-FileCopyrightText: 2024 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]>
@@ -24,6 +24,7 @@
2424
#include <QToolButton>
2525
#include <QToolTip>
2626
#include <QVBoxLayout>
27+
#include <core/settings.h>
2728

2829
namespace Gui {
2930

@@ -143,25 +144,27 @@ bool TextView::eventFilter(QObject *obj, QEvent *event)
143144
if (event->type() == QEvent::Paint)
144145
updateMarkRect();
145146
if (event->type() == QEvent::ToolTip) {
146-
if (const auto *codedocument = qobject_cast<Core::CodeDocument *>(m_document)) {
147-
if (const auto *helpEvent = dynamic_cast<QHelpEvent *>(event)) {
148-
auto cursor = codedocument->textEdit()->cursorForPosition(helpEvent->pos());
149-
150-
// Make the textEdit a guarded pointer, as it might have been destroyed once the hover
151-
// callback returns.
152-
QPointer<QPlainTextEdit> textEdit(codedocument->textEdit());
153-
QPoint position(helpEvent->globalPos());
154-
155-
// Hover spams the log if it doesn't find anything.
156-
// In our case, that's not a problem, so just disable the log.
157-
Core::LoggerDisabler ld;
158-
159-
codedocument->hover(cursor.position(), [textEdit, position](const auto &hoverText) {
160-
if (!textEdit.isNull() && textEdit->isVisible()) {
161-
QToolTip::showText(position, hoverText, textEdit);
162-
}
163-
});
164-
return true;
147+
if (Core::Settings::instance()->hasLsp()) {
148+
if (const auto *codedocument = qobject_cast<Core::CodeDocument *>(m_document)) {
149+
if (const auto *helpEvent = dynamic_cast<QHelpEvent *>(event)) {
150+
auto cursor = codedocument->textEdit()->cursorForPosition(helpEvent->pos());
151+
152+
// Make the textEdit a guarded pointer, as it might have been destroyed once the hover
153+
// callback returns.
154+
QPointer<QPlainTextEdit> textEdit(codedocument->textEdit());
155+
QPoint position(helpEvent->globalPos());
156+
157+
// Hover spams the log if it doesn't find anything.
158+
// In our case, that's not a problem, so just disable the log.
159+
Core::LoggerDisabler ld;
160+
161+
codedocument->hover(cursor.position(), [textEdit, position](const auto &hoverText) {
162+
if (!textEdit.isNull() && textEdit->isVisible()) {
163+
QToolTip::showText(position, hoverText, textEdit);
164+
}
165+
});
166+
return true;
167+
}
165168
}
166169
}
167170
}

0 commit comments

Comments
 (0)