未验证 提交 0ee441ed 编写于 作者: A Alex Dima

Scaffold viewport semantic tokens

上级 2f7b6c58
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { RunOnceScheduler } from 'vs/base/common/async';
import { Disposable } from 'vs/base/common/lifecycle';
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
import { registerEditorContribution } from 'vs/editor/browser/editorExtensions';
import { IEditorContribution } from 'vs/editor/common/editorCommon';
import { ITextModel } from 'vs/editor/common/model';
import { DocumentRangeSemanticTokensProviderRegistry, DocumentRangeSemanticTokensProvider } from 'vs/editor/common/modes';
class ViewportSemanticTokensContribution extends Disposable implements IEditorContribution {
public static readonly ID = 'editor.contrib.viewportSemanticTokens';
public static get(editor: ICodeEditor): ViewportSemanticTokensContribution {
return editor.getContribution<ViewportSemanticTokensContribution>(ViewportSemanticTokensContribution.ID);
}
private readonly _editor: ICodeEditor;
private readonly _tokenizeViewport: RunOnceScheduler;
constructor(editor: ICodeEditor) {
super();
this._editor = editor;
this._tokenizeViewport = new RunOnceScheduler(() => this._tokenizeViewportNow(), 100);
this._register(this._editor.onDidScrollChange(() => {
this._tokenizeViewport.schedule();
}));
this._register(this._editor.onDidChangeModel(() => {
this._tokenizeViewport.schedule();
}));
this._register(DocumentRangeSemanticTokensProviderRegistry.onDidChange(() => {
this._tokenizeViewport.schedule();
}));
}
private static _getSemanticColoringProvider(model: ITextModel): DocumentRangeSemanticTokensProvider | null {
const result = DocumentRangeSemanticTokensProviderRegistry.ordered(model);
return (result.length > 0 ? result[0] : null);
}
private _tokenizeViewportNow(): void {
if (!this._editor.hasModel()) {
return;
}
const model = this._editor.getModel();
const provider = ViewportSemanticTokensContribution._getSemanticColoringProvider(model);
if (!provider) {
return;
}
// const visibleRanges = this._editor.getVisibleRanges();
// console.log(`_tokenizeViewportNow ---> ${visibleRanges.map(r => r.toString()).join(', ')}`);
}
}
registerEditorContribution(ViewportSemanticTokensContribution.ID, ViewportSemanticTokensContribution);
......@@ -39,6 +39,7 @@ import 'vs/editor/contrib/snippet/snippetController2';
import 'vs/editor/contrib/suggest/suggestController';
import 'vs/editor/contrib/tokenization/tokenization';
import 'vs/editor/contrib/toggleTabFocusMode/toggleTabFocusMode';
import 'vs/editor/contrib/viewportSemanticTokens/viewportSemanticTokens';
import 'vs/editor/contrib/wordHighlighter/wordHighlighter';
import 'vs/editor/contrib/wordOperations/wordOperations';
import 'vs/editor/contrib/wordPartOperations/wordPartOperations';
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册