massive update, probably broken
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-json / node_modules / vscode-languageserver / lib / common / semanticTokens.js
1 "use strict";
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() {
12             return {
13                 on: (handler) => {
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));
17                     });
18                 },
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));
23                     });
24                 },
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));
29                     });
30                 }
31             };
32         }
33     };
34 };
35 exports.SemanticTokensFeature = SemanticTokensFeature;
36 class SemanticTokensBuilder {
37     constructor() {
38         this._prevData = undefined;
39         this.initialize();
40     }
41     initialize() {
42         this._id = Date.now();
43         this._prevLine = 0;
44         this._prevChar = 0;
45         this._data = [];
46         this._dataLen = 0;
47     }
48     push(line, char, length, tokenType, tokenModifiers) {
49         let pushLine = line;
50         let pushChar = char;
51         if (this._dataLen > 0) {
52             pushLine -= this._prevLine;
53             if (pushLine === 0) {
54                 pushChar -= this._prevChar;
55             }
56         }
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;
64     }
65     get id() {
66         return this._id.toString();
67     }
68     previousResult(id) {
69         if (this.id === id) {
70             this._prevData = this._data;
71         }
72         this.initialize();
73     }
74     build() {
75         this._prevData = undefined;
76         return {
77             resultId: this.id,
78             data: this._data
79         };
80     }
81     canBuildEdits() {
82         return this._prevData !== undefined;
83     }
84     buildEdits() {
85         if (this._prevData !== undefined) {
86             const prevDataLength = this._prevData.length;
87             const dataLength = this._data.length;
88             let startIndex = 0;
89             while (startIndex < dataLength && startIndex < prevDataLength && this._prevData[startIndex] === this._data[startIndex]) {
90                 startIndex++;
91             }
92             if (startIndex < dataLength && startIndex < prevDataLength) {
93                 // Find end index
94                 let endIndex = 0;
95                 while (endIndex < dataLength && endIndex < prevDataLength && this._prevData[prevDataLength - 1 - endIndex] === this._data[dataLength - 1 - endIndex]) {
96                     endIndex++;
97                 }
98                 const newData = this._data.slice(startIndex, dataLength - endIndex);
99                 const result = {
100                     resultId: this.id,
101                     edits: [
102                         { start: startIndex, deleteCount: prevDataLength - endIndex - startIndex, data: newData }
103                     ]
104                 };
105                 return result;
106             }
107             else if (startIndex < dataLength) {
108                 return { resultId: this.id, edits: [
109                         { start: startIndex, deleteCount: 0, data: this._data.slice(startIndex) }
110                     ] };
111             }
112             else if (startIndex < prevDataLength) {
113                 return { resultId: this.id, edits: [
114                         { start: startIndex, deleteCount: prevDataLength - startIndex }
115                     ] };
116             }
117             else {
118                 return { resultId: this.id, edits: [] };
119             }
120         }
121         else {
122             return this.build();
123         }
124     }
125 }
126 exports.SemanticTokensBuilder = SemanticTokensBuilder;
127 //# sourceMappingURL=semanticTokens.js.map