@@ -101,6 +101,9 @@ export class OutputPortEditUI extends AbstractUIExtension implements Switchable
101101 private port : DfdOutputPortImpl | undefined ;
102102 private editor ?: monaco . editor . IStandaloneCodeEditor ;
103103 private tree ?: ReplaceAutoCompleteTree ;
104+ private completionProvider ?: monaco . IDisposable ;
105+
106+ private static readonly DFD_LANGUAGE_NAME = "dfd-behavior" ;
104107
105108 constructor (
106109 @inject ( TYPES . IActionDispatcher ) private actionDispatcher : ActionDispatcher ,
@@ -145,15 +148,13 @@ export class OutputPortEditUI extends AbstractUIExtension implements Switchable
145148 this . validationLabel . classList . add ( "validation-label" ) ;
146149
147150 // Initialize the monaco editor and setup the language for highlighting and autocomplete.
148- const dfdLanguageName = "dfd-behavior" ;
149- monaco . languages . register ( { id : dfdLanguageName } ) ;
150- monaco . languages . setMonarchTokensProvider ( dfdLanguageName , assignemntLanguageMonarchDefinition ) ;
151- if ( this . tree ) {
152- monaco . languages . registerCompletionItemProvider (
153- dfdLanguageName ,
154- new MonacoEditorAssignmentLanguageCompletionProvider ( this . tree ) ,
155- ) ;
156- }
151+
152+ monaco . languages . register ( { id : OutputPortEditUI . DFD_LANGUAGE_NAME } ) ;
153+ monaco . languages . setMonarchTokensProvider (
154+ OutputPortEditUI . DFD_LANGUAGE_NAME ,
155+ assignemntLanguageMonarchDefinition ,
156+ ) ;
157+ this . registerCompletionProvider ( ) ;
157158
158159 const monacoTheme = ( ThemeManager ?. useDarkMode ?? true ) ? "vs-dark" : "vs" ;
159160 this . editor = monaco . editor . create ( this . editorContainer , {
@@ -166,7 +167,7 @@ export class OutputPortEditUI extends AbstractUIExtension implements Switchable
166167 wordBasedSuggestions : "off" , // Does not really work for our use case
167168 scrollBeyondLastLine : false , // Not needed
168169 theme : monacoTheme ,
169- language : dfdLanguageName ,
170+ language : OutputPortEditUI . DFD_LANGUAGE_NAME ,
170171 } ) ;
171172
172173 this . configureHandlers ( containerElement ) ;
@@ -213,7 +214,9 @@ export class OutputPortEditUI extends AbstractUIExtension implements Switchable
213214 } ) ;
214215
215216 // Run behavior validation when the behavior text changes.
216- this . editor ?. onDidChangeModelContent ( ( ) => { } ) ;
217+ this . editor ?. onDidChangeModelContent ( ( ) => {
218+ this . validateBehavior ( ) ;
219+ } ) ;
217220
218221 // When the content size of the editor changes, resize the editor accordingly.
219222 this . editor ?. onDidContentSizeChange ( ( ) => {
@@ -320,6 +323,8 @@ export class OutputPortEditUI extends AbstractUIExtension implements Switchable
320323 // Validation of loaded behavior text.
321324 this . validateBehavior ( ) ;
322325
326+ this . registerCompletionProvider ( ) ;
327+
323328 // Wait for the next event loop tick to focus the port edit UI.
324329 // The user may have clicked more times before the show click was processed
325330 // (showing the UI takes some time due to finding the element in the graph, etc.).
@@ -330,6 +335,17 @@ export class OutputPortEditUI extends AbstractUIExtension implements Switchable
330335 } , 0 ) ; // 0ms => next event loop tick
331336 }
332337
338+ private registerCompletionProvider ( ) {
339+ if ( ! this . tree ) {
340+ return ;
341+ }
342+ this . completionProvider ?. dispose ( ) ;
343+ this . completionProvider = monaco . languages . registerCompletionItemProvider (
344+ OutputPortEditUI . DFD_LANGUAGE_NAME ,
345+ new MonacoEditorAssignmentLanguageCompletionProvider ( this . tree ) ,
346+ ) ;
347+ }
348+
333349 /**
334350 * Sets the position of the UI to the position of the port that is currently edited.
335351 */
0 commit comments