1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
From 6fc3bf6e5bd540e842e32c4a959c2158c8573be5 Mon Sep 17 00:00:00 2001
From: Mark Nauwelaerts <mark.nauwelaerts@gmail.com>
Date: Mon, 13 Dec 2021 21:36:50 +0100
Subject: [PATCH] lspclient: send didSave notification if so requested
---
addons/lspclient/lspclientserver.cpp | 7 +++++--
addons/lspclient/lspclientservermanager.cpp | 15 +++++++++++++++
2 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/addons/lspclient/lspclientserver.cpp b/addons/lspclient/lspclientserver.cpp
index a7094fde2..9fb5844cd 100644
--- a/addons/lspclient/lspclientserver.cpp
+++ b/addons/lspclient/lspclientserver.cpp
@@ -1255,7 +1255,8 @@ private:
{QStringLiteral("documentSymbol"), QJsonObject{{QStringLiteral("hierarchicalDocumentSymbolSupport"), true}} },
{QStringLiteral("publishDiagnostics"), QJsonObject{{QStringLiteral("relatedInformation"), true}}},
{QStringLiteral("codeAction"), codeAction},
- {QStringLiteral("semanticTokens"), semanticTokens}
+ {QStringLiteral("semanticTokens"), semanticTokens},
+ {QStringLiteral("synchronization"), QJsonObject{{QStringLiteral("didSave"), true}}},
},
},
{QStringLiteral("window"),
@@ -1475,7 +1476,9 @@ public:
void didSave(const QUrl &document, const QString &text)
{
auto params = textDocumentParams(document);
- params[QStringLiteral("text")] = text;
+ if (!text.isNull()) {
+ params[QStringLiteral("text")] = text;
+ }
send(init_request(QStringLiteral("textDocument/didSave"), params));
}
diff --git a/addons/lspclient/lspclientservermanager.cpp b/addons/lspclient/lspclientservermanager.cpp
index 1e03801ea..551926e23 100644
--- a/addons/lspclient/lspclientservermanager.cpp
+++ b/addons/lspclient/lspclientservermanager.cpp
@@ -833,6 +833,7 @@ private:
connect(doc, &KTextEditor::Document::aboutToClose, this, &self_type::untrack, Qt::UniqueConnection);
connect(doc, &KTextEditor::Document::destroyed, this, &self_type::untrack, Qt::UniqueConnection);
connect(doc, &KTextEditor::Document::textChanged, this, &self_type::onTextChanged, Qt::UniqueConnection);
+ connect(doc, &KTextEditor::Document::documentSavedOrUploaded, this, &self_type::onDocumentSaved, Qt::UniqueConnection);
// in case of incremental change
connect(doc, &KTextEditor::Document::textInserted, this, &self_type::onTextInserted, Qt::UniqueConnection);
connect(doc, &KTextEditor::Document::textRemoved, this, &self_type::onTextRemoved, Qt::UniqueConnection);
@@ -976,6 +977,20 @@ private:
}
}
+ void onDocumentSaved(KTextEditor::Document *doc, bool saveAs)
+ {
+ if (!saveAs) {
+ auto it = m_docs.find(doc);
+ if (it != m_docs.end() && it->server) {
+ auto server = it->server;
+ const auto &saveOptions = server->capabilities().textDocumentSync.save;
+ if (saveOptions) {
+ server->didSave(doc->url(), saveOptions->includeText ? doc->text() : QString());
+ }
+ }
+ }
+ }
+
void onMessage(bool isLog, const LSPLogMessageParams ¶ms)
{
// determine server description
--
GitLab
|