@adecore/editor-react 0.62.1 → 0.63.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 (264) hide show
  1. package/README.md +2 -2
  2. package/dist/AnchoredPopup.d.ts +2 -1
  3. package/dist/CompletionPopup.js +0 -2
  4. package/dist/DiffView.d.ts +1 -28
  5. package/dist/EditorView.js +0 -1
  6. package/dist/HoverSections.d.ts +1 -8
  7. package/dist/HoverSections.js +2 -2
  8. package/dist/LanguagePopups.js +30 -14
  9. package/dist/PanelResizeHandle.js +0 -1
  10. package/dist/PeekPanel.js +0 -1
  11. package/dist/PickPopup.js +0 -1
  12. package/dist/RenderedDocs.js +0 -2
  13. package/dist/SplitDiffView.d.ts +1 -1
  14. package/dist/SymbolPicker.js +0 -1
  15. package/dist/call-hierarchy-model.js +0 -4
  16. package/dist/call-hierarchy.d.ts +9 -2
  17. package/dist/call-hierarchy.js +51 -67
  18. package/dist/clipboard-history.d.ts +3 -0
  19. package/dist/clipboard-history.js +0 -1
  20. package/dist/code-actions-model.js +1 -1
  21. package/dist/code-actions.d.ts +14 -2
  22. package/dist/code-actions.js +14 -9
  23. package/dist/code-authors.js +4 -12
  24. package/dist/code-vision-model.d.ts +0 -1
  25. package/dist/code-vision-model.js +1 -2
  26. package/dist/code-vision.d.ts +11 -3
  27. package/dist/code-vision.js +13 -18
  28. package/dist/completion-call.d.ts +1 -1
  29. package/dist/completion-call.js +2 -1
  30. package/dist/completion-model.d.ts +5 -4
  31. package/dist/completion-model.js +4 -4
  32. package/dist/completion.d.ts +13 -4
  33. package/dist/completion.js +19 -18
  34. package/dist/context-menu-rows.d.ts +2 -1
  35. package/dist/context-menu.d.ts +9 -3
  36. package/dist/context-menu.js +17 -19
  37. package/dist/definition-link.d.ts +8 -2
  38. package/dist/definition-link.js +4 -2
  39. package/dist/diagnostics-model.d.ts +6 -8
  40. package/dist/diagnostics-model.js +1 -54
  41. package/dist/diagnostics.d.ts +9 -7
  42. package/dist/diagnostics.js +6 -4
  43. package/dist/diff-view-props.d.ts +28 -0
  44. package/dist/diff-view-props.js +1 -0
  45. package/dist/doc-comment-model.js +0 -2
  46. package/dist/document-colors.d.ts +9 -4
  47. package/dist/document-colors.js +7 -4
  48. package/dist/document-links.d.ts +2 -3
  49. package/dist/document-links.js +2 -3
  50. package/dist/document-query.d.ts +2 -2
  51. package/dist/edit-locations.js +4 -22
  52. package/dist/editor-language.d.ts +12 -7
  53. package/dist/editor-language.js +54 -45
  54. package/dist/emmet.d.ts +3 -2
  55. package/dist/folding.d.ts +2 -4
  56. package/dist/folding.js +1 -2
  57. package/dist/format-on-type.d.ts +8 -2
  58. package/dist/format-on-type.js +8 -6
  59. package/dist/highlights.d.ts +2 -6
  60. package/dist/highlights.js +3 -3
  61. package/dist/history.d.ts +8 -2
  62. package/dist/history.js +4 -2
  63. package/dist/host-types.d.ts +39 -22
  64. package/dist/hover-content.js +0 -1
  65. package/dist/hover.d.ts +13 -2
  66. package/dist/hover.js +25 -28
  67. package/dist/index.d.ts +19 -9
  68. package/dist/index.js +5 -2
  69. package/dist/inlay-hints.d.ts +12 -21
  70. package/dist/inlay-hints.js +16 -15
  71. package/dist/inline-completion.d.ts +30 -10
  72. package/dist/inline-completion.js +346 -102
  73. package/dist/key-priority.d.ts +1 -1
  74. package/dist/key-priority.js +2 -2
  75. package/dist/language-context.d.ts +30 -0
  76. package/dist/language-context.js +1 -0
  77. package/dist/language-ids.d.ts +0 -1
  78. package/dist/language-ids.js +0 -32
  79. package/dist/line-text.js +0 -1
  80. package/dist/linked-editing.d.ts +2 -4
  81. package/dist/linked-editing.js +1 -3
  82. package/dist/live-templates.d.ts +14 -2
  83. package/dist/live-templates.js +15 -10
  84. package/dist/locales/en.d.ts +357 -0
  85. package/dist/locales/en.js +356 -0
  86. package/dist/locales/nl.d.ts +357 -0
  87. package/dist/locales/nl.js +356 -0
  88. package/dist/markup-context.d.ts +7 -6
  89. package/dist/markup-context.js +0 -1
  90. package/dist/markup.d.ts +8 -2
  91. package/dist/markup.js +19 -20
  92. package/dist/models.d.ts +2 -1
  93. package/dist/models.js +2 -1
  94. package/dist/navigation-history.d.ts +7 -0
  95. package/dist/navigation.d.ts +11 -8
  96. package/dist/navigation.js +9 -20
  97. package/dist/panel-size.d.ts +4 -0
  98. package/dist/paste-history.d.ts +8 -2
  99. package/dist/paste-history.js +4 -2
  100. package/dist/patch-layout.d.ts +0 -4
  101. package/dist/patch-layout.js +1 -1
  102. package/dist/peek-model.js +0 -1
  103. package/dist/peek.d.ts +8 -2
  104. package/dist/peek.js +31 -42
  105. package/dist/pick.d.ts +4 -2
  106. package/dist/pick.js +38 -15
  107. package/dist/popups.d.ts +25 -20
  108. package/dist/popups.js +31 -15
  109. package/dist/positions.d.ts +7 -0
  110. package/dist/positions.js +54 -0
  111. package/dist/postfix.d.ts +11 -2
  112. package/dist/postfix.js +10 -6
  113. package/dist/project-language.d.ts +11 -3
  114. package/dist/project-language.js +40 -9
  115. package/dist/project-problems.d.ts +7 -1
  116. package/dist/project-problems.js +2 -1
  117. package/dist/rename-model.js +1 -1
  118. package/dist/rename.d.ts +2 -2
  119. package/dist/rename.js +17 -22
  120. package/dist/rendered-docs.d.ts +8 -2
  121. package/dist/rendered-docs.js +5 -4
  122. package/dist/selection-ranges.d.ts +2 -2
  123. package/dist/semantic-tokens.d.ts +2 -4
  124. package/dist/semantic-tokens.js +2 -2
  125. package/dist/shortcut-keys.d.ts +2 -1
  126. package/dist/signature.d.ts +2 -2
  127. package/dist/signature.js +9 -15
  128. package/dist/snippet-field-transforms.js +1 -1
  129. package/dist/snippet-insert.d.ts +4 -2
  130. package/dist/snippet-insert.js +9 -15
  131. package/dist/snippet-session.d.ts +9 -4
  132. package/dist/snippet-session.js +14 -14
  133. package/dist/snippet-transform-format.d.ts +2 -1
  134. package/dist/snippet-transform-queue.d.ts +2 -4
  135. package/dist/snippet-transform-queue.js +5 -37
  136. package/dist/snippet.d.ts +2 -1
  137. package/dist/surround-constructs.d.ts +1 -1
  138. package/dist/surround.d.ts +13 -2
  139. package/dist/surround.js +15 -8
  140. package/dist/symbol-links.d.ts +0 -1
  141. package/dist/symbol-links.js +1 -1
  142. package/dist/symbol-picker-model.d.ts +0 -1
  143. package/dist/symbol-picker-model.js +1 -2
  144. package/dist/symbol-picker.d.ts +2 -2
  145. package/dist/symbol-picker.js +5 -10
  146. package/dist/symbols.d.ts +4 -3
  147. package/dist/template-builtins.d.ts +1 -1
  148. package/dist/template-builtins.js +0 -1
  149. package/dist/template-context.d.ts +3 -3
  150. package/dist/template-context.js +2 -11
  151. package/dist/template-types.d.ts +20 -0
  152. package/dist/template-types.js +1 -0
  153. package/dist/templates.d.ts +5 -20
  154. package/dist/templates.js +0 -1
  155. package/dist/testing.d.ts +6 -0
  156. package/dist/testing.js +42 -0
  157. package/dist/use-problem-counts.d.ts +1 -1
  158. package/dist/word-diff.d.ts +1 -1
  159. package/dist/word-diff.js +16 -25
  160. package/dist/workspace-edit.d.ts +1 -24
  161. package/dist/workspace-edit.js +0 -1
  162. package/package.json +10 -9
  163. package/src/AnchoredPopup.tsx +1 -1
  164. package/src/CompletionPopup.tsx +0 -2
  165. package/src/DiffView.tsx +6 -38
  166. package/src/EditorView.tsx +0 -1
  167. package/src/HoverSections.tsx +2 -2
  168. package/src/LanguagePopups.tsx +20 -14
  169. package/src/PanelResizeHandle.tsx +0 -1
  170. package/src/PeekPanel.tsx +0 -1
  171. package/src/PickPopup.tsx +0 -1
  172. package/src/RenderedDocs.tsx +0 -2
  173. package/src/SplitDiffView.tsx +1 -1
  174. package/src/SymbolPicker.tsx +0 -1
  175. package/src/call-hierarchy-model.ts +0 -7
  176. package/src/call-hierarchy.ts +32 -31
  177. package/src/clipboard-history.ts +5 -2
  178. package/src/code-actions-model.ts +1 -4
  179. package/src/code-actions.ts +26 -10
  180. package/src/code-authors.ts +4 -15
  181. package/src/code-vision-model.ts +1 -2
  182. package/src/code-vision.ts +23 -19
  183. package/src/completion-call.ts +2 -2
  184. package/src/completion-model.ts +12 -7
  185. package/src/completion.ts +31 -16
  186. package/src/context-menu-rows.ts +1 -1
  187. package/src/context-menu.ts +19 -10
  188. package/src/definition-link.ts +12 -4
  189. package/src/diagnostics-model.ts +8 -55
  190. package/src/diagnostics.ts +11 -20
  191. package/src/diff-view-props.ts +38 -0
  192. package/src/doc-comment-model.ts +0 -2
  193. package/src/document-colors.ts +14 -6
  194. package/src/document-links.ts +5 -6
  195. package/src/document-query.ts +3 -3
  196. package/src/edit-locations.ts +4 -19
  197. package/src/editor-language.ts +74 -39
  198. package/src/emmet.ts +2 -3
  199. package/src/folding.ts +4 -5
  200. package/src/format-on-type.ts +14 -7
  201. package/src/highlights.ts +6 -6
  202. package/src/history.ts +12 -4
  203. package/src/host-types.ts +52 -33
  204. package/src/hover-content.ts +0 -1
  205. package/src/hover.ts +29 -22
  206. package/src/index.ts +25 -14
  207. package/src/inlay-hints.ts +23 -17
  208. package/src/inline-completion.ts +340 -90
  209. package/src/key-priority.ts +2 -2
  210. package/src/language-context.ts +60 -0
  211. package/src/language-ids.ts +0 -34
  212. package/src/line-text.ts +0 -1
  213. package/src/linked-editing.ts +4 -6
  214. package/src/live-templates.ts +27 -13
  215. package/src/locales/en.ts +356 -0
  216. package/src/locales/nl.ts +356 -0
  217. package/src/markup-context.ts +6 -9
  218. package/src/markup.ts +19 -10
  219. package/src/models.ts +2 -1
  220. package/src/navigation-history.ts +11 -0
  221. package/src/navigation.ts +18 -20
  222. package/src/panel-size.ts +8 -0
  223. package/src/paste-history.ts +12 -4
  224. package/src/patch-layout.ts +1 -1
  225. package/src/peek-model.ts +0 -1
  226. package/src/peek.ts +22 -18
  227. package/src/pick.ts +30 -16
  228. package/src/popups.ts +61 -40
  229. package/src/positions.ts +54 -0
  230. package/src/postfix.ts +21 -8
  231. package/src/project-language.ts +63 -14
  232. package/src/project-problems.ts +10 -2
  233. package/src/proposal-model.ts +0 -1
  234. package/src/rename-model.ts +1 -1
  235. package/src/rename.ts +21 -24
  236. package/src/rendered-docs.ts +13 -6
  237. package/src/selection-ranges.ts +2 -2
  238. package/src/semantic-tokens.ts +5 -5
  239. package/src/shortcut-keys.ts +1 -1
  240. package/src/signature.ts +8 -8
  241. package/src/snippet-field-transforms.ts +1 -1
  242. package/src/snippet-insert.ts +21 -14
  243. package/src/snippet-session.ts +25 -24
  244. package/src/snippet-transform-format.ts +1 -1
  245. package/src/snippet-transform-queue.ts +5 -51
  246. package/src/snippet.ts +1 -1
  247. package/src/surround-constructs.ts +1 -1
  248. package/src/surround.ts +24 -12
  249. package/src/symbol-links.ts +1 -1
  250. package/src/symbol-picker-model.ts +1 -4
  251. package/src/symbol-picker.ts +6 -7
  252. package/src/symbols.ts +3 -4
  253. package/src/template-builtins.ts +1 -2
  254. package/src/template-context.ts +5 -14
  255. package/src/template-types.ts +43 -0
  256. package/src/templates.ts +9 -45
  257. package/src/testing.ts +52 -0
  258. package/src/use-problem-counts.ts +1 -1
  259. package/src/word-diff.ts +17 -28
  260. package/src/workspace-edit.ts +1 -34
  261. package/dist/locales/en.json +0 -356
  262. package/dist/locales/nl.json +0 -356
  263. package/src/locales/en.json +0 -356
  264. package/src/locales/nl.json +0 -356
@@ -1,11 +1,10 @@
1
- import { comparePositions, endOfInsertion, rangeHolds, sameRange, shiftPosition } from './diagnostics-model.js';
2
1
  import { KEY_PRIORITY } from './key-priority.js';
3
2
  import { textBeforeOf } from './line-text.js';
3
+ import { comparePositions, endOfInsertion, rangeHolds, sameRange, shiftPosition } from './positions.js';
4
4
  import { SnippetFieldTransforms } from './snippet-field-transforms.js';
5
5
  import { compareSnippetOrder, snippetOrderOf } from './snippet-range-order.js';
6
6
  import { SnippetTransformError } from './snippet-transform-client.js';
7
7
  import { MAX_TRANSFORM_CHARACTERS } from './snippet-transform-protocol.js';
8
- import { acquireSnippetTransforms } from './snippet-transform-queue.js';
9
8
  import { realTimers } from './timers.js';
10
9
  export function positionInInsertion(start, text, offset) {
11
10
  return endOfInsertion(start, text.slice(0, offset));
@@ -129,6 +128,7 @@ function activeOwners(active, changes) {
129
128
  }
130
129
  export class SnippetFeature {
131
130
  language;
131
+ peers;
132
132
  frames = [];
133
133
  placed = [];
134
134
  visiting = false;
@@ -140,15 +140,16 @@ export class SnippetFeature {
140
140
  fieldTransforms;
141
141
  exitGeneration = 0;
142
142
  detached = null;
143
- constructor(language, timers = realTimers) {
143
+ constructor(language, peers, timers = realTimers) {
144
144
  this.language = language;
145
- this.transforms = language.project === undefined ? null : acquireSnippetTransforms(language.project, timers);
145
+ this.peers = peers;
146
+ this.transforms = language.project === undefined ? null : language.project.acquireSnippetTransforms(timers);
146
147
  const {
147
148
  editor
148
149
  } = language;
149
150
  this.fieldTransforms = new SnippetFieldTransforms(editor, this.transforms, (targets, values) => this.applyFieldTransforms(targets, values));
150
151
  const key = event => this.key(event);
151
- const offs = [language.onKey === undefined ? editor.onKeyDown(key) : language.onKey(key, KEY_PRIORITY.snippets), editor.onTextChange(change => this.edited(change)), editor.onCaret(() => this.moved())];
152
+ const offs = [language.onKey(key, KEY_PRIORITY.snippets), editor.onTextChange(change => this.edited(change)), editor.onCaret(() => this.moved())];
152
153
  language.onDispose(() => {
153
154
  this.transforms?.dispose();
154
155
  this.end();
@@ -276,9 +277,9 @@ export class SnippetFeature {
276
277
  this.placed = [];
277
278
  }
278
279
  closeChoices() {
279
- const view = this.language.popups?.getState().pick;
280
+ const view = this.language.popups.slot('pick').get();
280
281
  if (this.choicePrefix !== null && view?.groups.some(group => group.rows.some(row => row.id.startsWith(this.choicePrefix)))) {
281
- this.language.pick?.close();
282
+ this.peers.pick.close();
282
283
  }
283
284
  this.choicePrefix = null;
284
285
  }
@@ -331,7 +332,6 @@ export class SnippetFeature {
331
332
  this.openChoices(frame);
332
333
  }
333
334
  }
334
- /* Says which field the caret moved to, with the number of choices when the field is a list. */
335
335
  announceField(frame, index) {
336
336
  const i18n = this.language.project?.i18n;
337
337
  if (i18n === undefined) {
@@ -353,13 +353,13 @@ export class SnippetFeature {
353
353
  }
354
354
  openChoices(frame, activeChoice) {
355
355
  const field = this.fieldOf(frame);
356
- if (field?.choices === undefined || field.choices.length === 0 || this.language.pick === undefined) {
356
+ if (field?.choices === undefined || field.choices.length === 0) {
357
357
  return;
358
358
  }
359
359
  const token = this.generation;
360
360
  const prefix = `snippet-${token}-`;
361
361
  this.choicePrefix = prefix;
362
- this.language.pick.open({
362
+ this.peers.pick.open({
363
363
  anchor: field.ranges[field.primary].start,
364
364
  title: this.language.project?.i18n.t('editor:language.snippet.choices'),
365
365
  active: prefix + (activeChoice ?? Math.max(0, field.choices.indexOf(this.language.editor.textInRange(field.ranges[field.primary])))),
@@ -417,8 +417,8 @@ export class SnippetFeature {
417
417
  return true;
418
418
  }
419
419
  if (event.key === 'Escape') {
420
- const popups = this.language.popups?.getState();
421
- if (popups !== undefined && [popups.completion, popups.signature, popups.hover, popups.pick, popups.peek, popups.callHierarchy].some(popup => popup !== null)) {
420
+ const popups = this.language.popups;
421
+ if (['completion', 'signature', 'hover', 'pick', 'peek', 'callHierarchy'].some(name => popups.slot(name).get() !== null)) {
422
422
  return false;
423
423
  }
424
424
  const active = this.isActive;
@@ -567,7 +567,7 @@ export class SnippetFeature {
567
567
  }
568
568
  }
569
569
  const frame = this.frames.at(-1);
570
- const pick = this.language.popups?.getState().pick;
570
+ const pick = this.language.popups.slot('pick').get();
571
571
  const activeChoice = this.choicePrefix !== null && pick?.active.startsWith(this.choicePrefix) ? Number(pick.active.slice(this.choicePrefix.length)) : undefined;
572
572
  const trackedFrames = [...new Set([...this.frames, ...targets.map(target => target.frame)])];
573
573
  const transformIds = new Set(targets.map(target => target.id));
@@ -626,7 +626,7 @@ export class SnippetFeature {
626
626
  this.detached = null;
627
627
  }
628
628
  // The generic picker closes on any text edit, including an exit elsewhere in the snippet.
629
- if (frame !== undefined && frame === this.frames.at(-1) && activeChoice !== undefined && this.language.popups?.getState().pick === null) {
629
+ if (frame !== undefined && frame === this.frames.at(-1) && activeChoice !== undefined && this.language.popups.slot('pick').get() === null) {
630
630
  this.openChoices(frame, activeChoice);
631
631
  }
632
632
  }
@@ -7,9 +7,10 @@ export declare function scanSnippetTransform(source: string, at: number): {
7
7
  end: number;
8
8
  };
9
9
  export declare function validateSnippetTransformJobs(jobs: readonly SnippetTransformJob[]): void;
10
- export interface SnippetTransformBudget {
10
+ interface SnippetTransformBudget {
11
11
  remaining: number;
12
12
  matches: number;
13
13
  }
14
14
  export declare function createSnippetTransformBudget(): SnippetTransformBudget;
15
15
  export declare function applySnippetTransform(job: SnippetTransformJob, maximum?: number, expression?: RegExp, budget?: SnippetTransformBudget): string;
16
+ export {};
@@ -1,5 +1,4 @@
1
1
  import type { WorkerRequestPort } from '@adecore/editor/worker-client';
2
- import type { ProjectLanguage } from './project-language.ts';
3
2
  import { type SnippetTransformJob } from './snippet-transform-protocol.ts';
4
3
  import { type Timers } from './timers.ts';
5
4
  interface RequestOptions {
@@ -20,13 +19,12 @@ export declare class SnippetTransforms {
20
19
  private active;
21
20
  private idle;
22
21
  private disposed;
23
- constructor(factory: () => WorkerRequestPort, timers?: Timers);
22
+ private readonly onDispose;
23
+ constructor(factory: () => WorkerRequestPort, timers?: Timers, onDispose?: () => void);
24
24
  acquire(): SnippetTransformLease;
25
25
  private request;
26
26
  private pump;
27
27
  private releaseOwner;
28
28
  dispose(): void;
29
29
  }
30
- export declare function acquireSnippetTransforms(project: ProjectLanguage, timers: Timers): SnippetTransformLease | null;
31
- export declare function disposeSnippetTransforms(project: ProjectLanguage): void;
32
30
  export {};
@@ -13,8 +13,11 @@ export class SnippetTransforms {
13
13
  active = null;
14
14
  idle;
15
15
  disposed = false;
16
- constructor(factory, timers = realTimers) {
16
+ onDispose;
17
+ /* `onDispose` runs when the queue ends, whether its owner called for it or the last lease let go. */
18
+ constructor(factory, timers = realTimers, onDispose) {
17
19
  this.timers = timers;
20
+ this.onDispose = onDispose;
18
21
  this.client = createSnippetTransformClient({
19
22
  workerFactory: factory,
20
23
  schedule: (callback, delay) => {
@@ -143,41 +146,6 @@ export class SnippetTransforms {
143
146
  this.pending.forEach(job => job.reject(error));
144
147
  this.pending = [];
145
148
  this.client.dispose();
149
+ this.onDispose?.();
146
150
  }
147
- }
148
- const projects = new WeakMap();
149
- export function acquireSnippetTransforms(project, timers) {
150
- const factory = project.host.snippetTransformWorker;
151
- if (factory === undefined) {
152
- return null;
153
- }
154
- let entry = projects.get(project);
155
- if (entry === undefined) {
156
- entry = {
157
- queue: new SnippetTransforms(factory, timers),
158
- references: 0
159
- };
160
- projects.set(project, entry);
161
- }
162
- const held = entry,
163
- lease = held.queue.acquire();
164
- held.references++;
165
- let disposed = false;
166
- return {
167
- request: (jobs, options) => lease.request(jobs, options),
168
- dispose: () => {
169
- if (disposed) {
170
- return;
171
- }
172
- disposed = true;
173
- lease.dispose();
174
- if (--held.references === 0 && projects.get(project) === held) {
175
- projects.delete(project);
176
- }
177
- }
178
- };
179
- }
180
- export function disposeSnippetTransforms(project) {
181
- projects.get(project)?.queue.dispose();
182
- projects.delete(project);
183
151
  }
package/dist/snippet.d.ts CHANGED
@@ -28,7 +28,7 @@ export interface ParsedSnippet {
28
28
  })[];
29
29
  }
30
30
  export type SnippetVariableResolver = (name: string) => string | undefined;
31
- export interface SnippetRenderOptions {
31
+ interface SnippetRenderOptions {
32
32
  readonly indentVariables?: boolean;
33
33
  }
34
34
  export interface SnippetTemplate {
@@ -42,3 +42,4 @@ export declare function tabOrder(parsed: ParsedSnippet): SnippetStop[];
42
42
  export declare function snippetVariables(source: string): ReadonlySet<string>;
43
43
  export declare function checkSnippet(source: string): string | null;
44
44
  export declare function escapeSnippetText(text: string): string;
45
+ export {};
@@ -1,5 +1,5 @@
1
1
  import type { CommentSyntax } from '@adecore/editor';
2
- import type { TemplateLanguage } from './templates.ts';
2
+ import type { TemplateLanguage } from './template-types.ts';
3
3
  export interface Construct {
4
4
  readonly id: string;
5
5
  readonly label: string;
@@ -1,7 +1,17 @@
1
- import type { EditorLanguage } from './editor-language.ts';
1
+ import type { LanguageContext } from './language-context.ts';
2
+ import type { MarkupFeature } from './markup.ts';
3
+ import type { PickFeature } from './pick.ts';
4
+ import { type InsertingSnippets } from './snippet-insert.ts';
5
+ import type { SnippetFeature } from './snippet-session.ts';
6
+ interface SurroundPeers {
7
+ readonly pick: Pick<PickFeature, 'open'>;
8
+ readonly markup: Pick<MarkupFeature, 'startWrap' | 'supported'>;
9
+ readonly snippets: InsertingSnippets & Pick<SnippetFeature, 'end'>;
10
+ }
2
11
  export declare class SurroundFeature {
3
12
  private readonly language;
4
- constructor(language: EditorLanguage);
13
+ private readonly peers;
14
+ constructor(language: LanguageContext, peers: SurroundPeers);
5
15
  open(): boolean;
6
16
  openTemplates(): boolean;
7
17
  unwrap(): boolean;
@@ -16,3 +26,4 @@ export declare class SurroundFeature {
16
26
  private applyUnwrap;
17
27
  private unwrapPreview;
18
28
  }
29
+ export {};
package/dist/surround.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import { commentSyntax } from '@adecore/editor';
2
- import { comparePositions, shiftRange } from './diagnostics-model.js';
3
2
  import { KEY_PRIORITY } from './key-priority.js';
4
3
  import { lineTextOf, textBeforeOf } from './line-text.js';
5
4
  import { enclosingElements, lineEndOf, lineStartOf, markupSyntaxOf, removeTagEdits } from './markup-context.js';
5
+ import { comparePositions, shiftRange } from './positions.js';
6
6
  import { isShortcut } from './shortcut-keys.js';
7
7
  import { indentSnippet } from './snippet-indent.js';
8
8
  import { bodyWithIndentUnit, dedentLines, insertSnippet } from './snippet-insert.js';
@@ -52,8 +52,10 @@ function mergedRanges(ranges) {
52
52
  */
53
53
  export class SurroundFeature {
54
54
  language;
55
- constructor(language) {
55
+ peers;
56
+ constructor(language, peers) {
56
57
  this.language = language;
58
+ this.peers = peers;
57
59
  language.onDispose(language.onKey(event => {
58
60
  if (isShortcut(language.shortcuts.surroundWith, event)) {
59
61
  return this.open();
@@ -76,9 +78,11 @@ export class SurroundFeature {
76
78
  unwrap() {
77
79
  const {
78
80
  editor,
79
- pick,
80
81
  project
81
82
  } = this.language;
83
+ const {
84
+ pick
85
+ } = this.peers;
82
86
  if (editor.isReadOnly?.() === true) {
83
87
  return true;
84
88
  }
@@ -107,9 +111,11 @@ export class SurroundFeature {
107
111
  show(templatesOnly) {
108
112
  const {
109
113
  editor,
110
- pick,
111
114
  project
112
115
  } = this.language;
116
+ const {
117
+ pick
118
+ } = this.peers;
113
119
  if (editor.isReadOnly?.() === true) {
114
120
  return true;
115
121
  }
@@ -236,7 +242,9 @@ export class SurroundFeature {
236
242
  }
237
243
  }
238
244
  const live = [];
239
- const markup = this.language.markup;
245
+ const {
246
+ markup
247
+ } = this.peers;
240
248
  if (markup.supported && (families.includes('html') || families.includes('xml')) && this.language.editor.getSelections().length === 1) {
241
249
  live.push({
242
250
  row: {
@@ -285,8 +293,8 @@ export class SurroundFeature {
285
293
  }
286
294
  /* Inserts the snippet around every range; a snippet that still runs ends first, as the previous template does in IntelliJ. */
287
295
  insert(source, placements) {
288
- this.language.snippets.end();
289
- void insertSnippet(this.language, bodyWithIndentUnit(source, this.indentUnit()), placements);
296
+ this.peers.snippets.end();
297
+ void insertSnippet(this.language, this.peers.snippets, bodyWithIndentUnit(source, this.indentUnit()), placements);
290
298
  }
291
299
  indentUnit() {
292
300
  const {
@@ -379,7 +387,6 @@ export class SurroundFeature {
379
387
  });
380
388
  editor.focus();
381
389
  }
382
- /* The lines of the construct before and after its edits. */
383
390
  unwrapPreview(text, row) {
384
391
  const edits = row.edits;
385
392
  const from = lineStartOf(text, Math.min(row.from, ...edits.map(edit => edit.from)));
@@ -1,5 +1,4 @@
1
1
  import type { Location, WorkspaceSymbolResult } from '@adecore/lsp';
2
- export declare const SYMBOL_LINK_CLASS = "cursor-pointer hover:text-accent hover:underline";
3
2
  export declare function isTypeName(name: string): boolean;
4
3
  export declare function linkTypeNames(html: string): string;
5
4
  export declare function declaredNameOf(code: string): string | null;
@@ -1,6 +1,6 @@
1
1
  import { uniqueBy } from './unique.js';
2
2
  /* The classes a name in a signature has: a pointer, an underline and the accent, all only on hover, so the signature keeps its colors at rest. */
3
- export const SYMBOL_LINK_CLASS = 'cursor-pointer hover:text-accent hover:underline';
3
+ const SYMBOL_LINK_CLASS = 'cursor-pointer hover:text-accent hover:underline';
4
4
  const TYPE_NAME = /^[A-Z][A-Za-z0-9_]*$/;
5
5
  /* A name that starts with a capital and has a lowercase letter, which leaves `DEFAULT_WEIGHTS` and `T` alone. */
6
6
  export function isTypeName(name) {
@@ -1,6 +1,5 @@
1
1
  import type { DocumentSymbolResult, WorkspaceSymbolResult } from '@adecore/lsp';
2
2
  export type SymbolGroup = 'namespaces' | 'classes' | 'interfaces' | 'enums' | 'functions' | 'methods' | 'properties' | 'variables' | 'constants' | 'other';
3
- export declare const SYMBOL_GROUPS: readonly SymbolGroup[];
4
3
  export declare function groupOfKind(kind: number): SymbolGroup;
5
4
  export declare function letterOfKind(kind: number): string;
6
5
  export type SymbolTone = 'callable' | 'value' | 'type' | 'other';
@@ -1,5 +1,5 @@
1
1
  /* The order the groups are listed in: what a file declares, then what those declare. */
2
- export const SYMBOL_GROUPS = ['namespaces', 'classes', 'interfaces', 'enums', 'functions', 'methods', 'properties', 'variables', 'constants', 'other'];
2
+ const SYMBOL_GROUPS = ['namespaces', 'classes', 'interfaces', 'enums', 'functions', 'methods', 'properties', 'variables', 'constants', 'other'];
3
3
  const GROUP_OF_KIND = {
4
4
  2: 'namespaces',
5
5
  3: 'namespaces',
@@ -34,7 +34,6 @@ const LETTERS = {
34
34
  constants: 'c',
35
35
  other: '·'
36
36
  };
37
- /* The letter in the badge in front of a symbol. */
38
37
  export function letterOfKind(kind) {
39
38
  return kind === ENUM_MEMBER ? 'e' : LETTERS[groupOfKind(kind)];
40
39
  }
@@ -1,8 +1,8 @@
1
- import type { EditorLanguage } from './editor-language.ts';
1
+ import type { LanguageContext } from './language-context.ts';
2
2
  import { type SymbolEntry, type WorkspaceEntry } from './symbol-picker-model.ts';
3
3
  export declare class SymbolPickerFeature {
4
4
  private readonly language;
5
- constructor(language: EditorLanguage);
5
+ constructor(language: LanguageContext);
6
6
  open(): Promise<void>;
7
7
  close(): void;
8
8
  goTo(entry: SymbolEntry): void;
@@ -41,11 +41,9 @@ export class SymbolPickerFeature {
41
41
  }
42
42
  try {
43
43
  const entries = entriesOf(await this.language.service.documentSymbols(uri));
44
- popups.setState({
45
- symbols: {
46
- file: basenameOf(this.language.uri),
47
- entries
48
- }
44
+ popups.slot('symbols').set({
45
+ file: basenameOf(this.language.uri),
46
+ entries
49
47
  });
50
48
  } catch (error) {
51
49
  if (!(error instanceof StaleResultError)) {
@@ -60,14 +58,11 @@ export class SymbolPickerFeature {
60
58
  }
61
59
  }
62
60
  close() {
63
- if (this.language.popups.getState().symbols !== null) {
64
- this.language.popups.setState({
65
- symbols: null
66
- });
61
+ if (this.language.popups.slot('symbols').get() !== null) {
62
+ this.language.popups.slot('symbols').set(null);
67
63
  this.language.editor.focus();
68
64
  }
69
65
  }
70
- /* Puts the caret on a symbol of the file. */
71
66
  goTo(entry) {
72
67
  this.close();
73
68
  this.language.jump({
package/dist/symbols.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import type { EditorBlock } from '@adecore/editor';
2
2
  import type { DocumentSymbolResult, Range } from '@adecore/lsp';
3
- import type { EditorLanguage } from './editor-language.ts';
3
+ import type { LanguageContext } from './language-context.ts';
4
4
  import { type Timers } from './timers.ts';
5
- export interface SymbolSpan {
5
+ interface SymbolSpan {
6
6
  readonly name: string;
7
7
  readonly kind: number;
8
8
  readonly range: Range;
@@ -13,6 +13,7 @@ export declare function blocksOf(result: DocumentSymbolResult, text?: string): E
13
13
  export declare class SymbolsFeature {
14
14
  private readonly refresher;
15
15
  private readonly listeners;
16
- constructor(language: EditorLanguage, timers?: Timers);
16
+ constructor(language: LanguageContext, timers?: Timers);
17
17
  onResult(listener: (result: DocumentSymbolResult) => void): () => void;
18
18
  }
19
+ export {};
@@ -1,3 +1,3 @@
1
- import type { LiveTemplate, PostfixTemplate } from './templates.ts';
1
+ import type { LiveTemplate, PostfixTemplate } from './template-types.ts';
2
2
  export declare const BUILT_IN_LIVE_TEMPLATES: readonly LiveTemplate[];
3
3
  export declare const BUILT_IN_POSTFIX_TEMPLATES: readonly PostfixTemplate[];
@@ -16,7 +16,6 @@ function phpFunction(key, modifiers, description) {
16
16
  }
17
17
  /* The keys and bodies of the live templates IntelliJ ships for JavaScript, PHP, HTML and XML. */
18
18
  export const BUILT_IN_LIVE_TEMPLATES = [live('javascript', 'log', ['javascript'], 'console.log($0);', 'Prints a value to the console'), live('javascript', 'itar', ['javascript'], body('for (let ${1:i} = 0; $1 < ${2:array}.length; $1++) {', '\tconst ${3:element} = $2[$1];', '\t$0', '}'), 'Iterate elements of array'), live('javascript', 'ritar', ['javascript'], body('for (let ${1:i} = ${2:array}.length - 1; $1 >= 0; $1--) {', '\tconst ${3:element} = $2[$1];', '\t$0', '}'), 'Iterate elements of array in reverse order'), live('javascript', 'iter', ['javascript'], body('for (const ${1:item} of ${2:iterable}) {', '\t$0', '}'), 'Iterate (for...of)'), live('javascript', 'itin', ['javascript'], body('for (const ${1:key} in ${2:object}) {', '\t$0', '}'), 'Iterate (for...in)'), live('php', 'fore', ['php'], body('foreach (\\$${1:iterable} as \\$${2:value}) {', '\t$0', '}'), 'foreach(iterable_expr as $value) {...}'), live('php', 'forek', ['php'], body('foreach (\\$${1:iterable} as \\$${2:key} => \\$${3:value}) {', '\t$0', '}'), 'foreach(iterable_expr as $key => $value) {...}'), phpFunction('pubf', 'public', 'public function'), phpFunction('prif', 'private', 'private function'), phpFunction('prof', 'protected', 'protected function'), phpFunction('pubsf', 'public static', 'public static function'), live('php', 'thr', ['php'], 'throw new $0;', 'throw new'), live('html', 'T', ['html', 'xml'], '<${1:tag}>$TM_SELECTED_TEXT</${1/\\s.*//}>', 'Surround with <tag></tag>'), live('xml', 'CD', ['xml'], body('<![CDATA[', '$TM_SELECTED_TEXT', ']]>'), 'Surround with CDATA section')];
19
- /* A block statement around the expression, with the caret inside it. */
20
19
  function block(head) {
21
20
  return body(`${head} {`, '\t$0', '}');
22
21
  }
@@ -1,6 +1,6 @@
1
1
  import type { EditorPosition } from '@adecore/editor';
2
- import type { EditorLanguage } from './editor-language.ts';
3
- import type { LiveTemplate, TemplateLanguage, TemplatePlace } from './templates.ts';
2
+ import type { LanguageContext } from './language-context.ts';
3
+ import type { LiveTemplate, TemplateLanguage, TemplatePlace } from './template-types.ts';
4
4
  export declare const SNIPPET_KIND = 15;
5
5
  export declare function sortAfterServer(key: string): string;
6
6
  export declare function familiesOf(languageId: string): readonly TemplateLanguage[];
@@ -8,5 +8,5 @@ export interface TemplateContext {
8
8
  readonly families: readonly TemplateLanguage[];
9
9
  readonly place: TemplatePlace;
10
10
  }
11
- export declare function templateContextAt(language: EditorLanguage, position: EditorPosition): TemplateContext;
11
+ export declare function templateContextAt(language: LanguageContext, position: EditorPosition): TemplateContext;
12
12
  export declare function templateApplies(template: LiveTemplate, context: TemplateContext): boolean;
@@ -1,4 +1,4 @@
1
- /* The completion item kind of a snippet. */
1
+ import { lspLanguageId } from '@adecore/lsp';
2
2
  export const SNIPPET_KIND = 15;
3
3
  /* Sorts a template row after the rows of the same score that a service answers. */
4
4
  export function sortAfterServer(key) {
@@ -6,19 +6,11 @@ export function sortAfterServer(key) {
6
6
  }
7
7
  /* The families a language id counts as; TypeScript builds on JavaScript. */
8
8
  export function familiesOf(languageId) {
9
- switch (languageId) {
9
+ switch (lspLanguageId(languageId)) {
10
10
  case 'javascript':
11
- case 'js':
12
- case 'mjs':
13
- case 'cjs':
14
- case 'jsx':
15
11
  case 'javascriptreact':
16
12
  return ['javascript'];
17
13
  case 'typescript':
18
- case 'ts':
19
- case 'mts':
20
- case 'cts':
21
- case 'tsx':
22
14
  case 'typescriptreact':
23
15
  return ['javascript', 'typescript'];
24
16
  case 'php':
@@ -50,7 +42,6 @@ export function templateContextAt(language, position) {
50
42
  place: place.kind
51
43
  };
52
44
  }
53
- /* Whether a template shares a family with the context and applies to its place. */
54
45
  export function templateApplies(template, context) {
55
46
  return template.languages.some(family => context.families.includes(family)) && (template.places ?? ['code']).includes(context.place);
56
47
  }
@@ -0,0 +1,20 @@
1
+ export type TemplateLanguage = 'javascript' | 'typescript' | 'php' | 'css' | 'html' | 'xml' | 'other';
2
+ export type TemplatePlace = 'code' | 'comment' | 'string';
3
+ export interface LiveTemplate {
4
+ readonly id: string;
5
+ readonly key: string;
6
+ readonly body: string;
7
+ readonly description?: string;
8
+ readonly languages: readonly TemplateLanguage[];
9
+ readonly places?: readonly TemplatePlace[];
10
+ readonly group?: string;
11
+ }
12
+ export interface PostfixTemplate {
13
+ readonly id: string;
14
+ readonly key: string;
15
+ readonly body: string;
16
+ readonly description?: string;
17
+ readonly example?: string;
18
+ readonly languages: readonly ('javascript' | 'typescript' | 'php')[];
19
+ readonly expression?: 'any' | 'statement';
20
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -1,25 +1,10 @@
1
1
  import { BUILT_IN_LIVE_TEMPLATES, BUILT_IN_POSTFIX_TEMPLATES } from './template-builtins.ts';
2
+ import type { LiveTemplate, PostfixTemplate, TemplateLanguage, TemplatePlace } from './template-types.ts';
2
3
  export { BUILT_IN_LIVE_TEMPLATES, BUILT_IN_POSTFIX_TEMPLATES };
3
- export { type TemplatesFeature } from './live-templates.ts';
4
- export type TemplateLanguage = 'javascript' | 'typescript' | 'php' | 'css' | 'html' | 'xml' | 'other';
5
- export type TemplatePlace = 'code' | 'comment' | 'string';
6
- export interface LiveTemplate {
7
- readonly id: string;
8
- readonly key: string;
9
- readonly body: string;
10
- readonly description?: string;
11
- readonly languages: readonly TemplateLanguage[];
12
- readonly places?: readonly TemplatePlace[];
13
- readonly group?: string;
14
- }
15
- export interface PostfixTemplate {
16
- readonly id: string;
17
- readonly key: string;
18
- readonly body: string;
19
- readonly description?: string;
20
- readonly example?: string;
21
- readonly languages: readonly ('javascript' | 'typescript' | 'php')[];
22
- readonly expression?: 'any' | 'statement';
4
+ export interface TemplatesHost {
5
+ readonly templates?: TemplateRegistry;
6
+ saveAsLiveTemplate?(draft: LiveTemplateDraft): void;
7
+ openTemplateSettings?(): void;
23
8
  }
24
9
  export interface TemplateSettings {
25
10
  readonly liveInCompletion?: boolean;
package/dist/templates.js CHANGED
@@ -1,7 +1,6 @@
1
1
  import { checkSnippet } from './snippet.js';
2
2
  import { BUILT_IN_LIVE_TEMPLATES, BUILT_IN_POSTFIX_TEMPLATES } from './template-builtins.js';
3
3
  export { BUILT_IN_LIVE_TEMPLATES, BUILT_IN_POSTFIX_TEMPLATES };
4
- export {} from './live-templates.js';
5
4
  const MAX_KEY_LENGTH = 40;
6
5
  const MAX_BODY_LENGTH = 20_000;
7
6
  const POSTFIX_LANGUAGES = ['javascript', 'typescript', 'php'];
package/dist/testing.d.ts CHANGED
@@ -1,5 +1,11 @@
1
+ import type { KeyChord } from '@adecore/editor';
1
2
  import { type LanguageService, type LanguageDocument, type LanguageRequestOptions, type DiagnosticsReport, type ContentChange, type Disposable, type ProviderOptions, type CallHierarchyIncomingCall, type CallHierarchyItem, type CallHierarchyOutgoingCall, type CodeAction, type CodeActionContext, type CodeLens, type Command, type CompletionContext, type CompletionItem, type CompletionResult, type DocumentHighlight, type DocumentSymbolResult, type FoldingRange, type FormattingOptions, type Hover, type InlayHint, type Location, type NavigationResult, type Position, type PrepareRenameResult, type Range, type SelectionRange, type SemanticTokens, type SemanticTokensDelta, type SignatureHelp, type SignatureHelpContext, type TextEdit, type WorkspaceEdit, type WorkspaceSymbolResult, type Color, type ColorInformation, type ColorPresentation, type DocumentLink, type InlineCompletionContext, type InlineCompletionResult, type InlineValue, type InlineValueContext, type LinkedEditingRanges, type Moniker, type PreviousResultId, type ServerMessage, type ShowDocumentParams, type ShowDocumentResult, type TextDocumentSaveReason, type TypeHierarchyItem, type WorkspaceDiagnosticReport } from '@adecore/lsp';
2
3
  export { ManualTimers } from './timers.ts';
4
+ export type KeyShortcut = KeyChord & {
5
+ readonly apple?: boolean;
6
+ };
7
+ export declare function keyOf(shortcut: KeyShortcut | null, apple?: boolean): Pick<KeyboardEvent, 'key' | 'code' | 'ctrlKey' | 'metaKey' | 'altKey' | 'shiftKey'>;
8
+ export declare function settle(): Promise<void>;
3
9
  export interface LanguageCall {
4
10
  method: string;
5
11
  uri: string;
package/dist/testing.js CHANGED
@@ -1,5 +1,47 @@
1
1
  import { applyContentChanges, ErrorCodes, LspError, StaleResultError } from '@adecore/lsp';
2
+ import { isApplePlatform } from '@adecore/ui';
2
3
  export { ManualTimers } from './timers.js';
4
+ const KEY_CODES = {
5
+ ',': 'Comma',
6
+ '.': 'Period',
7
+ '/': 'Slash',
8
+ ';': 'Semicolon',
9
+ "'": 'Quote',
10
+ '`': 'Backquote',
11
+ '\\': 'Backslash',
12
+ '[': 'BracketLeft',
13
+ ']': 'BracketRight',
14
+ '-': 'Minus',
15
+ '=': 'Equal'
16
+ };
17
+ /*
18
+ * The keydown a person pressing the shortcut sends, as `FakeEditor.press` takes it. `mod` is Meta on an Apple
19
+ * platform and Ctrl elsewhere: the platform of the shortcut, else the one given, else the page's.
20
+ */
21
+ export function keyOf(shortcut, apple) {
22
+ if (shortcut === null) {
23
+ throw new Error('The keymap has no shortcut for this');
24
+ }
25
+ const {
26
+ key
27
+ } = shortcut;
28
+ const onApple = shortcut.apple ?? apple ?? isApplePlatform();
29
+ const letter = /^[A-Z]$/.test(key);
30
+ return {
31
+ key: letter ? key.toLowerCase() : key === 'Space' ? ' ' : key,
32
+ code: letter ? `Key${key}` : /^[0-9]$/.test(key) ? `Digit${key}` : KEY_CODES[key] ?? key,
33
+ ctrlKey: shortcut.ctrl || shortcut.mod && !onApple,
34
+ metaKey: shortcut.meta || shortcut.mod && onApple,
35
+ altKey: shortcut.alt,
36
+ shiftKey: shortcut.shift
37
+ };
38
+ }
39
+ /* The fake language service has no I/O; a few event-loop turns drain its promise chains. */
40
+ export async function settle() {
41
+ for (let i = 0; i < 6; i++) {
42
+ await new Promise(resolve => setImmediate(resolve));
43
+ }
44
+ }
3
45
  export class FakeLanguageService {
4
46
  documents = new Map();
5
47
  calls = [];
@@ -1,3 +1,3 @@
1
- import type { ProblemCounts } from './diagnostics.ts';
1
+ import type { ProblemCounts } from './diagnostics-model.ts';
2
2
  import type { EditorLanguage } from './editor-language.ts';
3
3
  export declare function useProblemCounts(language: EditorLanguage | null): ProblemCounts;
@@ -1 +1 @@
1
- export declare function replacedWords(removed: readonly string[], added: readonly string[]): Array<Array<[number, number]>>;
1
+ export declare function replacedWords(lines: readonly string[], replaced: readonly string[]): Array<Array<[number, number]>>;