@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,7 +1,8 @@
1
1
  import { rememberCopy } from '@adecore/editor';
2
2
  import type { ClipboardEntry } from './clipboard-history.ts';
3
- import type { EditorLanguage } from './editor-language.ts';
4
3
  import { KEY_PRIORITY } from './key-priority.ts';
4
+ import type { LanguageContext } from './language-context.ts';
5
+ import type { PickFeature } from './pick.ts';
5
6
  import type { PickGroup } from './popups.ts';
6
7
  import { isShortcut } from './shortcut-keys.ts';
7
8
 
@@ -14,15 +15,22 @@ function labelOf(text: string): string {
14
15
  return flat.length > LABEL_LENGTH ? `${flat.slice(0, LABEL_LENGTH)}…` : flat;
15
16
  }
16
17
 
18
+ /* The sibling features PasteHistoryFeature drives, which the editor language hands over. */
19
+ interface PasteHistoryPeers {
20
+ readonly pick: Pick<PickFeature, 'open'>;
21
+ }
22
+
17
23
  /*
18
24
  * Paste from History: a list of what was copied in the editors of the project, newest first. Typing narrows it,
19
25
  * Shift with the arrows chooses several entries, which paste as one, and Delete forgets entries.
20
26
  */
21
27
  export class PasteHistoryFeature {
22
- private readonly language: EditorLanguage;
28
+ private readonly language: LanguageContext;
29
+ private readonly peers: PasteHistoryPeers;
23
30
 
24
- constructor(language: EditorLanguage) {
31
+ constructor(language: LanguageContext, peers: PasteHistoryPeers) {
25
32
  this.language = language;
33
+ this.peers = peers;
26
34
 
27
35
  const off = language.onKey((event) => {
28
36
  if (!isShortcut(this.language.shortcuts.pasteFromHistory, event)) {
@@ -66,7 +74,7 @@ export class PasteHistoryFeature {
66
74
 
67
75
  const rows = groups();
68
76
 
69
- this.language.pick.open({
77
+ this.peers.pick.open({
70
78
  anchor: editor.getCaret(),
71
79
  title: project.i18n.t('editor:language.pasteHistory.title'),
72
80
  groups: rows,
@@ -52,7 +52,7 @@ export interface PatchLimits {
52
52
  readonly maxCharacters?: number;
53
53
  }
54
54
 
55
- export const DEFAULT_PATCH_LIMITS = { maxLines: 50_000, maxCharacters: 4_000_000 } as const;
55
+ const DEFAULT_PATCH_LIMITS = { maxLines: 50_000, maxCharacters: 4_000_000 } as const;
56
56
 
57
57
  const OTHER: PatchLayoutLine = { role: 'other', old: null, new: null };
58
58
  const FILE_HEADER: PatchLayoutLine = { role: 'file-header', old: null, new: null };
package/src/peek-model.ts CHANGED
@@ -36,7 +36,6 @@ function columnsOf(range: Range, line: number, length: number): NameRange | null
36
36
  return range.start.character < end ? { start: range.start.character, end } : null;
37
37
  }
38
38
 
39
- /* The name of a place within its line once the indentation is cut off. */
40
39
  function trimmedNameOf(raw: string, range: Range, line: number): NameRange | null {
41
40
  const leading = raw.length - raw.trimStart().length;
42
41
  const columns = columnsOf(range, line, raw.length);
package/src/peek.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import type { EditorPosition } from '@adecore/editor';
2
2
  import { StaleResultError, type Location, type Range } from '@adecore/lsp';
3
- import type { EditorLanguage } from './editor-language.ts';
4
3
  import { messageOf } from './error-message.ts';
5
4
  import { KEY_PRIORITY } from './key-priority.ts';
5
+ import type { LanguageContext } from './language-context.ts';
6
6
  import { uniquePlaces } from './navigation.ts';
7
7
  import { PEEK_READ_FILES, definitionSnippetOf, peekFilesOf, snippetOf, type PeekFile } from './peek-model.ts';
8
8
  import type { PeekView } from './popups.ts';
@@ -22,13 +22,19 @@ const KINDS = {
22
22
  definitions: { method: 'textDocument/definition', unavailable: 'unavailableDefinition', none: 'noDefinition' }
23
23
  } as const;
24
24
 
25
+ /* The sibling features PeekFeature drives, which the editor language hands over. */
26
+ interface PeekPeers {
27
+ readonly callHierarchy: { close(): void };
28
+ }
29
+
25
30
  /*
26
31
  * The references of the name at the caret, between the lines of the file under the line it is on. The
27
32
  * editor keeps the keyboard: arrows pick a reference, Enter goes to it and Escape closes the peek; typing
28
33
  * closes it too. A click on a place shows its code and a second one goes there.
29
34
  */
30
35
  export class PeekFeature {
31
- private readonly language: EditorLanguage;
36
+ private readonly language: LanguageContext;
37
+ private readonly peers: PeekPeers;
32
38
  private readonly timers: Timers;
33
39
  private kind: PeekKind = 'references';
34
40
 
@@ -41,8 +47,9 @@ export class PeekFeature {
41
47
  private line = 0;
42
48
  private token = 0;
43
49
 
44
- constructor(language: EditorLanguage, timers: Timers = realTimers) {
50
+ constructor(language: LanguageContext, peers: PeekPeers, timers: Timers = realTimers) {
45
51
  this.language = language;
52
+ this.peers = peers;
46
53
  this.timers = timers;
47
54
  const { editor } = language;
48
55
 
@@ -75,7 +82,7 @@ export class PeekFeature {
75
82
  }
76
83
 
77
84
  get isOpen(): boolean {
78
- return this.language.popups.getState().peek !== null;
85
+ return this.language.popups.slot('peek').get() !== null;
79
86
  }
80
87
 
81
88
  async open(position: EditorPosition = this.language.editor.getCaret(), kind: PeekKind = 'references'): Promise<void> {
@@ -145,8 +152,8 @@ export class PeekFeature {
145
152
  : (files.flatMap((file) => file.places).find((place) => !(place.location.uri === uri && place.line === position.line)) ?? files[0]!.places[0]!);
146
153
 
147
154
  this.line = position.line;
148
- this.language.callHierarchy.close();
149
- this.language.popups.setState({ peek: { kind, container: null, files, active: first.id, collapsed: [], count: unique.length, preview: null } });
155
+ this.peers.callHierarchy.close();
156
+ this.language.popups.slot('peek').set({ kind, container: null, files, active: first.id, collapsed: [], count: unique.length, preview: null });
150
157
  this.select(first.id);
151
158
  // The editor draws a row once per id, so a peek opened over another needs an id of its own to get a container.
152
159
  editor.setWidgets([{ id: `peek-${token}`, line: this.line, height: PEEK_HEIGHT, render: (container) => this.mounted(container) }]);
@@ -154,7 +161,6 @@ export class PeekFeature {
154
161
  editor.focus();
155
162
  }
156
163
 
157
- /* The definition of the name at the caret, as its source between the lines of the file. */
158
164
  openDefinition(position: EditorPosition = this.language.editor.getCaret()): Promise<void> {
159
165
  return this.open(position, 'definitions');
160
166
  }
@@ -176,18 +182,17 @@ export class PeekFeature {
176
182
  close(): void {
177
183
  this.token++;
178
184
 
179
- if (this.language.popups.getState().peek === null) {
185
+ if (this.language.popups.slot('peek').get() === null) {
180
186
  return;
181
187
  }
182
188
 
183
- this.language.popups.setState({ peek: null });
189
+ this.language.popups.slot('peek').set(null);
184
190
  this.language.editor.setWidgets([]);
185
191
  this.language.editor.focus();
186
192
  }
187
193
 
188
- /* Shows the code around a place. */
189
194
  select(id: string): void {
190
- const view = this.language.popups.getState().peek;
195
+ const view = this.language.popups.slot('peek').get();
191
196
  const location = this.places.get(id);
192
197
 
193
198
  if (view === null || location === undefined) {
@@ -204,16 +209,15 @@ export class PeekFeature {
204
209
  ? definitionSnippetOf(text, line, this.targets.get(placeKey(location)) ?? null, location.range)
205
210
  : snippetOf(text, line, location.range);
206
211
 
207
- this.language.popups.setState({ peek: { ...view, active: id, preview: snippet === null ? null : { ...snippet, uri: location.uri } } });
212
+ this.language.popups.slot('peek').set({ ...view, active: id, preview: snippet === null ? null : { ...snippet, uri: location.uri } });
208
213
  }
209
214
 
210
- /* Folds the places of a file away from the list, or brings them back. */
211
215
  toggleFile(uri: string): void {
212
- const view = this.language.popups.getState().peek;
216
+ const view = this.language.popups.slot('peek').get();
213
217
 
214
218
  if (view !== null) {
215
219
  const collapsed = view.collapsed.includes(uri) ? view.collapsed.filter((other) => other !== uri) : [...view.collapsed, uri];
216
- this.language.popups.setState({ peek: { ...view, collapsed } });
220
+ this.language.popups.slot('peek').set({ ...view, collapsed });
217
221
  }
218
222
  }
219
223
 
@@ -228,16 +232,16 @@ export class PeekFeature {
228
232
  }
229
233
 
230
234
  private mounted(container: HTMLElement): void {
231
- const view = this.language.popups.getState().peek;
235
+ const view = this.language.popups.slot('peek').get();
232
236
 
233
237
  if (view !== null && view.container !== container) {
234
- this.language.popups.setState({ peek: { ...view, container } });
238
+ this.language.popups.slot('peek').set({ ...view, container });
235
239
  revealRow(this.timers, container);
236
240
  }
237
241
  }
238
242
 
239
243
  private key(event: KeyboardEvent): boolean {
240
- const view = this.language.popups.getState().peek;
244
+ const view = this.language.popups.slot('peek').get();
241
245
 
242
246
  if (view === null || event.metaKey || event.ctrlKey || event.altKey) {
243
247
  return false;
package/src/pick.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  import type { EditorPosition } from '@adecore/editor';
2
- import type { EditorLanguage } from './editor-language.ts';
2
+ import { fileUriToPath, type Location } from '@adecore/lsp';
3
3
  import { KEY_PRIORITY } from './key-priority.ts';
4
+ import type { LanguageContext } from './language-context.ts';
5
+ import { basenameOf } from './paths.ts';
4
6
  import type { PickGroup, PickPreview } from './popups.ts';
5
7
  import { realTimers, type Timers } from './timers.ts';
6
8
 
@@ -41,7 +43,7 @@ export interface PickSpec {
41
43
  * Escape, typing, a click elsewhere or a change of the text close it.
42
44
  */
43
45
  export class PickFeature {
44
- private readonly language: EditorLanguage;
46
+ private readonly language: LanguageContext;
45
47
  private readonly timers: Timers;
46
48
  private spec: PickSpec | null = null;
47
49
 
@@ -59,12 +61,11 @@ export class PickFeature {
59
61
  private previewTimer: unknown;
60
62
  private controller: AbortController | null = null;
61
63
 
62
- /* The rows that said why they cannot be taken, by id. */
63
64
  private refusals = new Map<string, string>();
64
65
 
65
66
  private attempting = false;
66
67
 
67
- constructor(language: EditorLanguage, timers: Timers = realTimers) {
68
+ constructor(language: LanguageContext, timers: Timers = realTimers) {
68
69
  this.language = language;
69
70
  this.timers = timers;
70
71
  const { editor } = language;
@@ -109,6 +110,13 @@ export class PickFeature {
109
110
  this.schedulePreview();
110
111
  }
111
112
 
113
+ /* Lists the places of a result under a position to choose from; choosing one goes there. */
114
+ locations(places: readonly Location[], anchor: EditorPosition, title: string): void {
115
+ const rows = places.map((place, index) => ({ id: String(index), ...locationRow(place, this.language.project.pathOfLocation(place.uri)) }));
116
+
117
+ this.open({ anchor, title, groups: [{ title: null, rows }], accept: (id) => this.language.goTo(places[Number(id)]!) });
118
+ }
119
+
112
120
  close(): void {
113
121
  if (this.spec === null) {
114
122
  return;
@@ -118,7 +126,7 @@ export class PickFeature {
118
126
  this.timers.clear(this.previewTimer);
119
127
  this.controller?.abort();
120
128
  this.controller = null;
121
- this.language.popups.setState({ pick: null });
129
+ this.language.popups.slot('pick').set(null);
122
130
  }
123
131
 
124
132
  /* Moves the active row; with `extend`, in a list of several choices, the rows between where the move began and the new row are chosen. */
@@ -139,7 +147,6 @@ export class PickFeature {
139
147
  this.settle(id);
140
148
  }
141
149
 
142
- /* Makes `id` the only row the list is on. */
143
150
  private settle(id: string): void {
144
151
  const hadChosen = this.chosen.length > 0;
145
152
 
@@ -427,16 +434,23 @@ export class PickFeature {
427
434
  const refusal = this.refusals.get(this.active);
428
435
  const shown = refusal === undefined ? preview : { removed: [], added: [], note: null, refusal };
429
436
 
430
- this.language.popups.setState({
431
- pick: {
432
- anchor: spec.anchor,
433
- groups: this.visibleGroups(),
434
- active: this.active,
435
- preview: shown,
436
- title: spec.title ?? null,
437
- query: spec.filter === true ? this.query : null,
438
- chosen: this.chosen
439
- }
437
+ this.language.popups.slot('pick').set({
438
+ anchor: spec.anchor,
439
+ groups: this.visibleGroups(),
440
+ active: this.active,
441
+ preview: shown,
442
+ title: spec.title ?? null,
443
+ query: spec.filter === true ? this.query : null,
444
+ chosen: this.chosen
440
445
  });
441
446
  }
442
447
  }
448
+
449
+ /* How a place reads in a list: the file and the line, with the folder it is in. */
450
+ function locationRow(location: Location, stored: string | null): { label: string; detail: string; path: true } {
451
+ const path = stored ?? fileUriToPath(location.uri) ?? location.uri;
452
+ const name = basenameOf(path);
453
+ const folder = path.slice(0, Math.max(0, path.length - name.length)).replace(/\/$/, '');
454
+
455
+ return { label: `${name}:${location.range.start.line + 1}`, detail: folder, path: true };
456
+ }
package/src/popups.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import type { EditorPosition, EditorRange, EditorRect } from '@adecore/editor';
2
2
  import type { Location } from '@adecore/lsp';
3
- import { createStore, type StoreApi } from 'zustand';
4
3
  import type { CallDirection, CallRow } from './call-hierarchy-model.ts';
5
4
  import type { ActionEntry } from './code-actions-model.ts';
6
5
  import type { CodeAuthorship } from './code-authors.ts';
6
+ import type { CompletionDocs } from './completion-model.ts';
7
7
  import type { Problem } from './diagnostics-model.ts';
8
8
  import type { HoverText } from './hover-content.ts';
9
9
  import type { PeekFile, PeekSnippet } from './peek-model.ts';
@@ -46,20 +46,11 @@ export interface CompletionRow {
46
46
  readonly deprecated: boolean;
47
47
  }
48
48
 
49
- /* What is said about the active suggestion beside the list. */
50
- export interface CompletionDocs {
51
- /* Where it comes from, such as `use Raxos\\Orm\\Property` or `Auto import from './lib.ts'`; one line, empty when the server says nothing. */
52
- readonly source: string;
53
- /* The signature, prose and tags the same way a hover has them. */
54
- readonly text: HoverText;
55
- }
56
-
57
49
  export interface CompletionView {
58
50
  /* The start of the word, which the list is placed under. */
59
51
  readonly anchor: EditorPosition;
60
52
  readonly rows: readonly CompletionRow[];
61
53
  readonly active: number;
62
- /* Whether the documentation of the active row is shown beside the list. */
63
54
  readonly detailsOpen: boolean;
64
55
  readonly docs: CompletionDocs | null;
65
56
  readonly server: string;
@@ -210,34 +201,64 @@ export interface WrapView {
210
201
  readonly error: string | null;
211
202
  }
212
203
 
213
- export interface PopupState {
214
- readonly hover: HoverView | null;
215
- readonly completion: CompletionView | null;
216
- readonly signature: SignatureView | null;
217
- readonly pick: PickView | null;
218
- readonly rename: RenameView | null;
219
- readonly peek: PeekView | null;
220
- readonly callHierarchy: CallHierarchyView | null;
221
- readonly symbols: SymbolsView | null;
222
- readonly menu: MenuView | null;
223
- readonly authors: AuthorsView | null;
224
- readonly wrap: WrapView | null;
225
- }
226
-
227
- export type PopupStore = StoreApi<PopupState>;
228
-
229
- export function createPopupStore(): PopupStore {
230
- return createStore<PopupState>(() => ({
231
- hover: null,
232
- completion: null,
233
- signature: null,
234
- pick: null,
235
- rename: null,
236
- peek: null,
237
- callHierarchy: null,
238
- symbols: null,
239
- menu: null,
240
- authors: null,
241
- wrap: null
242
- }));
204
+ /*
205
+ * The cards the features of one editor can have open, by the name of the slot each sits in. A feature
206
+ * opens and closes its own slot and reads a sibling's with `peers`; an app that adds a card of its own
207
+ * adds a name with `declare module '@adecore/editor-react' { interface PopupViews { ... } }`.
208
+ */
209
+ export interface PopupViews {
210
+ hover: HoverView;
211
+ completion: CompletionView;
212
+ signature: SignatureView;
213
+ pick: PickView;
214
+ rename: RenameView;
215
+ peek: PeekView;
216
+ callHierarchy: CallHierarchyView;
217
+ symbols: SymbolsView;
218
+ menu: MenuView;
219
+ authors: AuthorsView;
220
+ wrap: WrapView;
221
+ }
222
+
223
+ /* One card's state with a snapshot of its own, so a card draws again only for a change of its own view. */
224
+ export class PopupSlot<View> {
225
+ private view: View | null = null;
226
+ private readonly listeners = new Set<() => void>();
227
+
228
+ get(): View | null {
229
+ return this.view;
230
+ }
231
+
232
+ subscribe(listener: () => void): () => void {
233
+ this.listeners.add(listener);
234
+
235
+ return () => this.listeners.delete(listener);
236
+ }
237
+
238
+ set(view: View | null): void {
239
+ if (Object.is(view, this.view)) {
240
+ return;
241
+ }
242
+
243
+ this.view = view;
244
+
245
+ for (const listener of [...this.listeners]) {
246
+ listener();
247
+ }
248
+ }
249
+ }
250
+
251
+ export class Popups {
252
+ private readonly slots = new Map<keyof PopupViews, PopupSlot<unknown>>();
253
+
254
+ slot<Name extends keyof PopupViews>(name: Name): PopupSlot<PopupViews[Name]> {
255
+ let slot = this.slots.get(name);
256
+
257
+ if (slot === undefined) {
258
+ slot = new PopupSlot<unknown>();
259
+ this.slots.set(name, slot);
260
+ }
261
+
262
+ return slot as PopupSlot<PopupViews[Name]>;
263
+ }
243
264
  }
@@ -0,0 +1,54 @@
1
+ import type { EditorContentChange, EditorPosition, EditorRange } from '@adecore/editor';
2
+
3
+ export function comparePositions(left: EditorPosition, right: EditorPosition): number {
4
+ return left.line === right.line ? left.character - right.character : left.line - right.line;
5
+ }
6
+
7
+ export function sameRange(left: EditorRange, right: EditorRange): boolean {
8
+ return comparePositions(left.start, right.start) === 0 && comparePositions(left.end, right.end) === 0;
9
+ }
10
+
11
+ /* Where an insertion of `text` at `start` ends, counting a line break of any kind once. */
12
+ export function endOfInsertion(start: EditorPosition, text: string): EditorPosition {
13
+ const lines = text.split(/\r\n|\r|\n/);
14
+
15
+ return lines.length === 1
16
+ ? { line: start.line, character: start.character + text.length }
17
+ : { line: start.line + lines.length - 1, character: lines[lines.length - 1]!.length };
18
+ }
19
+
20
+ /* Where a position is once one change is applied to the text it was in. One inside the replaced range lands after the new text. */
21
+ export function shiftPosition(position: EditorPosition, change: EditorContentChange): EditorPosition {
22
+ const { start, end } = change.range;
23
+
24
+ if (comparePositions(position, start) < 0) {
25
+ return position;
26
+ }
27
+
28
+ const inserted = endOfInsertion(start, change.text);
29
+
30
+ if (comparePositions(position, end) < 0) {
31
+ return inserted;
32
+ }
33
+
34
+ return position.line === end.line
35
+ ? { line: inserted.line, character: inserted.character + (position.character - end.character) }
36
+ : { line: position.line + (inserted.line - end.line), character: position.character };
37
+ }
38
+
39
+ export function shiftRange(range: EditorRange, changes: readonly EditorContentChange[]): EditorRange {
40
+ let start = range.start;
41
+ let end = range.end;
42
+
43
+ for (const change of changes) {
44
+ start = shiftPosition(start, change);
45
+ end = shiftPosition(end, change);
46
+ }
47
+
48
+ return { start, end };
49
+ }
50
+
51
+ /* A range holds a position from its start up to and including its end, so a caret at either edge of a word is on it. An empty range holds only its own place. */
52
+ export function rangeHolds(range: EditorRange, position: EditorPosition): boolean {
53
+ return comparePositions(range.start, position) <= 0 && comparePositions(position, range.end) <= 0;
54
+ }
package/src/postfix.ts CHANGED
@@ -2,14 +2,16 @@ import type { EditorPosition, EditorPostfixOperand, EditorRange } from '@adecore
2
2
  import type { CompletionItem } from '@adecore/lsp';
3
3
  import { isIdentifierCharacter } from './completion-model.ts';
4
4
  import type { LocalCompletionItem } from './completion.ts';
5
- import { comparePositions } from './diagnostics-model.ts';
6
- import type { EditorLanguage } from './editor-language.ts';
5
+ import type { CompletionFeature } from './completion.ts';
6
+ import type { LanguageContext } from './language-context.ts';
7
7
  import { lineTextOf, textBeforeOf } from './line-text.ts';
8
+ import type { PickFeature } from './pick.ts';
8
9
  import type { PickRow } from './popups.ts';
9
- import { bodyWithIndentUnit, dedentLines, indentUnitOf, insertSnippet } from './snippet-insert.ts';
10
+ import { comparePositions } from './positions.ts';
11
+ import { bodyWithIndentUnit, dedentLines, indentUnitOf, insertSnippet, type InsertingSnippets } from './snippet-insert.ts';
10
12
  import { compileSnippet } from './snippet.ts';
11
13
  import { SNIPPET_KIND, sortAfterServer, templateContextAt } from './template-context.ts';
12
- import type { PostfixTemplate } from './templates.ts';
14
+ import type { PostfixTemplate } from './template-types.ts';
13
15
 
14
16
  const MAX_ROW_LENGTH = 80;
15
17
 
@@ -44,15 +46,24 @@ function rowLabel(text: string): string {
44
46
  return line.length > MAX_ROW_LENGTH ? `${line.slice(0, MAX_ROW_LENGTH - 1)}…` : line;
45
47
  }
46
48
 
49
+ /* The sibling features PostfixFeature drives, which the editor language hands over. */
50
+ interface PostfixPeers {
51
+ readonly completion: Pick<CompletionFeature, 'close' | 'showItems'>;
52
+ readonly pick: Pick<PickFeature, 'open'>;
53
+ readonly snippets: InsertingSnippets;
54
+ }
55
+
47
56
  /*
48
57
  * Postfix completion: a dot and a key after an expression, and Tab or an accepted row wraps the expression in a
49
58
  * template. The registry holds the templates and `TemplatesFeature` decides whether Tab is ours or a live template's.
50
59
  */
51
60
  export class PostfixFeature {
52
- private readonly language: EditorLanguage;
61
+ private readonly language: LanguageContext;
62
+ private readonly peers: PostfixPeers;
53
63
 
54
- constructor(language: EditorLanguage) {
64
+ constructor(language: LanguageContext, peers: PostfixPeers) {
55
65
  this.language = language;
66
+ this.peers = peers;
56
67
  }
57
68
 
58
69
  /* The key before the caret that a template of the registry applies to; null where Tab has no postfix template to expand. */
@@ -157,7 +168,7 @@ export class PostfixFeature {
157
168
 
158
169
  const start = { line: candidates.dot.line, character: candidates.dot.character + 1 };
159
170
 
160
- this.language.completion.showItems(
171
+ this.peers.completion.showItems(
161
172
  candidates.templates.map((template) => this.row(template, candidates, { start, end: caret }, template.id)),
162
173
  start
163
174
  );
@@ -175,7 +186,8 @@ export class PostfixFeature {
175
186
  return;
176
187
  }
177
188
 
178
- const { editor, completion, pick, project } = this.language;
189
+ const { editor, project } = this.language;
190
+ const { completion, pick } = this.peers;
179
191
  const rows = operands.map((operand, index): PickRow => ({ id: String(index), label: rowLabel(editor.textInRange(operand.range)), detail: '' }));
180
192
 
181
193
  completion.close();
@@ -195,6 +207,7 @@ export class PostfixFeature {
195
207
 
196
208
  return insertSnippet(
197
209
  this.language,
210
+ this.peers.snippets,
198
211
  bodyWithIndentUnit(template.body, indentUnitOf(editor)),
199
212
  [{ range: { start: operand.range.start, end: caret } }],
200
213
  (name) => (name === 'EXPR' ? expression : undefined)