Skip to content

Commit 13affa0

Browse files
committed
Add Force Tokenization command
1 parent c4b89c1 commit 13affa0

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
import * as nls from 'vs/nls';
7+
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
8+
import { EditorAction, ServicesAccessor, registerEditorAction } from 'vs/editor/browser/editorExtensions';
9+
import { StopWatch } from 'vs/base/common/stopwatch';
10+
11+
class ForceRetokenizeAction extends EditorAction {
12+
constructor() {
13+
super({
14+
id: 'editor.action.forceRetokenize',
15+
label: nls.localize('forceRetokenize', "Developer: Force Retokenize"),
16+
alias: 'Developer: Force Retokenize',
17+
precondition: null
18+
});
19+
}
20+
21+
public run(accessor: ServicesAccessor, editor: ICodeEditor): void {
22+
if (!editor.hasModel()) {
23+
return;
24+
}
25+
const model = editor.getModel();
26+
model.flushTokens();
27+
const sw = new StopWatch(true);
28+
model.forceTokenization(model.getLineCount());
29+
sw.stop();
30+
console.log(`tokenization took ${sw.elapsed()}`);
31+
}
32+
}
33+
34+
registerEditorAction(ForceRetokenizeAction);

src/vs/editor/editor.all.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import 'vs/editor/contrib/rename/rename';
3636
import 'vs/editor/contrib/smartSelect/smartSelect';
3737
import 'vs/editor/contrib/snippet/snippetController2';
3838
import 'vs/editor/contrib/suggest/suggestController';
39+
import 'vs/editor/contrib/tokenization/tokenization';
3940
import 'vs/editor/contrib/toggleTabFocusMode/toggleTabFocusMode';
4041
import 'vs/editor/contrib/wordHighlighter/wordHighlighter';
4142
import 'vs/editor/contrib/wordOperations/wordOperations';

0 commit comments

Comments
 (0)