From 089967be0f4c8ffad494861fef09577ebcc9ba7d Mon Sep 17 00:00:00 2001 From: Sosuke Suzuki Date: Wed, 5 Apr 2023 00:16:20 +0900 Subject: [PATCH 01/14] Modify to await the promise returned by `format` --- src/PrettierEditService.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/PrettierEditService.ts b/src/PrettierEditService.ts index 250980df8..325c5184a 100644 --- a/src/PrettierEditService.ts +++ b/src/PrettierEditService.ts @@ -465,7 +465,12 @@ export default class PrettierEditService implements Disposable { this.loggingService.logInfo("Prettier Options:", prettierOptions); try { - const formattedText = prettierInstance.format(text, prettierOptions); + const formattedResult = prettierInstance.format(text, prettierOptions); + // Since Prettier v3, `format` returns Promise. + const formattedText = + typeof formattedResult === "string" + ? formattedResult + : await formattedResult; this.statusBar.update(FormatterStatus.Success); return formattedText; From d053576aae0a70b6afce9c462a76f4f49a963840 Mon Sep 17 00:00:00 2001 From: Sosuke Suzuki Date: Thu, 6 Apr 2023 22:57:06 +0900 Subject: [PATCH 02/14] Add tests for Prettier v3 --- package.json | 2 +- src/test/suite/v3.test.ts | 11 +++++++++++ test-fixtures/test.code-workspace | 3 +++ test-fixtures/v3/.prettierrc | 3 +++ test-fixtures/v3/index.js | 7 +++++++ test-fixtures/v3/index.result.js | 3 +++ test-fixtures/v3/package.json | 16 ++++++++++++++++ test-fixtures/v3/yarn.lock | 8 ++++++++ 8 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 src/test/suite/v3.test.ts create mode 100644 test-fixtures/v3/.prettierrc create mode 100644 test-fixtures/v3/index.js create mode 100644 test-fixtures/v3/index.result.js create mode 100644 test-fixtures/v3/package.json create mode 100644 test-fixtures/v3/yarn.lock diff --git a/package.json b/package.json index 221a29dfd..4a4ff34a7 100644 --- a/package.json +++ b/package.json @@ -70,7 +70,7 @@ "scripts": { "clean": "node ./scripts/clean.js", "lint": "eslint -c .eslintrc.js --ext .ts .", - "pretest": "yarn test-compile && cd test-fixtures/plugins && yarn install && cd ../plugins-pnpm && pnpm i && cd ../outdated && yarn install && cd ../module && yarn install && cd ../specific-version && yarn install && cd ../explicit-dep && yarn install && cd implicit-dep && yarn install", + "pretest": "yarn test-compile && cd test-fixtures/plugins && yarn install && cd ../plugins-pnpm && pnpm i && cd ../outdated && yarn install && cd ../module && yarn install && cd ../specific-version && yarn install && cd ../explicit-dep && yarn install && cd implicit-dep && yarn install && cd ../../v3 && yarn install", "prettier": "prettier --write '**/*.{ts,json,md,hbs,yml,js}'", "test-compile": "yarn clean && tsc -p ./ && yarn webpack", "test": "node ./out/test/runTests.js", diff --git a/src/test/suite/v3.test.ts b/src/test/suite/v3.test.ts new file mode 100644 index 000000000..2e72bdf4c --- /dev/null +++ b/src/test/suite/v3.test.ts @@ -0,0 +1,11 @@ +import * as assert from "assert"; +import { format, getText } from "./format.test"; + +suite("Tests for Prettier v3", function () { + this.timeout(10000); + test("it formats by Prettier v3", async () => { + const { actual } = await format("v3", "index.js"); + const expected = await getText("v3", "index.result.js"); + assert.equal(actual, expected); + }); +}); diff --git a/test-fixtures/test.code-workspace b/test-fixtures/test.code-workspace index b6dbeeb5d..53748ac1c 100644 --- a/test-fixtures/test.code-workspace +++ b/test-fixtures/test.code-workspace @@ -35,6 +35,9 @@ }, { "path": "explicit-dep" + }, + { + "path": "v3" } ], "settings": { diff --git a/test-fixtures/v3/.prettierrc b/test-fixtures/v3/.prettierrc new file mode 100644 index 000000000..5fcd8a70c --- /dev/null +++ b/test-fixtures/v3/.prettierrc @@ -0,0 +1,3 @@ +{ + "tabWidth": 4 +} diff --git a/test-fixtures/v3/index.js b/test-fixtures/v3/index.js new file mode 100644 index 000000000..94293e7a1 --- /dev/null +++ b/test-fixtures/v3/index.js @@ -0,0 +1,7 @@ +function ugly(a , b ,c){ + + + return a + + + b; +} diff --git a/test-fixtures/v3/index.result.js b/test-fixtures/v3/index.result.js new file mode 100644 index 000000000..63cbaa58b --- /dev/null +++ b/test-fixtures/v3/index.result.js @@ -0,0 +1,3 @@ +function ugly(a, b, c) { + return a + b; +} diff --git a/test-fixtures/v3/package.json b/test-fixtures/v3/package.json new file mode 100644 index 000000000..820af7431 --- /dev/null +++ b/test-fixtures/v3/package.json @@ -0,0 +1,16 @@ +{ + "name": "v3", + "version": "1.0.0", + "description": "Test folder for Prettier v3", + "private": true, + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "Prettier", + "license": "MIT", + "devDependencies": { + "prettier": "3.0.0-alpha.6" + }, + "dependencies": {} + } + \ No newline at end of file diff --git a/test-fixtures/v3/yarn.lock b/test-fixtures/v3/yarn.lock new file mode 100644 index 000000000..849f35251 --- /dev/null +++ b/test-fixtures/v3/yarn.lock @@ -0,0 +1,8 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +prettier@3.0.0-alpha.6: + version "3.0.0-alpha.6" + resolved "https://registry.yarnpkg.com/prettier/-/prettier-3.0.0-alpha.6.tgz#c562f9f54966aff792c6920e6a29fbffd1ae07b6" + integrity sha512-AdbQSZ6Oo+iy9Ekzmsgno05P1uX2vqPkjOMJqRfP8hTe+m6iDw4Nt7bPFpWZ/HYCU+3f0P5U0o2ghxQwwkLH7A== From a4bcffe4ec2bdfe07b84ce1478537d7c84ad0b5d Mon Sep 17 00:00:00 2001 From: Sosuke Suzuki Date: Thu, 6 Apr 2023 23:04:47 +0900 Subject: [PATCH 03/14] Add CHANGELOG --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ba1d4ac0..d0193bcd1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to the "prettier-vscode" extension will be documented in thi +## [9.12.0] + +- Support 3.0.0 + ## [9.11.0] - Prettier 2.8.7 From 387352c5635a5760f8eb28ae572f9a0cce7d824e Mon Sep 17 00:00:00 2001 From: Sosuke Suzuki Date: Thu, 6 Apr 2023 23:31:47 +0900 Subject: [PATCH 04/14] Fix test cases --- test-fixtures/v3/.prettierrc | 3 --- test-fixtures/v3/.prettierrc.mjs | 3 +++ test-fixtures/v3/index.js | 12 +++++------- test-fixtures/v3/index.result.js | 9 ++++++--- 4 files changed, 14 insertions(+), 13 deletions(-) delete mode 100644 test-fixtures/v3/.prettierrc create mode 100644 test-fixtures/v3/.prettierrc.mjs diff --git a/test-fixtures/v3/.prettierrc b/test-fixtures/v3/.prettierrc deleted file mode 100644 index 5fcd8a70c..000000000 --- a/test-fixtures/v3/.prettierrc +++ /dev/null @@ -1,3 +0,0 @@ -{ - "tabWidth": 4 -} diff --git a/test-fixtures/v3/.prettierrc.mjs b/test-fixtures/v3/.prettierrc.mjs new file mode 100644 index 000000000..f34003b01 --- /dev/null +++ b/test-fixtures/v3/.prettierrc.mjs @@ -0,0 +1,3 @@ +export default { + tabWidth: 4 +} diff --git a/test-fixtures/v3/index.js b/test-fixtures/v3/index.js index 94293e7a1..ad6e42813 100644 --- a/test-fixtures/v3/index.js +++ b/test-fixtures/v3/index.js @@ -1,7 +1,5 @@ -function ugly(a , b ,c){ - - - return a + - - b; -} +const Counter = decorator("my-counter")( + (props: { initialCount?: number; label?: string }) => { + // ... + } +); diff --git a/test-fixtures/v3/index.result.js b/test-fixtures/v3/index.result.js index 63cbaa58b..31254b81d 100644 --- a/test-fixtures/v3/index.result.js +++ b/test-fixtures/v3/index.result.js @@ -1,3 +1,6 @@ -function ugly(a, b, c) { - return a + b; -} +const Counter = decorator("my-counter")((props: { + initialCount?: number, + label?: string, +}) => { + // ... +}); From 024d3fe462753d82b74e8f564fc00220029274ac Mon Sep 17 00:00:00 2001 From: Sosuke Suzuki Date: Sun, 9 Apr 2023 17:14:35 +0900 Subject: [PATCH 05/14] Await Support info --- src/PrettierEditService.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/PrettierEditService.ts b/src/PrettierEditService.ts index 325c5184a..d3a1feef9 100644 --- a/src/PrettierEditService.ts +++ b/src/PrettierEditService.ts @@ -255,7 +255,8 @@ export default class PrettierEditService implements Disposable { prettierInstance: PrettierModule, uri?: Uri ): Promise => { - const { languages } = prettierInstance.getSupportInfo(); + const supportInfo = await prettierInstance.getSupportInfo(); + const { languages } = supportInfo; languages.forEach((lang) => { if (lang && lang.vscodeLanguageIds) { From b80302e4579ddfcafed83761682ddaab29da3c72 Mon Sep 17 00:00:00 2001 From: Sosuke Suzuki Date: Sat, 15 Apr 2023 19:36:39 +0900 Subject: [PATCH 06/14] Remove dynmic checking --- src/PrettierEditService.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/PrettierEditService.ts b/src/PrettierEditService.ts index d3a1feef9..9f77f1070 100644 --- a/src/PrettierEditService.ts +++ b/src/PrettierEditService.ts @@ -466,12 +466,11 @@ export default class PrettierEditService implements Disposable { this.loggingService.logInfo("Prettier Options:", prettierOptions); try { - const formattedResult = prettierInstance.format(text, prettierOptions); // Since Prettier v3, `format` returns Promise. - const formattedText = - typeof formattedResult === "string" - ? formattedResult - : await formattedResult; + const formattedText = await prettierInstance.format( + text, + prettierOptions + ); this.statusBar.update(FormatterStatus.Success); return formattedText; From 60a161114eed133f3d9c7607991ed3b87dfa4bfb Mon Sep 17 00:00:00 2001 From: Sosuke Suzuki Date: Sat, 15 Apr 2023 19:55:57 +0900 Subject: [PATCH 07/14] Fix tests --- src/test/suite/v3.test.ts | 4 ++-- test-fixtures/v3/{index.result.js => index.result.ts} | 0 test-fixtures/v3/{index.js => index.ts} | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) rename test-fixtures/v3/{index.result.js => index.result.ts} (100%) rename test-fixtures/v3/{index.js => index.ts} (61%) diff --git a/src/test/suite/v3.test.ts b/src/test/suite/v3.test.ts index 2e72bdf4c..50c23ea29 100644 --- a/src/test/suite/v3.test.ts +++ b/src/test/suite/v3.test.ts @@ -4,8 +4,8 @@ import { format, getText } from "./format.test"; suite("Tests for Prettier v3", function () { this.timeout(10000); test("it formats by Prettier v3", async () => { - const { actual } = await format("v3", "index.js"); - const expected = await getText("v3", "index.result.js"); + const { actual } = await format("v3", "index.ts"); + const expected = await getText("v3", "index.result.ts"); assert.equal(actual, expected); }); }); diff --git a/test-fixtures/v3/index.result.js b/test-fixtures/v3/index.result.ts similarity index 100% rename from test-fixtures/v3/index.result.js rename to test-fixtures/v3/index.result.ts diff --git a/test-fixtures/v3/index.js b/test-fixtures/v3/index.ts similarity index 61% rename from test-fixtures/v3/index.js rename to test-fixtures/v3/index.ts index ad6e42813..3174ca3c6 100644 --- a/test-fixtures/v3/index.js +++ b/test-fixtures/v3/index.ts @@ -1,4 +1,4 @@ -const Counter = decorator("my-counter")( +const Counter = decorator("my-counter")( (props: { initialCount?: number; label?: string }) => { // ... } From 59777d7be4c0716c72f0fb023436cdac53b8ac89 Mon Sep 17 00:00:00 2001 From: Sosuke Suzuki Date: Sat, 15 Apr 2023 20:04:58 +0900 Subject: [PATCH 08/14] Fix test fixtures --- test-fixtures/v3/.prettierrc.mjs | 3 --- test-fixtures/v3/index.result.ts | 6 +++--- 2 files changed, 3 insertions(+), 6 deletions(-) delete mode 100644 test-fixtures/v3/.prettierrc.mjs diff --git a/test-fixtures/v3/.prettierrc.mjs b/test-fixtures/v3/.prettierrc.mjs deleted file mode 100644 index f34003b01..000000000 --- a/test-fixtures/v3/.prettierrc.mjs +++ /dev/null @@ -1,3 +0,0 @@ -export default { - tabWidth: 4 -} diff --git a/test-fixtures/v3/index.result.ts b/test-fixtures/v3/index.result.ts index 31254b81d..b4c2a2204 100644 --- a/test-fixtures/v3/index.result.ts +++ b/test-fixtures/v3/index.result.ts @@ -1,6 +1,6 @@ const Counter = decorator("my-counter")((props: { - initialCount?: number, - label?: string, + initialCount?: number; + label?: string; }) => { - // ... + // ... }); From 31e3ffb401e82540c299c8a752b3bc07ed9fcfdd Mon Sep 17 00:00:00 2001 From: Sosuke Suzuki Date: Sat, 15 Apr 2023 20:07:19 +0900 Subject: [PATCH 09/14] Run fmt --- foo.txt | 3 +++ test-fixtures/v3/package.json | 29 ++++++++++++++--------------- 2 files changed, 17 insertions(+), 15 deletions(-) create mode 100644 foo.txt diff --git a/foo.txt b/foo.txt new file mode 100644 index 000000000..4f3a16f7e --- /dev/null +++ b/foo.txt @@ -0,0 +1,3 @@ +Prettier Version: 2.8.7, +Prettier config file /Users/sosuke.suzuki/ghq/github.com/sosukesuzuki/prettier-vscode/.prettierrc, +fileName /Users/sosuke.suzuki/ghq/github.com/sosukesuzuki/prettier-vscode/test-fixtures/v3/index.ts \ No newline at end of file diff --git a/test-fixtures/v3/package.json b/test-fixtures/v3/package.json index 820af7431..a4f5ff9cf 100644 --- a/test-fixtures/v3/package.json +++ b/test-fixtures/v3/package.json @@ -1,16 +1,15 @@ { - "name": "v3", - "version": "1.0.0", - "description": "Test folder for Prettier v3", - "private": true, - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, - "author": "Prettier", - "license": "MIT", - "devDependencies": { - "prettier": "3.0.0-alpha.6" - }, - "dependencies": {} - } - \ No newline at end of file + "name": "v3", + "version": "1.0.0", + "description": "Test folder for Prettier v3", + "private": true, + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "Prettier", + "license": "MIT", + "devDependencies": { + "prettier": "3.0.0-alpha.6" + }, + "dependencies": {} +} From ab1b4ecfa540c634ddf2b2faaba1a60ab0a9ec57 Mon Sep 17 00:00:00 2001 From: Sosuke Suzuki Date: Sat, 15 Apr 2023 20:08:21 +0900 Subject: [PATCH 10/14] Remove foo.txt --- foo.txt | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 foo.txt diff --git a/foo.txt b/foo.txt deleted file mode 100644 index 4f3a16f7e..000000000 --- a/foo.txt +++ /dev/null @@ -1,3 +0,0 @@ -Prettier Version: 2.8.7, -Prettier config file /Users/sosuke.suzuki/ghq/github.com/sosukesuzuki/prettier-vscode/.prettierrc, -fileName /Users/sosuke.suzuki/ghq/github.com/sosukesuzuki/prettier-vscode/test-fixtures/v3/index.ts \ No newline at end of file From e766ad3be721bdb2af665b90be143bf6df19e690 Mon Sep 17 00:00:00 2001 From: Sosuke Suzuki Date: Sun, 16 Apr 2023 12:43:37 +0900 Subject: [PATCH 11/14] More await for Prettier API calls --- src/ModuleResolver.ts | 2 +- src/PrettierEditService.ts | 2 +- src/TemplateService.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ModuleResolver.ts b/src/ModuleResolver.ts index 410a359d2..9c0c69abf 100644 --- a/src/ModuleResolver.ts +++ b/src/ModuleResolver.ts @@ -324,7 +324,7 @@ export class ModuleResolver implements ModuleResolverInterface { * Clears the module and config cache */ public async dispose() { - prettier.clearConfigCache(); + await prettier.clearConfigCache(); this.path2Module.forEach((module) => { try { module.clearConfigCache(); diff --git a/src/PrettierEditService.ts b/src/PrettierEditService.ts index 9f77f1070..d2a360860 100644 --- a/src/PrettierEditService.ts +++ b/src/PrettierEditService.ts @@ -443,7 +443,7 @@ export default class PrettierEditService implements Disposable { this.loggingService.logWarning( `Parser not inferred, trying VS Code language.` ); - const languages = prettierInstance.getSupportInfo().languages; + const languages = (await prettierInstance.getSupportInfo()).languages; parser = getParserFromLanguageId(languages, uri, languageId); } diff --git a/src/TemplateService.ts b/src/TemplateService.ts index 4fc7741db..25173b11d 100644 --- a/src/TemplateService.ts +++ b/src/TemplateService.ts @@ -20,7 +20,7 @@ export class TemplateService { useTabs: settings.useTabs, }; - const templateSource = this.prettierModule.format( + const templateSource = await this.prettierModule.format( JSON.stringify(settings, null, 2), formatterOptions ); From 8de8baec7f70c3ae0553ac333413508f391c7eff Mon Sep 17 00:00:00 2001 From: Sosuke Suzuki Date: Sun, 16 Apr 2023 17:08:12 +0900 Subject: [PATCH 12/14] Address review --- src/PrettierEditService.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/PrettierEditService.ts b/src/PrettierEditService.ts index d2a360860..1e60acc06 100644 --- a/src/PrettierEditService.ts +++ b/src/PrettierEditService.ts @@ -255,8 +255,7 @@ export default class PrettierEditService implements Disposable { prettierInstance: PrettierModule, uri?: Uri ): Promise => { - const supportInfo = await prettierInstance.getSupportInfo(); - const { languages } = supportInfo; + const { languages } = await prettierInstance.getSupportInfo(); languages.forEach((lang) => { if (lang && lang.vscodeLanguageIds) { @@ -443,7 +442,7 @@ export default class PrettierEditService implements Disposable { this.loggingService.logWarning( `Parser not inferred, trying VS Code language.` ); - const languages = (await prettierInstance.getSupportInfo()).languages; + const { languages } = await prettierInstance.getSupportInfo(); parser = getParserFromLanguageId(languages, uri, languageId); } From 77d3c11a64befaf1bef73ef15d18a8f1296c08dc Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Tue, 18 Apr 2023 09:47:33 +0800 Subject: [PATCH 13/14] `await` another call --- src/test/suite/format.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/suite/format.test.ts b/src/test/suite/format.test.ts index 10bb941d9..4ad5b2ec5 100644 --- a/src/test/suite/format.test.ts +++ b/src/test/suite/format.test.ts @@ -92,7 +92,7 @@ async function formatSameAsPrettier( }, }; const { actual, source } = await format("project", file); - const prettierFormatted = prettier.format(source, prettierOptions); + const prettierFormatted = await prettier.format(source, prettierOptions); assert.equal(actual, prettierFormatted); } From 0623f3fd76db1dfbe08cdf8807fbf9d114242383 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Tue, 18 Apr 2023 11:15:37 +0800 Subject: [PATCH 14/14] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d0193bcd1..ec0832349 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ All notable changes to the "prettier-vscode" extension will be documented in thi ## [9.12.0] -- Support 3.0.0 +- Support Prettier v3 ## [9.11.0]