diff --git a/src/vs/editor/contrib/smartSelect/common/tokenTree.ts b/src/vs/editor/contrib/smartSelect/common/tokenTree.ts index 876e9bb663e53..6df5003825925 100644 --- a/src/vs/editor/contrib/smartSelect/common/tokenTree.ts +++ b/src/vs/editor/contrib/smartSelect/common/tokenTree.ts @@ -164,6 +164,7 @@ class TokenScanner { let tokenType = this._currentLineTokens.getTokenType(this._currentTokenIndex); let tokenEndIndex = this._currentLineTokens.getTokenEndIndex(this._currentTokenIndex, this._currentLineText.length); + let tmpTokenEndIndex = tokenEndIndex; let nextBracket: Range = null; if (this._currentModeBrackets && !ignoreBracketsInToken(tokenType)) { @@ -172,7 +173,7 @@ class TokenScanner { if (nextBracket && this._currentTokenStart < nextBracket.startColumn - 1) { // found a bracket, but it is not at the beginning of the token - tokenEndIndex = nextBracket.startColumn - 1; + tmpTokenEndIndex = nextBracket.startColumn - 1; nextBracket = null; } @@ -192,13 +193,18 @@ class TokenScanner { startLineNumber: this._currentLineNumber, startColumn: 1 + this._currentTokenStart, endLineNumber: this._currentLineNumber, - endColumn: 1 + tokenEndIndex + endColumn: 1 + tmpTokenEndIndex } }; - // console.log('TOKEN: <<' + this._currentLineText.substring(this._currentTokenStart, tokenEndIndex) + '>>'); - - this._currentTokenIndex += 1; - this._currentTokenStart = (this._currentTokenIndex < this._currentLineTokens.getTokenCount() ? this._currentLineTokens.getTokenStartIndex(this._currentTokenIndex) : 0); + // console.log('TOKEN: <<' + this._currentLineText.substring(this._currentTokenStart, tmpTokenEndIndex) + '>>'); + + if (tmpTokenEndIndex < tokenEndIndex) { + // there is a bracket somewhere in this token... + this._currentTokenStart = tmpTokenEndIndex; + } else { + this._currentTokenIndex += 1; + this._currentTokenStart = (this._currentTokenIndex < this._currentLineTokens.getTokenCount() ? this._currentLineTokens.getTokenStartIndex(this._currentTokenIndex) : 0); + } return token; } diff --git a/src/vs/editor/contrib/smartSelect/test/common/tokenSelectionSupport.test.ts b/src/vs/editor/contrib/smartSelect/test/common/tokenSelectionSupport.test.ts index cea395f423b17..b2ebca565fd4c 100644 --- a/src/vs/editor/contrib/smartSelect/test/common/tokenSelectionSupport.test.ts +++ b/src/vs/editor/contrib/smartSelect/test/common/tokenSelectionSupport.test.ts @@ -4,27 +4,61 @@ *--------------------------------------------------------------------------------------------*/ 'use strict'; -import 'vs/languages/typescript/common/typescript.contribution'; import * as assert from 'assert'; import URI from 'vs/base/common/uri'; import {Range} from 'vs/editor/common/core/range'; -import {IMode} from 'vs/editor/common/modes'; +import {IMode, IRichEditSupport, IndentAction} from 'vs/editor/common/modes'; import {TokenSelectionSupport} from 'vs/editor/contrib/smartSelect/common/tokenSelectionSupport'; -import {load} from 'vs/editor/test/common/modesUtil'; import {createMockModelService} from 'vs/editor/test/common/servicesTestUtils'; +import {MockTokenizingMode} from 'vs/editor/test/common/mocks/mockMode'; +import {RichEditSupport} from 'vs/editor/common/modes/supports/richEditSupport'; + +class MockJSMode extends MockTokenizingMode { + + public richEditSupport: IRichEditSupport; + + constructor() { + super('js', 'mock-js'); + + this.richEditSupport = new RichEditSupport(this.getId(), null, { + brackets: [ + ['(', ')'], + ['{', '}'], + ['[', ']'] + ], + + onEnterRules: [ + { + // e.g. /** | */ + beforeText: /^\s*\/\*\*(?!\/)([^\*]|\*(?!\/))*$/, + afterText: /^\s*\*\/$/, + action: { indentAction: IndentAction.IndentOutdent, appendText: ' * ' } + }, + { + // e.g. /** ...| + beforeText: /^\s*\/\*\*(?!\/)([^\*]|\*(?!\/))*$/, + action: { indentAction: IndentAction.None, appendText: ' * ' } + }, + { + // e.g. * ...| + beforeText: /^(\t|(\ \ ))*\ \*(\ ([^\*]|\*(?!\/))*)?$/, + action: { indentAction: IndentAction.None, appendText: '* ' } + }, + { + // e.g. */| + beforeText: /^(\t|(\ \ ))*\ \*\/\s*$/, + action: { indentAction: IndentAction.None, removeText: 1 } + } + ] + }); + } +} suite('TokenSelectionSupport', () => { let modelService = createMockModelService(); let tokenSelectionSupport = new TokenSelectionSupport(modelService); - let _mode: IMode; - - suiteSetup((done) => { - load('javascript').then(mode => { - _mode = mode; - done(); - }); - }); + let _mode: IMode = new MockJSMode(); function assertGetRangesToPosition(text:string[], lineNumber:number, column:number, ranges:Range[]): void { let uri = URI.file('test.js'); @@ -62,7 +96,7 @@ suite('TokenSelectionSupport', () => { new Range(3, 11, 3, 26), new Range(3, 17, 3, 26), new Range(3, 18, 3, 25), - new Range(3, 19, 3, 20) + // new Range(3, 19, 3, 20) ]); }); }); \ No newline at end of file diff --git a/src/vs/editor/test/common/modesUtil.ts b/src/vs/editor/test/common/modesUtil.ts index ece5c43d9a2ea..32c2d7b19e482 100644 --- a/src/vs/editor/test/common/modesUtil.ts +++ b/src/vs/editor/test/common/modesUtil.ts @@ -28,18 +28,6 @@ export function assertWords(actual:string[], expected:string[], message?:string) assert.deepEqual(actual, expected, message); } -export function load(modeId: string, preloadModes: string[] = [] ): TPromise { - var toLoad:string[] = [].concat(preloadModes).concat([modeId]); - - var modeService = createMockModeService(); - - var promises = toLoad.map(modeId => modeService.getOrCreateMode(modeId)); - - return TPromise.join(promises).then(modes => { - return modes[modes.length -1]; - }); -} - export function assertTokenization(tokenizationSupport: modes.ITokenizationSupport, tests: ITestItem[]): void { var state = tokenizationSupport.getInitialState(); for (var i = 0, len = tests.length; i < len; i++) { diff --git a/src/vs/languages/css/test/common/css.test.ts b/src/vs/languages/css/test/common/css.test.ts index 7c826967ff6fa..95d3cc889ca80 100644 --- a/src/vs/languages/css/test/common/css.test.ts +++ b/src/vs/languages/css/test/common/css.test.ts @@ -4,12 +4,13 @@ *--------------------------------------------------------------------------------------------*/ 'use strict'; -import 'vs/languages/css/common/css.contribution'; import cssMode = require('vs/languages/css/common/css'); import EditorCommon = require('vs/editor/common/editorCommon'); import Modes = require('vs/editor/common/modes'); import modesUtil = require('vs/editor/test/common/modesUtil'); -import {cssTokenTypes} from 'vs/languages/css/common/css'; +import {cssTokenTypes, CSSMode} from 'vs/languages/css/common/css'; +import {NULL_THREAD_SERVICE} from 'vs/platform/test/common/nullThreadService'; +import {createInstantiationService} from 'vs/platform/instantiation/common/instantiationService'; suite('CSS Colorizing', () => { @@ -18,14 +19,23 @@ suite('CSS Colorizing', () => { var tokenizationSupport: Modes.ITokenizationSupport; var assertOnEnter: modesUtil.IOnEnterAsserter; - suiteSetup((done) => { - modesUtil.load('css').then(mode => { - tokenizationSupport = mode.tokenizationSupport; - assertOnEnter = modesUtil.createOnEnterAsserter(mode.getId(), mode.richEditSupport); - wordDefinition = mode.richEditSupport.wordDefinition; - done(); + (function() { + let threadService = NULL_THREAD_SERVICE; + let inst = createInstantiationService({ + threadService: threadService, }); - }); + threadService.setInstantiationService(inst); + + let mode = new CSSMode( + { id: 'css' }, + inst, + threadService + ); + + tokenizationSupport = mode.tokenizationSupport; + assertOnEnter = modesUtil.createOnEnterAsserter(mode.getId(), mode.richEditSupport); + wordDefinition = mode.richEditSupport.wordDefinition; + })(); test('Skip whitespace', () => { modesUtil.assertTokenization(tokenizationSupport, [{ diff --git a/src/vs/languages/html/test/common/html-worker.test.ts b/src/vs/languages/html/test/common/html-worker.test.ts index c78ed97311133..273d3ac156197 100644 --- a/src/vs/languages/html/test/common/html-worker.test.ts +++ b/src/vs/languages/html/test/common/html-worker.test.ts @@ -4,7 +4,6 @@ *--------------------------------------------------------------------------------------------*/ 'use strict'; -import 'vs/languages/html/common/html.contribution'; import assert = require('assert'); import mm = require('vs/editor/common/model/mirrorModel'); import htmlWorker = require('vs/languages/html/common/htmlWorker'); @@ -16,17 +15,32 @@ import WinJS = require('vs/base/common/winjs.base'); import modesUtil = require('vs/editor/test/common/modesUtil'); import servicesUtil2 = require('vs/editor/test/common/servicesTestUtils'); import {NULL_THREAD_SERVICE} from 'vs/platform/test/common/nullThreadService'; +import {HTMLMode} from 'vs/languages/html/common/html'; +import {createInstantiationService} from 'vs/platform/instantiation/common/instantiationService'; +import {MockModeService} from 'vs/editor/test/common/mocks/mockModeService'; suite('HTML - worker', () => { var mode: Modes.IMode; - suiteSetup((done) => { - modesUtil.load('html').then(_mode => { - mode = _mode; - done(); + (function() { + + let threadService = NULL_THREAD_SERVICE; + let modeService = new MockModeService(); + let inst = createInstantiationService({ + threadService: threadService, + modeService: modeService }); - }); + threadService.setInstantiationService(inst); + + mode = new HTMLMode( + { id: 'html' }, + inst, + modeService, + threadService + ); + + })(); var mockHtmlWorkerEnv = function (url: URI, content: string): { worker: htmlWorker.HTMLWorker; model: mm.MirrorModel; } { var resourceService = new ResourceService.ResourceService(); diff --git a/src/vs/languages/html/test/common/html.test.ts b/src/vs/languages/html/test/common/html.test.ts index 0799f874b76d6..6228304925a09 100644 --- a/src/vs/languages/html/test/common/html.test.ts +++ b/src/vs/languages/html/test/common/html.test.ts @@ -22,7 +22,7 @@ import htmlWorker = require('vs/languages/html/common/htmlWorker'); import {MockTokenizingMode} from 'vs/editor/test/common/mocks/mockMode'; import {RichEditSupport} from 'vs/editor/common/modes/supports/richEditSupport'; -export class MockJSMode extends MockTokenizingMode { +class MockJSMode extends MockTokenizingMode { public richEditSupport: Modes.IRichEditSupport; diff --git a/src/vs/languages/json/test/common/json.test.ts b/src/vs/languages/json/test/common/json.test.ts index 2239e31d5dfb0..33d4b0a94caf0 100644 --- a/src/vs/languages/json/test/common/json.test.ts +++ b/src/vs/languages/json/test/common/json.test.ts @@ -4,26 +4,38 @@ *--------------------------------------------------------------------------------------------*/ 'use strict'; -import 'vs/languages/json/common/json.contribution'; import jsonMode = require('vs/languages/json/common/json'); import EditorCommon = require('vs/editor/common/editorCommon'); import Modes = require('vs/editor/common/modes'); import modesUtil = require('vs/editor/test/common/modesUtil'); import tokenization = require('vs/languages/json/common/features/tokenization'); import jsonTokenTypes = require('vs/languages/json/common/features/jsonTokenTypes'); +import {NULL_THREAD_SERVICE} from 'vs/platform/test/common/nullThreadService'; +import {createInstantiationService} from 'vs/platform/instantiation/common/instantiationService'; suite('JSON - tokenization', () => { var tokenizationSupport: Modes.ITokenizationSupport; var assertOnEnter: modesUtil.IOnEnterAsserter; - setup((done) => { - modesUtil.load('json').then(mode => { - tokenizationSupport = mode.tokenizationSupport; - assertOnEnter = modesUtil.createOnEnterAsserter(mode.getId(), mode.richEditSupport); - done(); + (function() { + + let threadService = NULL_THREAD_SERVICE; + let inst = createInstantiationService({ + threadService: threadService }); - }); + threadService.setInstantiationService(inst); + + let mode = new jsonMode.JSONMode( + { id: 'json' }, + inst, + threadService + ) + + tokenizationSupport = mode.tokenizationSupport; + assertOnEnter = modesUtil.createOnEnterAsserter(mode.getId(), mode.richEditSupport); + + })(); test('', () => { modesUtil.executeTests(tokenizationSupport,[ diff --git a/src/vs/languages/razor/test/common/razor.test.ts b/src/vs/languages/razor/test/common/razor.test.ts index dc4d1cc695b69..664da9726afc3 100644 --- a/src/vs/languages/razor/test/common/razor.test.ts +++ b/src/vs/languages/razor/test/common/razor.test.ts @@ -4,21 +4,38 @@ *--------------------------------------------------------------------------------------------*/ 'use strict'; -import 'vs/languages/razor/common/razor.contribution'; import modesUtil = require('vs/editor/test/common/modesUtil'); import Modes = require('vs/editor/common/modes'); import razorTokenTypes = require('vs/languages/razor/common/razorTokenTypes'); import {htmlTokenTypes} from 'vs/languages/html/common/html'; +import {RAZORMode} from 'vs/languages/razor/common/razor'; +import {NULL_THREAD_SERVICE} from 'vs/platform/test/common/nullThreadService'; +import {MockModeService} from 'vs/editor/test/common/mocks/mockModeService'; +import {createInstantiationService} from 'vs/platform/instantiation/common/instantiationService'; suite('Syntax Highlighting - Razor', () => { var tokenizationSupport: Modes.ITokenizationSupport; - setup((done) => { - modesUtil.load('razor').then(mode => { - tokenizationSupport = mode.tokenizationSupport; - done(); + + (function() { + + let threadService = NULL_THREAD_SERVICE; + let modeService = new MockModeService(); + let inst = createInstantiationService({ + threadService: threadService, + modeService: modeService }); - }); + threadService.setInstantiationService(inst); + + let mode = new RAZORMode( + { id: 'razor' }, + inst, + modeService, + threadService + ); + + tokenizationSupport = mode.tokenizationSupport; + })(); test('', () => { modesUtil.executeTests(tokenizationSupport,[ diff --git a/src/vs/languages/sass/test/common/sass.test.ts b/src/vs/languages/sass/test/common/sass.test.ts index 203921281c233..0298e1b9f807e 100644 --- a/src/vs/languages/sass/test/common/sass.test.ts +++ b/src/vs/languages/sass/test/common/sass.test.ts @@ -4,24 +4,43 @@ *--------------------------------------------------------------------------------------------*/ 'use strict'; -import 'vs/languages/sass/common/sass.contribution'; import SASS = require('vs/languages/sass/common/sass'); import modesUtil = require('vs/editor/test/common/modesUtil'); import Modes = require('vs/editor/common/modes'); import * as sassTokenTypes from 'vs/languages/sass/common/sassTokenTypes'; +import {NULL_THREAD_SERVICE} from 'vs/platform/test/common/nullThreadService'; +import {MockModeService} from 'vs/editor/test/common/mocks/mockModeService'; +import {createInstantiationService} from 'vs/platform/instantiation/common/instantiationService'; suite('Sass Colorizer', () => { var tokenizationSupport: Modes.ITokenizationSupport; var assertOnEnter: modesUtil.IOnEnterAsserter; - setup((done) => { - modesUtil.load('sass').then(mode => { - tokenizationSupport = mode.tokenizationSupport; - assertOnEnter = modesUtil.createOnEnterAsserter(mode.getId(), mode.richEditSupport); - done(); + (function() { + + let threadService = NULL_THREAD_SERVICE; + let modeService = new MockModeService(); + let inst = createInstantiationService({ + threadService: threadService, + modeService: modeService }); - }); + threadService.setInstantiationService(inst); + + + let mode = new SASS.SASSMode( + { id: 'sass' }, + inst, + threadService, + modeService, + null, + null + ); + + tokenizationSupport = mode.tokenizationSupport; + assertOnEnter = modesUtil.createOnEnterAsserter(mode.getId(), mode.richEditSupport); + + })(); test('', () => { modesUtil.executeTests(tokenizationSupport, [