Monaco Editor defined language does not close the brackets

This is my defined Monaco language and it doesn't automatically close the brackets: Among the parameters passed to initialize the language, is the autoclosingbrackets as "true".I also tried autoclosingbrackets = "always" and it doesn't work

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'] },
                ],

            });

Upvotes: 4

Views: 1408

Answers (1)

Ahmed Youssef
Ahmed Youssef

Reputation: 238

I believe the method that you're looking for it setLanguageConfiguration.

Also, I'm not sure whether this is the correct way to configure brackets.

Here is a working example

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);

Upvotes: 9

Related Questions