/
prettyhtml.ts
36 lines (28 loc) · 1.08 KB
/
prettyhtml.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import * as prettyhtml from '@starptech/prettyhtml';
import * as vscode from 'vscode-languageserver-protocol';
import { EmbeddedLanguageServicePlugin } from '@volar/vue-language-service-types';
export default function (options: {
getPrintWidth: (uri: string) => number | Promise<number>,
}): EmbeddedLanguageServicePlugin {
return {
async format(document, range, options_2) {
if (document.languageId !== 'html')
return;
const newHtml = prettyhtml(document.getText(), {
tabWidth: options_2.tabSize,
useTabs: !options_2.insertSpaces,
printWidth: await options.getPrintWidth(document.uri),
}).contents;
if (newHtml === document.getText())
return [];
const htmlEdit = vscode.TextEdit.replace(
vscode.Range.create(
document.positionAt(0),
document.positionAt(document.getText().length),
),
newHtml,
);
return [htmlEdit];
},
}
}