@@ -12,6 +12,11 @@ import { LabelTypeRegistry } from "../labels/LabelTypeRegistry";
1212import { SETTINGS } from "../settings/Settings" ;
1313import { EditorModeController } from "../settings/editorMode" ;
1414import { AccordionUiExtension } from "../accordionUiExtension" ;
15+ import { LanguageTreeNode , tokenize } from "../languages/tokenize" ;
16+ import { Word } from "../languages/words" ;
17+ import { constraintDslLanguageMonarchDefinition , ConstraintDslTreeBuilder , DSL_LANGUAGE_ID } from "./language" ;
18+ import { verify } from "../languages/verify" ;
19+ import { DfdCompletionItemProvider } from "../languages/autocomplete" ;
1520
1621@injectable ( )
1722export class ConstraintMenu extends AccordionUiExtension {
@@ -22,6 +27,7 @@ export class ConstraintMenu extends AccordionUiExtension {
2227 private forceReadOnly : boolean ;
2328 private optionsMenu ?: HTMLDivElement ;
2429 private ignoreCheckboxChange = false ;
30+ private readonly tree : LanguageTreeNode < Word > [ ]
2531
2632 constructor (
2733 @inject ( ConstraintRegistry ) private readonly constraintRegistry : ConstraintRegistry ,
@@ -46,6 +52,8 @@ export class ConstraintMenu extends AccordionUiExtension {
4652 }
4753 }
4854 } ) ;
55+
56+ this . tree = ConstraintDslTreeBuilder . buildTree ( modelSource , labelTypeRegistry )
4957 }
5058
5159 id ( ) : string {
@@ -86,6 +94,13 @@ export class ConstraintMenu extends AccordionUiExtension {
8694 keyboardShortcutLabel . innerHTML = "Press <kbd>CTRL</kbd>+<kbd>Space</kbd> for autocompletion" ;
8795 wrapper . appendChild ( keyboardShortcutLabel ) ;
8896
97+ monaco . languages . register ( { id : DSL_LANGUAGE_ID } ) ;
98+ monaco . languages . setMonarchTokensProvider ( DSL_LANGUAGE_ID , constraintDslLanguageMonarchDefinition ) ;
99+ monaco . languages . registerCompletionItemProvider (
100+ DSL_LANGUAGE_ID ,
101+ new DfdCompletionItemProvider ( this . tree ) ,
102+ ) ;
103+
89104 const monacoTheme = /*ThemeManager.useDarkMode ?*/ "vs-dark" //: "vs";
90105 this . editor = monaco . editor . create ( this . editorContainer , {
91106 minimap : {
@@ -97,7 +112,7 @@ export class ConstraintMenu extends AccordionUiExtension {
97112 scrollBeyondLastLine : false , // Not needed
98113 theme : monacoTheme ,
99114 wordWrap : "on" ,
100- // language: DSL_LANGUAGE_ID,
115+ language : DSL_LANGUAGE_ID ,
101116 scrollBeyondLastColumn : 0 ,
102117 scrollbar : {
103118 horizontal : "hidden" ,
@@ -128,7 +143,7 @@ export class ConstraintMenu extends AccordionUiExtension {
128143 const emptyContent = content . length == 0 || ( content . length == 1 && content [ 0 ] === "" ) ;
129144 // empty content gets accepted as valid as it represents no constraints
130145 if ( ! emptyContent ) {
131- /* const errors = this.tree. verify(content);
146+ const errors = verify ( tokenize ( content ) , this . tree )
132147 marker . push (
133148 ...errors . map ( ( e ) => ( {
134149 severity : monaco . MarkerSeverity . Error ,
@@ -138,7 +153,7 @@ export class ConstraintMenu extends AccordionUiExtension {
138153 endColumn : e . endColumn ,
139154 message : e . message ,
140155 } ) ) ,
141- );*/
156+ ) ;
142157 }
143158
144159 this . validationLabel . innerText =
0 commit comments