monaco-editor
当使用多个或者打开多次编辑器时,输入代码,会发现有多个重复提示,
此时 monaco.languages.registerCompletionItemProvider 已经注册多次了,使用一个全局变量控制多次注册
import { registerCount } from './registerCount' ``` // registerCount.js export const registerCount = {} ``` // 判断已注册的,避免重复注册 !registerCount[language] && monaco.languages.registerCompletionItemProvider(language, { provideCompletionItems: async function (model, position) { // 注册记录 registerCount[language] = 'ready'; let suggestions = []; const langLoader = await monaco.languages .getLanguages() .find((item) => { return item.id === language; }) .loader(); const keywords = langLoader.language.keywords;keywords.forEach((item) => { suggestions.push({ label: item, kind: monaco.languages.CompletionItemKind.Snippet, insertText: item, }); }); return { suggestions }; }, });
标签:language,提示,registerCount,languages,item,editor,注册,monaco From: https://www.cnblogs.com/hill-foryou/p/16991802.html