volar-service-html 0.0.47 → 0.0.48
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 +11 -11
- package/index.js +51 -25
- package/package.json +3 -3
package/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Disposable, DocumentSelector, FormattingOptions, ProviderResult,
|
|
1
|
+
import type { Disposable, DocumentSelector, FormattingOptions, ProviderResult, LanguageServiceContext, LanguageServicePlugin } from '@volar/language-service';
|
|
2
2
|
import * as html from 'vscode-html-languageservice';
|
|
3
3
|
import { TextDocument } from 'vscode-languageserver-textdocument';
|
|
4
4
|
export interface Provide {
|
|
@@ -6,17 +6,17 @@ export interface Provide {
|
|
|
6
6
|
'html/languageService': () => html.LanguageService;
|
|
7
7
|
'html/documentContext': () => html.DocumentContext;
|
|
8
8
|
}
|
|
9
|
-
export declare function create({ documentSelector, useDefaultDataProvider, getDocumentContext, isFormattingEnabled,
|
|
9
|
+
export declare function create({ documentSelector, useDefaultDataProvider, getDocumentContext, isFormattingEnabled, getFormattingOptions, getCompletionConfiguration, getHoverSettings, getCustomData, onDidChangeCustomData, }?: {
|
|
10
10
|
documentSelector?: DocumentSelector;
|
|
11
11
|
useDefaultDataProvider?: boolean;
|
|
12
|
-
isFormattingEnabled?(document: TextDocument, context:
|
|
13
|
-
isAutoCreateQuotesEnabled?(document: TextDocument, context:
|
|
14
|
-
isAutoClosingTagsEnabled?(document: TextDocument, context:
|
|
15
|
-
getDocumentContext?(context:
|
|
16
|
-
getFormattingOptions?(document: TextDocument, options: FormattingOptions, context:
|
|
17
|
-
getCompletionConfiguration?(document: TextDocument, context:
|
|
18
|
-
getHoverSettings?(document: TextDocument, context:
|
|
19
|
-
getCustomData?(context:
|
|
20
|
-
onDidChangeCustomData?(listener: () => void, context:
|
|
12
|
+
isFormattingEnabled?(document: TextDocument, context: LanguageServiceContext): ProviderResult<boolean>;
|
|
13
|
+
isAutoCreateQuotesEnabled?(document: TextDocument, context: LanguageServiceContext): ProviderResult<boolean>;
|
|
14
|
+
isAutoClosingTagsEnabled?(document: TextDocument, context: LanguageServiceContext): ProviderResult<boolean>;
|
|
15
|
+
getDocumentContext?(context: LanguageServiceContext): html.DocumentContext;
|
|
16
|
+
getFormattingOptions?(document: TextDocument, options: FormattingOptions, context: LanguageServiceContext): ProviderResult<html.HTMLFormatConfiguration>;
|
|
17
|
+
getCompletionConfiguration?(document: TextDocument, context: LanguageServiceContext): ProviderResult<html.CompletionConfiguration | undefined>;
|
|
18
|
+
getHoverSettings?(document: TextDocument, context: LanguageServiceContext): ProviderResult<html.HoverSettings | undefined>;
|
|
19
|
+
getCustomData?(context: LanguageServiceContext): ProviderResult<html.IHTMLDataProvider[]>;
|
|
20
|
+
onDidChangeCustomData?(listener: () => void, context: LanguageServiceContext): Disposable;
|
|
21
21
|
}): LanguageServicePlugin;
|
|
22
22
|
//# sourceMappingURL=index.d.ts.map
|
package/index.js
CHANGED
|
@@ -7,32 +7,28 @@ const vscode_uri_1 = require("vscode-uri");
|
|
|
7
7
|
function create({ documentSelector = ['html'], useDefaultDataProvider = true, getDocumentContext = context => {
|
|
8
8
|
return {
|
|
9
9
|
resolveReference(ref, base) {
|
|
10
|
-
|
|
10
|
+
let baseUri = vscode_uri_1.URI.parse(base);
|
|
11
|
+
const decoded = context.decodeEmbeddedDocumentUri(baseUri);
|
|
11
12
|
if (decoded) {
|
|
12
|
-
|
|
13
|
+
baseUri = decoded[0];
|
|
13
14
|
}
|
|
14
15
|
if (ref.match(/^\w[\w\d+.-]*:/)) {
|
|
15
16
|
// starts with a schema
|
|
16
17
|
return ref;
|
|
17
18
|
}
|
|
18
|
-
if (ref[0] === '/') { // resolve absolute path against the current workspace folder
|
|
19
|
-
let folderUri = context.env.
|
|
19
|
+
if (ref[0] === '/' && context.env.workspaceFolders.length) { // resolve absolute path against the current workspace folder
|
|
20
|
+
let folderUri = context.env.workspaceFolders[0].toString();
|
|
20
21
|
if (!folderUri.endsWith('/')) {
|
|
21
22
|
folderUri += '/';
|
|
22
23
|
}
|
|
23
24
|
return folderUri + ref.substring(1);
|
|
24
25
|
}
|
|
25
|
-
const baseUri = vscode_uri_1.URI.parse(base);
|
|
26
26
|
const baseUriDir = baseUri.path.endsWith('/') ? baseUri : vscode_uri_1.Utils.dirname(baseUri);
|
|
27
27
|
return vscode_uri_1.Utils.resolvePath(baseUriDir, ref).toString(true);
|
|
28
28
|
},
|
|
29
29
|
};
|
|
30
30
|
}, isFormattingEnabled = async (_document, context) => {
|
|
31
31
|
return await context.env.getConfiguration?.('html.format.enable') ?? true;
|
|
32
|
-
}, isAutoCreateQuotesEnabled = async (_document, context) => {
|
|
33
|
-
return await context.env.getConfiguration?.('html.autoCreateQuotes') ?? true;
|
|
34
|
-
}, isAutoClosingTagsEnabled = async (_document, context) => {
|
|
35
|
-
return await context.env.getConfiguration?.('html.autoClosingTags') ?? true;
|
|
36
32
|
}, getFormattingOptions = async (_document, options, context) => {
|
|
37
33
|
const formatSettings = {
|
|
38
34
|
...options,
|
|
@@ -55,15 +51,18 @@ function create({ documentSelector = ['html'], useDefaultDataProvider = true, ge
|
|
|
55
51
|
const customData = await context.env.getConfiguration?.('html.customData') ?? [];
|
|
56
52
|
const newData = [];
|
|
57
53
|
for (const customDataPath of customData) {
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
54
|
+
for (const workspaceFolder of context.env.workspaceFolders) {
|
|
55
|
+
const uri = vscode_uri_1.Utils.resolvePath(workspaceFolder, customDataPath);
|
|
56
|
+
const json = await context.env.fs?.readFile?.(uri);
|
|
57
|
+
if (json) {
|
|
58
|
+
try {
|
|
59
|
+
const data = JSON.parse(json);
|
|
60
|
+
newData.push(html.newHTMLDataProvider(customDataPath, data));
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
console.error(error);
|
|
64
|
+
}
|
|
65
|
+
break;
|
|
67
66
|
}
|
|
68
67
|
}
|
|
69
68
|
}
|
|
@@ -76,16 +75,43 @@ function create({ documentSelector = ['html'], useDefaultDataProvider = true, ge
|
|
|
76
75
|
},
|
|
77
76
|
};
|
|
78
77
|
}, } = {}) {
|
|
78
|
+
const configurationSections = {
|
|
79
|
+
autoCreateQuotes: 'html.autoCreateQuotes',
|
|
80
|
+
autoClosingTags: 'html.autoClosingTags',
|
|
81
|
+
};
|
|
79
82
|
return {
|
|
80
83
|
name: 'html',
|
|
81
|
-
|
|
82
|
-
|
|
84
|
+
capabilities: {
|
|
85
|
+
completionProvider: {
|
|
86
|
+
// https://github.com/microsoft/vscode/blob/09850876e652688fb142e2e19fd00fd38c0bc4ba/extensions/html-language-features/server/src/htmlServer.ts#L183
|
|
87
|
+
triggerCharacters: ['.', ':', '<', '"', '=', '/'],
|
|
88
|
+
},
|
|
89
|
+
renameProvider: {
|
|
90
|
+
prepareProvider: true,
|
|
91
|
+
},
|
|
92
|
+
hoverProvider: true,
|
|
93
|
+
documentHighlightProvider: true,
|
|
94
|
+
documentLinkProvider: {},
|
|
95
|
+
documentSymbolProvider: true,
|
|
96
|
+
foldingRangeProvider: true,
|
|
97
|
+
selectionRangeProvider: true,
|
|
98
|
+
documentFormattingProvider: true,
|
|
99
|
+
linkedEditingRangeProvider: true,
|
|
100
|
+
autoInsertionProvider: {
|
|
101
|
+
triggerCharacters: ['=', '>', '/'],
|
|
102
|
+
configurationSections: [
|
|
103
|
+
configurationSections.autoCreateQuotes,
|
|
104
|
+
configurationSections.autoClosingTags,
|
|
105
|
+
configurationSections.autoClosingTags,
|
|
106
|
+
],
|
|
107
|
+
},
|
|
108
|
+
},
|
|
83
109
|
create(context) {
|
|
84
110
|
const htmlDocuments = new WeakMap();
|
|
85
111
|
const fileSystemProvider = {
|
|
86
|
-
stat: async (uri) => await context.env.fs?.stat(uri)
|
|
112
|
+
stat: async (uri) => await context.env.fs?.stat(vscode_uri_1.URI.parse(uri))
|
|
87
113
|
?? { type: html.FileType.Unknown, ctime: 0, mtime: 0, size: 0 },
|
|
88
|
-
readDirectory: async (uri) => await context.env.fs?.readDirectory(uri) ?? [],
|
|
114
|
+
readDirectory: async (uri) => await context.env.fs?.readDirectory(vscode_uri_1.URI.parse(uri)) ?? [],
|
|
89
115
|
};
|
|
90
116
|
const documentContext = getDocumentContext(context);
|
|
91
117
|
const htmlLs = html.getLanguageService({
|
|
@@ -267,14 +293,14 @@ function create({ documentSelector = ['html'], useDefaultDataProvider = true, ge
|
|
|
267
293
|
return { ranges };
|
|
268
294
|
});
|
|
269
295
|
},
|
|
270
|
-
async
|
|
296
|
+
async provideAutoInsertSnippet(document, selection, change) {
|
|
271
297
|
// selection must at end of change
|
|
272
298
|
if (document.offsetAt(selection) !== change.rangeOffset + change.text.length) {
|
|
273
299
|
return;
|
|
274
300
|
}
|
|
275
301
|
return worker(document, async (htmlDocument) => {
|
|
276
302
|
if (change.rangeLength === 0 && change.text.endsWith('=')) {
|
|
277
|
-
const enabled = await
|
|
303
|
+
const enabled = await context.env.getConfiguration?.('html.autoCreateQuotes') ?? true;
|
|
278
304
|
if (enabled) {
|
|
279
305
|
const completionConfiguration = await getCompletionConfiguration(document, context);
|
|
280
306
|
const text = htmlLs.doQuoteComplete(document, selection, htmlDocument, completionConfiguration);
|
|
@@ -284,7 +310,7 @@ function create({ documentSelector = ['html'], useDefaultDataProvider = true, ge
|
|
|
284
310
|
}
|
|
285
311
|
}
|
|
286
312
|
if (change.rangeLength === 0 && (change.text.endsWith('>') || change.text.endsWith('/'))) {
|
|
287
|
-
const enabled = await
|
|
313
|
+
const enabled = await context.env.getConfiguration?.('html.autoClosingTags') ?? true;
|
|
288
314
|
if (enabled) {
|
|
289
315
|
const text = htmlLs.doTagComplete(document, selection, htmlDocument);
|
|
290
316
|
if (text) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "volar-service-html",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.48",
|
|
4
4
|
"description": "Integrate vscode-languageservice-html into Volar",
|
|
5
5
|
"homepage": "https://github.com/volarjs/services/tree/master/packages/html",
|
|
6
6
|
"bugs": "https://github.com/volarjs/services/issues",
|
|
@@ -32,12 +32,12 @@
|
|
|
32
32
|
"@types/node": "latest"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
|
-
"@volar/language-service": "~2.
|
|
35
|
+
"@volar/language-service": "~2.3.0-alpha.0"
|
|
36
36
|
},
|
|
37
37
|
"peerDependenciesMeta": {
|
|
38
38
|
"@volar/language-service": {
|
|
39
39
|
"optional": true
|
|
40
40
|
}
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "6a80c92133e154907a79eefa05603f63994214c3"
|
|
43
43
|
}
|