Merge pull request #12856 from maxunbearable/improvement/tbel-utils-autcompletes

Implemented tbel utils autocompletes and highlights
This commit is contained in:
Igor Kulikov 2025-03-13 19:10:06 +02:00 committed by GitHub
commit 16538c7d74
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 1344 additions and 7 deletions

View File

@ -79,4 +79,10 @@
background: #f3f3f3; background: #f3f3f3;
} }
} }
.ace_tb {
&.ace_tbel-utils-func {
color: rgb(49, 132, 149);
}
}
} }

View File

@ -50,6 +50,7 @@ import { JsFuncModulesComponent } from '@shared/components/js-func-modules.compo
import { HttpClient } from '@angular/common/http'; import { HttpClient } from '@angular/common/http';
import { map, Observable, of } from 'rxjs'; import { map, Observable, of } from 'rxjs';
import { catchError } from 'rxjs/operators'; import { catchError } from 'rxjs/operators';
import { tbelUtilsAutocompletes, tbelUtilsFuncHighlightRules } from '@shared/models/ace/tbel-utils.models';
@Component({ @Component({
selector: 'tb-js-func', selector: 'tb-js-func',
@ -560,6 +561,9 @@ export class JsFuncComponent implements OnInit, OnChanges, OnDestroy, ControlVal
break; break;
case 'scriptLanguage': case 'scriptLanguage':
this.updatedScriptLanguage(); this.updatedScriptLanguage();
this.updateHighlightRules();
this.updateCompleters();
this.updateJsWorkerGlobals();
break; break;
case 'disableUndefinedCheck': case 'disableUndefinedCheck':
case 'globalVariables': case 'globalVariables':
@ -576,19 +580,24 @@ export class JsFuncComponent implements OnInit, OnChanges, OnDestroy, ControlVal
private updateHighlightRules(): void { private updateHighlightRules(): void {
// @ts-ignore // @ts-ignore
if (!!this.highlightRules && !!this.jsEditor.session.$mode) { if (!!this.jsEditor.session.$mode) {
// @ts-ignore // @ts-ignore
const newMode = new this.jsEditor.session.$mode.constructor(); const newMode = new this.jsEditor.session.$mode.constructor();
newMode.$highlightRules = new newMode.HighlightRules(); newMode.$highlightRules = new newMode.HighlightRules();
for(const group in this.highlightRules) { if (!!this.highlightRules) {
if(!!newMode.$highlightRules.$rules[group]) { for(const group in this.highlightRules) {
newMode.$highlightRules.$rules[group].unshift(...this.highlightRules[group]); if(!!newMode.$highlightRules.$rules[group]) {
} else { newMode.$highlightRules.$rules[group].unshift(...this.highlightRules[group]);
newMode.$highlightRules.$rules[group] = this.highlightRules[group]; } else {
newMode.$highlightRules.$rules[group] = this.highlightRules[group];
}
} }
} }
if (this.scriptLanguage === ScriptLanguage.TBEL) {
newMode.$highlightRules.$rules.start = [...tbelUtilsFuncHighlightRules, ...newMode.$highlightRules.$rules.start];
}
const identifierRule = newMode.$highlightRules.$rules.no_regex.find(rule => rule.token?.includes('identifier')); const identifierRule = newMode.$highlightRules.$rules.no_regex.find(rule => rule.token?.includes('identifier'));
if (identifierRule) { if (identifierRule && identifierRule.next === 'no_regex') {
identifierRule.next = 'start'; identifierRule.next = 'start';
} }
// @ts-ignore // @ts-ignore
@ -641,6 +650,9 @@ export class JsFuncComponent implements OnInit, OnChanges, OnDestroy, ControlVal
if (modulesCompleter) { if (modulesCompleter) {
completers.push(modulesCompleter); completers.push(modulesCompleter);
} }
if (this.scriptLanguage === ScriptLanguage.TBEL) {
completers.push(tbelUtilsAutocompletes);
}
completers.push(...this.initialCompleters); completers.push(...this.initialCompleters);
this.jsEditor.completers = completers; this.jsEditor.completers = completers;
}); });

File diff suppressed because it is too large Load Diff