提交 a8eadbd8 编写于 作者: M Martin Aeschlimann

Clean up __characterPairSupport, fixes #6889

上级 db21446a
......@@ -94,16 +94,14 @@ export function activate(context: ExtensionContext) {
languages.setLanguageConfiguration('json', {
wordPattern: /(-?\d*\.\d\w*)|([^\[\{\]\}\:\"\,\s]+)/g,
__characterPairSupport: {
autoClosingPairs: [
{ open: '{', close: '}' },
{ open: '[', close: ']' },
{ open: '(', close: ')' },
{ open: '"', close: '"', notIn: ['string'] },
{ open: '\'', close: '\'', notIn: ['string', 'comment'] },
{ open: '`', close: '`', notIn: ['string', 'comment'] }
]
}
autoClosingPairs: [
{ open: '{', close: '}' },
{ open: '[', close: ']' },
{ open: '(', close: ')' },
{ open: '"', close: '"', notIn: ['string'] },
{ open: '\'', close: '\'', notIn: ['string', 'comment'] },
{ open: '`', close: '`', notIn: ['string', 'comment'] }
]
});
});
}
......
......@@ -28,14 +28,12 @@ export function activate(context: ExtensionContext): any {
languages.setLanguageConfiguration('php', {
wordPattern: /(-?\d*\.\d\w*)|([^\-\`\~\!\@\#\%\^\&\*\(\)\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\?\s]+)/g,
__characterPairSupport: {
autoClosingPairs: [
{ open: '{', close: '}' },
{ open: '[', close: ']' },
{ open: '(', close: ')' },
{ open: '"', close: '"', notIn: ['string'] },
{ open: '\'', close: '\'', notIn: ['string', 'comment'] }
]
}
autoClosingPairs: [
{ open: '{', close: '}' },
{ open: '[', close: ']' },
{ open: '(', close: ')' },
{ open: '"', close: '"', notIn: ['string'] },
{ open: '\'', close: '\'', notIn: ['string', 'comment'] }
]
});
}
\ No newline at end of file
......@@ -192,16 +192,14 @@ class LanguageProvider {
docComment: { scope: 'comment.documentation', open: '/**', lineStart: ' * ', close: ' */' }
},
__characterPairSupport: {
autoClosingPairs: [
{ open: '{', close: '}' },
{ open: '[', close: ']' },
{ open: '(', close: ')' },
{ open: '"', close: '"', notIn: ['string'] },
{ open: '\'', close: '\'', notIn: ['string', 'comment'] },
{ open: '`', close: '`', notIn: ['string', 'comment'] }
]
}
autoClosingPairs: [
{ open: '{', close: '}' },
{ open: '[', close: ']' },
{ open: '(', close: ')' },
{ open: '"', close: '"', notIn: ['string'] },
{ open: '\'', close: '\'', notIn: ['string', 'comment'] },
{ open: '`', close: '`', notIn: ['string', 'comment'] }
]
});
});
}
......
......@@ -25,14 +25,12 @@ export function createRichEditSupport(lexer: ILexer): IRichLanguageConfiguration
brackets: lexer.standardBrackets,
autoClosingPairs: lexer.autoClosingPairs,
__electricCharacterSupport: {
// regexBrackets: lexer.enhancedBrackets,
caseInsensitive: lexer.ignoreCase,
embeddedElectricCharacters: lexer.outdentTriggers.split('')
},
__characterPairSupport: {
autoClosingPairs: lexer.autoClosingPairs
}
};
}
......@@ -4,24 +4,22 @@
*--------------------------------------------------------------------------------------------*/
'use strict';
import {IAutoClosingPair, IAutoClosingPairConditional, ILineContext, IMode, IRichEditCharacterPair} from 'vs/editor/common/modes';
import {IAutoClosingPair, IAutoClosingPairConditional, ILineContext, IMode, IRichEditCharacterPair, CharacterPair} from 'vs/editor/common/modes';
import {handleEvent} from 'vs/editor/common/modes/supports';
export interface ICharacterPairContribution {
autoClosingPairs: IAutoClosingPairConditional[];
surroundingPairs?: IAutoClosingPair[];
}
export class CharacterPairSupport implements IRichEditCharacterPair {
private _modeId: string;
private _autoClosingPairs: IAutoClosingPairConditional[];
private _surroundingPairs: IAutoClosingPair[];
constructor(modeId: string, contribution: ICharacterPairContribution) {
constructor(modeId: string, config: { brackets?: CharacterPair[]; autoClosingPairs?: IAutoClosingPairConditional[], surroundingPairs?: IAutoClosingPair[]}) {
this._modeId = modeId;
this._autoClosingPairs = contribution.autoClosingPairs;
this._surroundingPairs = Array.isArray(contribution.surroundingPairs) ? contribution.surroundingPairs : contribution.autoClosingPairs;
this._autoClosingPairs = config.autoClosingPairs;
if (!this._autoClosingPairs) {
this._autoClosingPairs = config.brackets ? config.brackets.map(b => ({ open: b[0], close: b[1] })) : [];
}
this._surroundingPairs = config.surroundingPairs || this._autoClosingPairs;
}
public getAutoClosingPairs(): IAutoClosingPair[] {
......
......@@ -4,10 +4,10 @@
*--------------------------------------------------------------------------------------------*/
'use strict';
import {ICommentsConfiguration, IRichEditBrackets, IRichEditCharacterPair, IRichEditOnEnter, IRichEditSupport, CharacterPair} from 'vs/editor/common/modes';
import {ICommentsConfiguration, IRichEditBrackets, IRichEditCharacterPair, IAutoClosingPair,
IAutoClosingPairConditional, IRichEditOnEnter, IRichEditSupport, CharacterPair} from 'vs/editor/common/modes';
import {NullMode} from 'vs/editor/common/modes/nullMode';
import {CharacterPairSupport} from 'vs/editor/common/modes/supports/characterPair';
import {ICharacterPairContribution} from 'vs/editor/common/modes/supports/characterPair';
import {BracketElectricCharacterSupport, IBracketElectricCharacterContribution} from 'vs/editor/common/modes/supports/electricCharacter';
import {IIndentationRules, IOnEnterRegExpRules, IOnEnterSupportOptions, OnEnterSupport} from 'vs/editor/common/modes/supports/onEnter';
import {RichEditBrackets} from 'vs/editor/common/modes/supports/richEditBrackets';
......@@ -23,8 +23,9 @@ export interface IRichLanguageConfiguration {
wordPattern?: RegExp;
indentationRules?: IIndentationRules;
onEnterRules?: IOnEnterRegExpRules[];
autoClosingPairs?: IAutoClosingPairConditional[];
surroundingPairs?: IAutoClosingPair[];
__electricCharacterSupport?: IBracketElectricCharacterContribution;
__characterPairSupport?: ICharacterPairContribution;
}
export class RichEditSupport implements IRichEditSupport {
......@@ -55,8 +56,8 @@ export class RichEditSupport implements IRichEditSupport {
this._handleComments(modeId, this._conf);
if (this._conf.__characterPairSupport) {
this.characterPair = new CharacterPairSupport(modeId, this._conf.__characterPairSupport);
if (this._conf.autoClosingPairs) {
this.characterPair = new CharacterPairSupport(modeId, this._conf);
}
if (this._conf.__electricCharacterSupport || this._conf.brackets) {
......@@ -73,8 +74,9 @@ export class RichEditSupport implements IRichEditSupport {
wordPattern: (prev ? current.wordPattern || prev.wordPattern : current.wordPattern),
indentationRules: (prev ? current.indentationRules || prev.indentationRules : current.indentationRules),
onEnterRules: (prev ? current.onEnterRules || prev.onEnterRules : current.onEnterRules),
autoClosingPairs: (prev ? current.autoClosingPairs || prev.autoClosingPairs : current.autoClosingPairs),
surroundingPairs: (prev ? current.surroundingPairs || prev.surroundingPairs : current.surroundingPairs),
__electricCharacterSupport: (prev ? current.__electricCharacterSupport || prev.__electricCharacterSupport : current.__electricCharacterSupport),
__characterPairSupport: (prev ? current.__characterPairSupport || prev.__characterPairSupport : current.__characterPairSupport),
};
}
......
......@@ -81,17 +81,11 @@ export class LanguageConfigurationFileHandler {
}
if (configuration.autoClosingPairs) {
richEditConfig.__characterPairSupport = {
autoClosingPairs: this._mapCharacterPairs(configuration.autoClosingPairs)
};
} else if (configuration.brackets) {
richEditConfig.__characterPairSupport = {
autoClosingPairs: this._mapCharacterPairs(configuration.brackets)
};
richEditConfig.autoClosingPairs = this._mapCharacterPairs(configuration.autoClosingPairs);
}
if (richEditConfig.__characterPairSupport && configuration.surroundingPairs) {
richEditConfig.__characterPairSupport.surroundingPairs = this._mapCharacterPairs(configuration.surroundingPairs);
if (configuration.surroundingPairs) {
richEditConfig.surroundingPairs = this._mapCharacterPairs(configuration.surroundingPairs);
}
this._modeService.registerRichEditSupport(modeId, richEditConfig);
......
......@@ -1078,9 +1078,7 @@ class SurroundingMode extends TestMode {
constructor() {
super();
this.richEditSupport = new RichEditSupport(this.getId(), null, {
__characterPairSupport: {
autoClosingPairs: [{ open: '(', close: ')' }]
}
autoClosingPairs: [{ open: '(', close: ')' }]
});
}
}
......
......@@ -313,15 +313,13 @@ export class CSSMode extends AbstractMode {
['(', ')']
],
__characterPairSupport: {
autoClosingPairs: [
{ open: '{', close: '}' },
{ open: '[', close: ']' },
{ open: '(', close: ')' },
{ open: '"', close: '"', notIn: ['string'] },
{ open: '\'', close: '\'', notIn: ['string'] }
]
}
autoClosingPairs: [
{ open: '{', close: '}' },
{ open: '[', close: ']' },
{ open: '(', close: ')' },
{ open: '"', close: '"', notIn: ['string'] },
{ open: '\'', close: '\'', notIn: ['string'] }
]
});
this.inplaceReplaceSupport = this;
......
......@@ -169,20 +169,19 @@ export class HandlebarsMode extends htmlMode.HTMLMode<htmlWorker.HTMLWorker> {
embeddedElectricCharacters: ['*', '}', ']', ')']
},
__characterPairSupport: {
autoClosingPairs: [
{ open: '{', close: '}' },
{ open: '[', close: ']' },
{ open: '(', close: ')' },
{ open: '"', close: '"' },
{ open: '\'', close: '\'' }
],
surroundingPairs: [
{ open: '<', close: '>' },
{ open: '"', close: '"' },
{ open: '\'', close: '\'' }
]
},
autoClosingPairs: [
{ open: '{', close: '}' },
{ open: '[', close: ']' },
{ open: '(', close: ')' },
{ open: '"', close: '"' },
{ open: '\'', close: '\'' }
],
surroundingPairs: [
{ open: '<', close: '>' },
{ open: '"', close: '"' },
{ open: '\'', close: '\'' }
],
onEnterRules: [
{
......
......@@ -391,19 +391,18 @@ export class HTMLMode<W extends htmlWorker.HTMLWorker> extends AbstractMode impl
embeddedElectricCharacters: ['*', '}', ']', ')']
},
__characterPairSupport: {
autoClosingPairs: [
{ open: '{', close: '}' },
{ open: '[', close: ']' },
{ open: '(', close: ')' },
{ open: '"', close: '"' },
{ open: '\'', close: '\'' }
],
surroundingPairs: [
{ open: '"', close: '"' },
{ open: '\'', close: '\'' }
]
},
autoClosingPairs: [
{ open: '{', close: '}' },
{ open: '[', close: ']' },
{ open: '(', close: ')' },
{ open: '"', close: '"' },
{ open: '\'', close: '\'' }
],
surroundingPairs: [
{ open: '"', close: '"' },
{ open: '\'', close: '\'' }
],
onEnterRules: [
{
......
......@@ -54,13 +54,11 @@ export class JSONMode extends AbstractMode {
['[', ']']
],
__characterPairSupport: {
autoClosingPairs: [
{ open: '{', close: '}', notIn: ['string'] },
{ open: '[', close: ']', notIn: ['string'] },
{ open: '"', close: '"', notIn: ['string'] }
]
}
autoClosingPairs: [
{ open: '{', close: '}', notIn: ['string'] },
{ open: '[', close: ']', notIn: ['string'] },
{ open: '"', close: '"', notIn: ['string'] }
]
});
modes.HoverProviderRegistry.register(this.getId(), {
......
......@@ -482,15 +482,13 @@ export class PHPMode extends AbstractMode implements ITokenizationCustomization
['(', ')']
],
__characterPairSupport: {
autoClosingPairs: [
{ open: '{', close: '}', notIn: ['string.php'] },
{ open: '[', close: ']', notIn: ['string.php'] },
{ open: '(', close: ')', notIn: ['string.php'] },
{ open: '"', close: '"', notIn: ['string.php'] },
{ open: '\'', close: '\'', notIn: ['string.php'] }
]
}
autoClosingPairs: [
{ open: '{', close: '}', notIn: ['string.php'] },
{ open: '[', close: ']', notIn: ['string.php'] },
{ open: '(', close: ')', notIn: ['string.php'] },
{ open: '"', close: '"', notIn: ['string.php'] },
{ open: '\'', close: '\'', notIn: ['string.php'] }
]
});
if (editorWorkerService) {
......
......@@ -123,19 +123,17 @@ export class RAZORMode extends htmlMode.HTMLMode<RAZORWorker> {
embeddedElectricCharacters: ['*', '}', ']', ')']
},
__characterPairSupport: {
autoClosingPairs: [
{ open: '{', close: '}' },
{ open: '[', close: ']' },
{ open: '(', close: ')' },
{ open: '"', close: '"' },
{ open: '\'', close: '\'' }
],
surroundingPairs: [
{ open: '"', close: '"' },
{ open: '\'', close: '\'' }
]
},
autoClosingPairs: [
{ open: '{', close: '}' },
{ open: '[', close: ']' },
{ open: '(', close: ')' },
{ open: '"', close: '"' },
{ open: '\'', close: '\'' }
],
surroundingPairs: [
{ open: '"', close: '"' },
{ open: '\'', close: '\'' }
],
onEnterRules: [
{
......
......@@ -85,16 +85,14 @@ const richEditConfiguration:IRichLanguageConfiguration = {
docComment: {scope:'comment.doc', open:'/**', lineStart:' * ', close:' */'}
},
__characterPairSupport: {
autoClosingPairs: [
{ open: '{', close: '}' },
{ open: '[', close: ']' },
{ open: '(', close: ')' },
{ open: '"', close: '"', notIn: ['string'] },
{ open: '\'', close: '\'', notIn: ['string', 'comment'] },
{ open: '`', close: '`' }
]
}
autoClosingPairs: [
{ open: '{', close: '}' },
{ open: '[', close: ']' },
{ open: '(', close: ')' },
{ open: '"', close: '"', notIn: ['string'] },
{ open: '\'', close: '\'', notIn: ['string', 'comment'] },
{ open: '`', close: '`' }
]
};
export function createRichEditSupport(modeId:string): RichEditSupport {
......
......@@ -2300,6 +2300,26 @@ declare namespace vscode {
*/
onEnterRules?: OnEnterRule[];
/**
* The language's auto closing pairs. The 'close' character is automatically inserted with the
* 'open' character is typed. If not set, the configured brackets will be used.
*/
autoClosingPairs?: {
open: string;
close: string;
notIn?: string[];
}[];
/**
* The language's surrounding pairs. When the 'open' character is typed on a selection, the
* selected string is surrounded by the open and close characters. If not set, the autoclosing pairs
* settings will be used.
*/
surroundingPairs?: {
open: string;
close: string;
}[];
/**
* **Deprecated** Do not use.
*
......@@ -2323,7 +2343,7 @@ declare namespace vscode {
/**
* **Deprecated** Do not use.
*
* @deprecated Will be replaced by a better API soon.
* @deprecated Use autoClosingPairs and surroundingPairs instead.
*/
__characterPairSupport?: {
autoClosingPairs: {
......
......@@ -419,6 +419,12 @@ export class ExtHostAPIImplementation {
setWordDefinitionFor(modeId, null);
}
// backward compatibility, migrate deprecated setting
if (configuration.__characterPairSupport && !configuration.autoClosingPairs) {
configuration.autoClosingPairs = configuration.__characterPairSupport.autoClosingPairs;
delete configuration.__characterPairSupport;
}
return this.Modes_RichEditSupport_register(modeId, configuration);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册