File: upstream_ca61073b_Implement-LSPClientConfigPage-defaults-correctly.patch

package info (click to toggle)
kate 4%3A25.04.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 53,220 kB
  • sloc: cpp: 103,394; xml: 88,828; javascript: 1,835; ansic: 1,762; python: 141; lisp: 82; sh: 79; perl: 39; php: 28; makefile: 23; f90: 19; ruby: 15; tcl: 10
file content (297 lines) | stat: -rw-r--r-- 12,856 bytes parent folder | download
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
From ca61073bf026561c68aa5c18db0e8290bf660f82 Mon Sep 17 00:00:00 2001
From: Igor Kushnir <igorkuo@gmail.com>
Date: Sun, 11 May 2025 17:17:42 +0300
Subject: [PATCH] Implement LSPClientConfigPage::defaults() correctly

Functions that override KTextEditor::ConfigPage::defaults() are empty or
simply call reset() in many KTextEditor and Kate classes. This is not a
problem for Kate, KWrite, RKWard, Kile or KTechLab, because these
applications never invoke defaults(). KDevelop, however, invokes
defaults() when the user clicks the Restore Defaults button in the
Configure KDevelop dialog.

Instead of calling reset() in LSPClientConfigPage::defaults(), set the
checked state of each checkbox on the Client Settings tab of the LSP
Client configuration page to the default value of the corresponding
option as defined in LSPClientPlugin::readConfig().

Do not clear the empty-by-default UI elements on the second and third
tabs of the LSP Client configuration page to avoid accidental user data
loss. KDevelop's Clazy and Clang-Tidy configuration pages similarly do
not remove check sets configured by the user when the Restore Defaults
button is clicked.

Extract struct LSPClientPluginOptions and initialize its data members to
the actual default values defined in LSPClientPlugin::readConfig() so as
to reuse the default values of the LSP Client options and thus prevent
them from getting out of sync. The extracted struct also allows to share
between LSPClientConfigPage::reset() and LSPClientConfigPage::defaults()
the code that populates the checkboxes.

Reorder the declarations of the data members moved into
LSPClientPluginOptions and the assignments to them in
LSPClientPlugin::readConfig() to match the order in
LSPClientConfigPage::apply() and LSPClientConfigPage::reset().

Make LSPClientPlugin::readConfig() private and document the assumption
relied upon by the updated definition of this function.
---
 addons/lspclient/lspclientconfigpage.cpp | 54 ++++++++++++---------
 addons/lspclient/lspclientconfigpage.h   |  3 ++
 addons/lspclient/lspclientplugin.cpp     | 47 ++++++++++--------
 addons/lspclient/lspclientplugin.h       | 62 +++++++++++++++---------
 4 files changed, 102 insertions(+), 64 deletions(-)

diff --git a/addons/lspclient/lspclientconfigpage.cpp b/addons/lspclient/lspclientconfigpage.cpp
index f55079e3f4..83fa669dd3 100644
--- a/addons/lspclient/lspclientconfigpage.cpp
+++ b/addons/lspclient/lspclientconfigpage.cpp
@@ -157,30 +157,35 @@ void LSPClientConfigPage::apply()
     m_plugin->writeConfig();
 }
 
+void LSPClientConfigPage::resetUiTo(const LSPClientPluginOptions &options)
+{
+    ui->chkSymbolDetails->setChecked(options.m_symbolDetails);
+    ui->chkSymbolTree->setChecked(options.m_symbolTree);
+    ui->chkSymbolExpand->setChecked(options.m_symbolExpand);
+    ui->chkSymbolSort->setChecked(options.m_symbolSort);
+
+    ui->chkShowCompl->setChecked(options.m_showCompl);
+    ui->chkComplDoc->setChecked(options.m_complDoc);
+    ui->chkRefDeclaration->setChecked(options.m_refDeclaration);
+    ui->chkComplParens->setChecked(options.m_complParens);
+
+    ui->chkAutoHover->setChecked(options.m_autoHover);
+    ui->chkOnTypeFormatting->setChecked(options.m_onTypeFormatting);
+    ui->chkIncrementalSync->setChecked(options.m_incrementalSync);
+    ui->chkHighlightGoto->setChecked(options.m_highlightGoto);
+    ui->chkSemanticHighlighting->setChecked(options.m_semanticHighlighting);
+    ui->chkSignatureHelp->setChecked(options.m_signatureHelp);
+    ui->chkAutoImport->setChecked(options.m_autoImport);
+    ui->chkFmtOnSave->setChecked(options.m_fmtOnSave);
+    ui->chkInlayHint->setChecked(options.m_inlayHints);
+
+    ui->chkDiagnostics->setChecked(options.m_diagnostics);
+    ui->chkMessages->setChecked(options.m_messages);
+}
+
 void LSPClientConfigPage::reset()
 {
-    ui->chkSymbolDetails->setChecked(m_plugin->m_symbolDetails);
-    ui->chkSymbolTree->setChecked(m_plugin->m_symbolTree);
-    ui->chkSymbolExpand->setChecked(m_plugin->m_symbolExpand);
-    ui->chkSymbolSort->setChecked(m_plugin->m_symbolSort);
-
-    ui->chkShowCompl->setChecked(m_plugin->m_showCompl);
-    ui->chkComplDoc->setChecked(m_plugin->m_complDoc);
-    ui->chkRefDeclaration->setChecked(m_plugin->m_refDeclaration);
-    ui->chkComplParens->setChecked(m_plugin->m_complParens);
-
-    ui->chkAutoHover->setChecked(m_plugin->m_autoHover);
-    ui->chkOnTypeFormatting->setChecked(m_plugin->m_onTypeFormatting);
-    ui->chkIncrementalSync->setChecked(m_plugin->m_incrementalSync);
-    ui->chkHighlightGoto->setChecked(m_plugin->m_highlightGoto);
-    ui->chkSemanticHighlighting->setChecked(m_plugin->m_semanticHighlighting);
-    ui->chkSignatureHelp->setChecked(m_plugin->m_signatureHelp);
-    ui->chkAutoImport->setChecked(m_plugin->m_autoImport);
-    ui->chkFmtOnSave->setChecked(m_plugin->m_fmtOnSave);
-    ui->chkInlayHint->setChecked(m_plugin->m_inlayHints);
-
-    ui->chkDiagnostics->setChecked(m_plugin->m_diagnostics);
-    ui->chkMessages->setChecked(m_plugin->m_messages);
+    resetUiTo(*m_plugin);
 
     ui->edtConfigPath->setUrl(m_plugin->m_configPath);
 
@@ -196,7 +201,10 @@ void LSPClientConfigPage::reset()
 
 void LSPClientConfigPage::defaults()
 {
-    reset();
+    resetUiTo(LSPClientPluginOptions{});
+
+    // The user can easily manually revert the list of Allowed & Blocked Servers and the User Server Settings
+    // to their empty defaults. So do not automatically clear the possibly valuable user data on the other tabs.
 }
 
 void LSPClientConfigPage::readUserConfig(const QString &fileName)
diff --git a/addons/lspclient/lspclientconfigpage.h b/addons/lspclient/lspclientconfigpage.h
index 9c05f6a40f..dd920feb21 100644
--- a/addons/lspclient/lspclientconfigpage.h
+++ b/addons/lspclient/lspclientconfigpage.h
@@ -9,6 +9,7 @@
 #include <KTextEditor/ConfigPage>
 
 class LSPClientPlugin;
+struct LSPClientPluginOptions;
 
 namespace Ui
 {
@@ -35,6 +36,8 @@ public:
     void showContextMenuAllowedBlocked(const QPoint &pos);
 
 private:
+    void resetUiTo(const LSPClientPluginOptions &options);
+
     void readUserConfig(const QString &fileName);
     void updateConfigTextErrorState();
 
diff --git a/addons/lspclient/lspclientplugin.cpp b/addons/lspclient/lspclientplugin.cpp
index 6367a3a6b9..d1becb8dc1 100644
--- a/addons/lspclient/lspclientplugin.cpp
+++ b/addons/lspclient/lspclientplugin.cpp
@@ -110,27 +110,36 @@ KTextEditor::ConfigPage *LSPClientPlugin::configPage(int number, QWidget *parent
 
 void LSPClientPlugin::readConfig()
 {
+    // the indirection allows to make this function reusable by simply replacing
+    // the reference `defaults` with `const LSPClientPluginOptions defaults`.
+    const auto &defaults = *this;
+
     KConfigGroup config(KSharedConfig::openConfig(), CONFIG_LSPCLIENT);
-    m_symbolDetails = config.readEntry(CONFIG_SYMBOL_DETAILS, false);
-    m_symbolTree = config.readEntry(CONFIG_SYMBOL_TREE, true);
-    m_symbolExpand = config.readEntry(CONFIG_SYMBOL_EXPAND, true);
-    m_symbolSort = config.readEntry(CONFIG_SYMBOL_SORT, false);
-    m_complDoc = config.readEntry(CONFIG_COMPLETION_DOC, true);
-    m_refDeclaration = config.readEntry(CONFIG_REFERENCES_DECLARATION, true);
-    m_complParens = config.readEntry(CONFIG_COMPLETION_PARENS, true);
-    m_autoHover = config.readEntry(CONFIG_AUTO_HOVER, true);
-    m_onTypeFormatting = config.readEntry(CONFIG_TYPE_FORMATTING, false);
-    m_incrementalSync = config.readEntry(CONFIG_INCREMENTAL_SYNC, false);
-    m_highlightGoto = config.readEntry(CONFIG_HIGHLIGHT_GOTO, true);
-    m_diagnostics = config.readEntry(CONFIG_DIAGNOSTICS, true);
-    m_messages = config.readEntry(CONFIG_MESSAGES, true);
+
+    m_symbolDetails = config.readEntry(CONFIG_SYMBOL_DETAILS, defaults.m_symbolDetails);
+    m_symbolTree = config.readEntry(CONFIG_SYMBOL_TREE, defaults.m_symbolTree);
+    m_symbolExpand = config.readEntry(CONFIG_SYMBOL_EXPAND, defaults.m_symbolExpand);
+    m_symbolSort = config.readEntry(CONFIG_SYMBOL_SORT, defaults.m_symbolSort);
+
+    m_showCompl = config.readEntry(CONFIG_SHOW_COMPL, defaults.m_showCompl);
+    m_complDoc = config.readEntry(CONFIG_COMPLETION_DOC, defaults.m_complDoc);
+    m_refDeclaration = config.readEntry(CONFIG_REFERENCES_DECLARATION, defaults.m_refDeclaration);
+    m_complParens = config.readEntry(CONFIG_COMPLETION_PARENS, defaults.m_complParens);
+
+    m_autoHover = config.readEntry(CONFIG_AUTO_HOVER, defaults.m_autoHover);
+    m_onTypeFormatting = config.readEntry(CONFIG_TYPE_FORMATTING, defaults.m_onTypeFormatting);
+    m_incrementalSync = config.readEntry(CONFIG_INCREMENTAL_SYNC, defaults.m_incrementalSync);
+    m_highlightGoto = config.readEntry(CONFIG_HIGHLIGHT_GOTO, defaults.m_highlightGoto);
+    m_semanticHighlighting = config.readEntry(CONFIG_SEMANTIC_HIGHLIGHTING, defaults.m_semanticHighlighting);
+    m_signatureHelp = config.readEntry(CONFIG_SIGNATURE_HELP, defaults.m_signatureHelp);
+    m_autoImport = config.readEntry(CONFIG_AUTO_IMPORT, defaults.m_autoImport);
+    m_fmtOnSave = config.readEntry(CONFIG_FORMAT_ON_SAVE, defaults.m_fmtOnSave);
+    m_inlayHints = config.readEntry(CONFIG_INLAY_HINT, defaults.m_inlayHints);
+
+    m_diagnostics = config.readEntry(CONFIG_DIAGNOSTICS, defaults.m_diagnostics);
+    m_messages = config.readEntry(CONFIG_MESSAGES, defaults.m_messages);
+
     m_configPath = config.readEntry(CONFIG_SERVER_CONFIG, QUrl());
-    m_semanticHighlighting = config.readEntry(CONFIG_SEMANTIC_HIGHLIGHTING, true);
-    m_signatureHelp = config.readEntry(CONFIG_SIGNATURE_HELP, true);
-    m_autoImport = config.readEntry(CONFIG_AUTO_IMPORT, true);
-    m_fmtOnSave = config.readEntry(CONFIG_FORMAT_ON_SAVE, false);
-    m_inlayHints = config.readEntry(CONFIG_INLAY_HINT, false);
-    m_showCompl = config.readEntry(CONFIG_SHOW_COMPL, true);
 
     // read allow + block lists as two separate keys, let block always win
     const auto allowed = config.readEntry(CONFIG_ALLOWED_COMMANDS, QStringList());
diff --git a/addons/lspclient/lspclientplugin.h b/addons/lspclient/lspclientplugin.h
index f87b752082..8ede057f1f 100644
--- a/addons/lspclient/lspclientplugin.h
+++ b/addons/lspclient/lspclientplugin.h
@@ -17,7 +17,38 @@
 
 class LSPClientServerManager;
 
-class LSPClientPlugin : public KTextEditor::Plugin
+/**
+ * This struct aggregates the options that are reset to their
+ * default values when the user clicks the Restore Defaults button.
+ *
+ * @see LSPClientConfigPage::defaults()
+ */
+struct LSPClientPluginOptions {
+    bool m_symbolDetails = false;
+    bool m_symbolTree = true;
+    bool m_symbolExpand = true;
+    bool m_symbolSort = false;
+
+    bool m_showCompl = true;
+    bool m_complDoc = true;
+    bool m_refDeclaration = true;
+    bool m_complParens = true;
+
+    bool m_autoHover = true;
+    bool m_onTypeFormatting = false;
+    bool m_incrementalSync = false;
+    bool m_highlightGoto = true;
+    bool m_semanticHighlighting = true;
+    bool m_signatureHelp = true;
+    bool m_autoImport = true;
+    bool m_fmtOnSave = false;
+    bool m_inlayHints = false;
+
+    bool m_diagnostics = true;
+    bool m_messages = true;
+};
+
+class LSPClientPlugin : public KTextEditor::Plugin, public LSPClientPluginOptions
 {
     Q_OBJECT
 
@@ -38,7 +69,6 @@ public:
     int configPages() const override;
     KTextEditor::ConfigPage *configPage(int number = 0, QWidget *parent = nullptr) override;
 
-    void readConfig();
     void writeConfig() const;
 
     // path for local setting files, auto-created on load
@@ -49,27 +79,7 @@ public:
 
     QStringList m_alwaysDisabledLanguages;
 
-    // settings
-    bool m_symbolDetails = false;
-    bool m_symbolExpand = false;
-    bool m_symbolTree = false;
-    bool m_symbolSort = false;
-    bool m_complDoc = false;
-    bool m_refDeclaration = false;
-    bool m_complParens = false;
-    bool m_diagnostics = false;
-    bool m_messages = false;
-    bool m_autoHover = false;
-    bool m_onTypeFormatting = false;
-    bool m_incrementalSync = false;
-    bool m_highlightGoto = true;
     QUrl m_configPath;
-    bool m_semanticHighlighting = false;
-    bool m_signatureHelp = true;
-    bool m_autoImport = true;
-    bool m_fmtOnSave = false;
-    bool m_inlayHints = false;
-    bool m_showCompl = true;
 
     // debug mode?
     const bool m_debugMode;
@@ -110,6 +120,14 @@ private Q_SLOTS:
     void askForCommandLinePermission(const QString &fullCommandLineString);
 
 private:
+    /**
+     * Read from config and assign to data members.
+     *
+     * This function may be called only from the constructor because it assumes
+     * that the LSPClientPluginOptions base of this object is default-initialized.
+     */
+    void readConfig();
+
     // server manager to pass along
     std::shared_ptr<LSPClientServerManager> m_serverManager;
 };
-- 
GitLab