@@ -101,6 +101,9 @@ export class OutputPortEditUI extends AbstractUIExtension implements Switchable
101
101
private port : DfdOutputPortImpl | undefined ;
102
102
private editor ?: monaco . editor . IStandaloneCodeEditor ;
103
103
private tree ?: ReplaceAutoCompleteTree ;
104
+ private completionProvider ?: monaco . IDisposable ;
105
+
106
+ private static readonly DFD_LANGUAGE_NAME = "dfd-behavior" ;
104
107
105
108
constructor (
106
109
@inject ( TYPES . IActionDispatcher ) private actionDispatcher : ActionDispatcher ,
@@ -145,15 +148,13 @@ export class OutputPortEditUI extends AbstractUIExtension implements Switchable
145
148
this . validationLabel . classList . add ( "validation-label" ) ;
146
149
147
150
// 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 ( ) ;
157
158
158
159
const monacoTheme = ( ThemeManager ?. useDarkMode ?? true ) ? "vs-dark" : "vs" ;
159
160
this . editor = monaco . editor . create ( this . editorContainer , {
@@ -166,7 +167,7 @@ export class OutputPortEditUI extends AbstractUIExtension implements Switchable
166
167
wordBasedSuggestions : "off" , // Does not really work for our use case
167
168
scrollBeyondLastLine : false , // Not needed
168
169
theme : monacoTheme ,
169
- language : dfdLanguageName ,
170
+ language : OutputPortEditUI . DFD_LANGUAGE_NAME ,
170
171
} ) ;
171
172
172
173
this . configureHandlers ( containerElement ) ;
@@ -213,7 +214,9 @@ export class OutputPortEditUI extends AbstractUIExtension implements Switchable
213
214
} ) ;
214
215
215
216
// Run behavior validation when the behavior text changes.
216
- this . editor ?. onDidChangeModelContent ( ( ) => { } ) ;
217
+ this . editor ?. onDidChangeModelContent ( ( ) => {
218
+ this . validateBehavior ( ) ;
219
+ } ) ;
217
220
218
221
// When the content size of the editor changes, resize the editor accordingly.
219
222
this . editor ?. onDidContentSizeChange ( ( ) => {
@@ -320,6 +323,8 @@ export class OutputPortEditUI extends AbstractUIExtension implements Switchable
320
323
// Validation of loaded behavior text.
321
324
this . validateBehavior ( ) ;
322
325
326
+ this . registerCompletionProvider ( ) ;
327
+
323
328
// Wait for the next event loop tick to focus the port edit UI.
324
329
// The user may have clicked more times before the show click was processed
325
330
// (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
330
335
} , 0 ) ; // 0ms => next event loop tick
331
336
}
332
337
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
+
333
349
/**
334
350
* Sets the position of the UI to the position of the port that is currently edited.
335
351
*/
0 commit comments