@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,4 +1,8 @@
1
- /* One copy or cut, as the editors of a project made it. */
1
+ export interface ClipboardHost {
2
+ /* What Paste from History lists. A new `ClipboardHistory` that lives as long as the project without one; pass one to choose its size or to keep its entries. */
3
+ readonly clipboard?: ClipboardHistory;
4
+ }
5
+
2
6
  export interface ClipboardEntry {
3
7
  readonly text: string;
4
8
  /* The copy took the lines of bare carets, which paste back above the lines of bare carets. */
@@ -82,7 +86,6 @@ export class ClipboardHistory {
82
86
  this.listeners.forEach((listener) => listener());
83
87
  }
84
88
 
85
- /* Keeps the newest entries that fit the limit and the total length. */
86
89
  private trimmed(entries: readonly ClipboardEntry[]): readonly ClipboardEntry[] {
87
90
  const kept: ClipboardEntry[] = [];
88
91
  let length = 0;
@@ -1,5 +1,5 @@
1
1
  import { applyTextEdits, type CodeAction, type Command, type Diagnostic, type Range, type WorkspaceEdit } from '@adecore/lsp';
2
- import { comparePositions } from './diagnostics-model.ts';
2
+ import { comparePositions } from './positions.ts';
3
3
  import { uniqueBy } from './unique.ts';
4
4
  import { resourceOperationsOf, textEntriesOf } from './workspace-edit.ts';
5
5
 
@@ -99,11 +99,8 @@ export interface EditPreview {
99
99
  readonly hiddenLines: number;
100
100
  /* The other files the edit edits, apart from the ones it makes. */
101
101
  readonly otherFiles: number;
102
- /* The files it moves. */
103
102
  readonly moves: number;
104
- /* The files it makes. */
105
103
  readonly creates?: number;
106
- /* The files it deletes. */
107
104
  readonly deletes?: number;
108
105
  }
109
106
 
@@ -12,12 +12,17 @@ import {
12
12
  type ActionEntry,
13
13
  type ActionGroup
14
14
  } from './code-actions-model.ts';
15
- import { comparePositions, type Problem } from './diagnostics-model.ts';
16
- import type { EditorLanguage } from './editor-language.ts';
15
+ import type { CompletionFeature } from './completion.ts';
16
+ import { type Problem } from './diagnostics-model.ts';
17
+ import type { DiagnosticsFeature } from './diagnostics.ts';
17
18
  import { messageOf } from './error-message.ts';
18
19
  import { KEY_PRIORITY } from './key-priority.ts';
20
+ import type { LanguageContext } from './language-context.ts';
21
+ import type { PickFeature } from './pick.ts';
19
22
  import type { PickGroup, PickPreview } from './popups.ts';
23
+ import { comparePositions } from './positions.ts';
20
24
  import { Refresher } from './refresher.ts';
25
+ import type { RenameFeature } from './rename.ts';
21
26
  import { isShortcut } from './shortcut-keys.ts';
22
27
  import { realTimers, type Timers } from './timers.ts';
23
28
 
@@ -60,13 +65,22 @@ interface AskOptions {
60
65
  readonly groups?: readonly ActionGroup[];
61
66
  }
62
67
 
68
+ /* The sibling features CodeActionsFeature drives, which the editor language hands over. */
69
+ interface CodeActionsPeers {
70
+ readonly diagnostics: Pick<DiagnosticsFeature, 'at' | 'onChange' | 'problems'>;
71
+ readonly completion: Pick<CompletionFeature, 'close'>;
72
+ readonly pick: Pick<PickFeature, 'open'>;
73
+ readonly rename: Pick<RenameFeature, 'start'>;
74
+ }
75
+
63
76
  /*
64
77
  * What the servers offer at the caret or the selection: the gutter's lightbulb, the list under the caret
65
78
  * with a preview of each change, a problem's Quick fix, organize imports and format. An action is resolved
66
79
  * before it is applied, since a server fills in its edit only when asked for it.
67
80
  */
68
81
  export class CodeActionsFeature {
69
- private readonly language: EditorLanguage;
82
+ private readonly language: LanguageContext;
83
+ private readonly peers: CodeActionsPeers;
70
84
  private readonly refresher: Refresher;
71
85
 
72
86
  /* While a list is being asked for, the lightbulb waits: both are the same request and the newer one would cancel the older. */
@@ -74,8 +88,9 @@ export class CodeActionsFeature {
74
88
 
75
89
  private readonly resolved = new Map<ActionEntry, CodeAction>();
76
90
 
77
- constructor(language: EditorLanguage, timers: Timers = realTimers) {
91
+ constructor(language: LanguageContext, peers: CodeActionsPeers, timers: Timers = realTimers) {
78
92
  this.language = language;
93
+ this.peers = peers;
79
94
  const { editor } = language;
80
95
  this.refresher = new Refresher((signal) => this.hint(signal), PAUSE_MS, timers);
81
96
 
@@ -107,7 +122,7 @@ export class CodeActionsFeature {
107
122
 
108
123
  return false;
109
124
  }, KEY_PRIORITY.codeActions),
110
- language.diagnostics.onChange(() => this.refresher.later()),
125
+ peers.diagnostics.onChange(() => this.refresher.later()),
111
126
  providers
112
127
  ];
113
128
 
@@ -265,9 +280,9 @@ export class CodeActionsFeature {
265
280
  return rows.length === 0 ? [] : [{ title: this.say(`groups.${group}`), rows }];
266
281
  });
267
282
 
268
- this.language.completion.close();
283
+ this.peers.completion.close();
269
284
 
270
- this.language.pick.open({
285
+ this.peers.pick.open({
271
286
  anchor: options.anchor,
272
287
  groups,
273
288
  accept: (id) => {
@@ -284,7 +299,8 @@ export class CodeActionsFeature {
284
299
 
285
300
  /* Asks the servers; null when they could not answer, with the reason said aloud for a request a person made. */
286
301
  private async request(range: EditorRange, triggerKind: number, options: RequestOptions = {}): Promise<ActionEntry[] | null> {
287
- const { uri, diagnostics } = this.language;
302
+ const { uri } = this.language;
303
+ const { diagnostics } = this.peers;
288
304
  const { only, signal, order } = options;
289
305
 
290
306
  try {
@@ -325,7 +341,7 @@ export class CodeActionsFeature {
325
341
  return entries;
326
342
  }
327
343
 
328
- const all = this.language.diagnostics.problems.map((problem) => problem.diagnostic);
344
+ const all = this.peers.diagnostics.problems.map((problem) => problem.diagnostic);
329
345
 
330
346
  if (diagnosticsAt(all, range).length > 0) {
331
347
  return entries;
@@ -480,7 +496,7 @@ export class CodeActionsFeature {
480
496
 
481
497
  if (target?.position !== undefined && target.textDocument?.uri === this.language.uri) {
482
498
  this.language.editor.setCaret(target.position);
483
- await this.language.rename.start();
499
+ await this.peers.rename.start();
484
500
  }
485
501
  }
486
502
 
@@ -1,4 +1,4 @@
1
- import { diffLines, splitLines } from '@adecore/merge';
1
+ import { lineMap, splitLines } from '@adecore/merge';
2
2
  import { formatNumber } from '@adecore/ui/format';
3
3
  import type { i18n } from 'i18next';
4
4
  import type { GitBlameCommit, GitBlameResult } from './host-types.ts';
@@ -19,23 +19,13 @@ export function mapBlame(blame: GitBlameResult, base: string, current: readonly
19
19
  }
20
20
 
21
21
  const mapped = new Int32Array(current.length).fill(UNCOMMITTED);
22
- let basePosition = 0;
23
- let position = 0;
24
22
 
25
- const carry = (until: number): void => {
26
- for (; position < until; position++, basePosition++) {
27
- mapped[position] = blame.lines[basePosition]!;
23
+ for (const [index, place] of lineMap(baseLines, current).entries()) {
24
+ if (place >= 0) {
25
+ mapped[place] = blame.lines[index]!;
28
26
  }
29
- };
30
-
31
- for (const change of diffLines(baseLines, current)) {
32
- carry(change.otherStart);
33
- position = change.otherEnd;
34
- basePosition = change.baseEnd;
35
27
  }
36
28
 
37
- carry(current.length);
38
-
39
29
  return mapped;
40
30
  }
41
31
 
@@ -53,7 +43,6 @@ export interface CodeAuthorship {
53
43
  readonly uncommittedLines: number;
54
44
  /* Whether any line of the range, a blank one too, is changed since the commit it came from. */
55
45
  readonly modified: boolean;
56
- /* The newest commit that wrote a line of the range. */
57
46
  readonly latest: GitBlameCommit | null;
58
47
  }
59
48
 
@@ -3,7 +3,7 @@ import { formatNumber } from '@adecore/ui/format';
3
3
  import type { i18n } from 'i18next';
4
4
 
5
5
  /* Past this many declarations in one file the rows are left out, since that many rows would be noise. */
6
- export const MAX_DECLARATIONS = 3000;
6
+ const MAX_DECLARATIONS = 3000;
7
7
 
8
8
  /* LSP's SymbolKind: the kinds a row is drawn for and the ones whose children can be declarations too. */
9
9
  const CLASS = 5;
@@ -259,7 +259,6 @@ export function declarationsOf(result: DocumentSymbolResult, source: Declaration
259
259
  return declarations;
260
260
  }
261
261
 
262
- /* "No usages", "1 usage" and "N usages". */
263
262
  export function usagesText(count: number, i18n: i18n): string {
264
263
  return count === 0
265
264
  ? i18n.t('editor:language.codeVision.usagesNone')
@@ -1,10 +1,10 @@
1
- import type { EditorCodeVision, EditorCodeVisionEntry, EditorRect } from '@adecore/editor';
1
+ import type { EditorCodeVision, EditorCodeVisionEntry, EditorPosition, EditorRect } from '@adecore/editor';
2
2
  import type { DocumentSymbolResult, Location } from '@adecore/lsp';
3
3
  import { splitLines } from '@adecore/merge';
4
4
  import { type CodeAuthorship, authorsText, authorshipOf, mapBlame } from './code-authors.ts';
5
5
  import { type CodeVisionDeclaration, declarationsOf, usagesText } from './code-vision-model.ts';
6
- import type { EditorLanguage } from './editor-language.ts';
7
6
  import type { GitBlameCommit, GitBlameResult } from './host-types.ts';
7
+ import type { LanguageContext } from './language-context.ts';
8
8
  import { realTimers, type Timers } from './timers.ts';
9
9
  import { placeKey } from './unique.ts';
10
10
 
@@ -19,7 +19,7 @@ const MAX_PARALLEL = 3;
19
19
  const SCROLL_PAUSE_MS = 150;
20
20
 
21
21
  /* Past this many lines a file gets no rows at all, which is also what keeps blame and the walk of symbols cheap. */
22
- export const MAX_LINES = 20_000;
22
+ const MAX_LINES = 20_000;
23
23
 
24
24
  export interface CodeVisionSettings {
25
25
  readonly usages: boolean;
@@ -34,6 +34,13 @@ export type BlameSource =
34
34
  | { readonly kind: 'pending' }
35
35
  | { readonly kind: 'ready'; readonly blame: GitBlameResult; readonly base: string; openCommit?(hash: string): void };
36
36
 
37
+ /* What the code vision feature takes from its sibling features, which the editor language hands over. */
38
+ interface CodeVisionPeers {
39
+ /* Told whenever the document symbols are read; returns the way to stop listening. */
40
+ onSymbols(listener: (result: DocumentSymbolResult) => void): () => void;
41
+ readonly peek: { open(position: EditorPosition): Promise<void> };
42
+ }
43
+
37
44
  /*
38
45
  * The rows above declarations: how often each is used and who wrote it. A row holds its height from the
39
46
  * first answer on, empty until its entries are in, so the text never moves when they arrive. Counts are
@@ -41,7 +48,8 @@ export type BlameSource =
41
48
  * stays on its row until the new one is in.
42
49
  */
43
50
  export class CodeVisionFeature {
44
- private readonly language: EditorLanguage;
51
+ private readonly language: LanguageContext;
52
+ private readonly peers: CodeVisionPeers;
45
53
  private readonly timers: Timers;
46
54
  private settings: CodeVisionSettings = { usages: false, authors: false };
47
55
  private declarations: CodeVisionDeclaration[] = [];
@@ -70,13 +78,14 @@ export class CodeVisionFeature {
70
78
  private publishing = false;
71
79
  private disposed = false;
72
80
 
73
- constructor(language: EditorLanguage, onSymbols: (listener: (result: DocumentSymbolResult) => void) => () => void, timers: Timers = realTimers) {
81
+ constructor(language: LanguageContext, peers: CodeVisionPeers, timers: Timers = realTimers) {
74
82
  this.language = language;
83
+ this.peers = peers;
75
84
  this.timers = timers;
76
85
  const { editor } = language;
77
86
 
78
87
  const offs = [
79
- onSymbols((result) => this.read(result)),
88
+ peers.onSymbols((result) => this.read(result)),
80
89
  editor.onTextChange(() => {
81
90
  this.edited = true;
82
91
  this.closeAuthors();
@@ -112,7 +121,6 @@ export class CodeVisionFeature {
112
121
  });
113
122
  }
114
123
 
115
- /* Which rows to draw, from the settings of the client. */
116
124
  configure(settings: CodeVisionSettings): void {
117
125
  if (settings.usages === this.settings.usages && settings.authors === this.settings.authors) {
118
126
  return;
@@ -123,7 +131,6 @@ export class CodeVisionFeature {
123
131
  this.plan();
124
132
  }
125
133
 
126
- /* What git says about the file, from the client that asked it. */
127
134
  setBlame(blame: BlameSource | null): void {
128
135
  this.blame = blame;
129
136
  this.mapped = null;
@@ -152,7 +159,6 @@ export class CodeVisionFeature {
152
159
  return this.settings.usages && this.language.service.supports(REFERENCES, this.language.uri);
153
160
  }
154
161
 
155
- /* Queues the declarations in view whose count is not from the current text, nearest the top of the view first. */
156
162
  private plan(): void {
157
163
  if (this.disposed || this.edited || !this.canCount) {
158
164
  return;
@@ -243,7 +249,7 @@ export class CodeVisionFeature {
243
249
  entries.push({
244
250
  id: 'usages',
245
251
  text: usagesText(known.count, this.language.project.i18n),
246
- activate: () => void this.language.peek.open(declaration.position)
252
+ activate: () => void this.peers.peek.open(declaration.position)
247
253
  });
248
254
  }
249
255
 
@@ -289,20 +295,18 @@ export class CodeVisionFeature {
289
295
  const source = this.blame;
290
296
  const openCommit = source?.kind === 'ready' ? source.openCommit : undefined;
291
297
 
292
- this.language.popups.setState({
293
- authors: {
294
- anchor,
295
- name: declaration.name,
296
- authorship,
297
- openCommit: openCommit === undefined || authorship.latest === null ? null : () => openCommit(authorship.latest!.hash)
298
- }
298
+ this.language.popups.slot('authors').set({
299
+ anchor,
300
+ name: declaration.name,
301
+ authorship,
302
+ openCommit: openCommit === undefined || authorship.latest === null ? null : () => openCommit(authorship.latest!.hash)
299
303
  });
300
304
  }
301
305
 
302
306
  /* Closes the card of the authors; `restoreFocus` is for a close that came from the keyboard, which gives the editor its keys back. */
303
307
  closeAuthors(restoreFocus = false): void {
304
- if (this.language.popups.getState().authors !== null) {
305
- this.language.popups.setState({ authors: null });
308
+ if (this.language.popups.slot('authors').get() !== null) {
309
+ this.language.popups.slot('authors').set(null);
306
310
 
307
311
  if (restoreFocus) {
308
312
  this.language.editor.focus();
@@ -1,10 +1,10 @@
1
- import type { CompletionItem } from '@adecore/lsp';
1
+ import { SCRIPT_LANGUAGE_IDS, type CompletionItem } from '@adecore/lsp';
2
2
  import { CLASS_KIND, SNIPPET_FORMAT, SOURCE_LINE, isCallableKind, type Insertion } from './completion-model.ts';
3
3
 
4
4
  /* What the platform's editors send to ask for parameter info once an item is in; the card is ours to open. */
5
5
  export const PARAMETER_HINTS_COMMAND = 'editor.action.triggerParameterHints';
6
6
 
7
- const CALL_LANGUAGES = new Set(['typescript', 'typescriptreact', 'javascript', 'javascriptreact', 'vue', 'php', 'python']);
7
+ const CALL_LANGUAGES = new Set<string>([...SCRIPT_LANGUAGE_IDS, 'vue', 'php', 'python']);
8
8
  const MARKUP_LANGUAGES = new Set(['typescriptreact', 'javascriptreact', 'vue']);
9
9
 
10
10
  const IMPORT_BRACE = /\b(?:import|export)(?:\s+type)?(?:\s+[\w$]+\s*,)?\s*$/;
@@ -1,13 +1,20 @@
1
1
  import type { EditorContentChange, EditorPosition, EditorRange } from '@adecore/editor';
2
2
  import { applyCompletionDefaults, type CompletionItem, type CompletionResult, type MarkupContent } from '@adecore/lsp';
3
3
  import { labelCollator } from '@adecore/ui/format';
4
- import { comparePositions, sameRange } from './diagnostics-model.ts';
5
4
  import { escapeMarkdown, isEmptyHover, splitSignatures, type HoverText } from './hover-content.ts';
6
- import type { CompletionDocs } from './popups.ts';
5
+ import { comparePositions, sameRange } from './positions.ts';
7
6
  import { indentSnippet } from './snippet-indent.ts';
8
7
  import type { SnippetTransformJob } from './snippet-transform-protocol.ts';
9
8
  import { compileSnippet, parseSnippet, tabOrder, type SnippetField, type SnippetStop, type SnippetTemplate, type SnippetVariableResolver } from './snippet.ts';
10
9
 
10
+ /* What is said about the active suggestion beside the list. */
11
+ export interface CompletionDocs {
12
+ /* Where it comes from, such as `use Raxos\\Orm\\Property` or `Auto import from './lib.ts'`; one line, empty when the server says nothing. */
13
+ readonly source: string;
14
+ /* The signature, prose and tags the same way a hover has them. */
15
+ readonly text: HoverText;
16
+ }
17
+
11
18
  const IDENTIFIER_CHARACTER = /[\p{L}\p{N}\p{M}_$]/u;
12
19
 
13
20
  export function isIdentifierCharacter(character: string): boolean {
@@ -69,7 +76,6 @@ interface LabelShape {
69
76
  readonly lower: string;
70
77
  /* Where each word of the label starts: after an underscore, a dollar sign, a space or a hyphen, and at each capital. */
71
78
  readonly offsets: readonly number[];
72
- /* The lowercased first letter of each word. */
73
79
  readonly initials: string;
74
80
  }
75
81
 
@@ -219,7 +225,6 @@ export function prefixFor(item: CompletionItem, caret: EditorPosition, lineBefor
219
225
  export interface Ranked {
220
226
  readonly item: CompletionItem;
221
227
  readonly score: number;
222
- /* What was typed of the item, which its matched characters are found against. */
223
228
  readonly prefix: string;
224
229
  }
225
230
 
@@ -304,9 +309,9 @@ export function snippetToText(snippet: string): string {
304
309
  return parseSnippet(snippet).text;
305
310
  }
306
311
 
307
- export const METHOD_KIND = 2;
308
- export const FUNCTION_KIND = 3;
309
- export const CONSTRUCTOR_KIND = 4;
312
+ const METHOD_KIND = 2;
313
+ const FUNCTION_KIND = 3;
314
+ const CONSTRUCTOR_KIND = 4;
310
315
  export const CLASS_KIND = 7;
311
316
  export const SNIPPET_FORMAT = 2;
312
317
 
package/src/completion.ts CHANGED
@@ -17,18 +17,21 @@ import {
17
17
  type Insertion,
18
18
  type Ranked
19
19
  } from './completion-model.ts';
20
- import { comparePositions, sameRange, shiftPosition } from './diagnostics-model.ts';
21
- import type { EditorLanguage } from './editor-language.ts';
22
20
  import { messageOf } from './error-message.ts';
23
21
  import { KEY_PRIORITY } from './key-priority.ts';
22
+ import type { LanguageContext } from './language-context.ts';
24
23
  import { shikiLanguageOf } from './language-ids.ts';
25
24
  import { lineTextOf, textBeforeOf } from './line-text.ts';
25
+ import type { PickFeature } from './pick.ts';
26
26
  import type { CompletionRow, CompletionView } from './popups.ts';
27
+ import { comparePositions, sameRange, shiftPosition } from './positions.ts';
27
28
  import { isEmptyRange } from './proposal-model.ts';
28
29
  import { RecentChoices, recentChoicesOf } from './recent-choices.ts';
29
30
  import { wordRangeAt } from './rename-model.ts';
30
31
  import { isShortcut } from './shortcut-keys.ts';
32
+ import type { SignatureFeature } from './signature.ts';
31
33
  import { jobTable } from './snippet-field-transforms.ts';
34
+ import type { SnippetFeature } from './snippet-session.ts';
32
35
  import { SnippetTransformError } from './snippet-transform-client.ts';
33
36
  import { MAX_TRANSFORM_JOBS, MAX_TRANSFORM_WORK } from './snippet-transform-protocol.ts';
34
37
  import { SnippetTransformQueueError } from './snippet-transform-queue.ts';
@@ -100,8 +103,7 @@ export interface LocalCompletionItem {
100
103
  accept(): void;
101
104
  }
102
105
 
103
- /** What a source is asked for when the list is requested. */
104
- export interface CompletionRequest {
106
+ interface CompletionRequest {
105
107
  readonly position: EditorPosition;
106
108
 
107
109
  /** Whether the person asked for the list with the keyboard. */
@@ -115,13 +117,24 @@ export interface CompletionSource {
115
117
  items(request: CompletionRequest): readonly LocalCompletionItem[];
116
118
  }
117
119
 
120
+ /* The sibling features CompletionFeature drives, which the editor language hands over. */
121
+ interface CompletionPeers {
122
+ readonly pick: Pick<PickFeature, 'close'>;
123
+ readonly snippets: Pick<
124
+ SnippetFeature,
125
+ 'applyEdits' | 'beginInstances' | 'end' | 'hasPendingTransforms' | 'isActive' | 'settleTransforms' | 'token' | 'transformVariables'
126
+ >;
127
+ readonly signature: Pick<SignatureFeature, 'trigger'>;
128
+ }
129
+
118
130
  /*
119
131
  * The suggestions that open while a word is typed. A single typed identifier character or a trigger
120
132
  * character of the server asks for the list; every character after that only filters the list that
121
133
  * is already there, unless the server called it incomplete. Enter inserts, Tab replaces, Escape closes.
122
134
  */
123
135
  export class CompletionFeature {
124
- private readonly language: EditorLanguage;
136
+ private readonly language: LanguageContext;
137
+ private readonly peers: CompletionPeers;
125
138
  private readonly timers: Timers;
126
139
  private pool: readonly CompletionItem[] = [];
127
140
  private incomplete = false;
@@ -161,8 +174,9 @@ export class CompletionFeature {
161
174
  /* Whether the list holds the rows `showItems` gave it and no request refreshes it. */
162
175
  private shown = false;
163
176
 
164
- constructor(language: EditorLanguage, timers: Timers = realTimers) {
177
+ constructor(language: LanguageContext, peers: CompletionPeers, timers: Timers = realTimers) {
165
178
  this.language = language;
179
+ this.peers = peers;
166
180
  this.timers = timers;
167
181
  const { editor } = language;
168
182
 
@@ -190,12 +204,12 @@ export class CompletionFeature {
190
204
  }
191
205
 
192
206
  get isOpen(): boolean {
193
- return this.language.popups.getState().completion !== null;
207
+ return this.language.popups.slot('completion').get() !== null;
194
208
  }
195
209
 
196
210
  /* Asks for suggestions at the caret now, as Ctrl+Space does. */
197
211
  invoke(): void {
198
- this.language.pick.close();
212
+ this.peers.pick.close();
199
213
  this.explicit = true;
200
214
  this.beginRequest({ triggerKind: 1 }, 0);
201
215
  }
@@ -211,7 +225,7 @@ export class CompletionFeature {
211
225
 
212
226
  /** Opens the list with only these rows, the typed prefix starting at `start`, as Insert Live Template does. */
213
227
  showItems(items: readonly LocalCompletionItem[], start: EditorPosition): void {
214
- this.language.pick.close();
228
+ this.peers.pick.close();
215
229
  this.close();
216
230
  this.shown = true;
217
231
  this.locals = new Map(items.map((local) => [local.item, local]));
@@ -264,7 +278,8 @@ export class CompletionFeature {
264
278
  return;
265
279
  }
266
280
 
267
- const { editor, project, uri, snippets } = this.language;
281
+ const { editor, project, uri } = this.language;
282
+ const { snippets } = this.peers;
268
283
  const acceptSequence = ++this.acceptSequence;
269
284
  this.accepting?.abort();
270
285
  const accepting = new AbortController();
@@ -504,7 +519,7 @@ export class CompletionFeature {
504
519
  const landed = editor.getSelections();
505
520
 
506
521
  if (commit === undefined) {
507
- this.language.snippets.beginInstances(
522
+ this.peers.snippets.beginInstances(
508
523
  [...mirrored, primary].map((insertion, index) => {
509
524
  const rendered = insertion === primary ? main : instances.get(insertion)!;
510
525
 
@@ -575,7 +590,6 @@ export class CompletionFeature {
575
590
  editor.setSelections(selections);
576
591
  }
577
592
 
578
- /* The lines above the insertion down to where it starts, and the rest of the line past what it replaces. */
579
593
  private surroundings(insertion: Insertion, caret: EditorPosition, lineAfter: string): { before: string; rest: string } {
580
594
  const { editor } = this.language;
581
595
  const { start, end } = insertion.range;
@@ -587,7 +601,8 @@ export class CompletionFeature {
587
601
 
588
602
  /* Parameter info for a call that was opened (or that the server asks for), then the item's own command. */
589
603
  private afterInsert(item: CompletionItem, commit: string | undefined, lineBefore: string): void {
590
- const { editor, uri, signature } = this.language;
604
+ const { editor, uri } = this.language;
605
+ const { signature } = this.peers;
591
606
  const { start } = editor.getSelection();
592
607
  const insideCall = start.character > 0 && editor.textInRange({ start: { line: start.line, character: start.character - 1 }, end: start }) === '(';
593
608
 
@@ -652,8 +667,8 @@ export class CompletionFeature {
652
667
  this.locals = new Map();
653
668
  this.shown = false;
654
669
 
655
- if (this.language.popups.getState().completion !== null) {
656
- this.language.popups.setState({ completion: null });
670
+ if (this.language.popups.slot('completion').get() !== null) {
671
+ this.language.popups.slot('completion').set(null);
657
672
  }
658
673
  }
659
674
 
@@ -1015,6 +1030,6 @@ export class CompletionFeature {
1015
1030
  highlightLanguage
1016
1031
  };
1017
1032
 
1018
- this.language.popups.setState({ completion: view });
1033
+ this.language.popups.slot('completion').set(view);
1019
1034
  }
1020
1035
  }
@@ -28,7 +28,7 @@ const CHANGES: readonly MenuRowSpec[] = [
28
28
  { id: 'codeActions', method: 'textDocument/codeAction', shortcut: 'codeActions' }
29
29
  ];
30
30
 
31
- export interface MenuGroups {
31
+ interface MenuGroups {
32
32
  readonly goTo: readonly MenuRowSpec[];
33
33
  readonly references: readonly MenuRowSpec[];
34
34
  readonly changes: readonly MenuRowSpec[];
@@ -1,17 +1,25 @@
1
- import type { EditorLanguage } from './editor-language.ts';
1
+ import type { CodeActionsFeature } from './code-actions.ts';
2
+ import type { LanguageContext } from './language-context.ts';
2
3
 
3
- export type ClipboardAction = 'cut' | 'copy' | 'paste';
4
+ type ClipboardAction = 'cut' | 'copy' | 'paste';
5
+
6
+ /* The sibling features ContextMenuFeature drives, which the editor language hands over. */
7
+ interface ContextMenuPeers {
8
+ readonly codeActions: Pick<CodeActionsFeature, 'list'>;
9
+ }
4
10
 
5
11
  /*
6
12
  * The editor only says where its context menu was asked for; `EditorContextMenu` draws it from what the
7
13
  * servers support at the caret. The refactors are asked for while it opens, so it never waits for them.
8
14
  */
9
15
  export class ContextMenuFeature {
10
- private readonly language: EditorLanguage;
16
+ private readonly language: LanguageContext;
17
+ private readonly peers: ContextMenuPeers;
11
18
  private request = 0;
12
19
 
13
- constructor(language: EditorLanguage) {
20
+ constructor(language: LanguageContext, peers: ContextMenuPeers) {
14
21
  this.language = language;
22
+ this.peers = peers;
15
23
 
16
24
  const off = language.editor.onContextMenu((menu) => {
17
25
  // A right click outside the selection moves the caret first, so the menu is about what was clicked.
@@ -31,8 +39,8 @@ export class ContextMenuFeature {
31
39
  close(): void {
32
40
  this.request++;
33
41
 
34
- if (this.language.popups.getState().menu !== null) {
35
- this.language.popups.setState({ menu: null });
42
+ if (this.language.popups.slot('menu').get() !== null) {
43
+ this.language.popups.slot('menu').set(null);
36
44
  }
37
45
  }
38
46
 
@@ -55,14 +63,15 @@ export class ContextMenuFeature {
55
63
 
56
64
  private open(x: number, y: number): void {
57
65
  const request = ++this.request;
58
- const { popups, codeActions } = this.language;
59
- popups.setState({ menu: { x, y, refactors: [] } });
66
+ const { popups } = this.language;
67
+ const { codeActions } = this.peers;
68
+ popups.slot('menu').set({ x, y, refactors: [] });
60
69
 
61
70
  void codeActions.list(['refactor']).then((entries) => {
62
- const shown = popups.getState().menu;
71
+ const shown = popups.slot('menu').get();
63
72
 
64
73
  if (request === this.request && shown !== null && entries !== null) {
65
- popups.setState({ menu: { ...shown, refactors: entries } });
74
+ popups.slot('menu').set({ ...shown, refactors: entries });
66
75
  }
67
76
  });
68
77
  }
@@ -1,7 +1,8 @@
1
1
  import type { EditorPosition } from '@adecore/editor';
2
2
  import { isIdentifierCharacter } from './completion-model.ts';
3
- import type { EditorLanguage } from './editor-language.ts';
3
+ import type { DocumentLinksFeature } from './document-links.ts';
4
4
  import { locationsOf } from './hover-content.ts';
5
+ import type { LanguageContext } from './language-context.ts';
5
6
  import { lineTextOf } from './line-text.ts';
6
7
  import { wordRangeAt } from './rename-model.ts';
7
8
 
@@ -32,13 +33,19 @@ export function followModKey(apple: boolean, onHeld: (held: boolean) => void): (
32
33
  };
33
34
  }
34
35
 
36
+ /* The sibling features DefinitionLinkFeature drives, which the editor language hands over. */
37
+ interface DefinitionLinkPeers {
38
+ readonly links: Pick<DocumentLinksFeature, 'rangeAt'>;
39
+ }
40
+
35
41
  /*
36
42
  * The name under the pointer drawn as a link while Cmd (Ctrl elsewhere) is held and a server knows where it
37
43
  * is defined, which is what a Mod+click on it follows. A document link under the pointer goes first. The
38
44
  * editor only says where the pointer is, so the key comes from the window.
39
45
  */
40
46
  export class DefinitionLinkFeature {
41
- private readonly language: EditorLanguage;
47
+ private readonly language: LanguageContext;
48
+ private readonly peers: DefinitionLinkPeers;
42
49
  private held = false;
43
50
  private pointer: EditorPosition | null = null;
44
51
  private shownKey = '';
@@ -46,8 +53,9 @@ export class DefinitionLinkFeature {
46
53
  private request = 0;
47
54
  private lookup: AbortController | null = null;
48
55
 
49
- constructor(language: EditorLanguage) {
56
+ constructor(language: LanguageContext, peers: DefinitionLinkPeers) {
50
57
  this.language = language;
58
+ this.peers = peers;
51
59
  const { editor } = language;
52
60
 
53
61
  const offs = [
@@ -90,7 +98,7 @@ export class DefinitionLinkFeature {
90
98
  private update(): void {
91
99
  const { pointer } = this;
92
100
 
93
- const link = pointer === null ? null : this.language.links.rangeAt(pointer);
101
+ const link = pointer === null ? null : this.peers.links.rangeAt(pointer);
94
102
  if (this.held && link !== null) {
95
103
  const key = `link:${link.start.line}:${link.start.character}`;
96
104
  if (key !== this.shownKey) {