2 /* --------------------------------------------------------------------------------------------
3 * Copyright (c) Microsoft Corporation. All rights reserved.
4 * Licensed under the MIT License. See License.txt in the project root for license information.
5 * ------------------------------------------------------------------------------------------ */
6 Object.defineProperty(exports, "__esModule", { value: true });
7 exports.SemanticTokensBuilder = exports.SemanticTokensFeature = void 0;
8 const vscode_languageserver_protocol_1 = require("vscode-languageserver-protocol");
9 const SemanticTokensFeature = (Base) => {
10 return class extends Base {
11 get semanticTokens() {
14 const type = vscode_languageserver_protocol_1.SemanticTokensRequest.type;
15 this.connection.onRequest(type, (params, cancel) => {
16 return handler(params, cancel, this.attachWorkDoneProgress(params), this.attachPartialResultProgress(type, params));
19 onDelta: (handler) => {
20 const type = vscode_languageserver_protocol_1.SemanticTokensDeltaRequest.type;
21 this.connection.onRequest(type, (params, cancel) => {
22 return handler(params, cancel, this.attachWorkDoneProgress(params), this.attachPartialResultProgress(type, params));
25 onRange: (handler) => {
26 const type = vscode_languageserver_protocol_1.SemanticTokensRangeRequest.type;
27 this.connection.onRequest(type, (params, cancel) => {
28 return handler(params, cancel, this.attachWorkDoneProgress(params), this.attachPartialResultProgress(type, params));
35 exports.SemanticTokensFeature = SemanticTokensFeature;
36 class SemanticTokensBuilder {
38 this._prevData = undefined;
42 this._id = Date.now();
48 push(line, char, length, tokenType, tokenModifiers) {
51 if (this._dataLen > 0) {
52 pushLine -= this._prevLine;
54 pushChar -= this._prevChar;
57 this._data[this._dataLen++] = pushLine;
58 this._data[this._dataLen++] = pushChar;
59 this._data[this._dataLen++] = length;
60 this._data[this._dataLen++] = tokenType;
61 this._data[this._dataLen++] = tokenModifiers;
62 this._prevLine = line;
63 this._prevChar = char;
66 return this._id.toString();
70 this._prevData = this._data;
75 this._prevData = undefined;
82 return this._prevData !== undefined;
85 if (this._prevData !== undefined) {
86 const prevDataLength = this._prevData.length;
87 const dataLength = this._data.length;
89 while (startIndex < dataLength && startIndex < prevDataLength && this._prevData[startIndex] === this._data[startIndex]) {
92 if (startIndex < dataLength && startIndex < prevDataLength) {
95 while (endIndex < dataLength && endIndex < prevDataLength && this._prevData[prevDataLength - 1 - endIndex] === this._data[dataLength - 1 - endIndex]) {
98 const newData = this._data.slice(startIndex, dataLength - endIndex);
102 { start: startIndex, deleteCount: prevDataLength - endIndex - startIndex, data: newData }
107 else if (startIndex < dataLength) {
108 return { resultId: this.id, edits: [
109 { start: startIndex, deleteCount: 0, data: this._data.slice(startIndex) }
112 else if (startIndex < prevDataLength) {
113 return { resultId: this.id, edits: [
114 { start: startIndex, deleteCount: prevDataLength - startIndex }
118 return { resultId: this.id, edits: [] };
126 exports.SemanticTokensBuilder = SemanticTokensBuilder;
127 //# sourceMappingURL=semanticTokens.js.map