當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript modes.TokenizationRegistry類代碼示例

本文整理匯總了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();
	});
開發者ID:diarmaidm,項目名稱:vscode,代碼行數:48,代碼來源:textModelWithTokens.test.ts

示例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);
		});
開發者ID:developers23,項目名稱:vscode,代碼行數:7,代碼來源:colorizer.ts

示例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);
				}
			}));
		}
開發者ID:KTXSoftware,項目名稱:KodeStudio,代碼行數:27,代碼來源:model.test.ts

示例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();
				}
			});
		});
開發者ID:PKRoma,項目名稱:vscode,代碼行數:30,代碼來源:colorizer.ts

示例5: constructor

	constructor(tokenType:string) {
		super();

		TokenizationRegistry.register(this.getId(), new TokenizationSupport(null, this.getId(), {
			getInitialState: () => new StateForMockTokenizingMode(this.getId(), tokenType)
		}, false));
	}
開發者ID:aminroosta,項目名稱:vscode,代碼行數:7,代碼來源:mockMode.ts

示例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;
	}
開發者ID:AllureFer,項目名稱:vscode,代碼行數:32,代碼來源:standaloneThemeServiceImpl.ts

示例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);
		});
	}
開發者ID:developers23,項目名稱:vscode,代碼行數:29,代碼來源:colorizer.ts

示例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;
	}
開發者ID:gokulakrishna9,項目名稱:vscode,代碼行數:31,代碼來源:decorationsOverviewRuler.ts

示例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('');
}
開發者ID:fs814,項目名稱:vscode,代碼行數:27,代碼來源:colorizer.ts

示例10:

		return new TPromise<void>((c, e, p) => {
			listener = TokenizationRegistry.onDidChange((e) => {
				if (e.languageId === languageId) {
					stopListening();
					c(void 0);
				}
			});
		}, stopListening);
開發者ID:StateFarmIns,項目名稱:vscode,代碼行數:8,代碼來源:colorizer.ts


注:本文中的vs/editor/common/modes.TokenizationRegistry類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。