本文整理汇总了TypeScript中vs/editor/common/modes.TokenizationRegistry类的典型用法代码示例。如果您正苦于以下问题:TypeScript TokenizationRegistry类的具体用法?TypeScript TokenizationRegistry怎么用?TypeScript TokenizationRegistry使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TokenizationRegistry类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: test
test('Microsoft/monaco-editor#122: Unhandled Exception: TypeError: Unable to get property \'replace\' of undefined or null reference', () => {
function assertViewLineTokens(model: Model, lineNumber: number, forceTokenization: boolean, expected: ViewLineToken[]): void {
let actual = model.getLineTokens(lineNumber, !forceTokenization).inflate();
assert.deepEqual(actual, expected);
}
let _tokenId = 10;
const LANG_ID1 = 'indicisiveMode1';
const LANG_ID2 = 'indicisiveMode2';
const languageIdentifier1 = new LanguageIdentifier(LANG_ID1, 3);
const languageIdentifier2 = new LanguageIdentifier(LANG_ID2, 4);
const tokenizationSupport: ITokenizationSupport = {
getInitialState: () => NULL_STATE,
tokenize: undefined,
tokenize2: (line, state) => {
let myId = ++_tokenId;
let tokens = new Uint32Array(2);
tokens[0] = 0;
tokens[1] = (
myId << MetadataConsts.FOREGROUND_OFFSET
) >>> 0;
return new TokenizationResult2(tokens, state);
}
};
let registration1 = TokenizationRegistry.register(LANG_ID1, tokenizationSupport);
let registration2 = TokenizationRegistry.register(LANG_ID2, tokenizationSupport);
let model = Model.createFromString('A model with\ntwo lines');
assertViewLineTokens(model, 1, true, [new ViewLineToken(12, 'mtk1')]);
assertViewLineTokens(model, 2, true, [new ViewLineToken(9, 'mtk1')]);
model.setMode(languageIdentifier1);
assertViewLineTokens(model, 1, true, [new ViewLineToken(12, 'mtk11')]);
assertViewLineTokens(model, 2, true, [new ViewLineToken(9, 'mtk12')]);
model.setMode(languageIdentifier2);
assertViewLineTokens(model, 1, false, [new ViewLineToken(12, 'mtk1')]);
assertViewLineTokens(model, 2, false, [new ViewLineToken(9, 'mtk1')]);
model.dispose();
registration1.dispose();
registration2.dispose();
});
示例2: timeout
return TPromise.any([this._tokenizationSupportChangedPromise(language), timeout(500)]).then(_ => {
let tokenizationSupport = TokenizationRegistry.get(language);
if (tokenizationSupport) {
return _colorize(lines, options.tabSize, tokenizationSupport);
}
return _fakeColorize(lines, options.tabSize);
});
示例3: constructor
constructor() {
super(OUTER_LANGUAGE_ID);
this._register(LanguageConfigurationRegistry.register(this.getLanguageIdentifier(), {}));
this._register(TokenizationRegistry.register(this.getLanguageIdentifier().language, {
getInitialState: (): IState => NULL_STATE,
tokenize: undefined,
tokenize2: (line: string, state: IState): TokenizationResult2 => {
const tokensArr: number[] = [];
let prevLanguageId: LanguageIdentifier | undefined = undefined;
for (let i = 0; i < line.length; i++) {
const languageId = (line.charAt(i) === 'x' ? INNER_LANGUAGE_ID : OUTER_LANGUAGE_ID);
if (prevLanguageId !== languageId) {
tokensArr.push(i);
tokensArr.push((languageId.id << MetadataConsts.LANGUAGEID_OFFSET));
}
prevLanguageId = languageId;
}
const tokens = new Uint32Array(tokensArr.length);
for (let i = 0; i < tokens.length; i++) {
tokens[i] = tokensArr[i];
}
return new TokenizationResult2(tokens, state);
}
}));
}
示例4: _colorize
return new Promise<string>((resolve, reject) => {
let listener: IDisposable | null = null;
let timeout: TimeoutTimer | null = null;
const execute = () => {
if (listener) {
listener.dispose();
listener = null;
}
if (timeout) {
timeout.dispose();
timeout = null;
}
const tokenizationSupport = TokenizationRegistry.get(language!);
if (tokenizationSupport) {
_colorize(lines, tabSize, tokenizationSupport).then(resolve, reject);
return;
}
resolve(_fakeColorize(lines, tabSize));
};
// wait 500ms for mode to load, then give up
timeout = new TimeoutTimer();
timeout.cancelAndSet(execute, 500);
listener = TokenizationRegistry.onDidChange((e) => {
if (e.changedLanguages.indexOf(language!) >= 0) {
execute();
}
});
});
示例5: constructor
constructor(tokenType:string) {
super();
TokenizationRegistry.register(this.getId(), new TokenizationSupport(null, this.getId(), {
getInitialState: () => new StateForMockTokenizingMode(this.getId(), tokenType)
}, false));
}
示例6: setTheme
public setTheme(themeName: string): string {
let theme: StandaloneTheme;
if (this._knownThemes.has(themeName)) {
theme = this._knownThemes.get(themeName);
} else {
theme = this._knownThemes.get(VS_THEME_NAME);
}
this._theme = theme;
let cssRules: string[] = [];
let hasRule: { [rule: string]: boolean; } = {};
let ruleCollector: ICssStyleCollector = {
addRule: (rule: string) => {
if (!hasRule[rule]) {
cssRules.push(rule);
hasRule[rule] = true;
}
}
};
themingRegistry.getThemingParticipants().forEach(p => p(theme, ruleCollector));
let tokenTheme = theme.tokenTheme;
let colorMap = tokenTheme.getColorMap();
ruleCollector.addRule(generateTokensCSSForColorMap(colorMap));
this._styleElement.innerHTML = cssRules.join('\n');
TokenizationRegistry.setColorMap(colorMap);
this._onThemeChange.fire(theme);
return theme.id;
}
示例7: colorize
public static colorize(modeService: IModeService, text: string, mimeType: string, options: IColorizerOptions): TPromise<string> {
if (strings.startsWithUTF8BOM(text)) {
text = text.substr(1);
}
let lines = text.split(/\r\n|\r|\n/);
let language = modeService.getModeId(mimeType);
options = options || {};
if (typeof options.tabSize === 'undefined') {
options.tabSize = 4;
}
// Send out the event to create the mode
modeService.getOrCreateMode(language);
let tokenizationSupport = TokenizationRegistry.get(language);
if (tokenizationSupport) {
return TPromise.as(_colorize(lines, options.tabSize, tokenizationSupport));
}
// wait 500ms for mode to load, then give up
return TPromise.any([this._tokenizationSupportChangedPromise(language), timeout(500)]).then(_ => {
let tokenizationSupport = TokenizationRegistry.get(language);
if (tokenizationSupport) {
return _colorize(lines, options.tabSize, tokenizationSupport);
}
return _fakeColorize(lines, options.tabSize);
});
}
示例8: constructor
constructor(config: editorCommon.IConfiguration, theme: ITheme) {
this.lineHeight = config.editor.lineHeight;
this.pixelRatio = config.editor.pixelRatio;
this.overviewRulerLanes = config.editor.viewInfo.overviewRulerLanes;
this.renderBorder = config.editor.viewInfo.overviewRulerBorder;
const borderColor = theme.getColor(editorOverviewRulerBorder);
this.borderColor = borderColor ? borderColor.toString() : null;
this.hideCursor = config.editor.viewInfo.hideCursorInOverviewRuler;
const cursorColor = theme.getColor(editorCursorForeground);
this.cursorColor = cursorColor ? cursorColor.transparent(0.7).toString() : null;
this.themeType = theme.type;
const minimapEnabled = config.editor.viewInfo.minimap.enabled;
const backgroundColor = (minimapEnabled ? TokenizationRegistry.getDefaultBackground() : null);
this.backgroundColor = (backgroundColor ? Color.Format.CSS.formatHex(backgroundColor) : null);
const position = config.editor.layoutInfo.overviewRuler;
this.top = position.top;
this.right = position.right;
this.domWidth = position.width;
this.domHeight = position.height;
this.canvasWidth = (this.domWidth * this.pixelRatio) | 0;
this.canvasHeight = (this.domHeight * this.pixelRatio) | 0;
const [x, w] = this._initLanes(1, this.canvasWidth, this.overviewRulerLanes);
this.x = x;
this.w = w;
}
示例9: _actualColorize
function _actualColorize(lines: string[], tabSize: number, tokenizationSupport: ITokenizationSupport): string {
let html: string[] = [];
let state = tokenizationSupport.getInitialState();
let colorMap = TokenizationRegistry.getColorMap();
for (let i = 0, length = lines.length; i < length; i++) {
let line = lines[i];
let tokenizeResult = tokenizationSupport.tokenize2(line, state, 0);
let lineTokens = new LineTokens(colorMap, tokenizeResult.tokens, line);
let renderResult = renderLine(new RenderLineInput(
line,
tabSize,
0,
-1,
'none',
false,
new LineParts(lineTokens.inflate(), line.length + 1)
));
html = html.concat(renderResult.output);
html.push('<br/>');
state = tokenizeResult.endState;
}
return html.join('');
}
示例10:
return new TPromise<void>((c, e, p) => {
listener = TokenizationRegistry.onDidChange((e) => {
if (e.languageId === languageId) {
stopListening();
c(void 0);
}
});
}, stopListening);