@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
@@ -14,14 +14,24 @@ import {
14
14
  import i18next, { type i18n } from 'i18next';
15
15
  import { ClipboardHistory } from './clipboard-history.ts';
16
16
  import { EditLocations } from './edit-locations.ts';
17
- import type { LanguageHost } from './host-types.ts';
17
+ import type { LanguageHost, ProjectFiles } from './host-types.ts';
18
18
  import { NavigationHistory, type Place } from './navigation-history.ts';
19
19
  import { PANEL_BODY_HEIGHT } from './panel-size.ts';
20
20
  import { relativeTo } from './paths.ts';
21
21
  import { ProjectProblems, serviceProblems } from './project-problems.ts';
22
- import { disposeSnippetTransforms } from './snippet-transform-queue.ts';
22
+ import { SnippetTransforms, type SnippetTransformLease } from './snippet-transform-queue.ts';
23
23
  import { TemplateRegistry } from './templates.ts';
24
- import { applyWorkspaceEdit, type ProjectFiles } from './workspace-edit.ts';
24
+ import { realTimers, type Timers } from './timers.ts';
25
+ import { applyWorkspaceEdit } from './workspace-edit.ts';
26
+
27
+ /*
28
+ * Builds the service of a project that needs what the project knows: the text of the editor that holds a
29
+ * document, and the way an edit a server asks for is applied. Called once by the constructor; both are
30
+ * methods of the project, so the service may keep them and call them later.
31
+ */
32
+ export type LanguageServiceFactory<Service extends LanguageService = LanguageService> = (
33
+ project: Pick<ProjectLanguage, 'openTextOf' | 'applyWorkspaceEdit'>
34
+ ) => Service;
25
35
 
26
36
  export interface LanguageDocumentHandle {
27
37
  readonly uri: string;
@@ -120,8 +130,8 @@ function filesOf(targets: readonly FileOperationTarget[]): Array<{ uri: string;
120
130
  * A shared language service and document ownership for the editors of a project. Two editors on the same
121
131
  * file hold one document, and only the first one sends changes, since both would report the same edit.
122
132
  */
123
- export class ProjectLanguage {
124
- readonly service: LanguageService;
133
+ export class ProjectLanguage<Service extends LanguageService = LanguageService> {
134
+ readonly service: Service;
125
135
  readonly host: LanguageHost;
126
136
  readonly i18n: i18n;
127
137
  readonly folder: string;
@@ -132,6 +142,7 @@ export class ProjectLanguage {
132
142
  readonly templates: TemplateRegistry;
133
143
  private readonly holders = new Map<string, Holder>();
134
144
  private readonly files: ProjectFiles | null;
145
+ private snippetQueue: SnippetTransforms | null = null;
135
146
 
136
147
  /* The body height of the peek and call hierarchy panels, shared by the editors of the project. */
137
148
  panelBodyHeight: number;
@@ -141,25 +152,36 @@ export class ProjectLanguage {
141
152
  private lastPlace: Place | null = null;
142
153
  private disposed = false;
143
154
  private readonly subscriptions: readonly Disposable[];
155
+ private readonly disposers: Array<() => void> = [];
144
156
  /* The result id the server gave each document in its last workspace report, which the next asks with. */
145
157
  private readonly workspaceResults = new Map<string, string>();
146
158
 
147
- constructor(service: LanguageService, host: LanguageHost = {}) {
148
- this.service = service;
159
+ constructor(service: Service | LanguageServiceFactory<Service>, host: LanguageHost = {}) {
149
160
  this.host = host;
150
161
  this.i18n = host.i18n ?? i18next;
151
162
  this.folder = host.folder ?? '';
152
163
  this.files = host.files ?? null;
164
+ this.service = typeof service === 'function' ? service(this) : service;
153
165
  this.edits = new EditLocations(host.editHistoryLimit);
154
166
  this.clipboard = host.clipboard ?? new ClipboardHistory();
155
167
  this.templates = host.templates ?? new TemplateRegistry();
156
168
  this.panelBodyHeight = host.panelBodyHeight ?? PANEL_BODY_HEIGHT;
157
- this.problems = new ProjectProblems(host.problemSource ?? serviceProblems(service, (uri) => this.pathOfLocation(uri) ?? uri));
158
- const shows = service.onShowDocument?.((params) => this.showDocument(params));
159
- const messages = host.onServerMessage === undefined ? undefined : service.onServerMessage?.((message) => host.onServerMessage!(message));
169
+ this.problems = new ProjectProblems(host.problemSource ?? serviceProblems(this.service, (uri) => this.pathOfLocation(uri) ?? uri));
170
+ const shows = this.service.onShowDocument?.((params) => this.showDocument(params));
171
+ const messages = host.onServerMessage === undefined ? undefined : this.service.onServerMessage?.((message) => host.onServerMessage!(message));
160
172
  this.subscriptions = [shows, messages].flatMap((subscription) => (subscription === undefined ? [] : [subscription]));
161
173
  }
162
174
 
175
+ /* Runs `dispose` when the project is disposed, after the editors' documents are closed. */
176
+ onDispose(dispose: () => void): void {
177
+ this.disposers.push(dispose);
178
+ }
179
+
180
+ /* The text of the editor that holds a document first, or undefined when no editor holds it. */
181
+ openTextOf(uri: string): string | undefined {
182
+ return this.holders.get(uri)?.editors[0]?.getText();
183
+ }
184
+
163
185
  /* Open panels of other editors of the project follow a resize. */
164
186
  onPanelBodyChange(listener: (height: number) => void): () => void {
165
187
  this.panelListeners.add(listener);
@@ -206,7 +228,6 @@ export class ProjectLanguage {
206
228
  return this.service.willCreateFiles?.(filesOf(targets)) ?? Promise.resolve(null);
207
229
  }
208
230
 
209
- /* Tells the servers that files were made, once they are. */
210
231
  didCreateFiles(targets: readonly FileOperationTarget[]): Promise<void> {
211
232
  return this.service.didCreateFiles?.(filesOf(targets)) ?? Promise.resolve();
212
233
  }
@@ -216,7 +237,6 @@ export class ProjectLanguage {
216
237
  return this.service.willDeleteFiles?.(filesOf(targets)) ?? Promise.resolve(null);
217
238
  }
218
239
 
219
- /* Tells the servers that files were deleted, once they are. */
220
240
  didDeleteFiles(targets: readonly FileOperationTarget[]): Promise<void> {
221
241
  const files = filesOf(targets);
222
242
 
@@ -230,7 +250,7 @@ export class ProjectLanguage {
230
250
  * text file. A document of a scheme a server owns, such as a decompiled class, is read from that server.
231
251
  */
232
252
  async readText(uri: string): Promise<string | null> {
233
- const open = this.holders.get(uri)?.editors[0]?.getText();
253
+ const open = this.openTextOf(uri);
234
254
 
235
255
  if (open !== undefined) {
236
256
  return open;
@@ -249,6 +269,10 @@ export class ProjectLanguage {
249
269
  * offers workspace diagnostics. A file the server reports as unchanged keeps what it had. False when no server offers them.
250
270
  */
251
271
  async pullWorkspaceProblems(uri: string, options: { readonly signal?: AbortSignal } = {}): Promise<boolean> {
272
+ if (this.host.pullWorkspaceProblems !== undefined) {
273
+ return this.host.pullWorkspaceProblems(uri, options);
274
+ }
275
+
252
276
  const { service } = this;
253
277
  if (service.workspaceDiagnostics === undefined || !service.supports('workspace/diagnostic', uri)) {
254
278
  return false;
@@ -323,6 +347,27 @@ export class ProjectLanguage {
323
347
  return pending.position;
324
348
  }
325
349
 
350
+ /* A lease on the project's one snippet transform queue, which runs one job at a time for every editor; null when the host brought no worker. The queue keeps the clock of the first editor that asked. */
351
+ acquireSnippetTransforms(timers: Timers = realTimers): SnippetTransformLease | null {
352
+ const factory = this.host.snippetTransformWorker;
353
+
354
+ if (factory === undefined) {
355
+ return null;
356
+ }
357
+
358
+ if (this.snippetQueue === null) {
359
+ const queue = new SnippetTransforms(factory, timers, () => {
360
+ if (this.snippetQueue === queue) {
361
+ this.snippetQueue = null;
362
+ }
363
+ });
364
+
365
+ this.snippetQueue = queue;
366
+ }
367
+
368
+ return this.snippetQueue.acquire();
369
+ }
370
+
326
371
  /* Whether the editor is the first to hold the document, the one whose changes stand for the document's. */
327
372
  holdsFirst(uri: string, editor: Editor): boolean {
328
373
  return this.holders.get(uri)?.editors[0] === editor;
@@ -423,7 +468,7 @@ export class ProjectLanguage {
423
468
  for (const subscription of this.subscriptions) {
424
469
  subscription.dispose();
425
470
  }
426
- disposeSnippetTransforms(this);
471
+ this.snippetQueue?.dispose();
427
472
 
428
473
  for (const [uri, holder] of this.holders) {
429
474
  if (holder.sync === null) {
@@ -440,5 +485,9 @@ export class ProjectLanguage {
440
485
 
441
486
  this.holders.clear();
442
487
  this.problems.dispose();
488
+
489
+ for (const dispose of this.disposers.splice(0).reverse()) {
490
+ dispose();
491
+ }
443
492
  }
444
493
  }
@@ -1,6 +1,7 @@
1
1
  import type { Diagnostic, LanguageService } from '@adecore/lsp';
2
- import { comparePositions, problemCountsOf, severityOf } from './diagnostics-model.ts';
3
- import type { ProblemCounts } from './diagnostics.ts';
2
+ import { problemCountsOf, severityOf } from './diagnostics-model.ts';
3
+ import type { ProblemCounts } from './diagnostics-model.ts';
4
+ import { comparePositions } from './positions.ts';
4
5
 
5
6
  /* One problem of a file and the server that reported it. */
6
7
  export interface ProblemRow {
@@ -32,6 +33,13 @@ export interface ProblemReport {
32
33
  }
33
34
 
34
35
  /* Hands every report to `listener` until the function it returns runs. */
36
+ export interface ProblemsHost {
37
+ /* Where `project.problems` reads its reports, such as a machine that also reports files no editor here holds; the service's diagnostics without one. */
38
+ readonly problemSource?: ProblemSource;
39
+ /* Asks the servers of `uri` for the problems of every file they know and lists them in `project.problems`; false when none offers them. Without it the service's workspace diagnostics are pulled. */
40
+ pullWorkspaceProblems?(uri: string, options: { readonly signal?: AbortSignal }): Promise<boolean>;
41
+ }
42
+
35
43
  export type ProblemSource = (listener: (report: ProblemReport) => void) => () => void;
36
44
 
37
45
  /* The diagnostics a service reports, by the stored path `pathOf` gives each URI. */
@@ -158,7 +158,6 @@ export function fitReplacement(selected: string, replacement: string): string {
158
158
  return breaks === '\n' ? fitted : fitted.replace(/\n/g, breaks);
159
159
  }
160
160
 
161
- /* One stretch of the proposal as the card draws it. */
162
161
  export interface DiffSegment {
163
162
  readonly kind: 'same' | 'added' | 'removed';
164
163
  readonly text: string;
@@ -1,7 +1,7 @@
1
1
  import type { EditorPosition, EditorRange } from '@adecore/editor';
2
2
  import type { DocumentSymbol, DocumentSymbolResult, Location, PrepareRenameResult, TextEdit, WorkspaceEdit } from '@adecore/lsp';
3
3
  import { isIdentifierCharacter } from './completion-model.ts';
4
- import { rangeHolds } from './diagnostics-model.ts';
4
+ import { rangeHolds } from './positions.ts';
5
5
  import { textEntriesOf } from './workspace-edit.ts';
6
6
 
7
7
  /* The identifier the caret is in or touches; null where there is none. */
package/src/rename.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import type { EditorRange } from '@adecore/editor';
2
2
  import { StaleResultError, type Location, type PrepareRenameResult, type WorkspaceEdit } 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 { lineTextOf } from './line-text.ts';
7
7
  import type { RenameView } from './popups.ts';
8
8
  import { occurrencesOf, renameKindOf, renamePreviewOf, renameTargetOf, wordRangeAt, type RenameTarget } from './rename-model.ts';
@@ -33,10 +33,10 @@ interface Session {
33
33
  * Edits to other files land as unsaved drafts (`applyWorkspaceEdit`), so nothing is written to disk here.
34
34
  */
35
35
  export class RenameFeature {
36
- private readonly language: EditorLanguage;
36
+ private readonly language: LanguageContext;
37
37
  private session: Session | null = null;
38
38
 
39
- constructor(language: EditorLanguage) {
39
+ constructor(language: LanguageContext) {
40
40
  this.language = language;
41
41
  const { editor } = language;
42
42
 
@@ -161,7 +161,6 @@ export class RenameFeature {
161
161
  }
162
162
  }
163
163
 
164
- /* Applies the edit the preview showed. */
165
164
  async confirm(): Promise<void> {
166
165
  const session = this.session;
167
166
 
@@ -180,7 +179,7 @@ export class RenameFeature {
180
179
 
181
180
  /* The name was changed, which answers the failure under it. */
182
181
  edited(): void {
183
- if (this.language.popups.getState().rename?.error != null) {
182
+ if (this.language.popups.slot('rename').get()?.error != null) {
184
183
  this.publish({ error: null });
185
184
  }
186
185
  }
@@ -211,7 +210,7 @@ export class RenameFeature {
211
210
  this.session?.names.abort();
212
211
  this.session = null;
213
212
  const { editor, popups } = this.language;
214
- popups.setState({ rename: null });
213
+ popups.slot('rename').set(null);
215
214
  editor.setHighlights([]);
216
215
  editor.focus();
217
216
  }
@@ -326,24 +325,22 @@ export class RenameFeature {
326
325
  }
327
326
 
328
327
  const { popups } = this.language;
329
- const current = popups.getState().rename;
330
-
331
- popups.setState({
332
- rename: {
333
- phase: 'input',
334
- range: session.target.range,
335
- original: session.original,
336
- placeholder: session.target.placeholder,
337
- occurrences: null,
338
- busy: false,
339
- error: null,
340
- name: session.target.placeholder,
341
- files: [],
342
- operations: [],
343
- suggestions: [],
344
- ...current,
345
- ...patch
346
- }
328
+ const current = popups.slot('rename').get();
329
+
330
+ popups.slot('rename').set({
331
+ phase: 'input',
332
+ range: session.target.range,
333
+ original: session.original,
334
+ placeholder: session.target.placeholder,
335
+ occurrences: null,
336
+ busy: false,
337
+ error: null,
338
+ name: session.target.placeholder,
339
+ files: [],
340
+ operations: [],
341
+ suggestions: [],
342
+ ...current,
343
+ ...patch
347
344
  });
348
345
  }
349
346
 
@@ -1,9 +1,10 @@
1
1
  import { findDocComments, type DocComment, type EditorPosition, type EditorRange, type EditorReplacement, type EditorTrackedRange } from '@adecore/editor';
2
- import { comparePositions } from './diagnostics-model.ts';
3
2
  import { parseDocComment, type ParsedDocComment } from './doc-comment-model.ts';
4
- import type { EditorLanguage } from './editor-language.ts';
5
3
  import { KEY_PRIORITY } from './key-priority.ts';
4
+ import type { LanguageContext } from './language-context.ts';
6
5
  import { lineTextOf } from './line-text.ts';
6
+ import type { NavigationFeature } from './navigation.ts';
7
+ import { comparePositions } from './positions.ts';
7
8
  import { isShortcut } from './shortcut-keys.ts';
8
9
  import { realTimers, type Timers } from './timers.ts';
9
10
 
@@ -74,6 +75,11 @@ function samePlace(range: EditorRange | null, position: EditorPosition): boolean
74
75
  return range !== null && comparePositions(range.start, position) === 0;
75
76
  }
76
77
 
78
+ /* The sibling features RenderedDocsFeature drives, which the editor language hands over. */
79
+ interface RenderedDocsPeers {
80
+ readonly navigation: Pick<NavigationFeature, 'goToName'>;
81
+ }
82
+
77
83
  /*
78
84
  * Documentation comments drawn as formatted text in place of their lines, the way the Reader mode of the
79
85
  * documentation does, and the button in the gutter that switches one between that and its source. The
@@ -81,7 +87,8 @@ function samePlace(range: EditorRange | null, position: EditorPosition): boolean
81
87
  * it can be edited, and shown formatted again when the caret leaves it.
82
88
  */
83
89
  export class RenderedDocsFeature {
84
- private readonly language: EditorLanguage;
90
+ private readonly language: LanguageContext;
91
+ private readonly peers: RenderedDocsPeers;
85
92
  private readonly timers: Timers;
86
93
  private settings: RenderedDocsSettings = { renderDocComments: false };
87
94
  private enabled = true;
@@ -108,8 +115,9 @@ export class RenderedDocsFeature {
108
115
 
109
116
  private disposed = false;
110
117
 
111
- constructor(language: EditorLanguage, timers: Timers = realTimers) {
118
+ constructor(language: LanguageContext, peers: RenderedDocsPeers, timers: Timers = realTimers) {
112
119
  this.language = language;
120
+ this.peers = peers;
113
121
  this.timers = timers;
114
122
  const { editor } = language;
115
123
 
@@ -259,11 +267,10 @@ export class RenderedDocsFeature {
259
267
  return this.language.service.supports('workspace/symbol', uri);
260
268
  }
261
269
 
262
- /* Goes to what a link in a comment names. */
263
270
  follow(name: string, comment: DocComment): void {
264
271
  const member = name.split(/::|[#.\\]/).filter((part) => part !== '');
265
272
  const target = (member.at(-1) ?? name).replace(/\(\)$/, '');
266
- void this.language.navigation.goToName(target, startOf(comment), null);
273
+ void this.peers.navigation.goToName(target, startOf(comment), null);
267
274
  }
268
275
 
269
276
  /* By place in the document, so a row keeps its element when an edit above it moves its lines. */
@@ -1,6 +1,6 @@
1
1
  import type { EditorRange } from '@adecore/editor';
2
2
  import type { SelectionRange } from '@adecore/lsp';
3
- import type { EditorLanguage } from './editor-language.ts';
3
+ import type { LanguageContext } from './language-context.ts';
4
4
 
5
5
  const METHOD = 'textDocument/selectionRange';
6
6
 
@@ -20,7 +20,7 @@ export function selectionChainOf(selection: SelectionRange): EditorRange[] {
20
20
  * follow the syntax of the file. Where no server offers them the editor grows by its own rule.
21
21
  */
22
22
  export class SelectionRangesFeature {
23
- constructor(language: EditorLanguage) {
23
+ constructor(language: LanguageContext) {
24
24
  const { editor, uri } = language;
25
25
 
26
26
  editor.setSelectionRanges(async (positions) => {
@@ -1,7 +1,7 @@
1
1
  import type { EditorRange, EditorSemanticToken } from '@adecore/editor';
2
2
  import { StaleResultError, type SemanticTokens, type SemanticTokensDelta, type SemanticTokensLegend } from '@adecore/lsp';
3
- import type { EditorLanguage } from './editor-language.ts';
4
3
  import { covers, withMargin } from './inlay-hints.ts';
4
+ import type { LanguageContext } from './language-context.ts';
5
5
  import { lineTextOf } from './line-text.ts';
6
6
  import { Refresher } from './refresher.ts';
7
7
  import { applySemanticEdits } from './semantic-delta.ts';
@@ -15,9 +15,9 @@ const PAUSE_MS = 200;
15
15
  const SCROLL_PAUSE_MS = 100;
16
16
 
17
17
  /* A document with more lines or characters than this is first asked for what is in view, when the server answers ranges. */
18
- export const DEFAULT_RANGE_LINES = 5000;
18
+ const DEFAULT_RANGE_LINES = 5000;
19
19
 
20
- export const DEFAULT_RANGE_CHARACTERS = 500_000;
20
+ const DEFAULT_RANGE_CHARACTERS = 500_000;
21
21
 
22
22
  /* What decides when a document is too large to wait for in full. */
23
23
  export interface SemanticTokensOptions {
@@ -42,7 +42,7 @@ interface Held {
42
42
  export class SemanticTokensFeature {
43
43
  private readonly refresher: Refresher;
44
44
  private readonly scrolled: Refresher;
45
- private readonly language: EditorLanguage;
45
+ private readonly language: LanguageContext;
46
46
  private readonly options: SemanticTokensOptions;
47
47
  private held: Held | null = null;
48
48
  private heldLegend = '';
@@ -56,7 +56,7 @@ export class SemanticTokensFeature {
56
56
  private drawn: EditorSemanticToken[] = [];
57
57
  private epoch = 0;
58
58
 
59
- constructor(language: EditorLanguage, timers: Timers = realTimers, options: SemanticTokensOptions = {}) {
59
+ constructor(language: LanguageContext, timers: Timers = realTimers, options: SemanticTokensOptions = {}) {
60
60
  const { editor } = language;
61
61
  this.language = language;
62
62
  this.options = options;
@@ -2,7 +2,7 @@ import type { KeyChord } from '@adecore/editor';
2
2
  import { chordOf, KEYMAP_IDS, parseChord, type Keymap, typesInsteadOfChord } from '@adecore/editor/keymap';
3
3
  import { matchesShortcut } from '@adecore/ui';
4
4
 
5
- export interface LanguageShortcut extends KeyChord {
5
+ interface LanguageShortcut extends KeyChord {
6
6
  readonly apple: boolean;
7
7
  }
8
8
 
package/src/signature.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import type { EditorPosition, EditorTextChange } from '@adecore/editor';
2
2
  import type { SignatureHelp, SignatureHelpContext } from '@adecore/lsp';
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
5
  import { isShortcut } from './shortcut-keys.ts';
6
6
  import { signatureViewOf } from './signature-model.ts';
7
7
  import { realTimers, type Timers } from './timers.ts';
@@ -15,7 +15,7 @@ const PAUSE_MS = 60;
15
15
  * so the active parameter follows; the server answering nothing is the caret leaving the call.
16
16
  */
17
17
  export class SignatureFeature {
18
- private readonly language: EditorLanguage;
18
+ private readonly language: LanguageContext;
19
19
  private readonly timers: Timers;
20
20
  private timer: unknown;
21
21
  private request = 0;
@@ -23,7 +23,7 @@ export class SignatureFeature {
23
23
  private help: SignatureHelp | null = null;
24
24
  private anchor: EditorPosition | null = null;
25
25
 
26
- constructor(language: EditorLanguage, timers: Timers = realTimers) {
26
+ constructor(language: LanguageContext, timers: Timers = realTimers) {
27
27
  this.language = language;
28
28
  this.timers = timers;
29
29
  const { editor } = language;
@@ -33,7 +33,7 @@ export class SignatureFeature {
33
33
  editor.onCaret(() => this.retrigger()),
34
34
  editor.onBlur(() => this.close()),
35
35
  language.onKey((event) => {
36
- if (event.key === 'Escape' && this.isOpen && this.language.popups.getState().callHierarchy === null) {
36
+ if (event.key === 'Escape' && this.isOpen && this.language.popups.slot('callHierarchy').get() === null) {
37
37
  this.close();
38
38
 
39
39
  return true;
@@ -63,7 +63,7 @@ export class SignatureFeature {
63
63
  }
64
64
 
65
65
  get isOpen(): boolean {
66
- return this.language.popups.getState().signature !== null;
66
+ return this.language.popups.slot('signature').get() !== null;
67
67
  }
68
68
 
69
69
  /* Asks for the parameters of the call at the caret, as its key does. */
@@ -93,7 +93,7 @@ export class SignatureFeature {
93
93
  }
94
94
 
95
95
  this.help = next;
96
- this.language.popups.setState({ signature: { anchor: this.anchor, model } });
96
+ this.language.popups.slot('signature').set({ anchor: this.anchor, model });
97
97
 
98
98
  return true;
99
99
  }
@@ -106,7 +106,7 @@ export class SignatureFeature {
106
106
  this.anchor = null;
107
107
 
108
108
  if (this.isOpen) {
109
- this.language.popups.setState({ signature: null });
109
+ this.language.popups.slot('signature').set(null);
110
110
  }
111
111
  }
112
112
 
@@ -187,6 +187,6 @@ export class SignatureFeature {
187
187
 
188
188
  this.help = help;
189
189
  this.anchor ??= caret;
190
- this.language.popups.setState({ signature: { anchor: this.anchor, model } });
190
+ this.language.popups.slot('signature').set({ anchor: this.anchor, model });
191
191
  }
192
192
  }
@@ -1,5 +1,5 @@
1
1
  import type { Editor, EditorContentChange, EditorRange } from '@adecore/editor';
2
- import { comparePositions, shiftPosition } from './diagnostics-model.ts';
2
+ import { comparePositions, shiftPosition } from './positions.ts';
3
3
  import type { SnippetTransformJob } from './snippet-transform-protocol.ts';
4
4
  import type { SnippetTransformLease } from './snippet-transform-queue.ts';
5
5
  import type { SnippetTransform } from './snippet.ts';
@@ -1,12 +1,12 @@
1
1
  import type { Editor, EditorContentChange, EditorPosition, EditorRange } from '@adecore/editor';
2
2
  import { fileUriToPath } from '@adecore/lsp';
3
- import { comparePositions, shiftPosition } from './diagnostics-model.ts';
4
- import type { EditorLanguage } from './editor-language.ts';
3
+ import type { LanguageContext } from './language-context.ts';
5
4
  import { lineTextOf, textBeforeOf } from './line-text.ts';
5
+ import { comparePositions, shiftPosition } from './positions.ts';
6
6
  import { wordRangeAt } from './rename-model.ts';
7
7
  import { jobTable } from './snippet-field-transforms.ts';
8
8
  import { indentSnippet } from './snippet-indent.ts';
9
- import { positionInInsertion } from './snippet-session.ts';
9
+ import { positionInInsertion, type SnippetFeature } from './snippet-session.ts';
10
10
  import { SnippetTransformError } from './snippet-transform-client.ts';
11
11
  import { MAX_TRANSFORM_JOBS, MAX_TRANSFORM_WORK } from './snippet-transform-protocol.ts';
12
12
  import { SnippetTransformQueueError } from './snippet-transform-queue.ts';
@@ -18,6 +18,9 @@ const MAX_CHARACTERS = 2_000_000;
18
18
  const MAX_RANGES = 1_000;
19
19
  const TOAST_ID = 'language-completion';
20
20
 
21
+ /* What inserting a snippet asks of the session it starts or joins. */
22
+ export type InsertingSnippets = Pick<SnippetFeature, 'applyEdits' | 'beginInstances' | 'isActive' | 'token' | 'transformVariables'>;
23
+
21
24
  export interface SnippetPlacement {
22
25
  readonly range: EditorRange;
23
26
 
@@ -38,12 +41,10 @@ interface Draft {
38
41
  parsed: ParsedSnippet;
39
42
  }
40
43
 
41
- /* Each line's leading tabs become the editor's own indentation unit. */
42
44
  export function bodyWithIndentUnit(body: string, unit: string): string {
43
45
  return unit === '\t' ? body : body.replace(/^\t+/gm, (tabs) => unit.repeat(tabs.length));
44
46
  }
45
47
 
46
- /* One level of the editor's indentation: spaces for a tab size, or a tab. */
47
48
  export function indentUnitOf(editor: Editor): string {
48
49
  const { tabSize, insertSpaces } = editor.getIndentation();
49
50
 
@@ -77,12 +78,13 @@ function sizeOf(parsed: ParsedSnippet): number {
77
78
  * to the text before the placement, and a running session takes the insertion as a nested one. False when nothing was inserted.
78
79
  */
79
80
  export async function insertSnippet(
80
- language: EditorLanguage,
81
+ language: LanguageContext,
82
+ snippets: InsertingSnippets,
81
83
  source: string,
82
84
  placements: readonly SnippetPlacement[],
83
85
  extra?: (name: string) => string | undefined
84
86
  ): Promise<boolean> {
85
- const { editor, project, uri, snippets } = language;
87
+ const { editor, project, uri } = language;
86
88
 
87
89
  if (placements.length === 0 || editor.isReadOnly?.() === true) {
88
90
  return false;
@@ -140,7 +142,7 @@ export async function insertSnippet(
140
142
  }
141
143
  }
142
144
 
143
- await transformVariables(language, template, drafts, current);
145
+ await transformVariables(language, snippets, template, drafts, current);
144
146
 
145
147
  if (!current()) {
146
148
  return false;
@@ -165,7 +167,7 @@ export async function insertSnippet(
165
167
  }
166
168
 
167
169
  off();
168
- place(language, drafts, starts, continuing && snippets.isActive && snippets.token === token);
170
+ place(language, snippets, drafts, starts, continuing && snippets.isActive && snippets.token === token);
169
171
  editor.focus();
170
172
 
171
173
  return true;
@@ -195,8 +197,14 @@ export async function insertSnippet(
195
197
  }
196
198
 
197
199
  /* Runs the transforms of variables through the worker, once for all placements, and renders them again with the answers. */
198
- async function transformVariables(language: EditorLanguage, template: SnippetTemplate, drafts: Draft[], current: () => boolean): Promise<void> {
199
- const { editor, project, snippets } = language;
200
+ async function transformVariables(
201
+ language: LanguageContext,
202
+ snippets: InsertingSnippets,
203
+ template: SnippetTemplate,
204
+ drafts: Draft[],
205
+ current: () => boolean
206
+ ): Promise<void> {
207
+ const { editor, project } = language;
200
208
  const { jobs, slotOf } = jobTable();
201
209
  const slots = drafts.map((draft) =>
202
210
  (draft.raw.transforms ?? []).map((range) => slotOf({ ...range.transform, value: draft.raw.text.slice(range.start, range.end) }))
@@ -234,9 +242,8 @@ async function transformVariables(language: EditorLanguage, template: SnippetTem
234
242
  });
235
243
  }
236
244
 
237
- /* Starts the session on the tab stops, or puts the caret after the primary insertion when there are none. */
238
- function place(language: EditorLanguage, drafts: readonly Draft[], starts: readonly EditorPosition[], nested: boolean): void {
239
- const { editor, snippets } = language;
245
+ function place(language: LanguageContext, snippets: InsertingSnippets, drafts: readonly Draft[], starts: readonly EditorPosition[], nested: boolean): void {
246
+ const { editor } = language;
240
247
  const primary = drafts.at(-1)!.parsed;
241
248
 
242
249
  if (primary.stops.length > 0) {