volar-service-prettyhtml 0.0.30 → 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 +7 -2
- package/index.js +20 -9
- package/package.json +3 -3
package/index.d.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import type { ServicePlugin } from '@volar/language-service';
|
|
2
1
|
import * as prettyhtml from '@starptech/prettyhtml';
|
|
3
|
-
|
|
2
|
+
import type { DocumentSelector, FormattingOptions, Result, ServiceContext, ServicePlugin, TextDocument } from '@volar/language-service';
|
|
3
|
+
export type PrettyhtmlFormattingOptions = Parameters<typeof prettyhtml>[1];
|
|
4
|
+
export declare function create({ documentSelector, isFormattingEnabled, getFormattingOptions, }?: {
|
|
5
|
+
documentSelector?: DocumentSelector;
|
|
6
|
+
isFormattingEnabled?(document: TextDocument, context: ServiceContext): Result<boolean>;
|
|
7
|
+
getFormattingOptions?(document: TextDocument, options: FormattingOptions, context: ServiceContext): Result<PrettyhtmlFormattingOptions>;
|
|
8
|
+
}): ServicePlugin;
|
|
4
9
|
//# sourceMappingURL=index.d.ts.map
|
package/index.js
CHANGED
|
@@ -2,20 +2,23 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.create = void 0;
|
|
4
4
|
const prettyhtml = require("@starptech/prettyhtml");
|
|
5
|
-
function create(
|
|
5
|
+
function create({ documentSelector = ['html'], isFormattingEnabled = () => true, getFormattingOptions = (_document, options) => {
|
|
6
|
+
return {
|
|
7
|
+
tabWidth: options.tabSize,
|
|
8
|
+
useTabs: !options.insertSpaces,
|
|
9
|
+
};
|
|
10
|
+
}, } = {}) {
|
|
6
11
|
return {
|
|
7
12
|
name: 'prettyhtml',
|
|
8
|
-
create() {
|
|
13
|
+
create(context) {
|
|
9
14
|
return {
|
|
10
|
-
provideDocumentFormattingEdits(document, range, options) {
|
|
11
|
-
if (document
|
|
15
|
+
async provideDocumentFormattingEdits(document, range, options) {
|
|
16
|
+
if (!matchDocument(documentSelector, document))
|
|
17
|
+
return;
|
|
18
|
+
if (!await isFormattingEnabled(document, context))
|
|
12
19
|
return;
|
|
13
20
|
const oldRangeText = document.getText(range);
|
|
14
|
-
const newRangeText = prettyhtml(oldRangeText,
|
|
15
|
-
...configs,
|
|
16
|
-
tabWidth: options.tabSize,
|
|
17
|
-
useTabs: !options.insertSpaces,
|
|
18
|
-
}).contents;
|
|
21
|
+
const newRangeText = prettyhtml(oldRangeText, await getFormattingOptions(document, options, context)).contents;
|
|
19
22
|
if (newRangeText === oldRangeText)
|
|
20
23
|
return [];
|
|
21
24
|
const newText = document.getText({
|
|
@@ -40,4 +43,12 @@ function create(configs) {
|
|
|
40
43
|
};
|
|
41
44
|
}
|
|
42
45
|
exports.create = create;
|
|
46
|
+
function matchDocument(selector, document) {
|
|
47
|
+
for (const sel of selector) {
|
|
48
|
+
if (sel === document.languageId || (typeof sel === 'object' && sel.language === document.languageId)) {
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
43
54
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "volar-service-prettyhtml",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.32",
|
|
4
4
|
"description": "Integrate prettyhtml into Volar",
|
|
5
5
|
"homepage": "https://github.com/volarjs/services/tree/master/packages/prettyhtml",
|
|
6
6
|
"bugs": "https://github.com/volarjs/services/issues",
|
|
@@ -27,12 +27,12 @@
|
|
|
27
27
|
"@starptech/prettyhtml": "^0.10.0"
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|
|
30
|
-
"@volar/language-service": "~2.0
|
|
30
|
+
"@volar/language-service": "~2.1.0"
|
|
31
31
|
},
|
|
32
32
|
"peerDependenciesMeta": {
|
|
33
33
|
"@volar/language-service": {
|
|
34
34
|
"optional": true
|
|
35
35
|
}
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "717049e7dcd5c30f451f6db8eb71eaba43f74c83"
|
|
38
38
|
}
|