@vue/language-service 2.0.0 → 2.0.1
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 -0
- package/index.js +64 -0
- package/lib/ideFeatures/nameCasing.d.ts +13 -0
- package/lib/ideFeatures/nameCasing.js +211 -0
- package/lib/plugins/css.d.ts +2 -0
- package/lib/plugins/css.js +27 -0
- package/lib/plugins/data.d.ts +4 -0
- package/lib/plugins/data.js +91 -0
- package/lib/plugins/vue-autoinsert-dotvalue.d.ts +10 -0
- package/lib/plugins/vue-autoinsert-dotvalue.js +177 -0
- package/lib/plugins/vue-autoinsert-parentheses.d.ts +2 -0
- package/lib/plugins/vue-autoinsert-parentheses.js +60 -0
- package/lib/plugins/vue-autoinsert-space.d.ts +2 -0
- package/lib/plugins/vue-autoinsert-space.js +34 -0
- package/lib/plugins/vue-codelens-references.d.ts +2 -0
- package/lib/plugins/vue-codelens-references.js +38 -0
- package/lib/plugins/vue-directive-comments.d.ts +2 -0
- package/lib/plugins/vue-directive-comments.js +61 -0
- package/lib/plugins/vue-document-drop.d.ts +2 -0
- package/lib/plugins/vue-document-drop.js +81 -0
- package/lib/plugins/vue-extract-file.d.ts +8 -0
- package/lib/plugins/vue-extract-file.js +258 -0
- package/lib/plugins/vue-sfc.d.ts +7 -0
- package/lib/plugins/vue-sfc.js +163 -0
- package/lib/plugins/vue-template.d.ts +3 -0
- package/lib/plugins/vue-template.js +594 -0
- package/lib/plugins/vue-toggle-v-bind-codeaction.d.ts +2 -0
- package/lib/plugins/vue-toggle-v-bind-codeaction.js +126 -0
- package/lib/plugins/vue-twoslash-queries.d.ts +2 -0
- package/lib/plugins/vue-twoslash-queries.js +50 -0
- package/lib/plugins/vue-visualize-hidden-callback-param.d.ts +2 -0
- package/lib/plugins/vue-visualize-hidden-callback-param.js +45 -0
- package/lib/types.d.ts +10 -0
- package/lib/types.js +31 -0
- package/package.json +6 -6
- package/scripts/update-html-data.js +426 -0
|
@@ -0,0 +1,426 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const langs = [
|
|
5
|
+
{
|
|
6
|
+
name: 'en',
|
|
7
|
+
url: 'https://vuejs.org/',
|
|
8
|
+
repoUrl: 'https://raw.githubusercontent.com/vuejs/docs/',
|
|
9
|
+
supported: true,
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
name: 'zh-cn',
|
|
13
|
+
url: 'https://cn.vuejs.org/',
|
|
14
|
+
repoUrl: 'https://raw.githubusercontent.com/vuejs-translations/docs-zh-cn/',
|
|
15
|
+
supported: true,
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
name: 'ja',
|
|
19
|
+
url: 'https://ja.vuejs.org/',
|
|
20
|
+
repoUrl: 'https://raw.githubusercontent.com/vuejs-translations/docs-ja/',
|
|
21
|
+
supported: true,
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
name: 'ua',
|
|
25
|
+
url: 'https://ua.vuejs.org/',
|
|
26
|
+
repoUrl: 'https://raw.githubusercontent.com/vuejs-translations/docs-ua/',
|
|
27
|
+
supported: false,
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
name: 'fr',
|
|
31
|
+
url: 'https://fr.vuejs.org/',
|
|
32
|
+
repoUrl: 'https://raw.githubusercontent.com/vuejs-translations/docs-fr/',
|
|
33
|
+
supported: true,
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
name: 'ko',
|
|
37
|
+
url: 'https://ko.vuejs.org/',
|
|
38
|
+
repoUrl: 'https://raw.githubusercontent.com/vuejs-translations/docs-ko/',
|
|
39
|
+
supported: true,
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
name: 'pt',
|
|
43
|
+
url: 'https://pt.vuejs.org/',
|
|
44
|
+
repoUrl: 'https://raw.githubusercontent.com/vuejs-translations/docs-pt/',
|
|
45
|
+
supported: true,
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
name: 'bn',
|
|
49
|
+
url: 'https://bn.vuejs.org/',
|
|
50
|
+
repoUrl: 'https://raw.githubusercontent.com/vuejs-translations/docs-bn/',
|
|
51
|
+
supported: false,
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
name: 'it',
|
|
55
|
+
url: 'https://it.vuejs.org/',
|
|
56
|
+
repoUrl: 'https://raw.githubusercontent.com/vuejs-translations/docs-it/',
|
|
57
|
+
supported: true,
|
|
58
|
+
},
|
|
59
|
+
];
|
|
60
|
+
|
|
61
|
+
for (const lang of langs) {
|
|
62
|
+
if (lang.supported) {
|
|
63
|
+
templateWorker(lang);
|
|
64
|
+
sfcWorker(lang);
|
|
65
|
+
modelWorker(lang);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async function sfcWorker(lang) {
|
|
70
|
+
|
|
71
|
+
const sfcDoc = await fetchText(lang.repoUrl + 'HEAD/src/api/sfc-spec.md', lang.url);
|
|
72
|
+
const cssFeaturesDoc = await fetchText(lang.repoUrl + 'HEAD/src/api/sfc-css-features.md', lang.url);
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* @type {import('vscode-html-languageservice').IAttributeData}
|
|
76
|
+
*/
|
|
77
|
+
const langAttr = {
|
|
78
|
+
name: 'lang',
|
|
79
|
+
description: {
|
|
80
|
+
kind: 'markdown',
|
|
81
|
+
value: sfcDoc.split('\n## ')[4].split('\n').slice(1).join('\n'),
|
|
82
|
+
},
|
|
83
|
+
values: [
|
|
84
|
+
// // custom block
|
|
85
|
+
// { name: 'md' },
|
|
86
|
+
// { name: 'json' },
|
|
87
|
+
// { name: 'jsonc' },
|
|
88
|
+
// { name: 'json5' },
|
|
89
|
+
// { name: 'yaml' },
|
|
90
|
+
// { name: 'toml' },
|
|
91
|
+
// { name: 'gql' },
|
|
92
|
+
// { name: 'graphql' },
|
|
93
|
+
],
|
|
94
|
+
references: langs.map(lang => ({
|
|
95
|
+
name: lang.name,
|
|
96
|
+
url: `${lang.url}api/sfc-spec.html#pre-processors`,
|
|
97
|
+
})),
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* @type {import('vscode-html-languageservice').IAttributeData}
|
|
101
|
+
*/
|
|
102
|
+
const srcAttr = {
|
|
103
|
+
name: 'src',
|
|
104
|
+
description: {
|
|
105
|
+
kind: 'markdown',
|
|
106
|
+
value: sfcDoc.split('\n## ')[5].split('\n').slice(1).join('\n'),
|
|
107
|
+
},
|
|
108
|
+
references: langs.map(lang => ({
|
|
109
|
+
name: lang.name,
|
|
110
|
+
url: `${lang.url}api/sfc-spec.html#src-imports`,
|
|
111
|
+
})),
|
|
112
|
+
};
|
|
113
|
+
const languageBlocks = sfcDoc
|
|
114
|
+
.split('\n## ')[2]
|
|
115
|
+
.split('\n### ')
|
|
116
|
+
.slice(1)
|
|
117
|
+
.map((section) => {
|
|
118
|
+
const lines = section.split('\n');
|
|
119
|
+
const name = normalizeTagName(lines[0]);
|
|
120
|
+
/**
|
|
121
|
+
* @type {import('vscode-html-languageservice').ITagData}
|
|
122
|
+
*/
|
|
123
|
+
const data = {
|
|
124
|
+
name,
|
|
125
|
+
attributes: name === 'script setup' ? [] : [srcAttr],
|
|
126
|
+
description: {
|
|
127
|
+
kind: 'markdown',
|
|
128
|
+
value: lines.slice(1).join('\n'),
|
|
129
|
+
},
|
|
130
|
+
references: langs.map(lang => ({
|
|
131
|
+
name: lang.name,
|
|
132
|
+
url: `${lang.url}api/sfc-spec.html#${normalizeHash(name)}`,
|
|
133
|
+
})),
|
|
134
|
+
};
|
|
135
|
+
if (name === 'template') {
|
|
136
|
+
data.attributes.push({
|
|
137
|
+
...langAttr,
|
|
138
|
+
values: [
|
|
139
|
+
{ name: 'html' },
|
|
140
|
+
{ name: 'pug' },
|
|
141
|
+
],
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
if (name === 'script') {
|
|
145
|
+
data.attributes.push({
|
|
146
|
+
...langAttr,
|
|
147
|
+
values: [
|
|
148
|
+
{ name: 'ts' },
|
|
149
|
+
{ name: 'js' },
|
|
150
|
+
{ name: 'tsx' },
|
|
151
|
+
{ name: 'jsx' },
|
|
152
|
+
],
|
|
153
|
+
});
|
|
154
|
+
data.attributes.push({ name: 'generic' });
|
|
155
|
+
}
|
|
156
|
+
if (name === 'style') {
|
|
157
|
+
data.attributes.push({
|
|
158
|
+
...langAttr,
|
|
159
|
+
values: [
|
|
160
|
+
{ name: 'css' },
|
|
161
|
+
{ name: 'scss' },
|
|
162
|
+
{ name: 'less' },
|
|
163
|
+
{ name: 'stylus' },
|
|
164
|
+
{ name: 'postcss' },
|
|
165
|
+
{ name: 'sass' },
|
|
166
|
+
],
|
|
167
|
+
});
|
|
168
|
+
data.attributes.push({
|
|
169
|
+
name: 'scoped',
|
|
170
|
+
valueSet: 'v',
|
|
171
|
+
description: {
|
|
172
|
+
kind: 'markdown',
|
|
173
|
+
value: cssFeaturesDoc.split('\n## ')[1].split('\n').slice(1).join('\n'),
|
|
174
|
+
},
|
|
175
|
+
references: langs.map(lang => ({
|
|
176
|
+
name: lang.name,
|
|
177
|
+
url: `${lang.url}api/sfc-css-features.html#scoped-css`,
|
|
178
|
+
})),
|
|
179
|
+
});
|
|
180
|
+
data.attributes.push({
|
|
181
|
+
name: 'module',
|
|
182
|
+
valueSet: 'v',
|
|
183
|
+
description: {
|
|
184
|
+
kind: 'markdown',
|
|
185
|
+
value: cssFeaturesDoc.split('\n## ')[2].split('\n').slice(1).join('\n'),
|
|
186
|
+
},
|
|
187
|
+
references: langs.map(lang => ({
|
|
188
|
+
name: lang.name,
|
|
189
|
+
url: `${lang.url}api/sfc-css-features.html#css-modules`,
|
|
190
|
+
})),
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
return data;
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
const scriptBlock = languageBlocks.find(b => b.name === 'script');
|
|
197
|
+
const scriptSetupBlock = languageBlocks.find(b => b.name === 'script setup');
|
|
198
|
+
|
|
199
|
+
if (!scriptBlock || !scriptSetupBlock) {
|
|
200
|
+
throw new Error('script or script setup block not found');
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
scriptBlock.attributes.push({
|
|
204
|
+
name: 'setup',
|
|
205
|
+
valueSet: 'v',
|
|
206
|
+
description: scriptSetupBlock.description,
|
|
207
|
+
references: scriptSetupBlock.references,
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* @type {import('vscode-html-languageservice').HTMLDataV1}
|
|
212
|
+
*/
|
|
213
|
+
const data = {
|
|
214
|
+
version: 1.1,
|
|
215
|
+
tags: languageBlocks,
|
|
216
|
+
globalAttributes: [langAttr, srcAttr],
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
const writePath = path.resolve(__dirname, '../data/language-blocks/' + lang.name + '.json');
|
|
220
|
+
fs.writeFileSync(writePath, JSON.stringify(data, null, 2));
|
|
221
|
+
console.log(writePath);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
async function modelWorker(lang) {
|
|
225
|
+
|
|
226
|
+
const formsDoc = await fetchText(lang.repoUrl + 'HEAD/src/guide/essentials/forms.md', lang.url);
|
|
227
|
+
const modifiers = formsDoc
|
|
228
|
+
.split('\n## ')[3]
|
|
229
|
+
.split('\n### ')
|
|
230
|
+
.slice(1)
|
|
231
|
+
.map((section) => {
|
|
232
|
+
const lines = section.split('\n');
|
|
233
|
+
let name = normalizeAttrName(lines[0]);
|
|
234
|
+
name = name.split('.')[1];
|
|
235
|
+
/**
|
|
236
|
+
* @type {import('vscode-html-languageservice').IAttributeData}
|
|
237
|
+
*/
|
|
238
|
+
const data = {
|
|
239
|
+
name,
|
|
240
|
+
description: {
|
|
241
|
+
kind: 'markdown',
|
|
242
|
+
value: lines.slice(1).join('\n'),
|
|
243
|
+
},
|
|
244
|
+
references: langs.map(lang => ({
|
|
245
|
+
name: lang.name,
|
|
246
|
+
url: `${lang.url}guide/essentials/forms.html#${normalizeHash(name)}`,
|
|
247
|
+
})),
|
|
248
|
+
};
|
|
249
|
+
return data;
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* @type {import('vscode-html-languageservice').HTMLDataV1}
|
|
254
|
+
*/
|
|
255
|
+
const data = {
|
|
256
|
+
version: 1.1,
|
|
257
|
+
globalAttributes: modifiers,
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
const writePath = path.resolve(__dirname, '../data/model-modifiers/' + lang.name + '.json');
|
|
261
|
+
fs.writeFileSync(writePath, JSON.stringify(data, null, 2));
|
|
262
|
+
console.log(writePath);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
async function templateWorker(lang) {
|
|
266
|
+
|
|
267
|
+
const directivesDoc = await fetchText(lang.repoUrl + 'HEAD/src/api/built-in-directives.md', lang.url);
|
|
268
|
+
const attributesDoc = await fetchText(lang.repoUrl + 'HEAD/src/api/built-in-special-attributes.md', lang.url);
|
|
269
|
+
const componentsDoc = await fetchText(lang.repoUrl + 'HEAD/src/api/built-in-components.md', lang.url);
|
|
270
|
+
const elementsDoc = await fetchText(lang.repoUrl + 'HEAD/src/api/built-in-special-elements.md', lang.url);
|
|
271
|
+
|
|
272
|
+
const directives = directivesDoc
|
|
273
|
+
.split('\n## ')
|
|
274
|
+
.slice(1)
|
|
275
|
+
.map((section) => {
|
|
276
|
+
const lines = section.split('\n');
|
|
277
|
+
const name = normalizeAttrName(lines[0]);
|
|
278
|
+
/**
|
|
279
|
+
* @type {import('vscode-html-languageservice').IAttributeData}
|
|
280
|
+
*/
|
|
281
|
+
const data = {
|
|
282
|
+
name,
|
|
283
|
+
valueSet: name === 'v-else' ? 'v' : undefined,
|
|
284
|
+
description: {
|
|
285
|
+
kind: 'markdown',
|
|
286
|
+
value: lines.slice(1).join('\n'),
|
|
287
|
+
},
|
|
288
|
+
references: langs.map(lang => ({
|
|
289
|
+
name: lang.name,
|
|
290
|
+
url: `${lang.url}api/built-in-directives.html#${normalizeHash(name)}`,
|
|
291
|
+
})),
|
|
292
|
+
};
|
|
293
|
+
return data;
|
|
294
|
+
});
|
|
295
|
+
const attributes = attributesDoc
|
|
296
|
+
.split('\n## ')
|
|
297
|
+
.slice(1)
|
|
298
|
+
.map((section) => {
|
|
299
|
+
const lines = section.split('\n');
|
|
300
|
+
const name = normalizeAttrName(lines[0]);
|
|
301
|
+
/**
|
|
302
|
+
* @type {import('vscode-html-languageservice').IAttributeData}
|
|
303
|
+
*/
|
|
304
|
+
const data = {
|
|
305
|
+
name,
|
|
306
|
+
description: {
|
|
307
|
+
kind: 'markdown',
|
|
308
|
+
value: lines.slice(1).join('\n'),
|
|
309
|
+
},
|
|
310
|
+
references: langs.map(lang => ({
|
|
311
|
+
name: lang.name,
|
|
312
|
+
url: `${lang.url}api/built-in-special-attributes.html#${normalizeHash(name)}`,
|
|
313
|
+
})),
|
|
314
|
+
};
|
|
315
|
+
return data;
|
|
316
|
+
});
|
|
317
|
+
const components = componentsDoc
|
|
318
|
+
.split('\n## ')
|
|
319
|
+
.slice(1)
|
|
320
|
+
.map((section) => {
|
|
321
|
+
const lines = section.split('\n');
|
|
322
|
+
const name = normalizeTagName(lines[0]);
|
|
323
|
+
/**
|
|
324
|
+
* @type {import('vscode-html-languageservice').ITagData}
|
|
325
|
+
*/
|
|
326
|
+
const data = {
|
|
327
|
+
name,
|
|
328
|
+
description: {
|
|
329
|
+
kind: 'markdown',
|
|
330
|
+
value: lines.slice(1).join('\n'),
|
|
331
|
+
},
|
|
332
|
+
attributes: [],
|
|
333
|
+
references: langs.map(lang => ({
|
|
334
|
+
name: lang.name,
|
|
335
|
+
url: `${lang.url}api/built-in-components.html#${normalizeHash(name)}`,
|
|
336
|
+
})),
|
|
337
|
+
};
|
|
338
|
+
return data;
|
|
339
|
+
});
|
|
340
|
+
const elements = elementsDoc
|
|
341
|
+
.split('\n## ')
|
|
342
|
+
.slice(1)
|
|
343
|
+
.map((section) => {
|
|
344
|
+
const lines = section.split('\n');
|
|
345
|
+
const name = normalizeTagName(lines[0]);
|
|
346
|
+
/**
|
|
347
|
+
* @type {import('vscode-html-languageservice').ITagData}
|
|
348
|
+
*/
|
|
349
|
+
const data = {
|
|
350
|
+
name,
|
|
351
|
+
description: {
|
|
352
|
+
kind: 'markdown',
|
|
353
|
+
value: lines.slice(1).join('\n'),
|
|
354
|
+
},
|
|
355
|
+
attributes: [],
|
|
356
|
+
references: langs.map(lang => ({
|
|
357
|
+
name: lang.name,
|
|
358
|
+
url: `${lang.url}api/built-in-special-elements.html#${normalizeHash(name)}`,
|
|
359
|
+
})),
|
|
360
|
+
};
|
|
361
|
+
return data;
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* @type {import('vscode-html-languageservice').HTMLDataV1}
|
|
366
|
+
*/
|
|
367
|
+
const data = {
|
|
368
|
+
version: 1.1,
|
|
369
|
+
tags: [
|
|
370
|
+
...components,
|
|
371
|
+
...elements,
|
|
372
|
+
],
|
|
373
|
+
globalAttributes: [
|
|
374
|
+
...directives,
|
|
375
|
+
...attributes
|
|
376
|
+
],
|
|
377
|
+
};
|
|
378
|
+
|
|
379
|
+
const writePath = path.resolve(__dirname, '../data/template/' + lang.name + '.json');
|
|
380
|
+
fs.writeFileSync(writePath, JSON.stringify(data, null, 2));
|
|
381
|
+
console.log(writePath);
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
async function fetchText(url, baseUrl) {
|
|
385
|
+
let text = await (await fetch(url)).text();
|
|
386
|
+
text = text.replace(/```vue-html/g, '```html');
|
|
387
|
+
text = text.replace(/\{\#.*?\}/g, '')
|
|
388
|
+
text = resolveMarkdownLinks(text, baseUrl);
|
|
389
|
+
return text;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
function resolveMarkdownLinks(text, url) {
|
|
393
|
+
return text.replace(/\[(.*?)\]\(\/(.*?)\)/g, (match, p1, p2) => {
|
|
394
|
+
const p2Parts = p2.split('#');
|
|
395
|
+
if (!p2Parts[0].endsWith('.html')) {
|
|
396
|
+
p2Parts[0] += '.html';
|
|
397
|
+
}
|
|
398
|
+
p2 = p2Parts.join('#');
|
|
399
|
+
return `[${p1}](${url}${p2})`;
|
|
400
|
+
});
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
function normalizeTagName(name) {
|
|
404
|
+
name = name.trim();
|
|
405
|
+
return _normalizeName(name);
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
function normalizeAttrName(name) {
|
|
409
|
+
name = name.trim();
|
|
410
|
+
name = name.split(' ')[0];
|
|
411
|
+
return _normalizeName(name);
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
function _normalizeName(name) {
|
|
415
|
+
if (name.startsWith('`')) {
|
|
416
|
+
name = name.split('`')[1].split('`')[0];
|
|
417
|
+
}
|
|
418
|
+
if (name.startsWith('<')) {
|
|
419
|
+
name = name.split('<')[1].split('>')[0];
|
|
420
|
+
}
|
|
421
|
+
return name;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
function normalizeHash(str) {
|
|
425
|
+
return str.replace(/ /g, '-').toLowerCase();
|
|
426
|
+
}
|