@adecore/editor-react 0.31.11 → 0.32.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 (137) hide show
  1. package/dist/AnchoredPopup.js +73 -19
  2. package/dist/AttributionCard.js +162 -4
  3. package/dist/BaselineStatus.js +62 -8
  4. package/dist/CallHierarchyPanel.js +977 -60
  5. package/dist/ChangeReview.js +76 -25
  6. package/dist/CodeAuthorsCard.js +314 -14
  7. package/dist/CompletionPopup.js +490 -83
  8. package/dist/DiffView.js +548 -181
  9. package/dist/EditorContextMenu.js +352 -34
  10. package/dist/EditorView.js +276 -99
  11. package/dist/FindReplace.js +525 -67
  12. package/dist/HoverCard.js +378 -38
  13. package/dist/HoverSections.js +367 -56
  14. package/dist/LanguagePopups.js +95 -34
  15. package/dist/Markdown.js +41 -6
  16. package/dist/PanelResizeHandle.js +199 -66
  17. package/dist/PathText.js +49 -7
  18. package/dist/PeekPanel.js +675 -72
  19. package/dist/PickPopup.js +304 -34
  20. package/dist/RenameCard.js +679 -85
  21. package/dist/RenderedDocs.js +329 -58
  22. package/dist/SignatureCard.js +91 -7
  23. package/dist/SplitDiffView.js +344 -254
  24. package/dist/SymbolPicker.js +440 -85
  25. package/dist/call-hierarchy-model.js +102 -68
  26. package/dist/call-hierarchy.js +458 -359
  27. package/dist/code-actions-model.js +88 -76
  28. package/dist/code-actions.js +372 -283
  29. package/dist/code-authors.js +64 -55
  30. package/dist/code-vision-model.js +134 -127
  31. package/dist/code-vision.js +224 -206
  32. package/dist/completion-call.js +94 -67
  33. package/dist/completion-model.js +334 -244
  34. package/dist/completion.js +840 -649
  35. package/dist/conflict-model.js +35 -29
  36. package/dist/context-menu-rows.js +42 -17
  37. package/dist/context-menu.js +64 -46
  38. package/dist/definition-link.js +88 -85
  39. package/dist/diagnostics-model.js +74 -55
  40. package/dist/diagnostics.js +121 -100
  41. package/dist/diff-expansion.js +38 -35
  42. package/dist/diff-overlays.js +144 -22
  43. package/dist/diff-syntax.js +65 -42
  44. package/dist/diff-wordmarks.js +26 -23
  45. package/dist/doc-comment-model.js +265 -216
  46. package/dist/editor-language.js +177 -152
  47. package/dist/error-message.js +2 -2
  48. package/dist/find-query.js +49 -36
  49. package/dist/folding.js +81 -62
  50. package/dist/format-on-type.js +86 -67
  51. package/dist/highlight-layers.js +19 -20
  52. package/dist/highlights.js +105 -83
  53. package/dist/history.js +44 -38
  54. package/dist/holder.js +18 -18
  55. package/dist/host-types.js +1 -1
  56. package/dist/hover-content.js +167 -129
  57. package/dist/hover.js +285 -245
  58. package/dist/index.js +10 -10
  59. package/dist/inlay-hints.js +369 -324
  60. package/dist/key-priority.js +34 -31
  61. package/dist/language-ids.js +45 -42
  62. package/dist/line-edits.js +74 -28
  63. package/dist/line-text.js +18 -3
  64. package/dist/locales/en.json +38 -38
  65. package/dist/locales/nl.json +41 -41
  66. package/dist/models.js +1 -1
  67. package/dist/navigation-history.js +40 -41
  68. package/dist/navigation.js +141 -123
  69. package/dist/panel-size.js +8 -8
  70. package/dist/patch-decorations.js +236 -160
  71. package/dist/patch-layout.js +331 -262
  72. package/dist/paths.js +3 -3
  73. package/dist/peek-model.js +86 -69
  74. package/dist/peek.js +254 -192
  75. package/dist/pick.js +164 -157
  76. package/dist/popup-focus.js +5 -5
  77. package/dist/popup-placement.js +36 -21
  78. package/dist/popups.js +13 -13
  79. package/dist/project-language.js +228 -211
  80. package/dist/project-problems.js +81 -69
  81. package/dist/proposal-model.js +163 -126
  82. package/dist/recent-choices.js +25 -25
  83. package/dist/refresher.js +44 -49
  84. package/dist/rename-model.js +113 -113
  85. package/dist/rename.js +321 -233
  86. package/dist/rendered-docs.d.ts +4 -2
  87. package/dist/rendered-docs.js +384 -318
  88. package/dist/rendering-context.js +5 -3
  89. package/dist/rendering.js +22 -4
  90. package/dist/review-group.js +42 -39
  91. package/dist/row-host.d.ts +4 -2
  92. package/dist/row-host.js +90 -78
  93. package/dist/selection-ranges.js +21 -17
  94. package/dist/semantic-delta.js +22 -19
  95. package/dist/semantic-model.js +86 -73
  96. package/dist/semantic-tokens.js +201 -162
  97. package/dist/shortcut-keys.js +16 -10
  98. package/dist/signature-model.js +34 -28
  99. package/dist/signature.js +177 -129
  100. package/dist/snippet-field-transforms.js +118 -106
  101. package/dist/snippet-indent.js +48 -43
  102. package/dist/snippet-range-order.js +11 -11
  103. package/dist/snippet-session.js +703 -667
  104. package/dist/snippet-transform-client.js +59 -59
  105. package/dist/snippet-transform-format.js +285 -263
  106. package/dist/snippet-transform-protocol.js +1 -1
  107. package/dist/snippet-transform-queue.js +163 -153
  108. package/dist/snippet-transform-worker.js +42 -35
  109. package/dist/snippet-variable-names.js +1 -36
  110. package/dist/snippet-variables.js +53 -63
  111. package/dist/snippet.js +477 -405
  112. package/dist/split-alignment.js +47 -35
  113. package/dist/split-scroll.js +42 -40
  114. package/dist/symbol-links.js +33 -25
  115. package/dist/symbol-picker-model.js +126 -116
  116. package/dist/symbol-picker.js +98 -59
  117. package/dist/symbols.js +117 -88
  118. package/dist/testing.js +248 -165
  119. package/dist/timers.js +35 -30
  120. package/dist/use-panel-body.js +49 -8
  121. package/dist/use-problem-counts.js +29 -15
  122. package/dist/view-state.js +54 -33
  123. package/dist/word-diff.js +18 -18
  124. package/dist/workspace-edit.js +300 -249
  125. package/package.json +6 -6
  126. package/src/CallHierarchyPanel.tsx +2 -2
  127. package/src/DiffView.tsx +3 -3
  128. package/src/FindReplace.tsx +2 -2
  129. package/src/LanguagePopups.tsx +2 -0
  130. package/src/PeekPanel.tsx +3 -3
  131. package/src/RenderedDocs.tsx +9 -10
  132. package/src/SymbolPicker.tsx +2 -2
  133. package/src/diff-overlays.tsx +6 -4
  134. package/src/locales/en.json +38 -38
  135. package/src/locales/nl.json +41 -41
  136. package/src/rendered-docs.ts +14 -3
  137. package/src/row-host.ts +14 -3
@@ -1,5 +1,7 @@
1
1
  import { createContext, useContext } from 'react';
2
- export const RenderingContext = createContext({ theme: 'light' });
2
+ export const RenderingContext = createContext({
3
+ theme: 'light'
4
+ });
3
5
  export function useEditorRendering() {
4
- return useContext(RenderingContext);
5
- }
6
+ return useContext(RenderingContext);
7
+ }
package/dist/rendering.js CHANGED
@@ -1,5 +1,23 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
1
+ import { c as _c } from "react/compiler-runtime";
2
2
  import { RenderingContext } from './rendering-context.js';
3
- export function EditorRenderingProvider({ value, children }) {
4
- return _jsx(RenderingContext, { value: value, children: children });
5
- }
3
+ import { jsx as _jsx } from "react/jsx-runtime";
4
+ export function EditorRenderingProvider(t0) {
5
+ const $ = _c(3);
6
+ const {
7
+ value,
8
+ children
9
+ } = t0;
10
+ let t1;
11
+ if ($[0] !== children || $[1] !== value) {
12
+ t1 = /*#__PURE__*/_jsx(RenderingContext, {
13
+ value: value,
14
+ children: children
15
+ });
16
+ $[0] = children;
17
+ $[1] = value;
18
+ $[2] = t1;
19
+ } else {
20
+ t1 = $[2];
21
+ }
22
+ return t1;
23
+ }
@@ -4,47 +4,50 @@
4
4
  * change in front of a person that the other already took.
5
5
  */
6
6
  export class ReviewGroup {
7
- members = new Set();
8
- join(member) {
9
- this.members.add(member);
10
- return () => {
11
- this.members.delete(member);
12
- };
13
- }
14
- hide(runIds) {
15
- this.each((member) => member.hide(runIds));
16
- }
17
- show(runIds) {
18
- this.each((member) => member.show(runIds));
19
- }
20
- refresh() {
21
- this.each((member) => member.refresh());
22
- }
23
- /* Over a copy, since a member may leave while it hears. */
24
- each(action) {
25
- for (const member of [...this.members]) {
26
- action(member);
27
- }
7
+ members = new Set();
8
+ join(member) {
9
+ this.members.add(member);
10
+ return () => {
11
+ this.members.delete(member);
12
+ };
13
+ }
14
+ hide(runIds) {
15
+ this.each(member => member.hide(runIds));
16
+ }
17
+ show(runIds) {
18
+ this.each(member => member.show(runIds));
19
+ }
20
+ refresh() {
21
+ this.each(member => member.refresh());
22
+ }
23
+ /* Over a copy, since a member may leave while it hears. */
24
+ each(action) {
25
+ for (const member of [...this.members]) {
26
+ action(member);
28
27
  }
28
+ }
29
29
  }
30
30
  const groups = new Map();
31
31
  /* The host supplies a shared file key; the group is released with its last editor. */
32
32
  export function joinReviewGroup(key) {
33
- const held = groups.get(key) ?? { group: new ReviewGroup(), holders: 0 };
34
- groups.set(key, held);
35
- held.holders++;
36
- let left = false;
37
- return {
38
- group: held.group,
39
- leave: () => {
40
- if (left) {
41
- return;
42
- }
43
- left = true;
44
- held.holders--;
45
- if (held.holders === 0 && groups.get(key) === held) {
46
- groups.delete(key);
47
- }
48
- }
49
- };
50
- }
33
+ const held = groups.get(key) ?? {
34
+ group: new ReviewGroup(),
35
+ holders: 0
36
+ };
37
+ groups.set(key, held);
38
+ held.holders++;
39
+ let left = false;
40
+ return {
41
+ group: held.group,
42
+ leave: () => {
43
+ if (left) {
44
+ return;
45
+ }
46
+ left = true;
47
+ held.holders--;
48
+ if (held.holders === 0 && groups.get(key) === held) {
49
+ groups.delete(key);
50
+ }
51
+ }
52
+ };
53
+ }
@@ -18,9 +18,11 @@ declare abstract class ContainerHost {
18
18
  private readonly listeners;
19
19
  private version;
20
20
  private signature;
21
+ private shown;
21
22
  constructor(editor: Editor, owner: string);
22
- getVersion: () => number;
23
- subscribe: (listener: () => void) => (() => void);
23
+ getVersion(): number;
24
+ getContainers(): ReadonlyMap<string, HTMLElement>;
25
+ subscribe(listener: () => void): () => void;
24
26
  container(id: string): HTMLElement | undefined;
25
27
  protected replace(signature: string, ids: readonly string[]): boolean;
26
28
  protected mounted(id: string, container: HTMLElement): void;
package/dist/row-host.js CHANGED
@@ -1,49 +1,62 @@
1
1
  /* The elements an editor made for one owner's entries, and a version React reads them by. */
2
2
  class ContainerHost {
3
- editor;
4
- owner;
5
- containers = new Map();
6
- listeners = new Set();
7
- version = 0;
8
- signature = '';
9
- constructor(editor, owner) {
10
- this.editor = editor;
11
- this.owner = owner;
3
+ editor;
4
+ owner;
5
+ containers = new Map();
6
+ listeners = new Set();
7
+ version = 0;
8
+ signature = '';
9
+ shown = null;
10
+ constructor(editor, owner) {
11
+ this.editor = editor;
12
+ this.owner = owner;
13
+ }
14
+ getVersion() {
15
+ return this.version;
16
+ }
17
+ /* The elements by id as they stand now, one map until they change, so React can read them as a snapshot. */
18
+ getContainers() {
19
+ if (this.shown?.version !== this.version) {
20
+ this.shown = {
21
+ version: this.version,
22
+ containers: new Map(this.containers)
23
+ };
12
24
  }
13
- getVersion = () => this.version;
14
- subscribe = (listener) => {
15
- this.listeners.add(listener);
16
- return () => {
17
- this.listeners.delete(listener);
18
- };
25
+ return this.shown.containers;
26
+ }
27
+ subscribe(listener) {
28
+ this.listeners.add(listener);
29
+ return () => {
30
+ this.listeners.delete(listener);
19
31
  };
20
- container(id) {
21
- return this.containers.get(id);
32
+ }
33
+ container(id) {
34
+ return this.containers.get(id);
35
+ }
36
+ /* False for the same entries again, so an editor does not measure them twice; otherwise drops the elements of entries that left. */
37
+ replace(signature, ids) {
38
+ if (signature === this.signature) {
39
+ return false;
22
40
  }
23
- /* False for the same entries again, so an editor does not measure them twice; otherwise drops the elements of entries that left. */
24
- replace(signature, ids) {
25
- if (signature === this.signature) {
26
- return false;
27
- }
28
- this.signature = signature;
29
- const kept = new Set(ids);
30
- for (const id of [...this.containers.keys()]) {
31
- if (!kept.has(id)) {
32
- this.containers.delete(id);
33
- }
34
- }
35
- return true;
41
+ this.signature = signature;
42
+ const kept = new Set(ids);
43
+ for (const id of [...this.containers.keys()]) {
44
+ if (!kept.has(id)) {
45
+ this.containers.delete(id);
46
+ }
36
47
  }
37
- mounted(id, container) {
38
- this.containers.set(id, container);
39
- this.bump();
40
- }
41
- bump() {
42
- this.version++;
43
- for (const listener of [...this.listeners]) {
44
- listener();
45
- }
48
+ return true;
49
+ }
50
+ mounted(id, container) {
51
+ this.containers.set(id, container);
52
+ this.bump();
53
+ }
54
+ bump() {
55
+ this.version++;
56
+ for (const listener of [...this.listeners]) {
57
+ listener();
46
58
  }
59
+ }
47
60
  }
48
61
  /*
49
62
  * The rows of one owner in an editor, and the elements the editor draws them in, so React can portal
@@ -51,31 +64,30 @@ class ContainerHost {
51
64
  * row's content never keeps state of its own.
52
65
  */
53
66
  export class RowHost extends ContainerHost {
54
- set(rows) {
55
- const signature = rows.map((row) => `${row.id}@${row.line}${row.placement}:${row.height}:${row.fixed}:${row.filler}`).join('|');
56
- if (!this.replace(signature, rows.map((row) => row.id))) {
57
- return;
58
- }
59
- this.editor.setWidgets(rows.map((row) => ({
60
- id: row.filler ? `${row.id}-filler` : row.id,
61
- line: row.line,
62
- placement: row.placement,
63
- height: row.height,
64
- fixed: row.fixed,
65
- render: (container) => {
66
- if (row.filler) {
67
- container.classList.add('adecore-editor-diff-filler');
68
- }
69
- else {
70
- this.mounted(row.id, container);
71
- }
72
- }
73
- })), this.owner);
74
- this.bump();
75
- }
76
- clear() {
77
- this.set([]);
67
+ set(rows) {
68
+ const signature = rows.map(row => `${row.id}@${row.line}${row.placement}:${row.height}:${row.fixed}:${row.filler}`).join('|');
69
+ if (!this.replace(signature, rows.map(row => row.id))) {
70
+ return;
78
71
  }
72
+ this.editor.setWidgets(rows.map(row => ({
73
+ id: row.filler ? `${row.id}-filler` : row.id,
74
+ line: row.line,
75
+ placement: row.placement,
76
+ height: row.height,
77
+ fixed: row.fixed,
78
+ render: container => {
79
+ if (row.filler) {
80
+ container.classList.add('adecore-editor-diff-filler');
81
+ } else {
82
+ this.mounted(row.id, container);
83
+ }
84
+ }
85
+ })), this.owner);
86
+ this.bump();
87
+ }
88
+ clear() {
89
+ this.set([]);
90
+ }
79
91
  }
80
92
  /*
81
93
  * The actions of one owner after the end of lines in an editor, and the elements the editor makes for
@@ -83,19 +95,19 @@ export class RowHost extends ContainerHost {
83
95
  * its state.
84
96
  */
85
97
  export class LineActionHost extends ContainerHost {
86
- set(actions) {
87
- const signature = actions.map((action) => `${action.id}@${action.line}`).join('|');
88
- if (!this.replace(signature, actions.map((action) => action.id))) {
89
- return;
90
- }
91
- this.editor.setLineActions(actions.map((action) => ({
92
- id: action.id,
93
- line: action.line,
94
- render: (container) => this.mounted(action.id, container)
95
- })), this.owner);
96
- this.bump();
98
+ set(actions) {
99
+ const signature = actions.map(action => `${action.id}@${action.line}`).join('|');
100
+ if (!this.replace(signature, actions.map(action => action.id))) {
101
+ return;
97
102
  }
98
- clear() {
99
- this.set([]);
100
- }
101
- }
103
+ this.editor.setLineActions(actions.map(action => ({
104
+ id: action.id,
105
+ line: action.line,
106
+ render: container => this.mounted(action.id, container)
107
+ })), this.owner);
108
+ this.bump();
109
+ }
110
+ clear() {
111
+ this.set([]);
112
+ }
113
+ }
@@ -1,26 +1,30 @@
1
1
  const METHOD = 'textDocument/selectionRange';
2
2
  /* The links of one answer, the smallest range first. */
3
3
  export function selectionChainOf(selection) {
4
- const chain = [];
5
- for (let link = selection; link; link = link.parent) {
6
- chain.push(link.range);
7
- }
8
- return chain;
4
+ const chain = [];
5
+ for (let link = selection; link; link = link.parent) {
6
+ chain.push(link.range);
7
+ }
8
+ return chain;
9
9
  }
10
10
  /*
11
11
  * Extend and Shrink Selection grow through the ranges the language server knows around the caret, which
12
12
  * follow the syntax of the file. Where no server offers them the editor grows by its own rule.
13
13
  */
14
14
  export class SelectionRangesFeature {
15
- constructor(language) {
16
- const { editor, project, uri } = language;
17
- editor.setSelectionRanges(async (positions) => {
18
- if (!project.service.supports(METHOD, uri)) {
19
- return null;
20
- }
21
- const chains = await project.service.selectionRanges(uri, positions);
22
- return chains === null || chains.length !== positions.length ? null : chains.map(selectionChainOf);
23
- });
24
- language.onDispose(() => editor.setSelectionRanges(null));
25
- }
26
- }
15
+ constructor(language) {
16
+ const {
17
+ editor,
18
+ project,
19
+ uri
20
+ } = language;
21
+ editor.setSelectionRanges(async positions => {
22
+ if (!project.service.supports(METHOD, uri)) {
23
+ return null;
24
+ }
25
+ const chains = await project.service.selectionRanges(uri, positions);
26
+ return chains === null || chains.length !== positions.length ? null : chains.map(selectionChainOf);
27
+ });
28
+ language.onDispose(() => editor.setSelectionRanges(null));
29
+ }
30
+ }
@@ -4,24 +4,27 @@
4
4
  * whole number of tokens. The caller then asks for the full tokens instead. One pass over data and edits.
5
5
  */
6
6
  export function applySemanticEdits(data, edits) {
7
- const result = [];
8
- let cursor = 0;
9
- for (const edit of edits) {
10
- const { start, deleteCount } = edit;
11
- const inserted = edit.data ?? [];
12
- if (!Number.isInteger(start) || !Number.isInteger(deleteCount) || start < cursor || deleteCount < 0 || start + deleteCount > data.length) {
13
- return null;
14
- }
15
- for (let at = cursor; at < start; at++) {
16
- result.push(data[at]);
17
- }
18
- for (const value of inserted) {
19
- result.push(value);
20
- }
21
- cursor = start + deleteCount;
7
+ const result = [];
8
+ let cursor = 0;
9
+ for (const edit of edits) {
10
+ const {
11
+ start,
12
+ deleteCount
13
+ } = edit;
14
+ const inserted = edit.data ?? [];
15
+ if (!Number.isInteger(start) || !Number.isInteger(deleteCount) || start < cursor || deleteCount < 0 || start + deleteCount > data.length) {
16
+ return null;
22
17
  }
23
- for (let at = cursor; at < data.length; at++) {
24
- result.push(data[at]);
18
+ for (let at = cursor; at < start; at++) {
19
+ result.push(data[at]);
25
20
  }
26
- return result.length % 5 === 0 ? result : null;
27
- }
21
+ for (const value of inserted) {
22
+ result.push(value);
23
+ }
24
+ cursor = start + deleteCount;
25
+ }
26
+ for (let at = cursor; at < data.length; at++) {
27
+ result.push(data[at]);
28
+ }
29
+ return result.length % 5 === 0 ? result : null;
30
+ }
@@ -5,86 +5,99 @@
5
5
  * marks what is local to a function, so a variable it leaves unmarked is drawn as a global.
6
6
  */
7
7
  export function scopesOf(type, modifiers, scoped = false) {
8
- switch (type) {
9
- case 'namespace':
10
- return ['entity.name.namespace'];
11
- case 'class':
12
- return ['entity.name.type.class'];
13
- case 'enum':
14
- return ['entity.name.type.enum'];
15
- case 'interface':
16
- return ['entity.name.type.interface'];
17
- case 'struct':
18
- return ['entity.name.type.struct'];
19
- case 'type':
20
- return ['entity.name.type'];
21
- case 'typeParameter':
22
- return ['entity.name.type.parameter'];
23
- case 'parameter':
24
- return ['variable.parameter'];
25
- case 'property':
26
- return [modifiers.has('static') ? 'variable.other.property.static' : 'variable.other.property'];
27
- case 'enumMember':
28
- return ['variable.other.enummember'];
29
- case 'function':
30
- case 'method':
31
- if (modifiers.has('static')) {
32
- return ['entity.name.function.static'];
33
- }
34
- if (modifiers.has('declaration')) {
35
- return ['entity.name.function'];
36
- }
37
- return [type === 'method' ? 'entity.name.function.method' : 'entity.name.function.call'];
38
- case 'decorator':
39
- return ['meta.decorator'];
40
- case 'macro':
41
- return ['entity.name.function.macro'];
42
- case 'variable':
43
- if (scoped) {
44
- return modifiers.has('local') ? null : ['variable.other.constant'];
45
- }
46
- return modifiers.has('readonly') ? ['variable.other.constant'] : null;
47
- default:
48
- return null;
49
- }
8
+ switch (type) {
9
+ case 'namespace':
10
+ return ['entity.name.namespace'];
11
+ case 'class':
12
+ return ['entity.name.type.class'];
13
+ case 'enum':
14
+ return ['entity.name.type.enum'];
15
+ case 'interface':
16
+ return ['entity.name.type.interface'];
17
+ case 'struct':
18
+ return ['entity.name.type.struct'];
19
+ case 'type':
20
+ return ['entity.name.type'];
21
+ case 'typeParameter':
22
+ return ['entity.name.type.parameter'];
23
+ case 'parameter':
24
+ return ['variable.parameter'];
25
+ case 'property':
26
+ return [modifiers.has('static') ? 'variable.other.property.static' : 'variable.other.property'];
27
+ case 'enumMember':
28
+ return ['variable.other.enummember'];
29
+ case 'function':
30
+ case 'method':
31
+ if (modifiers.has('static')) {
32
+ return ['entity.name.function.static'];
33
+ }
34
+ if (modifiers.has('declaration')) {
35
+ return ['entity.name.function'];
36
+ }
37
+ return [type === 'method' ? 'entity.name.function.method' : 'entity.name.function.call'];
38
+ case 'decorator':
39
+ return ['meta.decorator'];
40
+ case 'macro':
41
+ return ['entity.name.function.macro'];
42
+ case 'variable':
43
+ if (scoped) {
44
+ return modifiers.has('local') ? null : ['variable.other.constant'];
45
+ }
46
+ return modifiers.has('readonly') ? ['variable.other.constant'] : null;
47
+ default:
48
+ return null;
49
+ }
50
50
  }
51
51
  /*
52
52
  * What a server sends for the language it reads inside a string (SQL in a PHP string). Outside a string the grammar
53
53
  * colors these better, so they only apply where the grammar says it is a string.
54
54
  */
55
55
  const EMBEDDED_SCOPES = {
56
- keyword: ['keyword'],
57
- string: ['string'],
58
- number: ['constant.numeric'],
59
- comment: ['comment'],
60
- operator: ['keyword.operator']
56
+ keyword: ['keyword'],
57
+ string: ['string'],
58
+ number: ['constant.numeric'],
59
+ comment: ['comment'],
60
+ operator: ['keyword.operator']
61
61
  };
62
62
  /* The encoded data of `textDocument/semanticTokens` as one token per classified range, the ones the theme has nothing to say about left out. */
63
63
  export function decodeSemanticTokens(tokens, legend) {
64
- const result = [];
65
- const { data } = tokens;
66
- const scoped = legend.tokenModifiers.includes('local');
67
- let line = 0;
68
- let character = 0;
69
- for (let at = 0; at + 4 < data.length; at += 5) {
70
- const deltaLine = data[at];
71
- line += deltaLine;
72
- character = deltaLine === 0 ? character + data[at + 1] : data[at + 1];
73
- const type = legend.tokenTypes[data[at + 3]];
74
- if (type === undefined) {
75
- continue;
76
- }
77
- const bits = data[at + 4];
78
- const modifiers = new Set(legend.tokenModifiers.filter((_, index) => (bits & (1 << index)) !== 0));
79
- const scopes = scopesOf(type, modifiers, scoped);
80
- if (scopes !== null) {
81
- result.push({ line, character, length: data[at + 2], scopes });
82
- continue;
83
- }
84
- const embedded = EMBEDDED_SCOPES[type];
85
- if (embedded !== undefined) {
86
- result.push({ line, character, length: data[at + 2], scopes: embedded, within: 'string' });
87
- }
64
+ const result = [];
65
+ const {
66
+ data
67
+ } = tokens;
68
+ const scoped = legend.tokenModifiers.includes('local');
69
+ let line = 0;
70
+ let character = 0;
71
+ for (let at = 0; at + 4 < data.length; at += 5) {
72
+ const deltaLine = data[at];
73
+ line += deltaLine;
74
+ character = deltaLine === 0 ? character + data[at + 1] : data[at + 1];
75
+ const type = legend.tokenTypes[data[at + 3]];
76
+ if (type === undefined) {
77
+ continue;
88
78
  }
89
- return result;
90
- }
79
+ const bits = data[at + 4];
80
+ const modifiers = new Set(legend.tokenModifiers.filter((_, index) => (bits & 1 << index) !== 0));
81
+ const scopes = scopesOf(type, modifiers, scoped);
82
+ if (scopes !== null) {
83
+ result.push({
84
+ line,
85
+ character,
86
+ length: data[at + 2],
87
+ scopes
88
+ });
89
+ continue;
90
+ }
91
+ const embedded = EMBEDDED_SCOPES[type];
92
+ if (embedded !== undefined) {
93
+ result.push({
94
+ line,
95
+ character,
96
+ length: data[at + 2],
97
+ scopes: embedded,
98
+ within: 'string'
99
+ });
100
+ }
101
+ }
102
+ return result;
103
+ }