in streampark-console/streampark-console-webapp/src/hooks/web/useMonaco.ts [42:102]
export function useMonaco(
target: Ref,
options: MonacoEditorOption,
beforeMount?: (monoao: any) => Promise<void>,
) {
const changeEventHook = createEventHook<string>();
const isSetup = ref(false);
let editor: Editor.IStandaloneCodeEditor;
let monacoInstance: any;
const registerCompletionMap = new Map();
let disposable;
const setContent = async (content: string) => {
await until(isSetup).toBeTruthy();
if (editor) editor.setValue(content);
};
const getContent = async () => {
await until(isSetup).toBeTruthy();
if (editor) {
return editor.getValue();
} else {
return '';
}
};
const getInstance = async () => {
await until(isSetup).toBeTruthy();
if (editor) {
return editor;
} else {
return null;
}
};
const getMonacoInstance = async () => {
await until(isSetup).toBeTruthy();
if (monacoInstance) {
return monacoInstance;
} else {
return null;
}
};
let suggestLabels: Array<Recordable> = [];
const createSuggestions = (
monaco: any,
range: TextRange,
preWord: string,
currentWord: string,
) => {
const suggestions: Array<Recordable> = [];
for (let i = 0; i < suggestLabels.length; i++) {
const id = suggestLabels[i].text;
const desc = suggestLabels[i].description;
suggestions.push({
label: `${id}${desc ? ':' + desc : ''}`,
insertText: `${preWord !== '{' && currentWord !== '{' ? '{' : ''}${id}}`,
detail: 'Variable Code',
kind: monaco.languages.CompletionItemKind.Variable,
range,
});
}
return suggestions;
};