RED-7571: Highlight and autocomplete drools keywords
This commit is contained in:
parent
3b6122f6aa
commit
c2d31e3a65
@ -3,7 +3,7 @@ import { PermissionsService } from '@services/permissions.service';
|
||||
import { IconButtonTypes, LoadingService, Toaster } from '@iqser/common-ui';
|
||||
import { RulesService } from '../../../services/rules.service';
|
||||
import { firstValueFrom } from 'rxjs';
|
||||
import { DOSSIER_TEMPLATE_ID, IRules } from '@red/domain';
|
||||
import { DOSSIER_TEMPLATE_ID, DroolsKeywords, IRules } from '@red/domain';
|
||||
import { EditorThemeService } from '@services/editor-theme.service';
|
||||
import { ComponentCanDeactivate } from '@guards/can-deactivate.guard';
|
||||
import { Debounce, getParam } from '@iqser/common-ui/lib/utils';
|
||||
@ -80,12 +80,13 @@ export class RulesScreenComponent implements OnInit, ComponentCanDeactivate {
|
||||
await this._initialize();
|
||||
}
|
||||
|
||||
onCodeEditorInit(editor: ICodeEditor) {
|
||||
async onCodeEditorInit(editor: ICodeEditor): Promise<void> {
|
||||
this._codeEditor = editor;
|
||||
for (const theme of this._editorThemeService.themes) {
|
||||
(window as any).monaco.editor.defineTheme(theme, this._editorThemeService.configurations[theme]);
|
||||
}
|
||||
(window as any).monaco.editor.setTheme(this._editorThemeService.getTheme(true));
|
||||
await this._configureSyntaxHighlighting();
|
||||
this._changeDetectorRef.detectChanges();
|
||||
}
|
||||
|
||||
@ -130,6 +131,37 @@ export class RulesScreenComponent implements OnInit, ComponentCanDeactivate {
|
||||
this._loadingService.stop();
|
||||
}
|
||||
|
||||
private async _configureSyntaxHighlighting() {
|
||||
const languages = (window as any).monaco.languages.getLanguages();
|
||||
const javaLang = languages.find(l => l.id === 'java');
|
||||
const { language: config } = await javaLang.loader();
|
||||
DroolsKeywords.forEach(k => {
|
||||
if (!config.keywords.includes(k)) {
|
||||
config.keywords.push(k);
|
||||
}
|
||||
});
|
||||
console.log({ config });
|
||||
|
||||
monaco.languages.registerCompletionItemProvider('java', {
|
||||
provideCompletionItems: (model, position) => {
|
||||
const word = model.getWordUntilPosition(position);
|
||||
const range = {
|
||||
startLineNumber: position.lineNumber,
|
||||
endLineNumber: position.lineNumber,
|
||||
startColumn: word.startColumn,
|
||||
endColumn: word.endColumn,
|
||||
};
|
||||
const suggestions = config.keywords.map(k => ({
|
||||
label: k,
|
||||
kind: monaco.languages.CompletionItemKind.Keyword,
|
||||
insertText: k,
|
||||
range,
|
||||
}));
|
||||
return { suggestions };
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
private _isNew(entry: string): boolean {
|
||||
return this.initialLines.indexOf(entry) < 0 && entry?.trim().length > 0;
|
||||
}
|
||||
|
||||
45
libs/red-domain/src/lib/shared/editor.types.ts
Normal file
45
libs/red-domain/src/lib/shared/editor.types.ts
Normal file
@ -0,0 +1,45 @@
|
||||
// https://docs.jboss.org/drools/release/5.2.0.Final/drools-expert-docs/html/ch05.html#d0e2854
|
||||
|
||||
export const DroolsKeywords = [
|
||||
'lock-on-active',
|
||||
'date-effective',
|
||||
'date-expires',
|
||||
'no-loop',
|
||||
'auto-focus',
|
||||
'activation-group',
|
||||
'agenda-group',
|
||||
'ruleflow-group',
|
||||
'entry-point',
|
||||
'duration',
|
||||
'package',
|
||||
'import',
|
||||
'dialect',
|
||||
'salience',
|
||||
'enabled',
|
||||
'attributes',
|
||||
'rule',
|
||||
'extend',
|
||||
'when',
|
||||
'then',
|
||||
'template',
|
||||
'query',
|
||||
'declare',
|
||||
'function',
|
||||
'global',
|
||||
'eval',
|
||||
'not',
|
||||
'in',
|
||||
'or',
|
||||
'and',
|
||||
'exists',
|
||||
'forall',
|
||||
'accumulate',
|
||||
'collect',
|
||||
'from',
|
||||
'action',
|
||||
'reverse',
|
||||
'result',
|
||||
'end',
|
||||
'over',
|
||||
'init',
|
||||
];
|
||||
@ -12,3 +12,4 @@ export * from './charts';
|
||||
export * from './app-config';
|
||||
export * from './system-preferences';
|
||||
export * from './component-rules';
|
||||
export * from './editor.types';
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user