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

Adopt StandardTokenType in electricCharacter

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