Path: blob/main/src/vs/editor/common/languages/supports/characterPair.ts
3296 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { IAutoClosingPair, StandardAutoClosingPairConditional, LanguageConfiguration } from '../languageConfiguration.js';67export class CharacterPairSupport {89static readonly DEFAULT_AUTOCLOSE_BEFORE_LANGUAGE_DEFINED_QUOTES = ';:.,=}])> \n\t';10static readonly DEFAULT_AUTOCLOSE_BEFORE_LANGUAGE_DEFINED_BRACKETS = '\'"`;:.,=}])> \n\t';11static readonly DEFAULT_AUTOCLOSE_BEFORE_WHITESPACE = ' \n\t';1213private readonly _autoClosingPairs: StandardAutoClosingPairConditional[];14private readonly _surroundingPairs: IAutoClosingPair[];15private readonly _autoCloseBeforeForQuotes: string;16private readonly _autoCloseBeforeForBrackets: string;1718constructor(config: LanguageConfiguration) {19if (config.autoClosingPairs) {20this._autoClosingPairs = config.autoClosingPairs.map(el => new StandardAutoClosingPairConditional(el));21} else if (config.brackets) {22this._autoClosingPairs = config.brackets.map(b => new StandardAutoClosingPairConditional({ open: b[0], close: b[1] }));23} else {24this._autoClosingPairs = [];25}2627if (config.__electricCharacterSupport && config.__electricCharacterSupport.docComment) {28const docComment = config.__electricCharacterSupport.docComment;29// IDocComment is legacy, only partially supported30this._autoClosingPairs.push(new StandardAutoClosingPairConditional({ open: docComment.open, close: docComment.close || '' }));31}3233this._autoCloseBeforeForQuotes = typeof config.autoCloseBefore === 'string' ? config.autoCloseBefore : CharacterPairSupport.DEFAULT_AUTOCLOSE_BEFORE_LANGUAGE_DEFINED_QUOTES;34this._autoCloseBeforeForBrackets = typeof config.autoCloseBefore === 'string' ? config.autoCloseBefore : CharacterPairSupport.DEFAULT_AUTOCLOSE_BEFORE_LANGUAGE_DEFINED_BRACKETS;3536this._surroundingPairs = config.surroundingPairs || this._autoClosingPairs;37}3839public getAutoClosingPairs(): StandardAutoClosingPairConditional[] {40return this._autoClosingPairs;41}4243public getAutoCloseBeforeSet(forQuotes: boolean): string {44return (forQuotes ? this._autoCloseBeforeForQuotes : this._autoCloseBeforeForBrackets);45}4647public getSurroundingPairs(): IAutoClosingPair[] {48return this._surroundingPairs;49}50}515253