55'use strict' ;
66
77import * as nls from 'vs/nls' ;
8-
9- import paths = require( 'vs/base/common/paths' ) ;
10- import errors = require( 'vs/base/common/errors' ) ;
11-
12- import * as Modes from 'vs/editor/common/modes' ;
13- import supports = require( 'vs/editor/common/modes/supports' ) ;
14- import collections = require( 'vs/base/common/collections' ) ;
15- import textMate = require( 'vscode-textmate' ) ;
16- import TMState = require( 'vs/editor/common/modes/TMState' ) ;
8+ import * as collections from 'vs/base/common/collections' ;
9+ import { onUnexpectedError } from 'vs/base/common/errors' ;
10+ import * as paths from 'vs/base/common/paths' ;
11+ import { IMessageCollector , PluginsRegistry } from 'vs/platform/plugins/common/pluginsRegistry' ;
12+ import { Bracket , ILineTokens , IMode , IToken , ITokenizationSupport } from 'vs/editor/common/modes' ;
13+ import { TMState } from 'vs/editor/common/modes/TMState' ;
14+ import { Token } from 'vs/editor/common/modes/supports' ;
1715import { IModeService } from 'vs/editor/common/services/modeService' ;
18- import { PluginsRegistry , IMessageCollector } from 'vs/platform/plugins/common/pluginsRegistry ' ;
16+ import { IGrammar , ITMToken , Registry } from 'vscode-textmate ' ;
1917
2018export interface ITMSyntaxExtensionPoint {
2119 language : string ;
@@ -48,15 +46,15 @@ let grammarsExtPoint = PluginsRegistry.registerExtensionPoint<ITMSyntaxExtension
4846} ) ;
4947
5048export class MainProcessTextMateSyntax {
51- private _grammarRegistry : textMate . Registry ;
49+ private _grammarRegistry : Registry ;
5250 private _modeService : IModeService ;
5351 private _scopeNameToFilePath : { [ scopeName :string ] : string ; } ;
5452
5553 constructor (
5654 @IModeService modeService : IModeService
5755 ) {
5856 this . _modeService = modeService ;
59- this . _grammarRegistry = new textMate . Registry ( {
57+ this . _grammarRegistry = new Registry ( {
6058 getFilePath : ( scopeName :string ) => {
6159 return this . _scopeNameToFilePath [ scopeName ] ;
6260 }
@@ -105,44 +103,44 @@ export class MainProcessTextMateSyntax {
105103 public registerDefinition ( modeId : string , scopeName : string ) : void {
106104 this . _grammarRegistry . loadGrammar ( scopeName , ( err , grammar ) => {
107105 if ( err ) {
108- errors . onUnexpectedError ( err ) ;
106+ onUnexpectedError ( err ) ;
109107 return ;
110108 }
111109
112- this . _modeService . registerTokenizationSupport ( modeId , ( mode : Modes . IMode ) => {
110+ this . _modeService . registerTokenizationSupport ( modeId , ( mode : IMode ) => {
113111 return createTokenizationSupport ( mode , grammar ) ;
114112 } ) ;
115113 } ) ;
116114 }
117115}
118116
119- function createTokenizationSupport ( mode : Modes . IMode , grammar : textMate . IGrammar ) : Modes . ITokenizationSupport {
117+ function createTokenizationSupport ( mode : IMode , grammar : IGrammar ) : ITokenizationSupport {
120118 var tokenizer = new Tokenizer ( mode . getId ( ) , grammar ) ;
121119 return {
122120 shouldGenerateEmbeddedModels : false ,
123- getInitialState : ( ) => new TMState . TMState ( mode , null , null ) ,
124- tokenize : ( line , state , offsetDelta ?, stopAtOffset ?) => tokenizer . tokenize ( line , < TMState . TMState > state , offsetDelta , stopAtOffset )
121+ getInitialState : ( ) => new TMState ( mode , null , null ) ,
122+ tokenize : ( line , state , offsetDelta ?, stopAtOffset ?) => tokenizer . tokenize ( line , < TMState > state , offsetDelta , stopAtOffset )
125123 } ;
126124}
127125
128126
129127
130128class Tokenizer {
131- private _grammar : textMate . IGrammar ;
129+ private _grammar : IGrammar ;
132130 private _modeId : string ;
133131
134- constructor ( modeId :string , grammar : textMate . IGrammar ) {
132+ constructor ( modeId :string , grammar : IGrammar ) {
135133 this . _modeId = modeId ;
136134 this . _grammar = grammar ;
137135 }
138136
139- public tokenize ( line : string , state : TMState . TMState , offsetDelta : number = 0 , stopAtOffset ?: number ) : Modes . ILineTokens {
137+ public tokenize ( line : string , state : TMState , offsetDelta : number = 0 , stopAtOffset ?: number ) : ILineTokens {
140138 if ( line . length >= 20000 ) {
141139 return {
142- tokens : < Modes . IToken [ ] > [ {
140+ tokens : < IToken [ ] > [ {
143141 startIndex : offsetDelta ,
144142 type : '' ,
145- bracket : Modes . Bracket . None
143+ bracket : Bracket . None
146144 } ] ,
147145 actualStopOffset : offsetDelta ,
148146 endState : state ,
@@ -155,7 +153,7 @@ class Tokenizer {
155153
156154 // Create the result early and fill in the tokens later
157155 let ret = {
158- tokens : < Modes . IToken [ ] > [ ] ,
156+ tokens : < IToken [ ] > [ ] ,
159157 actualStopOffset : offsetDelta + line . length ,
160158 endState : freshState ,
161159 modeTransitions : [ { startIndex : offsetDelta , mode : freshState . getMode ( ) } ] ,
@@ -170,7 +168,7 @@ class Tokenizer {
170168
171169 if ( t . isOpaqueToken ) {
172170 // Should not do any smartness to detect brackets on this token
173- ret . tokens . push ( new supports . Token ( tokenStartIndex + offsetDelta , t . tokenType ) ) ;
171+ ret . tokens . push ( new Token ( tokenStartIndex + offsetDelta , t . tokenType ) ) ;
174172 continue ;
175173 }
176174
@@ -206,27 +204,27 @@ class Tokenizer {
206204 if ( isBracket ) {
207205 if ( tokenStartIndex < i ) {
208206 // push a token before character `i`
209- ret . tokens . push ( new supports . Token ( tokenStartIndex + offsetDelta , t . tokenType ) ) ;
207+ ret . tokens . push ( new Token ( tokenStartIndex + offsetDelta , t . tokenType ) ) ;
210208 tokenStartIndex = i ;
211209 }
212210
213211 // push character `i` as a token
214- ret . tokens . push ( new supports . Token ( tokenStartIndex + offsetDelta , isBracket + '.' + t . modeToken ) ) ;
212+ ret . tokens . push ( new Token ( tokenStartIndex + offsetDelta , isBracket + '.' + t . modeToken ) ) ;
215213 tokenStartIndex = i + 1 ;
216214 }
217215 }
218216
219217 if ( tokenStartIndex < tokenEndIndex ) {
220218 // push the remaining text as a token
221- ret . tokens . push ( new supports . Token ( tokenStartIndex + offsetDelta , t . tokenType ) ) ;
219+ ret . tokens . push ( new Token ( tokenStartIndex + offsetDelta , t . tokenType ) ) ;
222220 }
223221 }
224222
225223 return ret ;
226224 }
227225}
228226
229- function decodeTextMateToken ( modeId :string , entry : textMate . IToken ) {
227+ function decodeTextMateToken ( modeId :string , entry : ITMToken ) {
230228 let tokenTypeArray : string [ ] = [ ] ;
231229 for ( let level = 1 /* deliberately skip scope 0*/ ; level < entry . scopes . length ; ++ level ) {
232230 tokenTypeArray = tokenTypeArray . concat ( entry . scopes [ level ] . split ( '.' ) ) ;
@@ -289,9 +287,9 @@ var _openSquare = '['.charCodeAt(0);
289287var _closeSquare = ']' . charCodeAt ( 0 ) ;
290288
291289var characterToBracket = collections . createNumberDictionary < number > ( ) ;
292- characterToBracket [ '(' . charCodeAt ( 0 ) ] = Modes . Bracket . Open ;
293- characterToBracket [ ')' . charCodeAt ( 0 ) ] = Modes . Bracket . Close ;
294- characterToBracket [ '{' . charCodeAt ( 0 ) ] = Modes . Bracket . Open ;
295- characterToBracket [ '}' . charCodeAt ( 0 ) ] = Modes . Bracket . Close ;
296- characterToBracket [ '[' . charCodeAt ( 0 ) ] = Modes . Bracket . Open ;
297- characterToBracket [ ']' . charCodeAt ( 0 ) ] = Modes . Bracket . Close ;
290+ characterToBracket [ '(' . charCodeAt ( 0 ) ] = Bracket . Open ;
291+ characterToBracket [ ')' . charCodeAt ( 0 ) ] = Bracket . Close ;
292+ characterToBracket [ '{' . charCodeAt ( 0 ) ] = Bracket . Open ;
293+ characterToBracket [ '}' . charCodeAt ( 0 ) ] = Bracket . Close ;
294+ characterToBracket [ '[' . charCodeAt ( 0 ) ] = Bracket . Open ;
295+ characterToBracket [ ']' . charCodeAt ( 0 ) ] = Bracket . Close ;
0 commit comments