Merge from vscode 6e530127a1bb8ffbd1bfb77dc680c321dc0d71f5 (#6844)

This commit is contained in:
Anthony Dresser
2019-08-20 21:07:47 -07:00
committed by GitHub
parent 1f00249646
commit ecb80f14f0
221 changed files with 3140 additions and 1552 deletions

View File

@@ -78,7 +78,9 @@ export interface LanguageConfiguration {
*
* @deprecated Will be replaced by a better API soon.
*/
__electricCharacterSupport?: IBracketElectricCharacterContribution;
__electricCharacterSupport?: {
docComment?: IDocComment;
};
}
/**
@@ -155,10 +157,6 @@ export interface OnEnterRule {
action: EnterAction;
}
export interface IBracketElectricCharacterContribution {
docComment?: IDocComment;
}
/**
* Definition of documentation comments (e.g. Javadoc/JSdoc)
*/

View File

@@ -12,7 +12,7 @@ import { Range } from 'vs/editor/common/core/range';
import { ITextModel } from 'vs/editor/common/model';
import { DEFAULT_WORD_REGEXP, ensureValidWordDefinition } from 'vs/editor/common/model/wordHelper';
import { LanguageId, LanguageIdentifier } from 'vs/editor/common/modes';
import { EnterAction, FoldingRules, IAutoClosingPair, IAutoClosingPairConditional, IndentAction, IndentationRule, LanguageConfiguration } from 'vs/editor/common/modes/languageConfiguration';
import { EnterAction, FoldingRules, IAutoClosingPair, IndentAction, IndentationRule, LanguageConfiguration, StandardAutoClosingPairConditional } from 'vs/editor/common/modes/languageConfiguration';
import { createScopedLineTokens } from 'vs/editor/common/modes/supports';
import { CharacterPairSupport } from 'vs/editor/common/modes/supports/characterPair';
import { BracketElectricCharacterSupport, IElectricAction } from 'vs/editor/common/modes/supports/electricCharacter';
@@ -97,16 +97,7 @@ export class RichEditSupport {
public get electricCharacter(): BracketElectricCharacterSupport | null {
if (!this._electricCharacter) {
let autoClosingPairs: IAutoClosingPairConditional[] = [];
if (this._conf.autoClosingPairs) {
autoClosingPairs = this._conf.autoClosingPairs;
} else if (this._conf.brackets) {
autoClosingPairs = this._conf.brackets.map(b => {
return { open: b[0], close: b[1] };
});
}
this._electricCharacter = new BracketElectricCharacterSupport(this.brackets, autoClosingPairs, this._conf.__electricCharacterSupport);
this._electricCharacter = new BracketElectricCharacterSupport(this.brackets);
}
return this._electricCharacter;
}
@@ -261,7 +252,7 @@ export class LanguageConfigurationRegistryImpl {
return value.characterPair || null;
}
public getAutoClosingPairs(languageId: LanguageId): IAutoClosingPair[] {
public getAutoClosingPairs(languageId: LanguageId): StandardAutoClosingPairConditional[] {
let characterPairSupport = this._getCharacterPairSupport(languageId);
if (!characterPairSupport) {
return [];
@@ -285,13 +276,9 @@ export class LanguageConfigurationRegistryImpl {
return characterPairSupport.getSurroundingPairs();
}
public shouldAutoClosePair(character: string, context: LineTokens, column: number): boolean {
let scopedLineTokens = createScopedLineTokens(context, column - 1);
let characterPairSupport = this._getCharacterPairSupport(scopedLineTokens.languageId);
if (!characterPairSupport) {
return false;
}
return characterPairSupport.shouldAutoClosePair(character, scopedLineTokens, column - scopedLineTokens.firstCharOffset);
public shouldAutoClosePair(autoClosingPair: StandardAutoClosingPairConditional, context: LineTokens, column: number): boolean {
const scopedLineTokens = createScopedLineTokens(context, column - 1);
return CharacterPairSupport.shouldAutoClosePair(autoClosingPair, scopedLineTokens, column - scopedLineTokens.firstCharOffset);
}
// end characterPair

View File

@@ -3,7 +3,7 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { CharacterPair, IAutoClosingPair, IAutoClosingPairConditional, StandardAutoClosingPairConditional } from 'vs/editor/common/modes/languageConfiguration';
import { IAutoClosingPair, StandardAutoClosingPairConditional, LanguageConfiguration } from 'vs/editor/common/modes/languageConfiguration';
import { ScopedLineTokens } from 'vs/editor/common/modes/supports';
export class CharacterPairSupport {
@@ -15,7 +15,7 @@ export class CharacterPairSupport {
private readonly _surroundingPairs: IAutoClosingPair[];
private readonly _autoCloseBefore: string;
constructor(config: { brackets?: CharacterPair[]; autoClosingPairs?: IAutoClosingPairConditional[], surroundingPairs?: IAutoClosingPair[], autoCloseBefore?: string }) {
constructor(config: LanguageConfiguration) {
if (config.autoClosingPairs) {
this._autoClosingPairs = config.autoClosingPairs.map(el => new StandardAutoClosingPairConditional(el));
} else if (config.brackets) {
@@ -24,12 +24,18 @@ export class CharacterPairSupport {
this._autoClosingPairs = [];
}
if (config.__electricCharacterSupport && config.__electricCharacterSupport.docComment) {
const docComment = config.__electricCharacterSupport.docComment;
// IDocComment is legacy, only partially supported
this._autoClosingPairs.push(new StandardAutoClosingPairConditional({ open: docComment.open, close: docComment.close || '' }));
}
this._autoCloseBefore = typeof config.autoCloseBefore === 'string' ? config.autoCloseBefore : CharacterPairSupport.DEFAULT_AUTOCLOSE_BEFORE_LANGUAGE_DEFINED;
this._surroundingPairs = config.surroundingPairs || this._autoClosingPairs;
}
public getAutoClosingPairs(): IAutoClosingPair[] {
public getAutoClosingPairs(): StandardAutoClosingPairConditional[] {
return this._autoClosingPairs;
}
@@ -37,22 +43,15 @@ export class CharacterPairSupport {
return this._autoCloseBefore;
}
public shouldAutoClosePair(character: string, context: ScopedLineTokens, column: number): boolean {
public static shouldAutoClosePair(autoClosingPair: StandardAutoClosingPairConditional, context: ScopedLineTokens, column: number): boolean {
// Always complete on empty line
if (context.getTokenCount() === 0) {
return true;
}
let tokenIndex = context.findTokenIndexAtOffset(column - 2);
let standardTokenType = context.getStandardTokenType(tokenIndex);
for (const autoClosingPair of this._autoClosingPairs) {
if (autoClosingPair.open === character) {
return autoClosingPair.isOK(standardTokenType);
}
}
return false;
const tokenIndex = context.findTokenIndexAtOffset(column - 2);
const standardTokenType = context.getStandardTokenType(tokenIndex);
return autoClosingPair.isOK(standardTokenType);
}
public getSurroundingPairs(): IAutoClosingPair[] {

View File

@@ -3,7 +3,6 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { IAutoClosingPairConditional, IBracketElectricCharacterContribution, StandardAutoClosingPairConditional } from 'vs/editor/common/modes/languageConfiguration';
import { ScopedLineTokens, ignoreBracketsInToken } from 'vs/editor/common/modes/supports';
import { BracketsUtils, RichEditBrackets } from 'vs/editor/common/modes/supports/richEditBrackets';
@@ -12,29 +11,17 @@ import { BracketsUtils, RichEditBrackets } from 'vs/editor/common/modes/supports
* @internal
*/
export interface IElectricAction {
// Only one of the following properties should be defined:
// The line will be indented at the same level of the line
// which contains the matching given bracket type.
matchOpenBracket?: string;
// The text will be appended after the electric character.
appendText?: string;
matchOpenBracket: string;
}
export class BracketElectricCharacterSupport {
private readonly _richEditBrackets: RichEditBrackets | null;
private readonly _complexAutoClosePairs: StandardAutoClosingPairConditional[];
constructor(richEditBrackets: RichEditBrackets | null, autoClosePairs: IAutoClosingPairConditional[], contribution: IBracketElectricCharacterContribution | null | undefined) {
contribution = contribution || {};
constructor(richEditBrackets: RichEditBrackets | null) {
this._richEditBrackets = richEditBrackets;
this._complexAutoClosePairs = autoClosePairs.filter(pair => pair.open.length > 1 && !!pair.close).map(el => new StandardAutoClosingPairConditional(el));
if (contribution.docComment) {
// IDocComment is legacy, only partially supported
this._complexAutoClosePairs.push(new StandardAutoClosingPairConditional({ open: contribution.docComment.open, close: contribution.docComment.close || '' }));
}
}
public getElectricCharacters(): string[] {
@@ -48,11 +35,6 @@ export class BracketElectricCharacterSupport {
}
}
// auto close
for (let pair of this._complexAutoClosePairs) {
result.push(pair.open.charAt(pair.open.length - 1));
}
// Filter duplicate entries
result = result.filter((item, pos, array) => {
return array.indexOf(item) === pos;
@@ -62,12 +44,6 @@ export class BracketElectricCharacterSupport {
}
public onElectricCharacter(character: string, context: ScopedLineTokens, column: number): IElectricAction | null {
return (this._onElectricAutoClose(character, context, column) ||
this._onElectricAutoIndent(character, context, column));
}
private _onElectricAutoIndent(character: string, context: ScopedLineTokens, column: number): IElectricAction | null {
if (!this._richEditBrackets || this._richEditBrackets.brackets.length === 0) {
return null;
}
@@ -103,44 +79,4 @@ export class BracketElectricCharacterSupport {
matchOpenBracket: bracketText
};
}
private _onElectricAutoClose(character: string, context: ScopedLineTokens, column: number): IElectricAction | null {
if (!this._complexAutoClosePairs.length) {
return null;
}
let line = context.getLineContent();
for (let i = 0, len = this._complexAutoClosePairs.length; i < len; i++) {
let pair = this._complexAutoClosePairs[i];
// See if the right electric character was pressed
if (character !== pair.open.charAt(pair.open.length - 1)) {
continue;
}
// check if the full open bracket matches
let start = column - pair.open.length + 1;
let actual = line.substring(start - 1, column - 1) + character;
if (actual !== pair.open) {
continue;
}
let lastTokenIndex = context.findTokenIndexAtOffset(column - 1);
let lastTokenStandardType = context.getStandardTokenType(lastTokenIndex);
// If we're in a scope listed in 'notIn', do nothing
if (!pair.isOK(lastTokenStandardType)) {
continue;
}
// If this line already contains the closing tag, do nothing.
if (line.indexOf(pair.close, column - 1) >= 0) {
continue;
}
return { appendText: pair.close };
}
return null;
}
}