From 6325f3d9cf848ba255a69c9df461a32f9c531cd5 Mon Sep 17 00:00:00 2001 From: Alex Dima Date: Tue, 1 Nov 2016 12:37:15 +0100 Subject: [PATCH] Begin to clean up ElectricCharacter --- src/vs/editor/common/core/modeTransition.ts | 19 ---------- .../modes/supports/electricCharacter.ts | 38 ++++++------------- .../test/common/modes/autoIndentation.test.ts | 4 +- src/vs/monaco.d.ts | 10 +++-- .../api/node/mainThreadLanguageFeatures.ts | 30 +++++++++++++-- 5 files changed, 47 insertions(+), 54 deletions(-) diff --git a/src/vs/editor/common/core/modeTransition.ts b/src/vs/editor/common/core/modeTransition.ts index a981bbb73bf..fc3f4213f93 100644 --- a/src/vs/editor/common/core/modeTransition.ts +++ b/src/vs/editor/common/core/modeTransition.ts @@ -20,23 +20,4 @@ export class ModeTransition { public static findIndexInSegmentsArray(arr: ModeTransition[], desiredIndex: number): number { return Arrays.findIndexInSegmentsArray(arr, desiredIndex); } - - public static equals(a: ModeTransition[], b: ModeTransition[]): boolean { - let aLen = a.length; - let bLen = b.length; - if (aLen !== bLen) { - return false; - } - for (let i = 0; i < aLen; i++) { - let aModeTransition = a[i]; - let bModeTransition = b[i]; - if (aModeTransition.startIndex !== bModeTransition.startIndex) { - return false; - } - if (aModeTransition.modeId !== bModeTransition.modeId) { - return false; - } - } - return true; - } } diff --git a/src/vs/editor/common/modes/supports/electricCharacter.ts b/src/vs/editor/common/modes/supports/electricCharacter.ts index bf7b6084a81..7521e0adb5b 100644 --- a/src/vs/editor/common/modes/supports/electricCharacter.ts +++ b/src/vs/editor/common/modes/supports/electricCharacter.ts @@ -13,10 +13,14 @@ import { BracketsUtils } from 'vs/editor/common/modes/supports/richEditBrackets' * Definition of documentation comments (e.g. Javadoc/JSdoc) */ export interface IDocComment { - scope: string; // What tokens should be used to detect a doc comment (e.g. 'comment.documentation'). - open: string; // The string that starts a doc comment (e.g. '/**') - lineStart: string; // The string that appears at the start of each line, except the first and last (e.g. ' * '). - close?: string; // The string that appears on the last line and closes the doc comment (e.g. ' */'). + /** + * The string that starts a doc comment (e.g. '/**') + */ + open: string; + /** + * The string that appears on the last line and closes the doc comment (e.g. ' * /'). + */ + close: string; } export interface IBracketElectricCharacterContribution { @@ -25,34 +29,16 @@ export interface IBracketElectricCharacterContribution { export class BracketElectricCharacterSupport { - private readonly contribution: IBracketElectricCharacterContribution; - private readonly brackets: Brackets; - - constructor(brackets: modes.IRichEditBrackets, autoClosePairs: modes.IAutoClosingPairConditional[], contribution: IBracketElectricCharacterContribution) { - this.contribution = contribution || {}; - this.brackets = new Brackets(brackets, autoClosePairs, this.contribution.docComment); - } - - public getElectricCharacters(): string[] { - return this.brackets.getElectricCharacters(); - } - - public onElectricCharacter(context: ScopedLineTokens, offset: number): modes.IElectricAction { - return this.brackets.onElectricCharacter(context, offset); - } -} - -export class Brackets { - private readonly _richEditBrackets: modes.IRichEditBrackets; private readonly _complexAutoClosePairs: modes.IAutoClosingPairConditional[]; - constructor(richEditBrackets: modes.IRichEditBrackets, autoClosePairs: modes.IAutoClosingPairConditional[], docComment?: IDocComment) { + constructor(richEditBrackets: modes.IRichEditBrackets, autoClosePairs: modes.IAutoClosingPairConditional[], contribution: IBracketElectricCharacterContribution) { + contribution = contribution || {}; this._richEditBrackets = richEditBrackets; this._complexAutoClosePairs = autoClosePairs.filter(pair => pair.open.length > 1 && !!pair.close); - if (docComment) { + if (contribution.docComment) { // IDocComment is legacy, only partially supported - this._complexAutoClosePairs.push({ open: docComment.open, close: docComment.close }); + this._complexAutoClosePairs.push({ open: contribution.docComment.open, close: contribution.docComment.close }); } } diff --git a/src/vs/editor/test/common/modes/autoIndentation.test.ts b/src/vs/editor/test/common/modes/autoIndentation.test.ts index 4a1488969b4..f446acf58e3 100644 --- a/src/vs/editor/test/common/modes/autoIndentation.test.ts +++ b/src/vs/editor/test/common/modes/autoIndentation.test.ts @@ -5,7 +5,7 @@ 'use strict'; import * as assert from 'assert'; -import { Brackets } from 'vs/editor/common/modes/supports/electricCharacter'; +import { BracketElectricCharacterSupport } from 'vs/editor/common/modes/supports/electricCharacter'; import { createFakeLineTokens } from 'vs/editor/test/common/modesTestUtils'; import { LineTokens } from 'vs/editor/common/core/lineTokens'; import { Token } from 'vs/editor/common/core/token'; @@ -37,7 +37,7 @@ function createScopedLineTokensFromTokenText(modeId: string, tokens: TokenText[] suite('Editor Modes - Auto Indentation', () => { test('Doc comments', () => { - var brackets = new Brackets(null, [{ open: '/**', close: ' */' }]); + var brackets = new BracketElectricCharacterSupport(null, [{ open: '/**', close: ' */' }], null); assert.equal(brackets.onElectricCharacter(createScopedLineTokensFromTokenText('test', [ { text: '/**', type: 'doc' }, diff --git a/src/vs/monaco.d.ts b/src/vs/monaco.d.ts index 986df4374af..87c608a1944 100644 --- a/src/vs/monaco.d.ts +++ b/src/vs/monaco.d.ts @@ -4179,10 +4179,14 @@ declare module monaco.languages { * Definition of documentation comments (e.g. Javadoc/JSdoc) */ export interface IDocComment { - scope: string; + /** + * The string that starts a doc comment (e.g. '/**') + */ open: string; - lineStart: string; - close?: string; + /** + * The string that appears on the last line and closes the doc comment (e.g. ' * /'). + */ + close: string; } /** diff --git a/src/vs/workbench/api/node/mainThreadLanguageFeatures.ts b/src/vs/workbench/api/node/mainThreadLanguageFeatures.ts index cf924f2f9fe..31b8e5fc3cd 100644 --- a/src/vs/workbench/api/node/mainThreadLanguageFeatures.ts +++ b/src/vs/workbench/api/node/mainThreadLanguageFeatures.ts @@ -226,13 +226,35 @@ export class MainThreadLanguageFeatures extends MainThreadLanguageFeaturesShape // --- configuration - $setLanguageConfiguration(handle: number, languageId: string, configuration: vscode.LanguageConfiguration): TPromise { + $setLanguageConfiguration(handle: number, languageId: string, _configuration: vscode.LanguageConfiguration): TPromise { - if (configuration.__characterPairSupport) { - (configuration).autoClosingPairs = configuration.__characterPairSupport.autoClosingPairs; + let configuration: LanguageConfiguration = { + comments: _configuration.comments, + brackets: _configuration.brackets, + wordPattern: _configuration.wordPattern, + indentationRules: _configuration.indentationRules, + onEnterRules: _configuration.onEnterRules, + + autoClosingPairs: null, + surroundingPairs: null, + __electricCharacterSupport: null + }; + + if (_configuration.__characterPairSupport) { + // backwards compatibility + configuration.autoClosingPairs = _configuration.__characterPairSupport.autoClosingPairs; } - this._registrations[handle] = LanguageConfigurationRegistry.register(languageId, configuration); + if (_configuration.__electricCharacterSupport && _configuration.__electricCharacterSupport.docComment) { + configuration.__electricCharacterSupport = { + docComment: { + open: _configuration.__electricCharacterSupport.docComment.open, + close: _configuration.__electricCharacterSupport.docComment.close + } + }; + } + + this._registrations[handle] = LanguageConfigurationRegistry.register(languageId, configuration); return undefined; }