Skip to content

Commit 297ac2f

Browse files
committed
feat: display parsing error through diagnostic
1 parent 86e80a6 commit 297ac2f

File tree

1 file changed

+30
-2
lines changed
  • packages/extension-shared/extension/views

1 file changed

+30
-2
lines changed

packages/extension-shared/extension/views/panel.ts

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1+
/* eslint-disable @typescript-eslint/no-unsafe-argument */
12
import {
3+
Diagnostic,
4+
DiagnosticSeverity,
25
type Disposable,
36
type ExtensionContext,
7+
languages,
8+
Position,
9+
Range,
410
type TextDocument,
511
type TextEditor,
612
Uri,
@@ -10,6 +16,7 @@ import {
1016
workspace,
1117
} from "vscode";
1218
import { type JSONTableSchema } from "shared/types/tableSchema";
19+
import { DiagnosticError } from "shared/types/diagnostic";
1320

1421
import { DIAGRAM_UPDATER_DEBOUNCE_TIME } from "../constants";
1522
import { ExtensionConfig } from "../helper/extensionConfigs";
@@ -26,6 +33,8 @@ export class MainPanel {
2633
private _lastTimeout: NodeJS.Timeout | null = null;
2734
public static parseCode: (code: string) => JSONTableSchema;
2835
public static fileExt: string;
36+
public static diagnosticCollection =
37+
languages.createDiagnosticCollection("dbml");
2938

3039
private constructor(
3140
panel: WebviewPanel,
@@ -163,9 +172,28 @@ export class MainPanel {
163172
payload: schema,
164173
key: document.uri.toString(),
165174
});
175+
176+
MainPanel.diagnosticCollection.clear();
166177
} catch (error) {
167-
// eslint-disable-next-line @typescript-eslint/no-floating-promises
168-
window.showErrorMessage(`${error as any}`);
178+
console.error(JSON.stringify(error));
179+
if (error instanceof DiagnosticError) {
180+
MainPanel.diagnosticCollection.set(document.uri, [
181+
new Diagnostic(
182+
new Range(
183+
new Position(
184+
error.location.start.line,
185+
error.location.start.column,
186+
),
187+
new Position(error.location.end.line, error.location.end.column),
188+
),
189+
error.message,
190+
DiagnosticSeverity.Error,
191+
),
192+
]);
193+
} else {
194+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
195+
window.showErrorMessage(`${error as any}`);
196+
}
169197
}
170198
};
171199

0 commit comments

Comments
 (0)