@codingame/monaco-vscode-treesitter-service-override 15.0.3 → 16.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (22) hide show
  1. package/index.js +1 -1
  2. package/package.json +9 -6
  3. package/vscode/src/vs/editor/common/languages/highlights/typescript.scm +488 -0
  4. package/vscode/src/vs/editor/common/model/tokenStore.d.ts +0 -1
  5. package/vscode/src/vs/editor/common/model/tokenStore.js +14 -8
  6. package/vscode/src/vs/editor/common/model/treeSitterTokenStoreService.d.ts +3 -0
  7. package/vscode/src/vs/editor/common/model/treeSitterTokenStoreService.js +33 -27
  8. package/vscode/src/vs/editor/common/services/treeSitter/cursorUtils.d.ts +6 -0
  9. package/vscode/src/vs/editor/common/services/treeSitter/cursorUtils.js +76 -0
  10. package/vscode/src/vs/editor/common/services/treeSitter/textModelTreeSitter.d.ts +88 -0
  11. package/vscode/src/vs/editor/common/services/treeSitter/textModelTreeSitter.js +675 -0
  12. package/vscode/src/vs/editor/common/services/treeSitter/treeSitterLanguages.d.ts +30 -0
  13. package/vscode/src/vs/editor/common/services/treeSitter/treeSitterLanguages.js +102 -0
  14. package/vscode/src/vs/editor/common/services/treeSitter/treeSitterParserService.d.ts +8 -80
  15. package/vscode/src/vs/editor/common/services/treeSitter/treeSitterParserService.js +20 -522
  16. package/vscode/src/vs/editor/common/services/treeSitterParserService.d.ts +16 -3
  17. package/vscode/src/vs/editor/common/services/treeSitterParserService.js +1 -1
  18. package/vscode/src/vs/workbench/services/treeSitter/browser/treeSitterCodeEditors.d.ts +7 -2
  19. package/vscode/src/vs/workbench/services/treeSitter/browser/treeSitterCodeEditors.js +43 -22
  20. package/vscode/src/vs/workbench/services/treeSitter/browser/treeSitterTokenizationFeature.d.ts +14 -14
  21. package/vscode/src/vs/workbench/services/treeSitter/browser/treeSitterTokenizationFeature.js +256 -169
  22. package/assets/typescript.scm +0 -388
package/index.js CHANGED
@@ -13,7 +13,7 @@ import './vscode/src/vs/workbench/services/treeSitter/browser/treeSitterTokeniza
13
13
  registerAssets({
14
14
  'vs/../../node_modules/@vscode/tree-sitter-wasm/wasm/tree-sitter.wasm': new URL('@vscode/tree-sitter-wasm/wasm/tree-sitter.wasm', import.meta.url).href,
15
15
  'vs/../../node_modules/@vscode/tree-sitter-wasm/wasm/tree-sitter-typescript.wasm': new URL('@vscode/tree-sitter-wasm/wasm/tree-sitter-typescript.wasm', import.meta.url).href,
16
- 'vs/editor/common/languages/highlights/typescript.scm': new URL('./assets/typescript.scm', import.meta.url).href
16
+ 'vs/editor/common/languages/highlights/typescript.scm': new URL('./vscode/src/vs/editor/common/languages/highlights/typescript.scm', import.meta.url).href
17
17
  });
18
18
  function getServiceOverride() {
19
19
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codingame/monaco-vscode-treesitter-service-override",
3
- "version": "15.0.3",
3
+ "version": "16.0.0",
4
4
  "private": false,
5
5
  "description": "VSCode public API plugged on the monaco editor - treesitter service-override",
6
6
  "keywords": [],
@@ -15,11 +15,11 @@
15
15
  },
16
16
  "type": "module",
17
17
  "dependencies": {
18
- "@codingame/monaco-vscode-168b98e5-dc20-5807-b1f9-798f1f92b37f-common": "15.0.3",
19
- "@codingame/monaco-vscode-7ba0af96-90c2-5e11-ad7f-befdbbf246c8-common": "15.0.3",
20
- "@codingame/monaco-vscode-9d0168a3-519b-57f3-9bcc-89efc41f951a-common": "15.0.3",
21
- "@codingame/monaco-vscode-api": "15.0.3",
22
- "@vscode/tree-sitter-wasm": "0.1.3"
18
+ "@codingame/monaco-vscode-7ba0af96-90c2-5e11-ad7f-befdbbf246c8-common": "16.0.0",
19
+ "@codingame/monaco-vscode-9d0168a3-519b-57f3-9bcc-89efc41f951a-common": "16.0.0",
20
+ "@codingame/monaco-vscode-ae8a8ca1-f243-508b-9c37-c88ebbd295fa-common": "16.0.0",
21
+ "@codingame/monaco-vscode-api": "16.0.0",
22
+ "@vscode/tree-sitter-wasm": "0.1.4"
23
23
  },
24
24
  "main": "index.js",
25
25
  "module": "index.js",
@@ -28,6 +28,9 @@
28
28
  ".": {
29
29
  "default": "./index.js"
30
30
  },
31
+ "./vscode/*.css": {
32
+ "default": "./vscode/src/*.css"
33
+ },
31
34
  "./vscode/*": {
32
35
  "types": "./vscode/src/*.d.ts",
33
36
  "default": "./vscode/src/*.js"
@@ -0,0 +1,488 @@
1
+ ; Order matters! Place lower precedence first.
2
+
3
+ ; Variables
4
+
5
+ (identifier) @variable.ts
6
+
7
+ (_
8
+ object: (identifier) @variable.other.object.ts)
9
+
10
+ ; Literals
11
+
12
+ (this) @variable.language.this.ts
13
+ (super) @variable.language.super.ts
14
+
15
+ (comment) @comment.ts
16
+
17
+ ; TODO: This doesn't seem to be working
18
+ (escape_sequence) @constant.character.escape.ts
19
+
20
+ ((string) @string.quoted.single.ts
21
+ (#match? @string.quoted.single.ts "^'.*'$"))
22
+
23
+ ((string) @string.quoted.double.ts
24
+ (#match? @string.quoted.double.ts "^\".*\"$"))
25
+
26
+ ([
27
+ (template_string)
28
+ (template_literal_type)
29
+ ] @string.template.ts)
30
+
31
+ (string .
32
+ ([
33
+ "\""
34
+ "'"
35
+ ]) @punctuation.definition.string.begin.ts)
36
+
37
+ (string
38
+ ([
39
+ "\""
40
+ "'"
41
+ ]) @punctuation.definition.string.end.ts .)
42
+
43
+ (template_string . ("`") @punctuation.definition.string.template.begin.ts)
44
+
45
+ (template_string ("`") @punctuation.definition.string.template.end.ts .)
46
+
47
+ ; NOTE: the typescript grammar doesn't break regex into nice parts so as to capture parts of it separately
48
+ (regex) @string.regexp.ts
49
+ (number) @constant.numeric.ts
50
+
51
+ ; Properties
52
+
53
+ (member_expression
54
+ object: (this)
55
+ property: (property_identifier) @variable.ts)
56
+
57
+ (member_expression
58
+ property: (property_identifier) @variable.other.constant.ts
59
+ (#match? @variable.other.constant.ts "^[A-Z][A-Z_]+$"))
60
+
61
+ [
62
+ (property_identifier)
63
+ (shorthand_property_identifier)
64
+ (shorthand_property_identifier_pattern)] @variable.ts
65
+
66
+ ; Function and method definitions
67
+
68
+ (function_expression
69
+ name: (identifier) @entity.name.function.ts)
70
+ (function_signature
71
+ name: (identifier) @entity.name.function.ts)
72
+ (function_declaration
73
+ name: (identifier) @entity.name.function.ts)
74
+ (method_definition
75
+ name: (property_identifier) @meta.definition.method.ts @entity.name.function.ts
76
+ (#not-eq? @entity.name.function.ts "constructor"))
77
+ (method_definition
78
+ name: (property_identifier) @meta.definition.method.ts @storage.type.ts
79
+ (#eq? @storage.type.ts "constructor"))
80
+ (method_signature
81
+ name: (property_identifier) @meta.definition.method.ts @entity.name.function.ts)
82
+ (generator_function_declaration
83
+ "*" @keyword.generator.asterisk.ts)
84
+ (generator_function_declaration
85
+ name: (identifier) @meta.definition.function.ts @entity.name.function.ts)
86
+
87
+ (pair
88
+ key: (property_identifier) @entity.name.function.ts
89
+ value: [(function_expression) (arrow_function)])
90
+
91
+ (assignment_expression
92
+ left: (member_expression
93
+ property: (property_identifier) @entity.name.function.ts)
94
+ right: [(function_expression) (arrow_function)])
95
+
96
+ (variable_declarator
97
+ name: (identifier) @entity.name.function.ts
98
+ value: [(function_expression) (arrow_function)])
99
+
100
+ (assignment_expression
101
+ left: (identifier) @entity.name.function.ts
102
+ right: [(function_expression) (arrow_function)])
103
+
104
+ (required_parameter
105
+ (identifier) @variable.parameter.ts)
106
+
107
+ (required_parameter
108
+ (_
109
+ ([
110
+ (identifier)
111
+ (shorthand_property_identifier_pattern)
112
+ ]) @variable.parameter.ts))
113
+
114
+ (optional_parameter
115
+ (identifier) @variable.parameter.ts)
116
+
117
+ (optional_parameter
118
+ (_
119
+ ([
120
+ (identifier)
121
+ (shorthand_property_identifier_pattern)
122
+ ]) @variable.parameter.ts))
123
+
124
+ (catch_clause
125
+ parameter: (identifier) @variable.parameter.ts)
126
+
127
+ (index_signature
128
+ name: (identifier) @variable.parameter.ts)
129
+
130
+ (arrow_function
131
+ parameter: (identifier) @variable.parameter.ts)
132
+
133
+ ; Function and method calls
134
+
135
+ (call_expression
136
+ function: (identifier) @entity.name.function.ts)
137
+
138
+ (call_expression
139
+ function: (member_expression
140
+ object: (identifier) @support.class.promise.ts)
141
+ (#eq? @support.class.promise.ts "Promise"))
142
+
143
+ (call_expression
144
+ function: (member_expression
145
+ property: (property_identifier) @entity.name.function.ts))
146
+
147
+ (new_expression) @new.expr.ts
148
+
149
+ (new_expression
150
+ constructor: (identifier) @entity.name.function.ts)
151
+
152
+
153
+ ; Special identifiers
154
+
155
+ (predefined_type) @support.type.ts
156
+ (predefined_type (["string" "boolean" "number" "any" "unknown" "never" "void"])) @support.type.primitive.ts
157
+
158
+ (_
159
+ (type_identifier) @entity.name.type.ts)
160
+
161
+ (type_annotation
162
+ ([
163
+ (type_identifier)
164
+ (nested_type_identifier)
165
+ ]) @meta.type.annotation.ts @entity.name.type.ts)
166
+
167
+ (class_declaration
168
+ (type_identifier) @entity.name.type.class.ts)
169
+
170
+ (type_alias_declaration
171
+ (type_identifier) @entity.name.type.alias.ts)
172
+ (type_alias_declaration
173
+ value: (_
174
+ (type_identifier) @entity.name.type.ts))
175
+
176
+ (interface_declaration
177
+ (type_identifier) @entity.name.type.interface.ts)
178
+
179
+ (internal_module
180
+ name: (identifier) @entity.name.type.ts)
181
+
182
+ (enum_declaration
183
+ name: (identifier) @entity.name.type.enum.ts)
184
+
185
+ (
186
+ [
187
+ (_ name: (identifier))
188
+ (shorthand_property_identifier)
189
+ (shorthand_property_identifier_pattern)
190
+ ] @variable.other.constant.ts
191
+ (#match? @variable.other.constant.ts "^[A-Z][A-Z_]+$"))
192
+
193
+ (extends_clause
194
+ value: (identifier) @entity.other.inherited-class.ts)
195
+
196
+ (extends_type_clause
197
+ type: (type_identifier) @entity.other.inherited-class.ts)
198
+
199
+ (implements_clause
200
+ (type_identifier) @entity.other.inherited-class.ts)
201
+
202
+ ; Tokens
203
+
204
+ [
205
+ ";"
206
+ "?."
207
+ "."
208
+ ","
209
+ ":"
210
+ "?"
211
+ ] @punctuation.delimiter.ts
212
+
213
+ [
214
+ "!"
215
+ "~"
216
+ "==="
217
+ "!=="
218
+ "&&"
219
+ "||"
220
+ "??"
221
+ ] @keyword.operator.logical.ts
222
+
223
+ (binary_expression ([
224
+ "-"
225
+ "+"
226
+ "*"
227
+ "/"
228
+ "%"
229
+ "^"
230
+ ]) @keyword.operator.arithmetic.ts)
231
+
232
+ (binary_expression ([
233
+ "<"
234
+ "<="
235
+ ">"
236
+ ">="
237
+ ]) @keyword.operator.relational.ts)
238
+
239
+ (unary_expression ([
240
+ "-"
241
+ ]) @keyword.operator.arithmetic.ts)
242
+
243
+ [
244
+ "="
245
+ ] @keyword.operator.assignment.ts
246
+
247
+ (augmented_assignment_expression ([
248
+ "-="
249
+ "+="
250
+ "*="
251
+ "/="
252
+ "%="
253
+ "^="
254
+ "&="
255
+ "|="
256
+ "&&="
257
+ "||="
258
+ "??="
259
+ ]) @keyword.operator.assignment.compound.ts)
260
+
261
+ [
262
+ "++"
263
+ ] @keyword.operator.increment.ts
264
+
265
+ [
266
+ "--"
267
+ ] @keyword.operator.decrement.ts
268
+
269
+ [
270
+ "**"
271
+ "**="
272
+ "<<"
273
+ "<<="
274
+ "=="
275
+ "!="
276
+ ">>"
277
+ ">>="
278
+ ">>>"
279
+ ">>>="
280
+ "~"
281
+ "&"
282
+ "|"
283
+ ] @keyword.operator.ts
284
+
285
+ (union_type
286
+ ("|") @keyword.operator.type.ts)
287
+
288
+ (intersection_type
289
+ ("&") @keyword.operator.type.ts)
290
+
291
+ (type_annotation
292
+ (":") @keyword.operator.type.annotation.ts)
293
+
294
+ (index_signature
295
+ (":") @keyword.operator.type.annotation.ts)
296
+
297
+ (type_predicate_annotation
298
+ (":") @keyword.operator.type.annotation.ts)
299
+
300
+ (conditional_type
301
+ ([
302
+ "?"
303
+ ":"
304
+ ]) @keyword.operator.ternary.ts)
305
+
306
+ [
307
+ "{"
308
+ "}"
309
+ "("
310
+ ")"
311
+ "["
312
+ "]"
313
+ ] @punctuation.ts
314
+
315
+ (template_substitution
316
+ "${" @punctuation.definition.template-expression.begin.ts
317
+ "}" @punctuation.definition.template-expression.end.ts)
318
+
319
+ (template_type
320
+ "${" @punctuation.definition.template-expression.begin.ts
321
+ "}" @punctuation.definition.template-expression.end.ts)
322
+
323
+ (type_arguments
324
+ "<" @punctuation.definition.typeparameters.begin.ts
325
+ ">" @punctuation.definition.typeparameters.end.ts)
326
+
327
+ (type_parameters
328
+ "<" @punctuation.definition.typeparameters.begin.ts
329
+ ">" @punctuation.definition.typeparameters.end.ts)
330
+
331
+ ; Keywords
332
+
333
+ ("typeof") @keyword.operator.expression.typeof.ts
334
+
335
+ (binary_expression "instanceof" @keyword.operator.expression.instanceof.ts)
336
+
337
+ ("of") @keyword.operator.expression.of.ts
338
+
339
+ ("is") @keyword.operator.expression.is.ts
340
+
341
+ [
342
+ "delete"
343
+ "in"
344
+ "infer"
345
+ "keyof"
346
+ ] @keyword.operator.expression.ts
347
+
348
+ [
349
+ "as"
350
+ "await"
351
+ "break"
352
+ "case"
353
+ "catch"
354
+ "continue"
355
+ "default"
356
+ "do"
357
+ "else"
358
+ "export"
359
+ "finally"
360
+ "for"
361
+ "from"
362
+ "if"
363
+ "import"
364
+ "require"
365
+ "return"
366
+ "satisfies"
367
+ "switch"
368
+ "throw"
369
+ "try"
370
+ "while"
371
+ "yield"
372
+ ] @keyword.control.ts
373
+
374
+ [
375
+ "abstract"
376
+ "async"
377
+ "declare"
378
+ "extends"
379
+ "implements"
380
+ "override"
381
+ "private"
382
+ "protected"
383
+ "public"
384
+ "readonly"
385
+ "static"
386
+ ] @storage.modifier.ts
387
+
388
+ [
389
+ "=>"
390
+ "class"
391
+ "const"
392
+ "enum"
393
+ "function"
394
+ "get"
395
+ "interface"
396
+ "let"
397
+ "namespace"
398
+ "set"
399
+ "var"
400
+ ] @storage.type.ts
401
+
402
+ ("type") @storage.type.type.ts
403
+
404
+ [
405
+ "module"
406
+ ] @storage.type.namespace.ts
407
+
408
+ [
409
+ "debugger"
410
+ "target"
411
+ "with"
412
+ ] @keyword.ts
413
+
414
+ (regex_flags) @keyword.ts
415
+
416
+ (unary_expression
417
+ "void" @keyword.operator.expression.void.ts)
418
+
419
+ [
420
+ "new"
421
+ ] @keyword.operator.new.ts
422
+
423
+ (public_field_definition
424
+ ("?") @keyword.operator.optional.ts)
425
+
426
+ (property_signature
427
+ ("?") @keyword.operator.optional.ts)
428
+
429
+ (method_signature
430
+ ("?") @keyword.operator.optional.ts)
431
+
432
+ (optional_parameter
433
+ ([
434
+ "?"
435
+ ":"
436
+ ]) @keyword.operator.optional.ts)
437
+
438
+ (ternary_expression
439
+ ([
440
+ "?"
441
+ ":"
442
+ ]) @keyword.operator.ternary.ts)
443
+
444
+ (optional_chain
445
+ ("?.") @punctuation.accessor.optional.ts)
446
+
447
+ (rest_pattern
448
+ ("...") @keyword.operator.rest.ts)
449
+ (rest_type
450
+ ("...") @keyword.operator.rest.ts)
451
+
452
+ (spread_element
453
+ ("...") @keyword.operator.spread.ts)
454
+
455
+ ; Language constants
456
+
457
+ [
458
+ (null)
459
+ ] @constant.language.null.ts
460
+
461
+ [
462
+ (undefined)
463
+ ] @constant.language.undefined.ts
464
+
465
+ ((identifier) @constant.language.nan.ts
466
+ (#eq? @constant.language.nan.ts "NaN"))
467
+
468
+ ((identifier) @constant.language.infinity.ts
469
+ (#eq? @constant.language.infinity.ts "Infinity"))
470
+
471
+ [
472
+ (true)
473
+ ] @constant.language.boolean.true.ts
474
+
475
+ [
476
+ (false)
477
+ ] @constant.language.boolean.false.ts
478
+
479
+ (literal_type
480
+ [
481
+ (null)
482
+ (undefined)
483
+ (true)
484
+ (false)
485
+ ] @support.type.builtin.ts)
486
+
487
+ (namespace_import
488
+ "*" @constant.language.ts)
@@ -27,7 +27,6 @@ export declare enum TokenQuality {
27
27
  type Node = ListNode | LeafNode;
28
28
  interface LeafNode {
29
29
  readonly length: number;
30
- parent?: ListNode;
31
30
  token: number;
32
31
  tokenQuality: TokenQuality;
33
32
  height: 0;
@@ -24,7 +24,9 @@ class ListNode {
24
24
  this._children.push(node);
25
25
  this._length += node.length;
26
26
  this._updateParentLength(node.length);
27
- node.parent = this;
27
+ if (!isLeaf(node)) {
28
+ node.parent = this;
29
+ }
28
30
  }
29
31
  _updateParentLength(delta) {
30
32
  let updateParent = this.parent;
@@ -46,7 +48,9 @@ class ListNode {
46
48
  this._children.unshift(node);
47
49
  this._length += node.length;
48
50
  this._updateParentLength(node.length);
49
- node.parent = this;
51
+ if (!isLeaf(node)) {
52
+ node.parent = this;
53
+ }
50
54
  }
51
55
  unprependChild() {
52
56
  const child = this._children.shift();
@@ -202,7 +206,9 @@ class TokenStore {
202
206
  const node = stack.pop();
203
207
  const currentOffset = node.offset;
204
208
  if (currentOffset < updateOffsetStart && currentOffset + node.node.length <= updateOffsetStart) {
205
- node.node.parent = undefined;
209
+ if (!isLeaf(node.node)) {
210
+ node.node.parent = undefined;
211
+ }
206
212
  precedingNodes.push(node.node);
207
213
  continue;
208
214
  }
@@ -213,11 +219,13 @@ class TokenStore {
213
219
  continue;
214
220
  }
215
221
  if (currentOffset >= firstUnchangedOffsetAfterUpdate) {
216
- node.node.parent = undefined;
222
+ if (!isLeaf(node.node)) {
223
+ node.node.parent = undefined;
224
+ }
217
225
  postcedingNodes.push(node.node);
218
226
  continue;
219
227
  }
220
- else if (isLeaf(node.node) && (currentOffset + node.node.length >= firstUnchangedOffsetAfterUpdate)) {
228
+ else if (isLeaf(node.node) && (currentOffset + node.node.length > firstUnchangedOffsetAfterUpdate)) {
221
229
  postcedingNodes.push({ length: currentOffset + node.node.length - firstUnchangedOffsetAfterUpdate, token: node.node.token, height: 0, tokenQuality: node.node.tokenQuality });
222
230
  continue;
223
231
  }
@@ -385,9 +393,7 @@ class TokenStore {
385
393
  const stack = [[this._root, false]];
386
394
  while (stack.length > 0) {
387
395
  const [node, visited] = stack.pop();
388
- if (isLeaf(node)) {
389
- node.parent = undefined;
390
- }
396
+ if (isLeaf(node)) ;
391
397
  else if (!visited) {
392
398
  stack.push([node, true]);
393
399
  for (let i = node.children.length - 1; i >= 0; i--) {
@@ -2,6 +2,7 @@ import { Range } from "@codingame/monaco-vscode-api/vscode/vs/editor/common/core
2
2
  import { ITextModel } from "@codingame/monaco-vscode-api/vscode/vs/editor/common/model";
3
3
  import { TokenQuality, TokenUpdate } from "./tokenStore.js";
4
4
  import { IDisposable } from "@codingame/monaco-vscode-api/vscode/vs/base/common/lifecycle";
5
+ import { IModelContentChangedEvent } from "@codingame/monaco-vscode-api/vscode/vs/editor/common/textModelEvents";
5
6
  import { ITreeSitterTokenizationStoreService } from "@codingame/monaco-vscode-api/vscode/vs/editor/common/model/treeSitterTokenStoreService.service";
6
7
  export interface TokenInformation {
7
8
  tokens: Uint32Array;
@@ -12,6 +13,7 @@ export declare class TreeSitterTokenizationStoreService implements ITreeSitterTo
12
13
  private readonly tokens;
13
14
  constructor();
14
15
  setTokens(model: ITextModel, tokens: TokenUpdate[], tokenQuality: TokenQuality): void;
16
+ handleContentChanged(model: ITextModel, e: IModelContentChangedEvent): void;
15
17
  rangeHasTokens(model: ITextModel, range: Range, minimumTokenQuality: TokenQuality): boolean;
16
18
  hasTokens(model: ITextModel, accurateForRange?: Range): boolean;
17
19
  getTokens(model: ITextModel, line: number): Uint32Array | undefined;
@@ -25,5 +27,6 @@ export declare class TreeSitterTokenizationStoreService implements ITreeSitterTo
25
27
  startOffset: number;
26
28
  endOffset: number;
27
29
  }[];
30
+ delete(model: ITextModel): void;
28
31
  dispose(): void;
29
32
  }
@@ -14,33 +14,6 @@ class TreeSitterTokenizationStoreService {
14
14
  const store = disposables.add(( new TokenStore(model)));
15
15
  this.tokens.set(model, { store: store, accurateVersion: model.getVersionId(), disposables, guessVersion: model.getVersionId() });
16
16
  store.buildStore(tokens, tokenQuality);
17
- disposables.add(model.onDidChangeContent(e => {
18
- const storeInfo = this.tokens.get(model);
19
- if (!storeInfo) {
20
- return;
21
- }
22
- storeInfo.guessVersion = e.versionId;
23
- for (const change of e.changes) {
24
- if (change.text.length > change.rangeLength) {
25
- const offset = change.rangeOffset > 0 ? change.rangeOffset - 1 : change.rangeOffset;
26
- const oldToken = storeInfo.store.getTokenAt(offset);
27
- let newToken;
28
- if (oldToken) {
29
- newToken = { startOffsetInclusive: oldToken.startOffsetInclusive, length: oldToken.length + change.text.length - change.rangeLength, token: oldToken.token };
30
- }
31
- else {
32
- newToken = { startOffsetInclusive: offset, length: change.text.length + 1, token: 0 };
33
- }
34
- storeInfo.store.update(oldToken?.length ?? 0, [newToken], TokenQuality.EditGuess);
35
- }
36
- else if (change.text.length < change.rangeLength) {
37
- const deletedCharCount = change.rangeLength - change.text.length;
38
- storeInfo.store.delete(deletedCharCount, change.rangeOffset);
39
- }
40
- const refreshLength = change.rangeLength > change.text.length ? change.rangeLength : change.text.length;
41
- storeInfo.store.markForRefresh(change.rangeOffset, change.rangeOffset + refreshLength);
42
- }
43
- }));
44
17
  disposables.add(model.onWillDispose(() => {
45
18
  const storeInfo = this.tokens.get(model);
46
19
  if (storeInfo) {
@@ -49,6 +22,32 @@ class TreeSitterTokenizationStoreService {
49
22
  }
50
23
  }));
51
24
  }
25
+ handleContentChanged(model, e) {
26
+ const storeInfo = this.tokens.get(model);
27
+ if (!storeInfo) {
28
+ return;
29
+ }
30
+ storeInfo.guessVersion = e.versionId;
31
+ for (const change of e.changes) {
32
+ if (change.text.length > change.rangeLength) {
33
+ const offset = change.rangeOffset > 0 ? change.rangeOffset - 1 : change.rangeOffset;
34
+ const oldToken = storeInfo.store.getTokenAt(offset);
35
+ let newToken;
36
+ if (oldToken) {
37
+ newToken = { startOffsetInclusive: oldToken.startOffsetInclusive, length: oldToken.length + change.text.length - change.rangeLength, token: oldToken.token };
38
+ storeInfo.store.markForRefresh(offset, change.rangeOffset + (change.text.length > change.rangeLength ? change.text.length : change.rangeLength));
39
+ }
40
+ else {
41
+ newToken = { startOffsetInclusive: offset, length: change.text.length, token: 0 };
42
+ }
43
+ storeInfo.store.update(oldToken?.length ?? 0, [newToken], TokenQuality.EditGuess);
44
+ }
45
+ else if (change.text.length < change.rangeLength) {
46
+ const deletedCharCount = change.rangeLength - change.text.length;
47
+ storeInfo.store.delete(deletedCharCount, change.rangeOffset);
48
+ }
49
+ }
50
+ }
52
51
  rangeHasTokens(model, range, minimumTokenQuality) {
53
52
  const tokens = this.tokens.get(model);
54
53
  if (!tokens) {
@@ -119,6 +118,13 @@ class TreeSitterTokenizationStoreService {
119
118
  endOffset: range.endOffset
120
119
  })));
121
120
  }
121
+ delete(model) {
122
+ const storeInfo = this.tokens.get(model);
123
+ if (storeInfo) {
124
+ storeInfo.disposables.dispose();
125
+ this.tokens.delete(model);
126
+ }
127
+ }
122
128
  dispose() {
123
129
  for (const [, value] of this.tokens) {
124
130
  value.disposables.dispose();