volar-service-html 0.0.13 → 0.0.15
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/LICENSE +21 -0
- package/README.md +25 -0
- package/out/index.d.ts +5 -3
- package/out/index.js +9 -69
- package/package.json +17 -5
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022-present Johnson Chu
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# volar-service-html
|
|
2
|
+
|
|
3
|
+
Volar plugin for [`vscode-html-languageservice`](https://github.com/microsoft/vscode-html-languageservice).
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm install volar-service-html
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
`volar.config.js`
|
|
14
|
+
|
|
15
|
+
```js
|
|
16
|
+
module.exports = {
|
|
17
|
+
services: [
|
|
18
|
+
require('volar-service-html').create(),
|
|
19
|
+
],
|
|
20
|
+
};
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## License
|
|
24
|
+
|
|
25
|
+
[MIT](LICENSE) © [Johnson Chu](https://github.com/johnsoncodehk)
|
package/out/index.d.ts
CHANGED
|
@@ -8,8 +8,10 @@ export interface Provide {
|
|
|
8
8
|
'html/updateCustomData': (extraData: html.IHTMLDataProvider[]) => void;
|
|
9
9
|
}
|
|
10
10
|
export declare function getHtmlDocument(document: TextDocument): html.HTMLDocument;
|
|
11
|
-
export declare function create(
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
export declare function create({ languageId, useDefaultDataProvider, useCustomDataProviders, }?: {
|
|
12
|
+
languageId?: string;
|
|
13
|
+
useDefaultDataProvider?: boolean;
|
|
14
|
+
useCustomDataProviders?: boolean;
|
|
14
15
|
}): Service<Provide>;
|
|
15
16
|
export default create;
|
|
17
|
+
//# sourceMappingURL=index.d.ts.map
|
package/out/index.js
CHANGED
|
@@ -1,31 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
3
|
exports.create = exports.getHtmlDocument = void 0;
|
|
27
|
-
const html =
|
|
28
|
-
const path =
|
|
4
|
+
const html = require("vscode-html-languageservice");
|
|
5
|
+
const path = require("path");
|
|
29
6
|
const vscode_uri_1 = require("vscode-uri");
|
|
30
7
|
const parserLs = html.getLanguageService();
|
|
31
8
|
const htmlDocuments = new WeakMap();
|
|
@@ -44,7 +21,7 @@ function getHtmlDocument(document) {
|
|
|
44
21
|
exports.getHtmlDocument = getHtmlDocument;
|
|
45
22
|
// https://github.com/microsoft/vscode/blob/09850876e652688fb142e2e19fd00fd38c0bc4ba/extensions/html-language-features/server/src/htmlServer.ts#L183
|
|
46
23
|
const triggerCharacters = ['.', ':', '<', '"', '=', '/'];
|
|
47
|
-
function create(
|
|
24
|
+
function create({ languageId = 'html', useDefaultDataProvider = true, useCustomDataProviders = true, } = {}) {
|
|
48
25
|
return (context) => {
|
|
49
26
|
if (!context) {
|
|
50
27
|
return { triggerCharacters };
|
|
@@ -85,7 +62,7 @@ function create(options = {}) {
|
|
|
85
62
|
return {
|
|
86
63
|
provide: {
|
|
87
64
|
'html/htmlDocument': (document) => {
|
|
88
|
-
if (document.languageId ===
|
|
65
|
+
if (document.languageId === languageId) {
|
|
89
66
|
return getHtmlDocument(document);
|
|
90
67
|
}
|
|
91
68
|
},
|
|
@@ -132,12 +109,7 @@ function create(options = {}) {
|
|
|
132
109
|
},
|
|
133
110
|
provideDocumentSymbols(document) {
|
|
134
111
|
return worker(document, (htmlDocument) => {
|
|
135
|
-
|
|
136
|
-
const symbols = [];
|
|
137
|
-
htmlDocument.roots.forEach(node => {
|
|
138
|
-
provideFileSymbolsInternal(document, node, symbols);
|
|
139
|
-
});
|
|
140
|
-
return symbols;
|
|
112
|
+
return htmlLs.findDocumentSymbols2(document, htmlDocument);
|
|
141
113
|
});
|
|
142
114
|
},
|
|
143
115
|
provideFoldingRanges(document) {
|
|
@@ -260,15 +232,15 @@ function create(options = {}) {
|
|
|
260
232
|
},
|
|
261
233
|
};
|
|
262
234
|
async function initCustomData() {
|
|
263
|
-
if (shouldUpdateCustomData &&
|
|
235
|
+
if (shouldUpdateCustomData && useCustomDataProviders) {
|
|
264
236
|
shouldUpdateCustomData = false;
|
|
265
237
|
customData = await getCustomData();
|
|
266
|
-
htmlLs.setDataProviders(
|
|
238
|
+
htmlLs.setDataProviders(useDefaultDataProvider, [...customData, ...extraData]);
|
|
267
239
|
}
|
|
268
240
|
}
|
|
269
241
|
function updateExtraCustomData(data) {
|
|
270
242
|
extraData = data;
|
|
271
|
-
htmlLs.setDataProviders(
|
|
243
|
+
htmlLs.setDataProviders(useDefaultDataProvider, [...customData, ...extraData]);
|
|
272
244
|
}
|
|
273
245
|
async function getCustomData() {
|
|
274
246
|
const customData = await context?.env.getConfiguration?.('html.customData') ?? [];
|
|
@@ -285,7 +257,7 @@ function create(options = {}) {
|
|
|
285
257
|
return newData;
|
|
286
258
|
}
|
|
287
259
|
async function worker(document, callback) {
|
|
288
|
-
if (document.languageId !==
|
|
260
|
+
if (document.languageId !== languageId)
|
|
289
261
|
return;
|
|
290
262
|
const htmlDocument = getHtmlDocument(document);
|
|
291
263
|
if (!htmlDocument)
|
|
@@ -305,36 +277,4 @@ const NL = '\n'.charCodeAt(0);
|
|
|
305
277
|
function isNewlineCharacter(charCode) {
|
|
306
278
|
return charCode === CR || charCode === NL;
|
|
307
279
|
}
|
|
308
|
-
function provideFileSymbolsInternal(document, node, symbols) {
|
|
309
|
-
const name = nodeToName(node);
|
|
310
|
-
const range = {
|
|
311
|
-
start: document.positionAt(node.start),
|
|
312
|
-
end: document.positionAt(node.end),
|
|
313
|
-
};
|
|
314
|
-
const symbol = {
|
|
315
|
-
name,
|
|
316
|
-
kind: 8,
|
|
317
|
-
range,
|
|
318
|
-
selectionRange: range,
|
|
319
|
-
};
|
|
320
|
-
symbols.push(symbol);
|
|
321
|
-
node.children.forEach(child => {
|
|
322
|
-
symbol.children ??= [];
|
|
323
|
-
provideFileSymbolsInternal(document, child, symbol.children);
|
|
324
|
-
});
|
|
325
|
-
}
|
|
326
|
-
function nodeToName(node) {
|
|
327
|
-
let name = node.tag;
|
|
328
|
-
if (node.attributes) {
|
|
329
|
-
const id = node.attributes['id'];
|
|
330
|
-
const classes = node.attributes['class'];
|
|
331
|
-
if (id) {
|
|
332
|
-
name += `#${id.replace(/[\"\']/g, '')}`;
|
|
333
|
-
}
|
|
334
|
-
if (classes) {
|
|
335
|
-
name += classes.replace(/[\"\']/g, '').split(/\s+/).map(className => `.${className}`).join('');
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
return name || '?';
|
|
339
|
-
}
|
|
340
280
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "volar-service-html",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.15",
|
|
4
|
+
"description": "Integrate vscode-languageservice-html into Volar",
|
|
5
|
+
"homepage": "https://github.com/volarjs/services/tree/master/packages/html",
|
|
6
|
+
"bugs": "https://github.com/volarjs/services/issues",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"keywords": [
|
|
9
|
+
"volar-service"
|
|
10
|
+
],
|
|
4
11
|
"main": "out/index.js",
|
|
5
12
|
"license": "MIT",
|
|
6
13
|
"files": [
|
|
@@ -12,12 +19,17 @@
|
|
|
12
19
|
"url": "https://github.com/volarjs/services.git",
|
|
13
20
|
"directory": "packages/html"
|
|
14
21
|
},
|
|
22
|
+
"author": {
|
|
23
|
+
"name": "Johnson Chu",
|
|
24
|
+
"email": "johnsoncodehk@gmail.com",
|
|
25
|
+
"url": "https://github.com/johnsoncodehk"
|
|
26
|
+
},
|
|
15
27
|
"dependencies": {
|
|
16
|
-
"vscode-html-languageservice": "^5.0
|
|
17
|
-
"vscode-uri": "^3.0.
|
|
28
|
+
"vscode-html-languageservice": "^5.1.0",
|
|
29
|
+
"vscode-uri": "^3.0.8"
|
|
18
30
|
},
|
|
19
31
|
"devDependencies": {
|
|
20
|
-
"vscode-languageserver-textdocument": "^1.0.
|
|
32
|
+
"vscode-languageserver-textdocument": "^1.0.11"
|
|
21
33
|
},
|
|
22
34
|
"peerDependencies": {
|
|
23
35
|
"@volar/language-service": "~1.10.0"
|
|
@@ -27,5 +39,5 @@
|
|
|
27
39
|
"optional": true
|
|
28
40
|
}
|
|
29
41
|
},
|
|
30
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "3a59378715a959b433ca65700d2515d708469388"
|
|
31
43
|
}
|