volar-service-prettier 0.0.9 → 0.0.10
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/out/index.d.ts +11 -2
- package/out/index.js +15 -9
- package/package.json +8 -5
package/out/index.d.ts
CHANGED
|
@@ -22,14 +22,23 @@ declare const _default: (options?: {
|
|
|
22
22
|
* @see https://github.com/volarjs/services/issues/5
|
|
23
23
|
*/
|
|
24
24
|
ignoreIdeOptions?: boolean | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* Determine if IDE options should be used as a fallback if there's no Prettier specific settings in the workspace
|
|
27
|
+
*/
|
|
28
|
+
useIdeOptionsFallback?: boolean | undefined;
|
|
25
29
|
/**
|
|
26
30
|
* Additional options to pass to Prettier
|
|
27
31
|
* This is useful, for instance, to add specific plugins you need.
|
|
28
32
|
*/
|
|
29
|
-
additionalOptions?: ((resolvedConfig: Options) => Options) | undefined;
|
|
33
|
+
additionalOptions?: ((resolvedConfig: Options) => Options | Promise<Options>) | undefined;
|
|
30
34
|
/**
|
|
31
35
|
* Options to use when resolving the Prettier config
|
|
32
36
|
*/
|
|
33
37
|
resolveConfigOptions?: ResolveConfigOptions | undefined;
|
|
34
|
-
|
|
38
|
+
/**
|
|
39
|
+
* Prettier instance to use. If undefined, Prettier will be imported through a normal `import('prettier')`.
|
|
40
|
+
* This property is useful whenever you want to load a specific instance of Prettier (for instance, loading the Prettier version installed in the user's project)
|
|
41
|
+
*/
|
|
42
|
+
prettier?: typeof import('prettier') | undefined;
|
|
43
|
+
}, getPrettierConfig?: (prettier: typeof import('prettier'), config?: ResolveConfigOptions) => Promise<Options>) => Service;
|
|
35
44
|
export default _default;
|
package/out/index.js
CHANGED
|
@@ -1,29 +1,35 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const configFile = prettier_1.resolveConfigFile.sync();
|
|
3
|
+
exports.default = (options = {}, getPrettierConfig = async (prettier, config) => {
|
|
4
|
+
const configFile = await prettier.resolveConfigFile();
|
|
6
5
|
if (configFile) {
|
|
7
|
-
return
|
|
6
|
+
return await prettier.resolveConfig(configFile, config) ?? {};
|
|
8
7
|
}
|
|
9
8
|
return {};
|
|
10
9
|
}) => (context) => {
|
|
11
10
|
if (!context) {
|
|
12
11
|
return {};
|
|
13
12
|
}
|
|
13
|
+
let prettier;
|
|
14
|
+
try {
|
|
15
|
+
prettier = options.prettier ?? require('prettier');
|
|
16
|
+
}
|
|
17
|
+
catch (e) {
|
|
18
|
+
throw new Error("Could not load Prettier: " + e);
|
|
19
|
+
}
|
|
14
20
|
const languages = options.languages ?? ['html', 'css', 'scss', 'typescript', 'javascript'];
|
|
15
21
|
return {
|
|
16
22
|
async provideDocumentFormattingEdits(document, _, formatOptions) {
|
|
17
23
|
if (!languages.includes(document.languageId)) {
|
|
18
24
|
return;
|
|
19
25
|
}
|
|
20
|
-
const filePrettierOptions = getPrettierConfig(options.resolveConfigOptions);
|
|
21
|
-
const fileInfo = await
|
|
26
|
+
const filePrettierOptions = await getPrettierConfig(prettier, options.resolveConfigOptions);
|
|
27
|
+
const fileInfo = await prettier.getFileInfo(context.env.uriToFileName(document.uri), { ignorePath: '.prettierignore' });
|
|
22
28
|
if (fileInfo.ignored) {
|
|
23
29
|
return;
|
|
24
30
|
}
|
|
25
31
|
const editorPrettierOptions = await context.env.getConfiguration?.('prettier', document.uri);
|
|
26
|
-
const ideFormattingOptions = formatOptions !== undefined &&
|
|
32
|
+
const ideFormattingOptions = formatOptions !== undefined && options.useIdeOptionsFallback // We need to check for options existing here because some editors might not have it
|
|
27
33
|
? {
|
|
28
34
|
tabWidth: formatOptions.tabSize,
|
|
29
35
|
useTabs: !formatOptions.insertSpaces,
|
|
@@ -43,7 +49,7 @@ exports.default = (options = {}, getPrettierConfig = (config) => {
|
|
|
43
49
|
// - Use the editor's basic configuration settings
|
|
44
50
|
const prettierOptions = returnObjectIfHasKeys(filePrettierOptions) || returnObjectIfHasKeys(editorPrettierOptions) || ideFormattingOptions;
|
|
45
51
|
const currentPrettierConfig = {
|
|
46
|
-
...options.additionalOptions ? options.additionalOptions(prettierOptions) : prettierOptions,
|
|
52
|
+
...options.additionalOptions ? await options.additionalOptions(prettierOptions) : prettierOptions,
|
|
47
53
|
filepath: context.env.uriToFileName(document.uri),
|
|
48
54
|
};
|
|
49
55
|
if (!options.ignoreIdeOptions) {
|
|
@@ -51,7 +57,7 @@ exports.default = (options = {}, getPrettierConfig = (config) => {
|
|
|
51
57
|
currentPrettierConfig.tabWidth = formatOptions.tabSize;
|
|
52
58
|
}
|
|
53
59
|
return [{
|
|
54
|
-
newText:
|
|
60
|
+
newText: await prettier.format(oldText, currentPrettierConfig),
|
|
55
61
|
range: {
|
|
56
62
|
start: document.positionAt(0),
|
|
57
63
|
end: document.positionAt(fullText.length),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "volar-service-prettier",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.10",
|
|
4
4
|
"main": "out/index.js",
|
|
5
5
|
"types": "out/index.d.ts",
|
|
6
6
|
"license": "MIT",
|
|
@@ -19,16 +19,19 @@
|
|
|
19
19
|
"url": "https://www.polv.cc"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
|
-
"
|
|
22
|
+
"prettier": "^3.0.0"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
|
-
"@volar/language-service": "
|
|
26
|
-
"prettier": "
|
|
25
|
+
"@volar/language-service": "~1.9.0",
|
|
26
|
+
"prettier": "^2.2 || ^3.0"
|
|
27
27
|
},
|
|
28
28
|
"peerDependenciesMeta": {
|
|
29
|
+
"prettier": {
|
|
30
|
+
"optional": true
|
|
31
|
+
},
|
|
29
32
|
"@volar/language-service": {
|
|
30
33
|
"optional": true
|
|
31
34
|
}
|
|
32
35
|
},
|
|
33
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "f3c11d5024bd8ae0d8abbae7cbfe8da8c80f4b71"
|
|
34
37
|
}
|