提交 d5b3efd8 编写于 作者: A Alex Dima

Adopt StandardTokenType in electricCharacter

上级 ca6a1f10
......@@ -96,10 +96,6 @@ export class ScopedLineTokens {
return this._actual.getTokenStartOffset(tokenIndex + this._firstTokenIndex) - this.firstCharOffset;
}
public getTokenType(tokenIndex: number): string {
return this._actual.getTokenType(tokenIndex + this._firstTokenIndex);
}
public getStandardTokenType(tokenIndex: number): StandardTokenType {
return this._actual.getStandardTokenType(tokenIndex + this._firstTokenIndex);
}
......
......@@ -8,7 +8,7 @@ import * as strings from 'vs/base/common/strings';
import { ScopedLineTokens, ignoreBracketsInToken } from 'vs/editor/common/modes/supports';
import { BracketsUtils } from 'vs/editor/common/modes/supports/richEditBrackets';
import { RichEditBrackets } from 'vs/editor/common/modes/supports/richEditBrackets';
import { IAutoClosingPairConditional, IBracketElectricCharacterContribution } from 'vs/editor/common/modes/languageConfiguration';
import { IAutoClosingPairConditional, IBracketElectricCharacterContribution, StandardAutoClosingPairConditional } from 'vs/editor/common/modes/languageConfiguration';
/**
* Interface used to support electric characters
......@@ -31,15 +31,15 @@ export interface IElectricAction {
export class BracketElectricCharacterSupport {
private readonly _richEditBrackets: RichEditBrackets;
private readonly _complexAutoClosePairs: IAutoClosingPairConditional[];
private readonly _complexAutoClosePairs: StandardAutoClosingPairConditional[];
constructor(richEditBrackets: RichEditBrackets, autoClosePairs: IAutoClosingPairConditional[], contribution: IBracketElectricCharacterContribution) {
contribution = contribution || {};
this._richEditBrackets = richEditBrackets;
this._complexAutoClosePairs = autoClosePairs.filter(pair => pair.open.length > 1 && !!pair.close);
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({ open: contribution.docComment.open, close: contribution.docComment.close });
this._complexAutoClosePairs.push(new StandardAutoClosingPairConditional({ open: contribution.docComment.open, close: contribution.docComment.close }));
}
}
......@@ -76,16 +76,6 @@ export class BracketElectricCharacterSupport {
this._onElectricAutoIndent(context, offset));
}
private containsTokenTypes(fullTokenSpec: string, tokensToLookFor: string): boolean {
var array = tokensToLookFor.split('.');
for (var i = 0; i < array.length; ++i) {
if (fullTokenSpec.indexOf(array[i]) < 0) {
return false;
}
}
return true;
}
private _onElectricAutoIndent(context: ScopedLineTokens, offset: number): IElectricAction {
if (!this._richEditBrackets || this._richEditBrackets.brackets.length === 0) {
......@@ -150,13 +140,10 @@ export class BracketElectricCharacterSupport {
continue;
}
// If we're in a scope listen in 'notIn', do nothing
if (pair.notIn) {
let tokenType = context.getTokenType(lastTokenIndex);
if (pair.notIn.some(scope => this.containsTokenTypes(tokenType, scope))) {
// If we're in a scope listed in 'notIn', do nothing
if (!pair.isOK(context.getStandardTokenType(lastTokenIndex))) {
continue;
}
}
return { appendText: pair.close };
}
......
......@@ -319,11 +319,8 @@ suite('Editor Modes - Tokenization', () => {
assert.deepEqual(scopedLineTokens1.modeId, 'A');
assert.equal(scopedLineTokens1.getTokenCount(), 3);
assert.equal(scopedLineTokens1.getTokenStartOffset(0), 0);
assert.equal(scopedLineTokens1.getTokenType(0), 'A.abc');
assert.equal(scopedLineTokens1.getTokenStartOffset(1), 3);
assert.equal(scopedLineTokens1.getTokenType(1), '');
assert.equal(scopedLineTokens1.getTokenStartOffset(2), 4);
assert.equal(scopedLineTokens1.getTokenType(2), 'A.(');
assert.deepEqual(scopedLineTokens1.firstCharOffset, 0);
assert.equal(scopedLineTokens1.getLineContent(), 'abc (');
......@@ -331,7 +328,6 @@ suite('Editor Modes - Tokenization', () => {
assert.deepEqual(scopedLineTokens2.modeId, 'B');
assert.equal(scopedLineTokens2.getTokenCount(), 1);
assert.equal(scopedLineTokens2.getTokenStartOffset(0), 0);
assert.equal(scopedLineTokens2.getTokenType(0), 'B.def');
assert.deepEqual(scopedLineTokens2.firstCharOffset, 5);
assert.equal(scopedLineTokens2.getLineContent(), 'def');
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册