Skip to content

Commit 33cd120

Browse files
committed
feat(fix) Remove diagnostic message when line in empty
1 parent 12e39d4 commit 33cd120

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

anycode-base/src/renderer/DiagnosticRenderer.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@ export class DiagnosticRenderer {
55
return line.querySelector('span.diagnostic');
66
}
77

8+
private isEmptyLine(line: AnycodeLine): boolean {
9+
for (const child of line.children) {
10+
if (child.tagName === 'BR') continue;
11+
if (child.classList.contains('diagnostic')) continue;
12+
return false;
13+
}
14+
return true;
15+
}
16+
817
private getInsertAnchor(line: AnycodeLine): ChildNode | null {
918
const last = line.lastChild;
1019
if (last && last.nodeType === Node.ELEMENT_NODE) {
@@ -14,14 +23,15 @@ export class DiagnosticRenderer {
1423
return null;
1524
}
1625

17-
public render(line: AnycodeLine, message?: string | null) {
26+
public render(line: AnycodeLine, diagnosticMessage?: string | null) {
1827
line.classList.remove('has-error');
1928
line.removeAttribute('data-error');
2029

21-
const text = message ? minimize(message) : '';
30+
const text = diagnosticMessage ? minimize(diagnosticMessage) : '';
2231
const existing = this.getDiagnosticSpan(line);
2332

24-
if (!text) {
33+
// Don't show diagnostics on empty lines
34+
if (!text || this.isEmptyLine(line)) {
2535
if (existing) existing.remove();
2636
return;
2737
}

0 commit comments

Comments
 (0)