Skip to content

Commit ae72443

Browse files
VikaCepckbedwell
andauthored
feat: add validation for k6 extensions and version pragmas (#1253)
* feat: add validation for k6 extensions and version pragmas * feat: add custom validation to monaco (#1259) * feat: add custom validation to monaco * fix: improve regex and minor changes * fix: tests * fix: lint --------- Co-authored-by: Virginia Cepeda <[email protected]> * fix: address review comments * fix: refactor monaco validation to use acorn --------- Co-authored-by: Chris Bedwell <[email protected]>
1 parent bc0a436 commit ae72443

File tree

7 files changed

+793
-0
lines changed

7 files changed

+793
-0
lines changed

src/components/CodeEditor/CodeEditor.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { CodeEditorProps, ConstrainedEditorProps } from './CodeEditor.types';
99
import k6Types from './k6.types';
1010

1111
import { initializeConstrainedInstance, updateConstrainedEditorRanges } from './CodeEditor.utils';
12+
import { wireCustomValidation } from './monacoValidation';
1213

1314
const addK6Types = (monaco: typeof monacoType) => {
1415
Object.entries(k6Types).map(([name, type]) => {
@@ -116,6 +117,9 @@ export const CodeEditor = forwardRef(function CodeEditor(
116117
handleValidation(monaco, editor);
117118
});
118119

120+
// Wire custom red-squiggle markers for forbidden syntax
121+
const disposeCustomValidation = wireCustomValidation(monaco, editor);
122+
119123
if (constrainedRanges) {
120124
const instance = initializeConstrainedInstance(monaco, editor);
121125
const model = editor.getModel();
@@ -126,6 +130,13 @@ export const CodeEditor = forwardRef(function CodeEditor(
126130
updateConstrainedEditorRanges(instance, model, value, constrainedRanges, onDidChangeContentInEditableRange);
127131
setConstrainedInstance(instance);
128132
}
133+
134+
// Cleanup subscriptions on dispose
135+
editor.onDidDispose(() => {
136+
if (typeof disposeCustomValidation === 'function') {
137+
disposeCustomValidation();
138+
}
139+
});
129140
};
130141

131142
useEffect(() => {

0 commit comments

Comments
 (0)