@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,6 +1,10 @@
1
- import type { EditorContentChange, EditorMarker, EditorMarkerSeverity, EditorPosition, EditorRange } from '@adecore/editor';
1
+ import type { EditorMarker, EditorMarkerSeverity, EditorPosition } from '@adecore/editor';
2
2
  import type { Diagnostic } from '@adecore/lsp';
3
- import type { ProblemCounts } from './diagnostics.ts';
3
+ export interface ProblemCounts {
4
+ readonly error: number;
5
+ readonly warning: number;
6
+ readonly info: number;
7
+ }
4
8
  export interface Problem {
5
9
  readonly diagnostic: Diagnostic;
6
10
  readonly server: string;
@@ -8,12 +12,6 @@ export interface Problem {
8
12
  export declare function severityOf(diagnostic: Diagnostic): EditorMarkerSeverity;
9
13
  export declare function markerOf(diagnostic: Diagnostic): EditorMarker;
10
14
  export declare function problemCountsOf(diagnostics: readonly Diagnostic[]): ProblemCounts;
11
- export declare function comparePositions(left: EditorPosition, right: EditorPosition): number;
12
- export declare function sameRange(left: EditorRange, right: EditorRange): boolean;
13
- export declare function endOfInsertion(start: EditorPosition, text: string): EditorPosition;
14
- export declare function shiftPosition(position: EditorPosition, change: EditorContentChange): EditorPosition;
15
- export declare function shiftRange(range: EditorRange, changes: readonly EditorContentChange[]): EditorRange;
16
- export declare function rangeHolds(range: EditorRange, position: EditorPosition): boolean;
17
15
  export declare function problemsAt(problems: readonly Problem[], position: EditorPosition): Problem[];
18
16
  export declare function neighborProblem(problems: readonly Problem[], from: EditorPosition, direction: 1 | -1): Problem | null;
19
17
  export declare function codeLabelOf(diagnostic: Diagnostic): string;
@@ -1,3 +1,4 @@
1
+ import { comparePositions, rangeHolds } from './positions.js';
1
2
  const SEVERITIES = {
2
3
  1: 'error',
3
4
  2: 'warning',
@@ -30,60 +31,6 @@ export function problemCountsOf(diagnostics) {
30
31
  info: count(3)
31
32
  };
32
33
  }
33
- export function comparePositions(left, right) {
34
- return left.line === right.line ? left.character - right.character : left.line - right.line;
35
- }
36
- export function sameRange(left, right) {
37
- return comparePositions(left.start, right.start) === 0 && comparePositions(left.end, right.end) === 0;
38
- }
39
- /* Where an insertion of `text` at `start` ends, counting a line break of any kind once. */
40
- export function endOfInsertion(start, text) {
41
- const lines = text.split(/\r\n|\r|\n/);
42
- return lines.length === 1 ? {
43
- line: start.line,
44
- character: start.character + text.length
45
- } : {
46
- line: start.line + lines.length - 1,
47
- character: lines[lines.length - 1].length
48
- };
49
- }
50
- /* 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. */
51
- export function shiftPosition(position, change) {
52
- const {
53
- start,
54
- end
55
- } = change.range;
56
- if (comparePositions(position, start) < 0) {
57
- return position;
58
- }
59
- const inserted = endOfInsertion(start, change.text);
60
- if (comparePositions(position, end) < 0) {
61
- return inserted;
62
- }
63
- return position.line === end.line ? {
64
- line: inserted.line,
65
- character: inserted.character + (position.character - end.character)
66
- } : {
67
- line: position.line + (inserted.line - end.line),
68
- character: position.character
69
- };
70
- }
71
- export function shiftRange(range, changes) {
72
- let start = range.start;
73
- let end = range.end;
74
- for (const change of changes) {
75
- start = shiftPosition(start, change);
76
- end = shiftPosition(end, change);
77
- }
78
- return {
79
- start,
80
- end
81
- };
82
- }
83
- /* 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. */
84
- export function rangeHolds(range, position) {
85
- return comparePositions(range.start, position) <= 0 && comparePositions(position, range.end) <= 0;
86
- }
87
34
  /* The problems under a position, worst first. A hint is not a problem, so it is left to the colors and the faded text. */
88
35
  export function problemsAt(problems, position) {
89
36
  const rank = problem => problem.diagnostic.severity ?? 1;
@@ -1,17 +1,18 @@
1
1
  import type { EditorPosition } from '@adecore/editor';
2
- import { type Problem } from './diagnostics-model.ts';
3
- import type { EditorLanguage } from './editor-language.ts';
4
- export interface ProblemCounts {
5
- readonly error: number;
6
- readonly warning: number;
7
- readonly info: number;
2
+ import { type Problem, type ProblemCounts } from './diagnostics-model.ts';
3
+ import type { LanguageContext } from './language-context.ts';
4
+ interface DiagnosticsPeers {
5
+ readonly hover: {
6
+ showProblemsAt(position: EditorPosition): boolean;
7
+ };
8
8
  }
9
9
  export declare class DiagnosticsFeature {
10
10
  private readonly language;
11
+ private readonly peers;
11
12
  private readonly reports;
12
13
  private readonly listeners;
13
14
  private list;
14
- constructor(language: EditorLanguage);
15
+ constructor(language: LanguageContext, peers: DiagnosticsPeers);
15
16
  get problems(): readonly Problem[];
16
17
  counts(): ProblemCounts;
17
18
  at(position: EditorPosition): Problem[];
@@ -23,3 +24,4 @@ export declare class DiagnosticsFeature {
23
24
  private rebuild;
24
25
  private collect;
25
26
  }
27
+ export {};
@@ -1,5 +1,6 @@
1
- import { comparePositions, markerOf, neighborProblem, problemCountsOf, problemsAt, sameRange, severityOf, shiftRange } from './diagnostics-model.js';
1
+ import { markerOf, neighborProblem, problemCountsOf, problemsAt, severityOf } from './diagnostics-model.js';
2
2
  import { KEY_PRIORITY } from './key-priority.js';
3
+ import { comparePositions, sameRange, shiftRange } from './positions.js';
3
4
  import { isShortcut } from './shortcut-keys.js';
4
5
  /*
5
6
  * The problems the servers report for one file. A report from a server replaces the one before it
@@ -8,11 +9,13 @@ import { isShortcut } from './shortcut-keys.js';
8
9
  */
9
10
  export class DiagnosticsFeature {
10
11
  language;
12
+ peers;
11
13
  reports = new Map();
12
14
  listeners = new Set();
13
15
  list = [];
14
- constructor(language) {
16
+ constructor(language, peers) {
15
17
  this.language = language;
18
+ this.peers = peers;
16
19
  const {
17
20
  editor,
18
21
  project,
@@ -64,7 +67,6 @@ export class DiagnosticsFeature {
64
67
  this.reveal(target, comparePositions(start, caret) > 0 ? 'centerDown' : 'centerUp');
65
68
  return true;
66
69
  }
67
- /* Puts the caret on the first problem of the file. */
68
70
  goToFirst() {
69
71
  const target = neighborProblem(this.list, {
70
72
  line: -1,
@@ -89,7 +91,7 @@ export class DiagnosticsFeature {
89
91
  } = this.language;
90
92
  editor.setCaret(problem.diagnostic.range.start, reveal);
91
93
  editor.focus();
92
- this.language.hover.showProblemsAt(editor.getCaret());
94
+ this.peers.hover.showProblemsAt(editor.getCaret());
93
95
  const severity = project.i18n.t(`editor:language.announce.severity.${severityOf(problem.diagnostic)}`);
94
96
  editor.announce(project.i18n.t('editor:language.announce.problem', {
95
97
  severity,
@@ -0,0 +1,28 @@
1
+ import type { Editor, EditorEngine, EditorTheme } from '@adecore/editor';
2
+ import type { DiffDocument, DiffSourceLine } from '@adecore/merge';
3
+ import type { Ref } from 'react';
4
+ import type { DiffLimits } from './diff-expansion.ts';
5
+ import type { DiffSourceTokens } from './diff-syntax.ts';
6
+ export interface DiffViewProps {
7
+ engine: EditorEngine;
8
+ document: DiffDocument;
9
+ theme: EditorTheme;
10
+ tokens?: DiffSourceTokens;
11
+ wrap?: boolean;
12
+ layout?: 'unified' | 'split';
13
+ splitWrapLimit?: number;
14
+ fill?: boolean;
15
+ maxHeight?: number;
16
+ unfoldLimits?: DiffLimits;
17
+ label: string;
18
+ numbered?: boolean;
19
+ className?: string;
20
+ ref?: Ref<HTMLDivElement>;
21
+ onMount?(editor: Editor, side?: 'old' | 'new'): void | (() => void);
22
+ onSource?(source: DiffSource): void | (() => void);
23
+ }
24
+ export interface DiffSource {
25
+ readonly editor: Editor;
26
+ readonly side?: 'old' | 'new';
27
+ at(): DiffSourceLine | null;
28
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -14,9 +14,7 @@ const ALIASES = {
14
14
  yields: 'yield',
15
15
  link: 'see'
16
16
  };
17
- /* Tags that carry a type before their subject. */
18
17
  const TYPED = new Set(['param', 'property', 'return', 'throws', 'var', 'type', 'yield', 'template', 'this']);
19
- /* Tags whose first word is the thing they are about. */
20
18
  const SUBJECT_FIRST = new Set(['param', 'property', 'var', 'template']);
21
19
  const TAG_START = /^@([A-Za-z][\w-]*)(?::[\w-]+)?[ \t]*(.*)$/;
22
20
  const FENCE = /^\s*(```|~~~)/;
@@ -1,15 +1,19 @@
1
- import type { Color, ColorInformation, ColorPresentation, TextEdit } from '@adecore/lsp';
2
- import type { EditorLanguage } from './editor-language.ts';
1
+ import type { Color, ColorInformation, ColorPresentation } from '@adecore/lsp';
2
+ import type { LanguageContext } from './language-context.ts';
3
+ import type { PickFeature } from './pick.ts';
3
4
  import { type Timers } from './timers.ts';
4
5
  export declare function cssColorOf(color: Color): string;
5
6
  export declare function colorOfHex(value: string): Color | null;
6
- export declare function presentationEdits(presentation: ColorPresentation, information: ColorInformation): TextEdit[];
7
+ interface DocumentColorsPeers {
8
+ readonly pick: Pick<PickFeature, 'open'>;
9
+ }
7
10
  export declare class DocumentColorsFeature {
8
11
  private readonly language;
12
+ private readonly peers;
9
13
  private colors;
10
14
  private readonly query;
11
15
  private enabled;
12
- constructor(language: EditorLanguage, timers?: Timers);
16
+ constructor(language: LanguageContext, peers: DocumentColorsPeers, timers?: Timers);
13
17
  get supported(): boolean;
14
18
  all(): readonly ColorInformation[];
15
19
  configure(settings: {
@@ -22,3 +26,4 @@ export declare class DocumentColorsFeature {
22
26
  private open;
23
27
  private choose;
24
28
  }
29
+ export {};
@@ -27,8 +27,7 @@ function hexOf(color) {
27
27
  const part = value => Math.round(Math.min(1, Math.max(0, value)) * 255).toString(16).padStart(2, '0');
28
28
  return `#${part(color.red)}${part(color.green)}${part(color.blue)}`;
29
29
  }
30
- /* The edits a presentation makes: its own text edit, or its label over the color, and the edits that come with it. */
31
- export function presentationEdits(presentation, information) {
30
+ function presentationEdits(presentation, information) {
32
31
  return [presentation.textEdit ?? {
33
32
  range: information.range,
34
33
  newText: presentation.label
@@ -41,11 +40,13 @@ export function presentationEdits(presentation, information) {
41
40
  */
42
41
  export class DocumentColorsFeature {
43
42
  language;
43
+ peers;
44
44
  colors = [];
45
45
  query;
46
46
  enabled = true;
47
- constructor(language, timers = realTimers) {
47
+ constructor(language, peers, timers = realTimers) {
48
48
  this.language = language;
49
+ this.peers = peers;
49
50
  this.query = new DocumentQuery(language, timers, DELAY_MS, signal => this.enabled && this.supported ? language.service.documentColors(language.uri, {
50
51
  signal
51
52
  }) : Promise.resolve(null), colors => this.show(colors ?? []));
@@ -131,9 +132,11 @@ export class DocumentColorsFeature {
131
132
  return;
132
133
  }
133
134
  const {
134
- pick,
135
135
  project
136
136
  } = this.language;
137
+ const {
138
+ pick
139
+ } = this.peers;
137
140
  const rows = presentations.map((presentation, index) => ({
138
141
  id: String(index),
139
142
  label: presentation.label,
@@ -1,6 +1,6 @@
1
1
  import type { EditorPosition, EditorRange } from '@adecore/editor';
2
2
  import type { DocumentLink } from '@adecore/lsp';
3
- import type { EditorLanguage } from './editor-language.ts';
3
+ import type { LanguageContext } from './language-context.ts';
4
4
  import { type Timers } from './timers.ts';
5
5
  export declare function linkPosition(target: string): {
6
6
  readonly uri: string;
@@ -10,7 +10,7 @@ export declare class DocumentLinksFeature {
10
10
  private readonly language;
11
11
  private links;
12
12
  private readonly query;
13
- constructor(language: EditorLanguage, timers?: Timers);
13
+ constructor(language: LanguageContext, timers?: Timers);
14
14
  get supported(): boolean;
15
15
  all(): readonly DocumentLink[];
16
16
  linkAt(position: EditorPosition): DocumentLink | null;
@@ -19,4 +19,3 @@ export declare class DocumentLinksFeature {
19
19
  follow(link: DocumentLink): Promise<boolean>;
20
20
  private resolve;
21
21
  }
22
- export declare function openTarget(language: EditorLanguage, target: string, selection?: EditorRange): void;
@@ -1,9 +1,8 @@
1
- import { comparePositions } from './diagnostics-model.js';
2
1
  import { DocumentQuery } from './document-query.js';
2
+ import { comparePositions } from './positions.js';
3
3
  import { realTimers } from './timers.js';
4
4
  const METHOD = 'textDocument/documentLink';
5
5
  const RESOLVE = 'documentLink/resolve';
6
- /* How long after the last edit the links are asked again. */
7
6
  const DELAY_MS = 500;
8
7
  /* `#L12`, `#12` or `#L12,4`: a line, from one, and a column, from one, the form editors write into a link. */
9
8
  const LINE_FRAGMENT = /^#L?(\d+)(?:[,:C](\d+))?$/i;
@@ -106,7 +105,7 @@ export class DocumentLinksFeature {
106
105
  }
107
106
  }
108
107
  /* Opens a file or a document of a server in the editor, and a web address through the host. */
109
- export function openTarget(language, target, selection) {
108
+ function openTarget(language, target, selection) {
110
109
  if (!opensInEditor(target)) {
111
110
  const {
112
111
  host
@@ -1,4 +1,4 @@
1
- import type { EditorLanguage } from './editor-language.ts';
1
+ import type { LanguageContext } from './language-context.ts';
2
2
  import type { Timers } from './timers.ts';
3
3
  export declare class DocumentQuery<Value> {
4
4
  private readonly language;
@@ -9,7 +9,7 @@ export declare class DocumentQuery<Value> {
9
9
  private timer;
10
10
  private controller;
11
11
  private generation;
12
- constructor(language: EditorLanguage, timers: Timers, delay: number, ask: (signal: AbortSignal) => Promise<Value | null>, apply: (value: Value | null) => void);
12
+ constructor(language: LanguageContext, timers: Timers, delay: number, ask: (signal: AbortSignal) => Promise<Value | null>, apply: (value: Value | null) => void);
13
13
  run(): void;
14
14
  private cancel;
15
15
  }
@@ -1,38 +1,22 @@
1
+ import { comparePositions, endOfInsertion } from './positions.js';
1
2
  const LIMIT = 150;
2
3
  /* Two places are one when they are in one file with as many carets, and every caret is within three lines of its twin. */
3
4
  function isSame(left, right) {
4
5
  return right !== null && left.uri === right.uri && left.selections.length === right.selections.length && left.selections.every((selection, index) => Math.abs(selection.end.line - right.selections[index].end.line) < 4);
5
6
  }
6
- function before(left, right) {
7
- return left.line < right.line || left.line === right.line && left.character < right.character;
8
- }
9
- /* Where the text of a change ends, in the text after the change. */
10
- function endOf(change) {
11
- const lines = change.text.split('\n');
12
- const {
13
- start
14
- } = change.range;
15
- return lines.length === 1 ? {
16
- line: start.line,
17
- character: start.character + change.text.length
18
- } : {
19
- line: start.line + lines.length - 1,
20
- character: lines[lines.length - 1].length
21
- };
22
- }
23
7
  /* A position after a change: untouched in front of it, at the start when the change replaced the text around it, moved along behind it. */
24
8
  function follow(position, change) {
25
9
  const {
26
10
  start,
27
11
  end
28
12
  } = change.range;
29
- if (!before(start, position)) {
13
+ if (comparePositions(start, position) >= 0) {
30
14
  return position;
31
15
  }
32
- if (before(position, end)) {
16
+ if (comparePositions(position, end) < 0) {
33
17
  return start;
34
18
  }
35
- const landed = endOf(change);
19
+ const landed = endOfInsertion(start, change.text);
36
20
  return position.line === end.line ? {
37
21
  line: landed.line,
38
22
  character: landed.character + position.character - end.character
@@ -57,7 +41,6 @@ export class EditLocations {
57
41
  get places() {
58
42
  return this.entries;
59
43
  }
60
- /* An edit left the carets here. */
61
44
  record(place) {
62
45
  const last = this.entries.at(-1);
63
46
  if (last !== undefined && isSame(last, place)) {
@@ -118,7 +101,6 @@ export class EditLocations {
118
101
  };
119
102
  });
120
103
  }
121
- /* Drops the places of files that are gone. */
122
104
  forget(matches) {
123
105
  this.entries = this.entries.filter(entry => !matches(entry.uri));
124
106
  this.index = this.entries.length;
@@ -16,6 +16,7 @@ import { HistoryFeature } from './history.ts';
16
16
  import { HoverFeature } from './hover.ts';
17
17
  import { InlayHintsFeature } from './inlay-hints.ts';
18
18
  import { InlineCompletionFeature } from './inline-completion.ts';
19
+ import type { LanguageContext } from './language-context.ts';
19
20
  import { LinkedEditingFeature } from './linked-editing.ts';
20
21
  import { TemplatesFeature } from './live-templates.ts';
21
22
  import { MarkupFeature } from './markup.ts';
@@ -24,6 +25,7 @@ import { NavigationFeature } from './navigation.ts';
24
25
  import { PasteHistoryFeature } from './paste-history.ts';
25
26
  import { PeekFeature } from './peek.ts';
26
27
  import { PickFeature } from './pick.ts';
28
+ import { Popups } from './popups.ts';
27
29
  import type { LanguageDocumentHandle, ProjectLanguage } from './project-language.ts';
28
30
  import { RenameFeature } from './rename.ts';
29
31
  import { RenderedDocsFeature } from './rendered-docs.ts';
@@ -35,20 +37,19 @@ import { SurroundFeature } from './surround.ts';
35
37
  import { SymbolPickerFeature } from './symbol-picker.ts';
36
38
  import { SymbolsFeature } from './symbols.ts';
37
39
  import { type Timers } from './timers.ts';
38
- export interface EditorLanguageOptions {
40
+ export interface EditorLanguageOptions<App extends object = {}> {
39
41
  semanticTokens?: SemanticTokensOptions;
40
42
  serve?: boolean;
43
+ features?(language: EditorLanguage): App;
41
44
  }
42
- export declare class EditorLanguage {
45
+ export declare class EditorLanguage<App extends object = {}> implements LanguageContext {
43
46
  readonly editor: Editor;
44
47
  readonly apple: boolean;
45
- readonly keymap: Keymap;
46
- readonly shortcuts: ReturnType<typeof shortcutsOf>;
47
48
  readonly project: ProjectLanguage;
48
49
  readonly document: LanguageDocumentHandle;
49
50
  readonly languageId: string;
50
51
  readonly served: boolean;
51
- readonly popups: import("./popups.ts").PopupStore;
52
+ readonly popups: Popups;
52
53
  readonly diagnostics: DiagnosticsFeature;
53
54
  readonly hover: HoverFeature;
54
55
  readonly inlayHints: InlayHintsFeature;
@@ -78,11 +79,15 @@ export declare class EditorLanguage {
78
79
  readonly colors: DocumentColorsFeature;
79
80
  readonly linkedEditing: LinkedEditingFeature;
80
81
  readonly inlineCompletion: InlineCompletionFeature;
82
+ readonly app: App;
81
83
  private readonly disposers;
82
84
  private readonly keys;
83
85
  private readonly timers;
84
86
  private disposed;
85
- constructor(project: ProjectLanguage, editor: Editor, uri: string, languageId: string, timers?: Timers, options?: EditorLanguageOptions);
87
+ private resolvedShortcuts;
88
+ constructor(project: ProjectLanguage, editor: Editor, uri: string, languageId: string, timers?: Timers, options?: EditorLanguageOptions<App>);
89
+ get keymap(): Keymap;
90
+ get shortcuts(): ReturnType<typeof shortcutsOf>;
86
91
  get uri(): string;
87
92
  get service(): LanguageService;
88
93
  get isDisposed(): boolean;
@@ -90,9 +95,9 @@ export declare class EditorLanguage {
90
95
  goTo(location: Location): void;
91
96
  jump(position: EditorPosition): void;
92
97
  visit(place: Place): void;
93
- locations(places: readonly Location[], anchor: EditorPosition, title: string): void;
94
98
  onProvidersChanged(listener: () => void): () => void;
95
99
  onKey(handler: EditorKeyHandler, priority?: number): () => void;
100
+ onServedKey(handler: EditorKeyHandler, priority?: number): () => void;
96
101
  prepareSave(reason?: TextDocumentSaveReason): Promise<void>;
97
102
  onDispose(dispose: () => void): void;
98
103
  dispose(): void;
@@ -19,11 +19,11 @@ import { KeyDispatcher } from './key-priority.js';
19
19
  import { LinkedEditingFeature } from './linked-editing.js';
20
20
  import { TemplatesFeature } from './live-templates.js';
21
21
  import { MarkupFeature } from './markup.js';
22
- import { NavigationFeature, locationRow } from './navigation.js';
22
+ import { NavigationFeature } from './navigation.js';
23
23
  import { PasteHistoryFeature } from './paste-history.js';
24
24
  import { PeekFeature } from './peek.js';
25
25
  import { PickFeature } from './pick.js';
26
- import { createPopupStore } from './popups.js';
26
+ import { Popups } from './popups.js';
27
27
  import { RenameFeature } from './rename.js';
28
28
  import { RenderedDocsFeature } from './rendered-docs.js';
29
29
  import { SelectionRangesFeature } from './selection-ranges.js';
@@ -35,7 +35,6 @@ import { SurroundFeature } from './surround.js';
35
35
  import { SymbolPickerFeature } from './symbol-picker.js';
36
36
  import { SymbolsFeature } from './symbols.js';
37
37
  import { realTimers } from './timers.js';
38
- /* How long the edits servers want before a save are waited for. */
39
38
  const SAVE_PARTICIPANT_MS = 1_000;
40
39
  /*
41
40
  * The one place that connects an editor to the language servers: it opens the file's document for
@@ -44,15 +43,13 @@ const SAVE_PARTICIPANT_MS = 1_000;
44
43
  export class EditorLanguage {
45
44
  editor;
46
45
  apple;
47
- keymap;
48
- shortcuts;
49
46
  project;
50
47
  document;
51
48
  languageId;
52
49
  /* Whether a server serves this document; read it where a host meant "a language server is behind this editor". */
53
50
  served;
54
51
  /* What the features of this editor have open over it: the hover card, the suggestions, the signature. */
55
- popups = createPopupStore();
52
+ popups = new Popups();
56
53
  diagnostics;
57
54
  hover;
58
55
  inlayHints;
@@ -82,15 +79,16 @@ export class EditorLanguage {
82
79
  colors;
83
80
  linkedEditing;
84
81
  inlineCompletion;
82
+ /* What the `features` option of the app built. */
83
+ app;
85
84
  disposers = [];
86
85
  keys = new KeyDispatcher();
87
86
  timers;
88
87
  disposed = false;
88
+ resolvedShortcuts = null;
89
89
  constructor(project, editor, uri, languageId, timers = realTimers, options = {}) {
90
90
  this.editor = editor;
91
91
  this.apple = project.host.apple ?? false;
92
- this.keymap = project.host.keymap ?? KEYMAP;
93
- this.shortcuts = shortcutsOf(this.keymap, this.apple);
94
92
  this.project = project;
95
93
  this.languageId = languageId;
96
94
  this.served = options.serve ?? true;
@@ -99,39 +97,48 @@ export class EditorLanguage {
99
97
  });
100
98
  this.timers = timers;
101
99
  this.onDispose(editor.onKeyDown(event => this.keys.dispatch(event)));
100
+ // A feature declares the siblings it drives as its `peers` and reads them when it acts; only a constructor that
101
+ // subscribes to one (code actions to diagnostics, templates to completion) needs that sibling built above it.
102
102
  this.pick = new PickFeature(this, timers);
103
- this.diagnostics = new DiagnosticsFeature(this);
104
- this.hover = new HoverFeature(this, timers);
105
- this.completion = new CompletionFeature(this, timers);
106
- this.snippets = new SnippetFeature(this, timers);
107
- this.markup = new MarkupFeature(this);
108
- this.templates = new TemplatesFeature(this);
109
- this.surround = new SurroundFeature(this);
103
+ this.diagnostics = new DiagnosticsFeature(this, this);
104
+ this.hover = new HoverFeature(this, this, timers);
105
+ this.completion = new CompletionFeature(this, this, timers);
106
+ this.snippets = new SnippetFeature(this, this, timers);
107
+ this.markup = new MarkupFeature(this, this);
108
+ this.templates = new TemplatesFeature(this, this);
109
+ this.surround = new SurroundFeature(this, this);
110
110
  this.signature = new SignatureFeature(this, timers);
111
111
  this.highlights = new HighlightsFeature(this, timers);
112
112
  this.symbols = new SymbolsFeature(this, timers);
113
113
  new SelectionRangesFeature(this);
114
114
  new SemanticTokensFeature(this, timers, options.semanticTokens);
115
- this.inlayHints = new InlayHintsFeature(this, timers);
116
- this.codeActions = new CodeActionsFeature(this, timers);
115
+ this.inlayHints = new InlayHintsFeature(this, this, timers);
116
+ this.codeActions = new CodeActionsFeature(this, this, timers);
117
117
  this.rename = new RenameFeature(this);
118
118
  // Before navigation, whose Mod+click goes to a definition: a link under the pointer goes first.
119
119
  this.links = new DocumentLinksFeature(this, timers);
120
- this.colors = new DocumentColorsFeature(this, timers);
120
+ this.colors = new DocumentColorsFeature(this, this, timers);
121
121
  this.linkedEditing = new LinkedEditingFeature(this, timers);
122
122
  this.inlineCompletion = new InlineCompletionFeature(this, timers);
123
- this.navigation = new NavigationFeature(this);
124
- this.peek = new PeekFeature(this, timers);
125
- this.callHierarchy = new CallHierarchyFeature(this, timers);
123
+ this.navigation = new NavigationFeature(this, this);
124
+ this.peek = new PeekFeature(this, this, timers);
125
+ this.callHierarchy = new CallHierarchyFeature(this, this, timers);
126
126
  this.symbolPicker = new SymbolPickerFeature(this);
127
- this.contextMenu = new ContextMenuFeature(this);
128
- this.history = new HistoryFeature(this);
129
- this.definitionLink = new DefinitionLinkFeature(this);
130
- this.codeVision = new CodeVisionFeature(this, listener => this.symbols.onResult(listener), timers);
131
- this.formatOnType = new FormatOnTypeFeature(this);
132
- this.renderedDocs = new RenderedDocsFeature(this, timers);
133
- this.pasteHistory = new PasteHistoryFeature(this);
127
+ this.contextMenu = new ContextMenuFeature(this, this);
128
+ this.history = new HistoryFeature(this, this);
129
+ this.definitionLink = new DefinitionLinkFeature(this, this);
130
+ this.codeVision = new CodeVisionFeature(this, {
131
+ onSymbols: listener => this.symbols.onResult(listener),
132
+ peek: {
133
+ open: position => this.peek.open(position)
134
+ }
135
+ }, timers);
136
+ this.formatOnType = new FormatOnTypeFeature(this, this);
137
+ this.renderedDocs = new RenderedDocsFeature(this, this, timers);
138
+ this.pasteHistory = new PasteHistoryFeature(this, this);
134
139
  new FoldingFeature(this, listener => this.symbols.onResult(listener), timers);
140
+ // Without `features` the app has nothing to hold, and `App` is the empty object it defaults to.
141
+ this.app = options.features?.(this) ?? {};
135
142
  const copies = editor.onCopy?.(copy => project.clipboard.add(copy.text, {
136
143
  wholeLines: copy.wholeLines
137
144
  }));
@@ -143,6 +150,21 @@ export class EditorLanguage {
143
150
  this.placeOpenedCaret(editor.getCaret());
144
151
  this.onDispose(editor.onCaret(position => this.placeOpenedCaret(position)));
145
152
  }
153
+ /* Read from the host on every use, so a rebound key reaches an editor that is already open. */
154
+ get keymap() {
155
+ return this.project.host.keymap ?? KEYMAP;
156
+ }
157
+ /* The keymap's shortcuts, resolved again only when the host hands a new keymap. */
158
+ get shortcuts() {
159
+ const keymap = this.keymap;
160
+ if (this.resolvedShortcuts?.keymap !== keymap) {
161
+ this.resolvedShortcuts = {
162
+ keymap,
163
+ shortcuts: shortcutsOf(keymap, this.apple)
164
+ };
165
+ }
166
+ return this.resolvedShortcuts.shortcuts;
167
+ }
146
168
  get uri() {
147
169
  return this.document.uri;
148
170
  }
@@ -187,22 +209,6 @@ export class EditorLanguage {
187
209
  this.project.openPlace(place);
188
210
  }
189
211
  }
190
- /* Lists places under a position to choose from; choosing one goes there. */
191
- locations(places, anchor, title) {
192
- const rows = places.map((place, index) => ({
193
- id: String(index),
194
- ...locationRow(place, this.project.pathOfLocation(place.uri))
195
- }));
196
- this.pick.open({
197
- anchor,
198
- title,
199
- groups: [{
200
- title: null,
201
- rows
202
- }],
203
- accept: id => this.goTo(places[Number(id)])
204
- });
205
- }
206
212
  /*
207
213
  * Runs `listener` once the document is open and again whenever the service says what it can ask for
208
214
  * this document changed. A service that is ready before the document opens never says so, so the
@@ -232,6 +238,10 @@ export class EditorLanguage {
232
238
  onKey(handler, priority = 0) {
233
239
  return this.keys.add(handler, priority);
234
240
  }
241
+ /* Like `onKey`, for a feature that needs a server behind the document: the editor of a document no server serves never gives it a key. */
242
+ onServedKey(handler, priority = 0) {
243
+ return this.onKey(event => this.served && handler(event), priority);
244
+ }
235
245
  /*
236
246
  * Lets the servers in before the host writes the file: tells them a save is coming and applies the edits they
237
247
  * want made first, such as organized imports. A server that has not answered within a second is passed over,
@@ -263,7 +273,6 @@ export class EditorLanguage {
263
273
  this.timers.clear(timer);
264
274
  }
265
275
  }
266
- /* Runs `dispose` when the editor lets go of its document. */
267
276
  onDispose(dispose) {
268
277
  this.disposers.push(dispose);
269
278
  }
package/dist/emmet.d.ts CHANGED
@@ -1,13 +1,14 @@
1
1
  import type { MarkupSyntax } from './markup-context.ts';
2
- export interface AbbreviationOptions {
2
+ interface AbbreviationOptions {
3
3
  readonly syntax: MarkupSyntax;
4
4
  readonly indent: string;
5
5
  readonly wrap?: readonly string[];
6
6
  }
7
- export interface FoundAbbreviation {
7
+ interface FoundAbbreviation {
8
8
  readonly abbreviation: string;
9
9
  readonly start: number;
10
10
  readonly end: number;
11
11
  }
12
12
  export declare function abbreviationBefore(line: string, character: number): FoundAbbreviation | null;
13
13
  export declare function expandAbbreviation(abbreviation: string, options: AbbreviationOptions): string | null;
14
+ export {};