volar-service-prettier 0.0.31-patch.2 → 0.0.32

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/index.d.ts CHANGED
@@ -4,7 +4,7 @@ export declare function create(
4
4
  /**
5
5
  * Prettier instance or getter to use.
6
6
  */
7
- prettierInstanceOrGetter: typeof import('prettier') | ((context: ServiceContext) => typeof import('prettier') | undefined), { html, documentSelector, isFormattingEnabled, getFormattingOptions, }?: {
7
+ prettierInstanceOrGetter: typeof import('prettier') | ((context: ServiceContext) => Result<typeof import('prettier') | undefined>), { html, documentSelector, isFormattingEnabled, getFormattingOptions, }?: {
8
8
  html?: {
9
9
  /**
10
10
  * Preprocessing to break "contents" from "HTML tags".
package/index.js CHANGED
@@ -9,14 +9,9 @@ function create(
9
9
  prettierInstanceOrGetter, { html, documentSelector = ['html', 'css', 'scss', 'typescript', 'javascript'], isFormattingEnabled = async (prettier, document) => {
10
10
  const uri = vscode_uri_1.URI.parse(document.uri);
11
11
  if (uri.scheme === 'file') {
12
- try {
13
- const fileInfo = await prettier.getFileInfo(uri.fsPath, { ignorePath: '.prettierignore', resolveConfig: false });
14
- if (fileInfo.ignored) {
15
- return false;
16
- }
17
- }
18
- catch (err) {
19
- console.warn(err);
12
+ const fileInfo = await prettier.getFileInfo(uri.fsPath, { ignorePath: '.prettierignore', resolveConfig: false });
13
+ if (fileInfo.ignored) {
14
+ return false;
20
15
  }
21
16
  }
22
17
  return true;
@@ -35,17 +30,19 @@ prettierInstanceOrGetter, { html, documentSelector = ['html', 'css', 'scss', 'ty
35
30
  return {
36
31
  name: 'prettier',
37
32
  create(context) {
38
- const prettier = typeof prettierInstanceOrGetter === 'function'
39
- ? prettierInstanceOrGetter(context)
40
- : prettierInstanceOrGetter;
41
- if (!prettier) {
42
- return {};
43
- }
33
+ let prettierInstanceOrPromise;
44
34
  return {
45
35
  async provideDocumentFormattingEdits(document, _, formatOptions) {
46
36
  if (!matchDocument(documentSelector, document)) {
47
37
  return;
48
38
  }
39
+ prettierInstanceOrPromise ??= typeof prettierInstanceOrGetter === 'function'
40
+ ? prettierInstanceOrGetter(context)
41
+ : prettierInstanceOrGetter;
42
+ const prettier = await prettierInstanceOrPromise;
43
+ if (!prettier) {
44
+ return;
45
+ }
49
46
  if (!isFormattingEnabled(prettier, document, context)) {
50
47
  return;
51
48
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "volar-service-prettier",
3
- "version": "0.0.31-patch.2",
3
+ "version": "0.0.32",
4
4
  "description": "Integrate Prettier into Volar",
5
5
  "homepage": "https://github.com/volarjs/services/tree/master/packages/prettier",
6
6
  "bugs": "https://github.com/volarjs/services/issues",
@@ -42,5 +42,6 @@
42
42
  "@volar/language-service": {
43
43
  "optional": true
44
44
  }
45
- }
45
+ },
46
+ "gitHead": "717049e7dcd5c30f451f6db8eb71eaba43f74c83"
46
47
  }
package/sample/README.md DELETED
@@ -1 +0,0 @@
1
- Copy from `*.vue.html` to `*.vue` and `Format Document With Volar` (or simply save in Visual Studio Code) to see the differences.