diff --git a/libs/remix-ui/editor/src/lib/providers/codeActionProvider.ts b/libs/remix-ui/editor/src/lib/providers/codeActionProvider.ts index aeb7b00fc3..d47a7d065d 100644 --- a/libs/remix-ui/editor/src/lib/providers/codeActionProvider.ts +++ b/libs/remix-ui/editor/src/lib/providers/codeActionProvider.ts @@ -104,45 +104,10 @@ export class RemixCodeActionProvider implements monaco.languages.CodeActionProvi } } else if (fix && nodeAtPosition && fix.nodeType !== nodeAtPosition.nodeType) return - if (Array.isArray(fix)) { - for (const element of fix) { - actions.push({ - title: element.title, - diagnostics: [error], - kind: "quickfix", - edit: { - edits: [ - { - resource: model.uri, - edit: { - range: element.range || error, - text: msg || element.message - } - } - ] - }, - isPreferred: true - }) - } - } else - actions.push({ - title: fix.title, - diagnostics: [error], - kind: "quickfix", - edit: { - edits: [ - { - resource: model.uri, - edit: { - range: fix.range || error, - text: msg || fix.message - } - } - ] - }, - isPreferred: true - }) - + if (Array.isArray(fix)) + for (const element of fix) + this.addQuickFix(actions, error, model.uri, {title: element.title, range: element.range || error, text: msg || element.message}) + else this.addQuickFix(actions, error, model.uri, {title: fix.title, range: fix.range || error, text: msg || fix.message}) } } @@ -151,4 +116,22 @@ export class RemixCodeActionProvider implements monaco.languages.CodeActionProvi dispose: () => {} } } + + addQuickFix(actions, error, uri, fixDetails) { + const {title, range, text} = fixDetails + actions.push({ + title, + diagnostics: [error], + kind: "quickfix", + edit: { + edits: [ + { + resource: uri, + edit: { range, text } + } + ] + }, + isPreferred: true + }) + } } \ No newline at end of file