Skip to content

Commit 5bdf88b

Browse files
committed
feat: add lintgutter setting to toggle lsp diag on gutter
1 parent 47976c7 commit 5bdf88b

File tree

5 files changed

+55
-15
lines changed

5 files changed

+55
-15
lines changed

src/cm/lsp/clientManager.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ export class LspClientManager {
8787
if (!servers.length) return [];
8888

8989
const lspExtensions = [];
90+
const diagnosticsUiExtension = this.options.diagnosticsUiExtension;
9091

9192
for (const server of servers) {
9293
let targetLanguageId = effectiveLang;
@@ -132,6 +133,10 @@ export class LspClientManager {
132133
}
133134
}
134135

136+
if (diagnosticsUiExtension && lspExtensions.length) {
137+
lspExtensions.push(...asArray(diagnosticsUiExtension));
138+
}
139+
135140
return lspExtensions;
136141
}
137142

src/cm/lsp/diagnostics.js

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ function lspLinterSource(view) {
114114
return mapDiagnostics(plugin, view.state);
115115
}
116116

117-
export function lspDiagnosticsExtension() {
117+
export function lspDiagnosticsClientExtension() {
118118
return {
119119
clientCapabilities: {
120120
textDocument: {
@@ -148,18 +148,31 @@ export function lspDiagnosticsExtension() {
148148
return true;
149149
},
150150
},
151-
editorExtension: [
152-
lspPublishedDiagnostics,
153-
lintGutter(),
154-
linter(lspLinterSource, {
155-
needsRefresh(update) {
156-
return update.transactions.some((tr) =>
157-
tr.effects.some((effect) => effect.is(setPublishedDiagnostics)),
158-
);
159-
},
160-
autoPanel: true,
161-
}),
162-
],
151+
};
152+
}
153+
154+
export function lspDiagnosticsUiExtension(includeGutter = true) {
155+
const extensions = [
156+
lspPublishedDiagnostics,
157+
linter(lspLinterSource, {
158+
needsRefresh(update) {
159+
return update.transactions.some((tr) =>
160+
tr.effects.some((effect) => effect.is(setPublishedDiagnostics)),
161+
);
162+
},
163+
autoPanel: true,
164+
}),
165+
];
166+
if (includeGutter) {
167+
extensions.splice(1, 0, lintGutter());
168+
}
169+
return extensions;
170+
}
171+
172+
export function lspDiagnosticsExtension(includeGutter = true) {
173+
return {
174+
...lspDiagnosticsClientExtension(),
175+
editorExtension: lspDiagnosticsUiExtension(includeGutter),
163176
};
164177
}
165178

src/lib/editorManager.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@ import {
3434
} from "@emmetio/codemirror6-plugin";
3535
import createBaseExtensions from "cm/baseExtensions";
3636
import lspClientManager from "cm/lsp/clientManager";
37-
import lspDiagnosticsExtension, {
37+
import {
3838
getLspDiagnostics,
3939
LSP_DIAGNOSTICS_EVENT,
40+
lspDiagnosticsClientExtension,
41+
lspDiagnosticsUiExtension,
4042
} from "cm/lsp/diagnostics";
4143
import { stopManagedServer } from "cm/lsp/serverLauncher";
4244
import serverRegistry from "cm/lsp/serverRegistry";
@@ -183,6 +185,9 @@ async function EditorManager($header, $body) {
183185
const languageCompartment = new Compartment();
184186
// Compartment for LSP extensions so we can swap per file
185187
const lspCompartment = new Compartment();
188+
const diagnosticsClientExt = lspDiagnosticsClientExtension();
189+
const buildDiagnosticsUiExt = () =>
190+
lspDiagnosticsUiExtension(appSettings?.value?.lintGutter !== false);
186191
let lspRequestToken = 0;
187192
let lastLspUri = null;
188193
const UNTITLED_URI_PREFIX = "untitled://acode/";
@@ -1167,7 +1172,8 @@ async function EditorManager($header, $body) {
11671172
}
11681173
return null;
11691174
},
1170-
clientExtensions: [lspDiagnosticsExtension()],
1175+
clientExtensions: [diagnosticsClientExt],
1176+
diagnosticsUiExtension: buildDiagnosticsUiExt(),
11711177
});
11721178
applyLspSettings();
11731179

@@ -1284,6 +1290,16 @@ async function EditorManager($header, $body) {
12841290
updateEditorLineNumbersFromSettings();
12851291
});
12861292

1293+
appSettings.on("update:lintGutter", function (value) {
1294+
lspClientManager.setOptions({
1295+
diagnosticsUiExtension: lspDiagnosticsUiExtension(value !== false),
1296+
});
1297+
const active = manager.activeFile;
1298+
if (active?.type === "editor") {
1299+
void configureLspForFile(active);
1300+
}
1301+
});
1302+
12871303
// appSettings.on("update:elasticTabstops", function (_value) {
12881304
// // Not applicable in CodeMirror (Ace-era). No-op for now.
12891305
// });

src/lib/settings.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ class Settings {
177177
showRetryToast: false,
178178
showSideButtons: true,
179179
showAnnotations: false,
180+
lintGutter: true,
180181
rainbowBrackets: true,
181182
pluginsDisabled: {}, // pluginId: true/false
182183
lsp: {

src/settings/editorSettings.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ export default function editorSettings() {
5555
text: strings["show line numbers"],
5656
checkbox: values.linenumbers,
5757
},
58+
{
59+
key: "lintGutter",
60+
text: strings["lint gutter"] || "Show lint gutter",
61+
checkbox: values.lintGutter ?? true,
62+
},
5863
{
5964
key: "lineHeight",
6065
text: strings["line height"],

0 commit comments

Comments
 (0)