1+ /*---------------------------------------------------------------------------------------------
2+ * Copyright (c) Microsoft Corporation. All rights reserved.
3+ * Licensed under the MIT License. See License.txt in the project root for license information.
4+ *--------------------------------------------------------------------------------------------*/
5+
6+ declare module "vscode-textmate" {
7+ /**
8+ * A single theme setting.
9+ */
10+ export interface IRawThemeSetting {
11+ readonly name ?: string ;
12+ readonly scope ?: string | string [ ] ;
13+ readonly settings : {
14+ readonly fontStyle ?: string ;
15+ readonly foreground ?: string ;
16+ readonly background ?: string ;
17+ } ;
18+ }
19+ /**
20+ * A TextMate theme.
21+ */
22+ export interface IRawTheme {
23+ readonly name ?: string ;
24+ readonly settings : IRawThemeSetting [ ] ;
25+ }
26+ /**
27+ * A registry helper that can locate grammar file paths given scope names.
28+ */
29+ export interface RegistryOptions {
30+ theme ?: IRawTheme ;
31+ getFilePath ( scopeName : string ) : string ;
32+ getInjections ?( scopeName : string ) : string [ ] ;
33+ }
34+ /**
35+ * A map from scope name to a language id. Please do not use language id 0.
36+ */
37+ export interface IEmbeddedLanguagesMap {
38+ [ scopeName : string ] : number ;
39+ }
40+ export const enum StandardTokenType {
41+ Other = 0 ,
42+ Comment = 1 ,
43+ String = 2 ,
44+ RegEx = 4 ,
45+ }
46+ /**
47+ * The registry that will hold all grammars.
48+ */
49+ export class Registry {
50+ private readonly _locator ;
51+ private readonly _syncRegistry ;
52+ constructor ( locator ?: RegistryOptions ) ;
53+ /**
54+ * Change the theme. Once called, no previous `ruleStack` should be used anymore.
55+ */
56+ setTheme ( theme : IRawTheme ) : void ;
57+ /**
58+ * Returns a lookup array for color ids.
59+ */
60+ getColorMap ( ) : string [ ] ;
61+ /**
62+ * Load the grammar for `scopeName` and all referenced included grammars asynchronously.
63+ * Please do not use language id 0.
64+ */
65+ loadGrammarWithEmbeddedLanguages ( initialScopeName : string , initialLanguage : number , embeddedLanguages : IEmbeddedLanguagesMap , callback : ( err : any , grammar : IGrammar ) => void ) : void ;
66+ /**
67+ * Load the grammar for `scopeName` and all referenced included grammars asynchronously.
68+ */
69+ loadGrammar ( initialScopeName : string , callback : ( err : any , grammar : IGrammar ) => void ) : void ;
70+ private _loadGrammar ( initialScopeName , callback ) ;
71+ /**
72+ * Load the grammar at `path` synchronously.
73+ */
74+ loadGrammarFromPathSync ( path : string , initialLanguage ?: number , embeddedLanguages ?: IEmbeddedLanguagesMap ) : IGrammar ;
75+ /**
76+ * Get the grammar for `scopeName`. The grammar must first be created via `loadGrammar` or `loadGrammarFromPathSync`.
77+ */
78+ grammarForScopeName ( scopeName : string , initialLanguage ?: number , embeddedLanguages ?: IEmbeddedLanguagesMap ) : IGrammar ;
79+ }
80+ /**
81+ * A grammar
82+ */
83+ export interface IGrammar {
84+ /**
85+ * Tokenize `lineText` using previous line state `prevState`.
86+ */
87+ tokenizeLine ( lineText : string , prevState : StackElement ) : ITokenizeLineResult ;
88+ /**
89+ * Tokenize `lineText` using previous line state `prevState`.
90+ * The result contains the tokens in binary format, resolved with the following information:
91+ * - language
92+ * - token type (regex, string, comment, other)
93+ * - font style
94+ * - foreground color
95+ * - background color
96+ * e.g. for getting the languageId: `(metadata & MetadataConsts.LANGUAGEID_MASK) >>> MetadataConsts.LANGUAGEID_OFFSET`
97+ */
98+ tokenizeLine2 ( lineText : string , prevState : StackElement ) : ITokenizeLineResult2 ;
99+ }
100+ export interface ITokenizeLineResult {
101+ readonly tokens : IToken [ ] ;
102+ /**
103+ * The `prevState` to be passed on to the next line tokenization.
104+ */
105+ readonly ruleStack : StackElement ;
106+ }
107+ /**
108+ * Helpers to manage the "collapsed" metadata of an entire StackElement stack.
109+ * The following assumptions have been made:
110+ * - languageId < 256 => needs 8 bits
111+ * - unique color count < 512 => needs 9 bits
112+ *
113+ * The binary format is:
114+ * - -------------------------------------------
115+ * 3322 2222 2222 1111 1111 1100 0000 0000
116+ * 1098 7654 3210 9876 5432 1098 7654 3210
117+ * - -------------------------------------------
118+ * xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx
119+ * bbbb bbbb bfff ffff ffFF FTTT LLLL LLLL
120+ * - -------------------------------------------
121+ * - L = LanguageId (8 bits)
122+ * - T = StandardTokenType (3 bits)
123+ * - F = FontStyle (3 bits)
124+ * - f = foreground color (9 bits)
125+ * - b = background color (9 bits)
126+ */
127+ export const enum MetadataConsts {
128+ LANGUAGEID_MASK = 255 ,
129+ TOKEN_TYPE_MASK = 1792 ,
130+ FONT_STYLE_MASK = 14336 ,
131+ FOREGROUND_MASK = 8372224 ,
132+ BACKGROUND_MASK = 4286578688 ,
133+ LANGUAGEID_OFFSET = 0 ,
134+ TOKEN_TYPE_OFFSET = 8 ,
135+ FONT_STYLE_OFFSET = 11 ,
136+ FOREGROUND_OFFSET = 14 ,
137+ BACKGROUND_OFFSET = 23 ,
138+ }
139+ export interface ITokenizeLineResult2 {
140+ /**
141+ * The tokens in binary format. Each token occupies two array indices. For token i:
142+ * - at offset 2*i => startIndex
143+ * - at offset 2*i + 1 => metadata
144+ *
145+ */
146+ readonly tokens : Uint32Array ;
147+ /**
148+ * The `prevState` to be passed on to the next line tokenization.
149+ */
150+ readonly ruleStack : StackElement ;
151+ }
152+ export interface IToken {
153+ startIndex : number ;
154+ readonly endIndex : number ;
155+ readonly scopes : string [ ] ;
156+ }
157+ /**
158+ * **IMPORTANT** - Immutable!
159+ */
160+ export interface StackElement {
161+ _stackElementBrand : void ;
162+ readonly depth : number ;
163+ equals ( other : StackElement ) : boolean ;
164+ }
165+
166+ }
0 commit comments