这是我定义的摩纳哥语言,不会自动将方括号括起来:在用于初始化语言的参数中,有autoclosingbrackets为“ true”。我也尝试过autoclosingbrackets =“ always”,但不起作用
monaco.languages.setMonarchTokensProvider('CustomExpressionLanguage', {
brackets: [
{ open: '{', close: '}', token: 'delimiter.curly' },
{ open: '[', close: ']', token: 'delimiter.square' },
{ open: '(', close: ')', token: 'delimiter.parenthesis' },
{ open: '<', close: '>', token: 'delimiter.angle' }
],
surroundingPairs: [
{ open: '{', close: '}' },
{ open: '[', close: ']' },
{ open: '(', close: ')' },
{ open: '<', close: '>' },
{ open: '\'', close: '\'' },
{ open: '"', close: '"' },
],
autoClosingPairs: [
{ open: '{', close: '}' },
{ open: '[', close: ']' },
{ open: '(', close: ')' },
{ open: '\'', close: '\'', notIn: ['string', 'comment'] },
{ open: '"', close: '"', notIn: ['string', 'comment'] },
],
});
setLanguageConfiguration
。 此外,我不确定这是否是配置brackets
的正确方法。
这是一个可行的示例
const config = {
surroundingPairs: [
{ open: '{', close: '}' },
{ open: '[', close: ']' },
{ open: '(', close: ')' },
{ open: '<', close: '>' },
{ open: "'", close: "'" },
{ open: '"', close: '"' },
],
autoClosingPairs: [
{ open: '{', close: '}' },
{ open: '[', close: ']' },
{ open: '(', close: ')' },
{ open: "'", close: "'", notIn: ['string', 'comment'] },
{ open: '"', close: '"', notIn: ['string', 'comment'] },
],
};
monaco.languages.setLanguageConfiguration('YOUR_CUSTOM_LANGUAGE', config);