pull/5370/head
filip mertens 2 years ago committed by yann300
parent 411b4a6895
commit e3d67d2c35
  1. 23
      apps/remix-ide/src/app/plugins/code-format.ts

@ -62,6 +62,13 @@ const defaultOptions = {
export class CodeFormat extends Plugin { export class CodeFormat extends Plugin {
prettier: any
ts: any
babel: any
espree: any
yml: any
sol: any
constructor() { constructor() {
super(profile) super(profile)
} }
@ -69,11 +76,13 @@ export class CodeFormat extends Plugin {
async format(file: string) { async format(file: string) {
// lazy load // lazy load
const prettier = await import('prettier/standalone') if (!this.prettier) {
const ts = await import('prettier/parser-typescript') this.prettier = await import('prettier/standalone')
const babel = await import('prettier/parser-babel') this.ts = await import('prettier/parser-typescript')
const espree = await import('prettier/parser-espree') this.babel = await import('prettier/parser-babel')
const yml = await import('prettier/parser-yaml') this.espree = await import('prettier/parser-espree')
this.yml = await import('prettier/parser-yaml')
}
try { try {
const content = await this.call('fileManager', 'readFile', file) const content = await this.call('fileManager', 'readFile', file)
@ -243,8 +252,8 @@ export class CodeFormat extends Plugin {
} }
const result = prettier.format(content, { const result = this.prettier.format(content, {
plugins: [sol as any, ts, babel, espree, yml], plugins: [sol as any, this.ts, this.babel, this.espree, this.yml],
parser: parserName, parser: parserName,
...options ...options
}) })

Loading…
Cancel
Save