Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Prettier v3 #2947

Merged
merged 15 commits into from
Apr 21, 2023
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to the "prettier-vscode" extension will be documented in thi

<!-- Check [Keep a Changelog](https://keepachangelog.com/) for recommendations on how to structure this file. -->

## [9.12.0]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a major release. 10.0.0

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should release v10 after Prettier releases v3? This PR is not breaking anything, just add support for v3 alpha.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ntotten I agree with fisker. If you too can agree with this, please merge and release.

Copy link
Member

@fisker fisker Apr 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems there is a release workflow. So I guess we can create a v9.12.0 tag to trigger release?

release:
runs-on: ubuntu-latest
needs: package
if: startsWith(github.ref, 'refs/tags/v')

But let's wait for ntotten to respond first.


- Support 3.0.0

## [9.11.0]

- Prettier 2.8.7
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 7 additions & 2 deletions src/PrettierEditService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,8 @@ export default class PrettierEditService implements Disposable {
prettierInstance: PrettierModule,
uri?: Uri
): Promise<ISelectors> => {
const { languages } = prettierInstance.getSupportInfo();
const supportInfo = await prettierInstance.getSupportInfo();
const { languages } = supportInfo;
fisker marked this conversation as resolved.
Show resolved Hide resolved

languages.forEach((lang) => {
if (lang && lang.vscodeLanguageIds) {
Expand Down Expand Up @@ -465,7 +466,11 @@ export default class PrettierEditService implements Disposable {
this.loggingService.logInfo("Prettier Options:", prettierOptions);

try {
const formattedText = prettierInstance.format(text, prettierOptions);
// Since Prettier v3, `format` returns Promise.
const formattedText = await prettierInstance.format(
text,
prettierOptions
);
this.statusBar.update(FormatterStatus.Success);

return formattedText;
Expand Down
11 changes: 11 additions & 0 deletions src/test/suite/v3.test.ts
Original file line number Diff line number Diff line change
@@ -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.ts");
const expected = await getText("v3", "index.result.ts");
assert.equal(actual, expected);
});
});
3 changes: 3 additions & 0 deletions test-fixtures/test.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
},
{
"path": "explicit-dep"
},
{
"path": "v3"
}
],
"settings": {
Expand Down
6 changes: 6 additions & 0 deletions test-fixtures/v3/index.result.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const Counter = decorator("my-counter")((props: {
initialCount?: number;
label?: string;
}) => {
// ...
});
5 changes: 5 additions & 0 deletions test-fixtures/v3/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const Counter = decorator("my-counter")(
(props: { initialCount?: number; label?: string }) => {
// ...
}
);
15 changes: 15 additions & 0 deletions test-fixtures/v3/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +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": {}
}
8 changes: 8 additions & 0 deletions test-fixtures/v3/yarn.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1


[email protected]:
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==