|
5 | 5 | 'use strict'; |
6 | 6 |
|
7 | 7 | import * as strings from 'vs/base/common/strings'; |
8 | | -import { IState, ITokenizationSupport, TokenizationRegistry, LanguageId } from 'vs/editor/common/modes'; |
9 | | -import { NULL_STATE, nullTokenize2 } from 'vs/editor/common/modes/nullMode'; |
| 8 | +import { ITokenizationSupport, IState, LanguageId } from 'vs/editor/common/modes'; |
10 | 9 | import { LineTokens, IViewLineTokens } from 'vs/editor/common/core/lineTokens'; |
11 | 10 | import { CharCode } from 'vs/base/common/charCode'; |
| 11 | +import { NULL_STATE, nullTokenize2 } from 'vs/editor/common/modes/nullMode'; |
| 12 | + |
| 13 | +const fallback = { |
| 14 | + getInitialState: () => NULL_STATE, |
| 15 | + tokenize: undefined, |
| 16 | + tokenize2: (buffer: string, state: IState, deltaOffset: number) => nullTokenize2(LanguageId.Null, buffer, state, deltaOffset) |
| 17 | +}; |
12 | 18 |
|
13 | | -export function tokenizeToString(text: string, languageId: string): string { |
14 | | - return _tokenizeToString(text, _getSafeTokenizationSupport(languageId)); |
| 19 | +export function tokenizeToString(text: string, tokenizationSupport: ITokenizationSupport = fallback): string { |
| 20 | + return _tokenizeToString(text, tokenizationSupport); |
15 | 21 | } |
16 | 22 |
|
17 | 23 | export function tokenizeLineToHTML(text: string, viewLineTokens: IViewLineTokens, colorMap: string[], startOffset: number, endOffset: number, tabSize: number): string { |
@@ -83,18 +89,6 @@ export function tokenizeLineToHTML(text: string, viewLineTokens: IViewLineTokens |
83 | 89 | return result; |
84 | 90 | } |
85 | 91 |
|
86 | | -function _getSafeTokenizationSupport(languageId: string): ITokenizationSupport { |
87 | | - let tokenizationSupport = TokenizationRegistry.get(languageId); |
88 | | - if (tokenizationSupport) { |
89 | | - return tokenizationSupport; |
90 | | - } |
91 | | - return { |
92 | | - getInitialState: () => NULL_STATE, |
93 | | - tokenize: undefined, |
94 | | - tokenize2: (buffer: string, state: IState, deltaOffset: number) => nullTokenize2(LanguageId.Null, buffer, state, deltaOffset) |
95 | | - }; |
96 | | -} |
97 | | - |
98 | 92 | function _tokenizeToString(text: string, tokenizationSupport: ITokenizationSupport): string { |
99 | 93 | let result = `<div class="monaco-tokenized-source">`; |
100 | 94 | let lines = text.split(/\r\n|\r|\n/); |
|
0 commit comments