Skip to content

Commit 3aa5ce6

Browse files
committed
Explore with diagnostics
1 parent 068a3c0 commit 3aa5ce6

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

packages/components/src/modifiers/hds-code-editor.ts

+17-10
Original file line numberDiff line numberDiff line change
@@ -274,16 +274,23 @@ export default class HdsCodeEditorModifier extends Modifier<HdsCodeEditorSignatu
274274

275275
let lintingExtension: Extension | undefined;
276276

277-
if (isLintingEnabled) {
278-
lintingExtension = linter(
279-
(view) => {
280-
console.log('Test linter triggered', view.state.doc.toString());
281-
return [
282-
{ from: 0, to: 0, severity: 'error', message: 'Test error' },
283-
];
284-
},
285-
{ delay: 0 }
286-
);
277+
if (isLintingEnabled && language === 'json') {
278+
lintingExtension = linter((view): Diagnostic[] => {
279+
const diagnostics: Diagnostic[] = [];
280+
try {
281+
JSON.parse(view.state.doc.toString());
282+
} catch (error: any) {
283+
const message = (error).message;
284+
const pos = (error).position || 0;
285+
diagnostics.push({
286+
from: pos,
287+
to: pos + 1,
288+
severity: 'error',
289+
message,
290+
});
291+
}
292+
return diagnostics;
293+
});
287294
}
288295

289296
console.log({ lintingExtension });

0 commit comments

Comments
 (0)