Skip to content

Commit 3585785

Browse files
committed
#3467 lsp: add setting to show log output as debug log
Signed-off-by: Patrizio Bekerle <patrizio@bekerle.com>
1 parent c91d17b commit 3585785

6 files changed

Lines changed: 61 additions & 13 deletions

File tree

CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,24 @@
1616
was called synchronously, causing a SIGSEGV in QtWidgets; the UI update is now
1717
deferred via `QTimer::singleShot` so it runs after the current event is fully
1818
processed (for [#3578](https://github.com/pbek/QOwnNotes/issues/3578))
19+
- Added a **Show all LSP server log output in debug log** checkbox to the
20+
**Markdown language server** section in the **Editor** settings; when
21+
enabled, every line written to the LSP server's stderr is forwarded to
22+
the Qt debug log so the full server output is visible (e.g. via
23+
`QT_LOGGING_RULES="*.debug=true"`); the checkbox is disabled when the
24+
LSP is not enabled (for [#3467](https://github.com/pbek/QOwnNotes/issues/3467))
25+
- All Markdown LSP server stderr output is then forwarded to the debug log
26+
(via `qDebug`) so the full server log is visible when running QOwnNotes
27+
with debug output enabled; previously only lines containing `ERR`/`ERROR`
28+
were forwarded
29+
- Added debug logging when `textDocument/publishDiagnostics` notifications
30+
are received from the Markdown LSP server and when they are applied to the
31+
note text edit, to help diagnose why error markers may not appear; note that
32+
`marksman` (the default LSP server) does not publish diagnostics — it
33+
focuses on cross-reference and wiki-link completion only; to get real-time
34+
wave-underline error markers in the note editor, configure a linting LSP
35+
such as `rumdl` (command: `rumdl`, argument: `server`) which provides 71
36+
Markdown lint rules and publishes `textDocument/publishDiagnostics`
1937

2038
## 26.4.22
2139

src/services/markdownlspclient.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ void MarkdownLspClient::setServerCommand(const QString &command, const QStringLi
2828
_arguments = arguments;
2929
}
3030

31+
void MarkdownLspClient::setVerboseLogging(bool enabled) { _verboseLogging = enabled; }
32+
3133
bool MarkdownLspClient::start() {
3234
if (_command.isEmpty()) {
3335
emit errorMessage(tr("Markdown LSP server command is empty"));
@@ -427,6 +429,10 @@ void MarkdownLspClient::onReadyReadStandardError() {
427429
if (trimmed.isEmpty()) {
428430
continue;
429431
}
432+
// Log all stderr output as debug if verbose logging is enabled
433+
if (_verboseLogging) {
434+
qDebug() << "Markdown LSP server:" << trimmed;
435+
}
430436
if (errorPattern.match(trimmed).hasMatch()) {
431437
emit errorMessage(trimmed);
432438
}
@@ -625,6 +631,7 @@ void MarkdownLspClient::handleNotification(const QJsonObject &object) {
625631
diagnostics.push_back(diagnostic);
626632
}
627633

634+
qDebug() << "Markdown LSP diagnostics received for" << uri << "- count:" << diagnostics.size();
628635
emit diagnosticsReceived(uri, diagnostics);
629636
}
630637

src/services/markdownlspclient.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class MarkdownLspClient : public QObject {
4545
~MarkdownLspClient() override;
4646

4747
void setServerCommand(const QString &command, const QStringList &arguments);
48+
void setVerboseLogging(bool enabled);
4849
bool start();
4950
void shutdown();
5051
bool isRunning() const;
@@ -99,6 +100,7 @@ class MarkdownLspClient : public QObject {
99100
QByteArray _readBuffer;
100101
QString _command;
101102
QStringList _arguments;
103+
bool _verboseLogging = false;
102104
int _nextRequestId = 1;
103105
int _initializeRequestId = -1;
104106
bool _initialized = false;

src/widgets/qownnotesmarkdowntextedit.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3439,6 +3439,8 @@ void QOwnNotesMarkdownTextEdit::applyMarkdownLspSettings() {
34393439
.toString();
34403440
const QStringList arguments =
34413441
settings.value(QStringLiteral("Editor/markdownLspArguments")).toStringList();
3442+
const bool verboseLogging =
3443+
settings.value(QStringLiteral("Editor/markdownLspVerboseLogging"), false).toBool();
34423444

34433445
if (!enabled) {
34443446
_markdownLspEnabled = false;
@@ -3473,6 +3475,7 @@ void QOwnNotesMarkdownTextEdit::applyMarkdownLspSettings() {
34733475
}
34743476

34753477
_markdownLspClient->setServerCommand(command, arguments);
3478+
_markdownLspClient->setVerboseLogging(verboseLogging);
34763479
if (_markdownLspClient->start()) {
34773480
const QString rootPath = NoteFolder::currentLocalPath();
34783481
_markdownLspClient->initialize(rootPath, QStringLiteral("QOwnNotes"),
@@ -3598,9 +3601,12 @@ void QOwnNotesMarkdownTextEdit::showMarkdownLspCompletions(int requestId,
35983601
void QOwnNotesMarkdownTextEdit::showMarkdownLspDiagnostics(
35993602
const QString &uri, const QVector<MarkdownLspClient::Diagnostic> &diagnostics) {
36003603
if (uri != _markdownLspUri) {
3604+
qDebug() << "Markdown LSP: ignoring diagnostics for" << uri
3605+
<< "(current:" << _markdownLspUri << ")";
36013606
return;
36023607
}
36033608

3609+
qDebug() << "Markdown LSP: applying" << diagnostics.size() << "diagnostics for" << uri;
36043610
_markdownLspDiagnostics = diagnostics;
36053611
_markdownLspDiagnosticsSelections.clear();
36063612
for (const MarkdownLspClient::Diagnostic &diagnostic : diagnostics) {

src/widgets/settings/editorsettingswidget.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ void EditorSettingsWidget::readSettings() {
9191
settings.value(QStringLiteral("Editor/markdownLspArguments"))
9292
.toStringList()
9393
.join(QLatin1Char(' ')));
94+
ui->markdownLspVerboseLoggingCheckBox->setChecked(
95+
settings.value(QStringLiteral("Editor/markdownLspVerboseLogging"), false).toBool());
9496
// Initialize dependent widget state for LSP fields
9597
on_markdownLspEnabledCheckBox_toggled(ui->markdownLspEnabledCheckBox->isChecked());
9698
ui->cursorWidthSpinBox->setValue(settings.value(QStringLiteral("cursorWidth"), 1).toInt());
@@ -147,6 +149,8 @@ void EditorSettingsWidget::storeSettings() {
147149
#else
148150
QRegularExpression(QStringLiteral("\\s+")), Qt::SkipEmptyParts));
149151
#endif
152+
settings.setValue(QStringLiteral("Editor/markdownLspVerboseLogging"),
153+
ui->markdownLspVerboseLoggingCheckBox->isChecked());
150154
settings.setValue(QStringLiteral("cursorWidth"), ui->cursorWidthSpinBox->value());
151155
settings.setValue(QStringLiteral("insertTimeFormat"), ui->timeFormatLineEdit->text());
152156
}
@@ -173,6 +177,7 @@ void EditorSettingsWidget::on_markdownLspEnabledCheckBox_toggled(bool checked) {
173177
ui->markdownLspArgumentsLineEdit->setEnabled(checked);
174178
ui->markdownLspCommandLabel->setEnabled(checked);
175179
ui->markdownLspArgumentsLabel->setEnabled(checked);
180+
ui->markdownLspVerboseLoggingCheckBox->setEnabled(checked);
176181
}
177182

178183
/**

src/widgets/settings/editorsettingswidget.ui

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -302,19 +302,29 @@
302302
</property>
303303
</widget>
304304
</item>
305-
<item row="2" column="1">
306-
<widget class="QLineEdit" name="markdownLspArgumentsLineEdit">
307-
<property name="toolTip">
308-
<string>Optional arguments separated by spaces.</string>
309-
</property>
310-
<property name="placeholderText">
311-
<string>Optional arguments</string>
312-
</property>
313-
<property name="clearButtonEnabled">
314-
<bool>true</bool>
315-
</property>
316-
</widget>
317-
</item>
305+
<item row="2" column="1">
306+
<widget class="QLineEdit" name="markdownLspArgumentsLineEdit">
307+
<property name="toolTip">
308+
<string>Optional arguments separated by spaces.</string>
309+
</property>
310+
<property name="placeholderText">
311+
<string>Optional arguments</string>
312+
</property>
313+
<property name="clearButtonEnabled">
314+
<bool>true</bool>
315+
</property>
316+
</widget>
317+
</item>
318+
<item row="3" column="0" colspan="2">
319+
<widget class="QCheckBox" name="markdownLspVerboseLoggingCheckBox">
320+
<property name="toolTip">
321+
<string>Log all LSP server output (stderr) to the debug log. Useful for troubleshooting LSP server issues.</string>
322+
</property>
323+
<property name="text">
324+
<string>Show all LSP server log output in debug log</string>
325+
</property>
326+
</widget>
327+
</item>
318328
</layout>
319329
</widget>
320330
</item>

0 commit comments

Comments
 (0)