@airalogy/aimd-editor 1.11.0 → 1.12.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.
package/dist/index.js CHANGED
@@ -1,44 +1,52 @@
1
- import { A as i, a as s, b as d, D as o, K as m, M as r, c as t, d as A, e as n, f as l, g as D, l as E, s as T } from "./theme-CB0dPzmd.js";
2
- import { _, a as c, b as f, c as u, u as M } from "./AimdEditorTopBar.vue_vue_type_script_setup_true_lang-CihhM95s.js";
3
- import { _ as p } from "./AimdSourceEditor.vue_vue_type_script_setup_true_lang-DrXCKgVI.js";
4
- import { A as k, a as x, _ as L, D as O, M as S, b as y, c as b, d as N, e as P, f as R, g as w, h, i as B, j as C, k as v, l as K, m as V, n as Y, r as j } from "./AimdWysiwygEditor.vue_vue_type_script_setup_true_lang-DPs--N5C.js";
1
+ import { A as i, a as s, b as d, D as o, K as r, M as m, c as t, d as A, e as l, f as n, g as I, l as D, s as E } from "./theme-CB0dPzmd.js";
2
+ import { A as u, a as c, c as F, b as _, n as p, p as f, s as g } from "./index-BqB8Xukp.js";
3
+ import { _ as O, a as k, b as x, c as L, u as S } from "./AimdEditorTopBar.vue_vue_type_script_setup_true_lang-BXsn4cFX.js";
4
+ import { _ as y } from "./AimdSourceEditor.vue_vue_type_script_setup_true_lang-CJJTlVZ7.js";
5
+ import { A as P, a as R, _ as w, D as B, M as h, b as C, c as v, d as K, e as V, f as Y, g as j, h as z, i as G, j as Q, k as U, l as W, m as q, n as H, r as J } from "./AimdWysiwygEditor.vue_vue_type_script_setup_true_lang-Dme3UQEf.js";
5
6
  export {
6
- k as AIMD_FIELD_TYPES,
7
- x as AIMD_FIELD_TYPE_DEFINITIONS,
8
- _ as AimdEditor,
9
- c as AimdEditorToolbar,
10
- f as AimdEditorTopBar,
11
- u as AimdFieldDialog,
12
- p as AimdSourceEditor,
7
+ P as AIMD_FIELD_TYPES,
8
+ R as AIMD_FIELD_TYPE_DEFINITIONS,
9
+ u as AIMD_FIG_ID_PATTERN,
10
+ O as AimdEditor,
11
+ k as AimdEditorToolbar,
12
+ x as AimdEditorTopBar,
13
+ L as AimdFieldDialog,
14
+ c as AimdFormalOutputError,
15
+ y as AimdSourceEditor,
13
16
  i as AimdSuffix,
14
17
  s as AimdToken,
15
18
  d as AimdTokenDefinition,
16
- L as AimdWysiwygEditor,
17
- O as DEFAULT_AIMD_EDITOR_LOCALE,
19
+ w as AimdWysiwygEditor,
20
+ B as DEFAULT_AIMD_EDITOR_LOCALE,
18
21
  o as DelimiterDefinition,
19
- m as KeywordDefinition,
20
- S as MD_TOOLBAR_ITEMS,
21
- y as MD_TOOLBAR_ITEM_DEFINITIONS,
22
- r as MarkupDefinition,
23
- b as aimdFieldInputRule,
24
- N as aimdFieldNode,
25
- P as aimdFieldView,
26
- R as aimdMilkdownPlugins,
27
- w as aimdRemarkPlugin,
22
+ r as KeywordDefinition,
23
+ h as MD_TOOLBAR_ITEMS,
24
+ C as MD_TOOLBAR_ITEM_DEFINITIONS,
25
+ m as MarkupDefinition,
26
+ v as aimdFieldInputRule,
27
+ K as aimdFieldNode,
28
+ V as aimdFieldView,
29
+ Y as aimdMilkdownPlugins,
30
+ j as aimdRemarkPlugin,
28
31
  t as aimdTheme,
29
32
  A as aimdTokenColors,
30
- h as buildAimdSyntax,
31
- n as completionItemProvider,
32
- l as conf,
33
- B as createAimdEditorMessages,
34
- D as createAimdExtendedTheme,
35
- C as createAimdFieldTypes,
36
- v as createAimdVarTypePresets,
37
- K as createMdToolbarItems,
38
- V as getDefaultAimdFields,
39
- Y as getQuickAimdSyntax,
40
- E as language,
41
- j as resolveAimdEditorLocale,
42
- T as scopeName,
43
- M as useEditorContent
33
+ z as buildAimdSyntax,
34
+ F as collectAimdFigureIds,
35
+ l as completionItemProvider,
36
+ n as conf,
37
+ G as createAimdEditorMessages,
38
+ I as createAimdExtendedTheme,
39
+ Q as createAimdFieldTypes,
40
+ _ as createAimdFigureId,
41
+ U as createAimdVarTypePresets,
42
+ W as createMdToolbarItems,
43
+ q as getDefaultAimdFields,
44
+ H as getQuickAimdSyntax,
45
+ D as language,
46
+ p as normalizeAimdFigureIds,
47
+ f as prepareAimdForFormalOutput,
48
+ J as resolveAimdEditorLocale,
49
+ g as scanAimdFigureBlocks,
50
+ E as scopeName,
51
+ S as useEditorContent
44
52
  };
package/dist/vue.js CHANGED
@@ -1,6 +1,6 @@
1
- import { _ as e, a as d, b as s, c as r, u as o } from "./AimdEditorTopBar.vue_vue_type_script_setup_true_lang-CihhM95s.js";
2
- import { _ as m } from "./AimdSourceEditor.vue_vue_type_script_setup_true_lang-DrXCKgVI.js";
3
- import { A as E, a as l, _ as I, D as _, M as T, b as D, c as F, d as M, e as u, f as c, g as n, h as g, i as L, j as O, k as p, l as S, m as y, n as b, r as f } from "./AimdWysiwygEditor.vue_vue_type_script_setup_true_lang-DPs--N5C.js";
1
+ import { _ as e, a as d, b as s, c as r, u as o } from "./AimdEditorTopBar.vue_vue_type_script_setup_true_lang-BXsn4cFX.js";
2
+ import { _ as m } from "./AimdSourceEditor.vue_vue_type_script_setup_true_lang-CJJTlVZ7.js";
3
+ import { A as E, a as l, _ as I, D as _, M as T, b as D, c as F, d as M, e as u, f as c, g as n, h as g, i as L, j as O, k as p, l as S, m as y, n as b, r as f } from "./AimdWysiwygEditor.vue_vue_type_script_setup_true_lang-Dme3UQEf.js";
4
4
  export {
5
5
  E as AIMD_FIELD_TYPES,
6
6
  l as AIMD_FIELD_TYPE_DEFINITIONS,
package/dist/wysiwyg.js CHANGED
@@ -1,4 +1,4 @@
1
- import { _ as a, D as r, i, j as d, k as t, r as A } from "./AimdWysiwygEditor.vue_vue_type_script_setup_true_lang-DPs--N5C.js";
1
+ import { _ as a, D as r, i, j as d, k as t, r as A } from "./AimdWysiwygEditor.vue_vue_type_script_setup_true_lang-Dme3UQEf.js";
2
2
  export {
3
3
  a as AimdWysiwygEditor,
4
4
  r as DEFAULT_AIMD_EDITOR_LOCALE,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@airalogy/aimd-editor",
3
3
  "type": "module",
4
- "version": "1.11.0",
4
+ "version": "1.12.0",
5
5
  "description": "AIMD (Airalogy Markdown) editor with Monaco source mode and Milkdown WYSIWYG mode",
6
6
  "license": "Apache-2.0",
7
7
  "repository": {
@@ -31,6 +31,10 @@
31
31
  "types": "./src/monaco.ts",
32
32
  "import": "./src/monaco.ts"
33
33
  },
34
+ "./authoring": {
35
+ "types": "./src/authoring/index.ts",
36
+ "import": "./src/authoring/index.ts"
37
+ },
34
38
  "./vue": {
35
39
  "types": "./src/vue/index.ts",
36
40
  "import": "./src/vue/index.ts"
@@ -59,8 +63,8 @@
59
63
  "@milkdown/kit": "^7.18.0",
60
64
  "@milkdown/theme-nord": "^7.18.0",
61
65
  "@milkdown/vue": "^7.18.0",
62
- "@airalogy/aimd-core": "^2.14.0",
63
- "@airalogy/aimd-renderer": "^2.11.0"
66
+ "@airalogy/aimd-core": "^2.16.0",
67
+ "@airalogy/aimd-renderer": "^2.13.0"
64
68
  },
65
69
  "peerDependencies": {
66
70
  "monaco-editor": ">=0.50.0",
@@ -0,0 +1,368 @@
1
+ import { validateFigDefinitions } from '@airalogy/aimd-core/parser'
2
+
3
+ export const AIMD_FIG_ID_PATTERN = /^[A-Za-z_][A-Za-z0-9_]*$/
4
+
5
+ export interface AimdTextEdit {
6
+ startOffset: number
7
+ endOffset: number
8
+ text: string
9
+ }
10
+
11
+ export interface AimdFigureSourceField {
12
+ value: string
13
+ lineStartOffset: number
14
+ lineEndOffset: number
15
+ indentation: string
16
+ }
17
+
18
+ export interface AimdFigureBlockInfo {
19
+ startOffset: number
20
+ endOffset: number
21
+ bodyStartOffset: number
22
+ bodyEndOffset: number
23
+ indentation: string
24
+ lineEnding: string
25
+ id?: AimdFigureSourceField
26
+ src?: AimdFigureSourceField
27
+ }
28
+
29
+ export interface GeneratedAimdFigureId {
30
+ id: string
31
+ src: string
32
+ blockStartOffset: number
33
+ edit: AimdTextEdit
34
+ }
35
+
36
+ export interface NormalizeAimdFigureIdsResult {
37
+ content: string
38
+ changed: boolean
39
+ generated: GeneratedAimdFigureId[]
40
+ }
41
+
42
+ export type PrepareAimdFormalOutputResult = NormalizeAimdFigureIdsResult
43
+
44
+ export class AimdFormalOutputError extends Error {
45
+ readonly issues: string[]
46
+
47
+ constructor(issues: string[]) {
48
+ super(issues.join('; '))
49
+ this.name = 'AimdFormalOutputError'
50
+ this.issues = issues
51
+ }
52
+ }
53
+
54
+ interface SourceLine {
55
+ startOffset: number
56
+ endOffset: number
57
+ textEndOffset: number
58
+ text: string
59
+ lineEnding: string
60
+ }
61
+
62
+ function splitSourceLines(content: string): SourceLine[] {
63
+ const lines: SourceLine[] = []
64
+ let startOffset = 0
65
+
66
+ while (startOffset < content.length) {
67
+ let textEndOffset = startOffset
68
+ while (
69
+ textEndOffset < content.length
70
+ && content[textEndOffset] !== '\n'
71
+ && content[textEndOffset] !== '\r'
72
+ ) {
73
+ textEndOffset += 1
74
+ }
75
+
76
+ let endOffset = textEndOffset
77
+ let lineEnding = ''
78
+ if (content[endOffset] === '\r' && content[endOffset + 1] === '\n') {
79
+ endOffset += 2
80
+ lineEnding = '\r\n'
81
+ }
82
+ else if (content[endOffset] === '\r' || content[endOffset] === '\n') {
83
+ lineEnding = content[endOffset]
84
+ endOffset += 1
85
+ }
86
+
87
+ lines.push({
88
+ startOffset,
89
+ endOffset,
90
+ textEndOffset,
91
+ text: content.slice(startOffset, textEndOffset),
92
+ lineEnding,
93
+ })
94
+ startOffset = endOffset
95
+ }
96
+
97
+ return lines
98
+ }
99
+
100
+ function getFenceOpening(line: string): { indentation: string, marker: string, language: string } | null {
101
+ const match = line.match(/^([ \t]{0,3})(`{3,}|~{3,})[ \t]*([^ \t]*)[^\r\n]*$/)
102
+ if (!match) return null
103
+ return {
104
+ indentation: match[1],
105
+ marker: match[2],
106
+ language: match[3].trim().toLowerCase(),
107
+ }
108
+ }
109
+
110
+ function isMatchingFenceClose(line: string, openingMarker: string): boolean {
111
+ const match = line.match(/^[ \t]{0,3}(`{3,}|~{3,})[ \t]*$/)
112
+ return Boolean(
113
+ match
114
+ && match[1][0] === openingMarker[0]
115
+ && match[1].length >= openingMarker.length,
116
+ )
117
+ }
118
+
119
+ function stripYamlComment(value: string): string {
120
+ let quote: '"' | "'" | null = null
121
+ let escaped = false
122
+
123
+ for (let index = 0; index < value.length; index += 1) {
124
+ const char = value[index]
125
+ if (escaped) {
126
+ escaped = false
127
+ continue
128
+ }
129
+ if (quote) {
130
+ if (char === '\\' && quote === '"') {
131
+ escaped = true
132
+ }
133
+ else if (char === quote) {
134
+ quote = null
135
+ }
136
+ continue
137
+ }
138
+ if (char === '"' || char === "'") {
139
+ quote = char
140
+ continue
141
+ }
142
+ if (char === '#' && (index === 0 || /\s/.test(value[index - 1]))) {
143
+ return value.slice(0, index)
144
+ }
145
+ }
146
+
147
+ return value
148
+ }
149
+
150
+ function parseScalarValue(rawValue: string): string {
151
+ const value = stripYamlComment(rawValue).trim()
152
+ if (!value) return ''
153
+
154
+ if (value.startsWith('"') && value.endsWith('"')) {
155
+ try {
156
+ const parsed = JSON.parse(value)
157
+ return typeof parsed === 'string' ? parsed : value
158
+ }
159
+ catch {
160
+ return value.slice(1, -1)
161
+ }
162
+ }
163
+ if (value.startsWith("'") && value.endsWith("'")) {
164
+ return value.slice(1, -1).replace(/''/g, "'")
165
+ }
166
+ return value
167
+ }
168
+
169
+ function parseFigureField(line: SourceLine): { key: 'id' | 'src', field: AimdFigureSourceField } | null {
170
+ const match = line.text.match(/^([ \t]*)(id|src)[ \t]*:[ \t]*(.*)$/i)
171
+ if (!match) return null
172
+ return {
173
+ key: match[2].toLowerCase() as 'id' | 'src',
174
+ field: {
175
+ value: parseScalarValue(match[3]),
176
+ lineStartOffset: line.startOffset,
177
+ lineEndOffset: line.textEndOffset,
178
+ indentation: match[1],
179
+ },
180
+ }
181
+ }
182
+
183
+ export function scanAimdFigureBlocks(content: string): AimdFigureBlockInfo[] {
184
+ const lines = splitSourceLines(content)
185
+ const blocks: AimdFigureBlockInfo[] = []
186
+
187
+ for (let index = 0; index < lines.length;) {
188
+ const opening = getFenceOpening(lines[index].text)
189
+ if (!opening) {
190
+ index += 1
191
+ continue
192
+ }
193
+
194
+ let closingIndex = index + 1
195
+ while (
196
+ closingIndex < lines.length
197
+ && !isMatchingFenceClose(lines[closingIndex].text, opening.marker)
198
+ ) {
199
+ closingIndex += 1
200
+ }
201
+
202
+ if (closingIndex >= lines.length) {
203
+ break
204
+ }
205
+
206
+ if (opening.language === 'fig') {
207
+ let id: AimdFigureSourceField | undefined
208
+ let src: AimdFigureSourceField | undefined
209
+ for (let bodyIndex = index + 1; bodyIndex < closingIndex; bodyIndex += 1) {
210
+ const parsedField = parseFigureField(lines[bodyIndex])
211
+ if (parsedField?.key === 'id') id = parsedField.field
212
+ if (parsedField?.key === 'src') src = parsedField.field
213
+ }
214
+
215
+ blocks.push({
216
+ startOffset: lines[index].startOffset,
217
+ endOffset: lines[closingIndex].textEndOffset,
218
+ bodyStartOffset: lines[index].endOffset,
219
+ bodyEndOffset: lines[closingIndex].startOffset,
220
+ indentation: opening.indentation,
221
+ lineEnding: lines[index].lineEnding,
222
+ id,
223
+ src,
224
+ })
225
+ }
226
+
227
+ index = closingIndex + 1
228
+ }
229
+
230
+ return blocks
231
+ }
232
+
233
+ function stableHash(value: string): string {
234
+ let hash = 0x811c9dc5
235
+ for (let index = 0; index < value.length; index += 1) {
236
+ hash ^= value.charCodeAt(index)
237
+ hash = Math.imul(hash, 0x01000193)
238
+ }
239
+ return (hash >>> 0).toString(16).padStart(8, '0').slice(0, 6)
240
+ }
241
+
242
+ function getFigureSourceStem(src: string): string {
243
+ let candidate = src.trim()
244
+ try {
245
+ const url = new URL(candidate)
246
+ candidate = url.pathname
247
+ }
248
+ catch {
249
+ candidate = candidate.split(/[?#]/, 1)[0]
250
+ }
251
+
252
+ const lastSegment = candidate.replace(/\\/g, '/').split('/').filter(Boolean).pop() ?? ''
253
+ let decodedSegment = lastSegment
254
+ try {
255
+ decodedSegment = decodeURIComponent(lastSegment)
256
+ }
257
+ catch {}
258
+
259
+ const lastDot = decodedSegment.lastIndexOf('.')
260
+ return lastDot > 0 ? decodedSegment.slice(0, lastDot) : decodedSegment
261
+ }
262
+
263
+ export function createAimdFigureId(src: string, usedIds: Iterable<string> = []): string {
264
+ let base = getFigureSourceStem(src)
265
+ .normalize('NFKD')
266
+ .replace(/[\u0300-\u036f]/g, '')
267
+ .replace(/[^A-Za-z0-9_]+/g, '_')
268
+ .replace(/^_+|_+$/g, '')
269
+ .toLowerCase()
270
+
271
+ if (!base) {
272
+ base = `fig_${stableHash(src || 'figure')}`
273
+ }
274
+ else if (/^[0-9]/.test(base)) {
275
+ base = `fig_${base}`
276
+ }
277
+
278
+ const used = new Set(usedIds)
279
+ let id = base
280
+ let suffix = 2
281
+ while (used.has(id)) {
282
+ id = `${base}_${suffix}`
283
+ suffix += 1
284
+ }
285
+ return id
286
+ }
287
+
288
+ export function collectAimdFigureIds(content: string): string[] {
289
+ return scanAimdFigureBlocks(content)
290
+ .map(block => block.id?.value ?? '')
291
+ .filter(Boolean)
292
+ }
293
+
294
+ function detectPreferredLineEnding(content: string): string {
295
+ return content.includes('\r\n') ? '\r\n' : '\n'
296
+ }
297
+
298
+ function createFigureIdEdit(
299
+ content: string,
300
+ block: AimdFigureBlockInfo,
301
+ id: string,
302
+ ): AimdTextEdit {
303
+ if (block.id) {
304
+ return {
305
+ startOffset: block.id.lineStartOffset,
306
+ endOffset: block.id.lineEndOffset,
307
+ text: `${block.id.indentation}id: ${id}`,
308
+ }
309
+ }
310
+
311
+ const lineEnding = block.lineEnding || detectPreferredLineEnding(content)
312
+ return {
313
+ startOffset: block.bodyStartOffset,
314
+ endOffset: block.bodyStartOffset,
315
+ text: `${block.src?.indentation ?? block.indentation}id: ${id}${lineEnding}`,
316
+ }
317
+ }
318
+
319
+ function applyTextEdits(content: string, edits: AimdTextEdit[]): string {
320
+ return [...edits]
321
+ .sort((left, right) => right.startOffset - left.startOffset)
322
+ .reduce(
323
+ (result, edit) => `${result.slice(0, edit.startOffset)}${edit.text}${result.slice(edit.endOffset)}`,
324
+ content,
325
+ )
326
+ }
327
+
328
+ export function normalizeAimdFigureIds(content: string): NormalizeAimdFigureIdsResult {
329
+ const blocks = scanAimdFigureBlocks(content)
330
+ const usedIds = new Set(
331
+ blocks.map(block => block.id?.value ?? '').filter(Boolean),
332
+ )
333
+ const generated: GeneratedAimdFigureId[] = []
334
+
335
+ for (const block of blocks) {
336
+ const src = block.src?.value ?? ''
337
+ if (block.id?.value || !src) continue
338
+
339
+ const id = createAimdFigureId(src, usedIds)
340
+ usedIds.add(id)
341
+ generated.push({
342
+ id,
343
+ src,
344
+ blockStartOffset: block.startOffset,
345
+ edit: createFigureIdEdit(content, block, id),
346
+ })
347
+ }
348
+
349
+ const normalizedContent = applyTextEdits(content, generated.map(item => item.edit))
350
+ return {
351
+ content: normalizedContent,
352
+ changed: generated.length > 0,
353
+ generated,
354
+ }
355
+ }
356
+
357
+ export function prepareAimdForFormalOutput(content: string): PrepareAimdFormalOutputResult {
358
+ const normalized = normalizeAimdFigureIds(content)
359
+ const figures = scanAimdFigureBlocks(normalized.content).map(block => ({
360
+ id: block.id?.value,
361
+ src: block.src?.value,
362
+ }))
363
+ const issues = validateFigDefinitions(figures)
364
+ if (issues.length > 0) {
365
+ throw new AimdFormalOutputError(issues)
366
+ }
367
+ return normalized
368
+ }
@@ -0,0 +1,15 @@
1
+ export {
2
+ AIMD_FIG_ID_PATTERN,
3
+ AimdFormalOutputError,
4
+ collectAimdFigureIds,
5
+ createAimdFigureId,
6
+ normalizeAimdFigureIds,
7
+ prepareAimdForFormalOutput,
8
+ scanAimdFigureBlocks,
9
+ type AimdFigureBlockInfo,
10
+ type AimdFigureSourceField,
11
+ type AimdTextEdit,
12
+ type GeneratedAimdFigureId,
13
+ type NormalizeAimdFigureIdsResult,
14
+ type PrepareAimdFormalOutputResult,
15
+ } from './fig'
package/src/index.ts CHANGED
@@ -7,4 +7,5 @@
7
7
  */
8
8
 
9
9
  export * from './monaco'
10
+ export * from './authoring/index'
10
11
  export * from './vue/index'
@@ -30,6 +30,7 @@ const editorContainer = ref<HTMLElement | null>(null)
30
30
 
31
31
  let monacoEditorInstance: any = null
32
32
  let monacoModule: any = null
33
+ let aimdCodeActionProviderDisposable: any = null
33
34
  let isSyncing = false
34
35
  const loading = ref(true)
35
36
 
@@ -217,7 +218,7 @@ function updateAimdDiagnostics() {
217
218
  const model = monacoEditorInstance.getModel()
218
219
  if (!model) return
219
220
 
220
- const markers = collectAimdDiagnostics(model.getValue()).map((diagnostic) => {
221
+ const markers = collectAimdDiagnostics(model.getValue(), props.resolvedMessages.diagnostics).map((diagnostic) => {
221
222
  const start = model.getPositionAt(diagnostic.startOffset)
222
223
  const end = model.getPositionAt(diagnostic.endOffset)
223
224
  return {
@@ -225,6 +226,7 @@ function updateAimdDiagnostics() {
225
226
  ? monacoModule.MarkerSeverity.Error
226
227
  : monacoModule.MarkerSeverity.Warning,
227
228
  message: diagnostic.message,
229
+ code: diagnostic.code,
228
230
  source: 'AIMD',
229
231
  startLineNumber: start.lineNumber,
230
232
  startColumn: start.column,
@@ -236,6 +238,65 @@ function updateAimdDiagnostics() {
236
238
  monacoModule.editor.setModelMarkers(model, AIMD_DIAGNOSTIC_OWNER, markers)
237
239
  }
238
240
 
241
+ function rangesOverlap(startOffset: number, endOffset: number, rangeStart: number, rangeEnd: number): boolean {
242
+ return startOffset <= rangeEnd && endOffset >= rangeStart
243
+ }
244
+
245
+ function registerAimdCodeActions(monaco: any) {
246
+ aimdCodeActionProviderDisposable?.dispose()
247
+ aimdCodeActionProviderDisposable = monaco.languages.registerCodeActionProvider('aimd', {
248
+ provideCodeActions(model: any, range: any, context: any) {
249
+ if (props.readonly || model !== monacoEditorInstance?.getModel()) {
250
+ return { actions: [], dispose() {} }
251
+ }
252
+
253
+ const rangeStart = model.getOffsetAt({
254
+ lineNumber: range.startLineNumber,
255
+ column: range.startColumn,
256
+ })
257
+ const rangeEnd = model.getOffsetAt({
258
+ lineNumber: range.endLineNumber,
259
+ column: range.endColumn,
260
+ })
261
+ const actions = collectAimdDiagnostics(model.getValue(), props.resolvedMessages.diagnostics)
262
+ .filter(diagnostic => diagnostic.quickFix && rangesOverlap(
263
+ diagnostic.startOffset,
264
+ diagnostic.endOffset,
265
+ rangeStart,
266
+ rangeEnd,
267
+ ))
268
+ .map((diagnostic) => {
269
+ const edit = diagnostic.quickFix!.edit
270
+ const editStart = model.getPositionAt(edit.startOffset)
271
+ const editEnd = model.getPositionAt(edit.endOffset)
272
+ return {
273
+ title: diagnostic.quickFix!.title,
274
+ kind: 'quickfix',
275
+ isPreferred: true,
276
+ diagnostics: context.markers.filter((marker: any) => marker.code === diagnostic.code),
277
+ edit: {
278
+ edits: [{
279
+ resource: model.uri,
280
+ textEdit: {
281
+ range: {
282
+ startLineNumber: editStart.lineNumber,
283
+ startColumn: editStart.column,
284
+ endLineNumber: editEnd.lineNumber,
285
+ endColumn: editEnd.column,
286
+ },
287
+ text: edit.text,
288
+ },
289
+ versionId: model.getVersionId(),
290
+ }],
291
+ },
292
+ }
293
+ })
294
+
295
+ return { actions, dispose() {} }
296
+ },
297
+ })
298
+ }
299
+
239
300
  function clearAimdDiagnostics() {
240
301
  if (!monacoModule || !monacoEditorInstance) return
241
302
 
@@ -267,6 +328,7 @@ function createEditor(monaco: any) {
267
328
  readOnly: props.readonly,
268
329
  ...safeMonacoOptions,
269
330
  })
331
+ registerAimdCodeActions(monaco)
270
332
  monacoEditorInstance.onDidChangeModelContent(() => {
271
333
  updateAimdDiagnostics()
272
334
  if (!isSyncing) {
@@ -292,6 +354,7 @@ onMounted(async () => {
292
354
 
293
355
  onBeforeUnmount(() => {
294
356
  clearAimdDiagnostics()
357
+ aimdCodeActionProviderDisposable?.dispose()
295
358
  monacoEditorInstance?.dispose()
296
359
  })
297
360