Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/editor/common/languages/supports/characterPair.ts
3296 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { IAutoClosingPair, StandardAutoClosingPairConditional, LanguageConfiguration } from '../languageConfiguration.js';
7
8
export class CharacterPairSupport {
9
10
static readonly DEFAULT_AUTOCLOSE_BEFORE_LANGUAGE_DEFINED_QUOTES = ';:.,=}])> \n\t';
11
static readonly DEFAULT_AUTOCLOSE_BEFORE_LANGUAGE_DEFINED_BRACKETS = '\'"`;:.,=}])> \n\t';
12
static readonly DEFAULT_AUTOCLOSE_BEFORE_WHITESPACE = ' \n\t';
13
14
private readonly _autoClosingPairs: StandardAutoClosingPairConditional[];
15
private readonly _surroundingPairs: IAutoClosingPair[];
16
private readonly _autoCloseBeforeForQuotes: string;
17
private readonly _autoCloseBeforeForBrackets: string;
18
19
constructor(config: LanguageConfiguration) {
20
if (config.autoClosingPairs) {
21
this._autoClosingPairs = config.autoClosingPairs.map(el => new StandardAutoClosingPairConditional(el));
22
} else if (config.brackets) {
23
this._autoClosingPairs = config.brackets.map(b => new StandardAutoClosingPairConditional({ open: b[0], close: b[1] }));
24
} else {
25
this._autoClosingPairs = [];
26
}
27
28
if (config.__electricCharacterSupport && config.__electricCharacterSupport.docComment) {
29
const docComment = config.__electricCharacterSupport.docComment;
30
// IDocComment is legacy, only partially supported
31
this._autoClosingPairs.push(new StandardAutoClosingPairConditional({ open: docComment.open, close: docComment.close || '' }));
32
}
33
34
this._autoCloseBeforeForQuotes = typeof config.autoCloseBefore === 'string' ? config.autoCloseBefore : CharacterPairSupport.DEFAULT_AUTOCLOSE_BEFORE_LANGUAGE_DEFINED_QUOTES;
35
this._autoCloseBeforeForBrackets = typeof config.autoCloseBefore === 'string' ? config.autoCloseBefore : CharacterPairSupport.DEFAULT_AUTOCLOSE_BEFORE_LANGUAGE_DEFINED_BRACKETS;
36
37
this._surroundingPairs = config.surroundingPairs || this._autoClosingPairs;
38
}
39
40
public getAutoClosingPairs(): StandardAutoClosingPairConditional[] {
41
return this._autoClosingPairs;
42
}
43
44
public getAutoCloseBeforeSet(forQuotes: boolean): string {
45
return (forQuotes ? this._autoCloseBeforeForQuotes : this._autoCloseBeforeForBrackets);
46
}
47
48
public getSurroundingPairs(): IAutoClosingPair[] {
49
return this._surroundingPairs;
50
}
51
}
52
53