mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-25 02:58:56 +01:00
SemanticTokens - implement feedback received in API call:
- extract a separate DocumentRangeSemanticTokensProvider that deals with a document range - extract a separate provideDocumentSemanticTokensEdits that deals with updating via SemanticTokensEdits a previous result
This commit is contained in:
@@ -11,7 +11,7 @@ const localize = nls.loadMessageBundle();
|
||||
import {
|
||||
languages, ExtensionContext, IndentAction, Position, TextDocument, Range, CompletionItem, CompletionItemKind, SnippetString, workspace,
|
||||
Disposable, FormattingOptions, CancellationToken, ProviderResult, TextEdit, CompletionContext, CompletionList, SemanticTokensLegend,
|
||||
SemanticTokensProvider, SemanticTokens
|
||||
DocumentSemanticTokensProvider, DocumentRangeSemanticTokensProvider, SemanticTokens
|
||||
} from 'vscode';
|
||||
import {
|
||||
LanguageClient, LanguageClientOptions, ServerOptions, TransportKind, RequestType, TextDocumentPositionParams, DocumentRangeFormattingParams,
|
||||
@@ -153,18 +153,26 @@ export function activate(context: ExtensionContext) {
|
||||
|
||||
client.sendRequest(SemanticTokenLegendRequest.type).then(legend => {
|
||||
if (legend) {
|
||||
const provider: SemanticTokensProvider = {
|
||||
provideSemanticTokens(doc, opts) {
|
||||
const provider: DocumentSemanticTokensProvider & DocumentRangeSemanticTokensProvider = {
|
||||
provideDocumentSemanticTokens(doc) {
|
||||
const params: SemanticTokenParams = {
|
||||
textDocument: client.code2ProtocolConverter.asTextDocumentIdentifier(doc),
|
||||
ranges: opts.ranges?.map(r => client.code2ProtocolConverter.asRange(r))
|
||||
};
|
||||
return client.sendRequest(SemanticTokenRequest.type, params).then(data => {
|
||||
return data && new SemanticTokens(new Uint32Array(data));
|
||||
});
|
||||
},
|
||||
provideDocumentRangeSemanticTokens(doc, range) {
|
||||
const params: SemanticTokenParams = {
|
||||
textDocument: client.code2ProtocolConverter.asTextDocumentIdentifier(doc),
|
||||
ranges: [client.code2ProtocolConverter.asRange(range)]
|
||||
};
|
||||
return client.sendRequest(SemanticTokenRequest.type, params).then(data => {
|
||||
return data && new SemanticTokens(new Uint32Array(data));
|
||||
});
|
||||
}
|
||||
};
|
||||
toDispose.push(languages.registerSemanticTokensProvider(documentSelector, provider, new SemanticTokensLegend(legend.types, legend.modifiers)));
|
||||
toDispose.push(languages.registerDocumentSemanticTokensProvider(documentSelector, provider, new SemanticTokensLegend(legend.types, legend.modifiers)));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user