@@ -4,7 +4,7 @@ import { bracketMatching } from "@codemirror/language";
44import { EditorState , type Extension } from "@codemirror/state" ;
55import { EditorView , keymap , placeholder } from "@codemirror/view" ;
66import { celLanguageSupport } from "@seljs/cel-lezer" ;
7- import { SELChecker , rules } from "@seljs/checker" ;
7+ import { SELChecker } from "@seljs/checker" ;
88
99import { selDarkTheme , selLightTheme } from "./theme" ;
1010import { createTypeDisplay } from "./type-display" ;
@@ -13,23 +13,35 @@ import { createTokenizerConfig } from "../language";
1313import { createSemanticHighlighter } from "../language/semantic-highlighter" ;
1414import { createSELLinter } from "../linting" ;
1515
16- import type { SELEditorConfig } from "./types" ;
16+ import type { SELEditorConfig , SELEditorFeatures } from "./types" ;
17+
18+ const resolveFeatures = ( features ?: SELEditorFeatures ) => ( {
19+ linting : features ?. linting ?? true ,
20+ autocomplete : features ?. autocomplete ?? true ,
21+ semanticHighlighting : features ?. semanticHighlighting ?? true ,
22+ typeDisplay : features ?. typeDisplay ?? false ,
23+ } ) ;
1724
1825export const buildExtensions = ( config : SELEditorConfig ) : Extension [ ] => {
19- const checker = new SELChecker ( config . schema , { rules : [ ...rules . builtIn ] } ) ;
26+ const checker = new SELChecker ( config . schema , config . checkerOptions ) ;
27+ const resolved = resolveFeatures ( config . features ) ;
2028 const extensions : Extension [ ] = [ ] ;
2129
2230 // Language support (includes syntax highlighting)
2331 extensions . push ( celLanguageSupport ( config . dark ) ) ;
2432 extensions . push ( bracketMatching ( ) ) ;
2533
2634 // Semantic highlighting (schema-aware identifier coloring)
27- const tokenizerConfig = createTokenizerConfig ( config . schema ) ;
28- extensions . push ( createSemanticHighlighter ( tokenizerConfig , config . dark ) ) ;
35+ if ( resolved . semanticHighlighting ) {
36+ const tokenizerConfig = createTokenizerConfig ( config . schema ) ;
37+ extensions . push ( createSemanticHighlighter ( tokenizerConfig , config . dark ) ) ;
38+ }
2939
3040 // Autocomplete (type-aware via checker)
31- extensions . push ( createSchemaCompletion ( config . schema , checker ) ) ;
32- extensions . push ( closeBrackets ( ) ) ;
41+ if ( resolved . autocomplete ) {
42+ extensions . push ( createSchemaCompletion ( config . schema , checker ) ) ;
43+ extensions . push ( closeBrackets ( ) ) ;
44+ }
3345
3446 // Keybindings
3547 extensions . push (
@@ -40,24 +52,24 @@ export const buildExtensions = (config: SELEditorConfig): Extension[] => {
4052 // Theme
4153 extensions . push ( config . dark ? selDarkTheme : selLightTheme ) ;
4254
43- // Validation / linting (built-in checker used when no validate callback provided)
44- const validate =
45- config . validate ??
46- ( ( expression : string ) => checker . check ( expression ) . diagnostics ) ;
47- extensions . push (
48- createSELLinter ( {
49- validate,
50- delay : config . validateDelay ,
51- } ) ,
52- ) ;
55+ // Validation / linting
56+ if ( resolved . linting ) {
57+ extensions . push (
58+ createSELLinter ( {
59+ validate : ( expression : string ) => checker . check ( expression ) . diagnostics ,
60+ } ) ,
61+ ) ;
62+ }
5363
54- // onChange listener
64+ // onChange listener with validity
5565 if ( config . onChange ) {
5666 const onChange = config . onChange ;
5767 extensions . push (
5868 EditorView . updateListener . of ( ( update ) => {
5969 if ( update . docChanged ) {
60- onChange ( update . state . doc . toString ( ) ) ;
70+ const value = update . state . doc . toString ( ) ;
71+ const result = checker . check ( value ) ;
72+ onChange ( value , result . valid ) ;
6173 }
6274 } ) ,
6375 ) ;
@@ -74,14 +86,9 @@ export const buildExtensions = (config: SELEditorConfig): Extension[] => {
7486 }
7587
7688 // Type display panel
77- if ( config . showType ) {
89+ if ( resolved . typeDisplay ) {
7890 extensions . push ( createTypeDisplay ( checker , config . dark ?? false ) ) ;
7991 }
8092
81- // User-provided extensions (last, so they can override)
82- if ( config . extensions ) {
83- extensions . push ( ...config . extensions ) ;
84- }
85-
8693 return extensions ;
8794} ;
0 commit comments