@vue/language-service 3.0.0-alpha.2 → 3.0.0-alpha.4
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/lib/plugins/vue-sfc.js +3 -1
- package/lib/plugins/vue-template.js +20 -11
- package/package.json +12 -12
- package/lib/ideFeatures/nameCasing.d.ts +0 -14
- package/lib/ideFeatures/nameCasing.js +0 -202
package/lib/plugins/vue-sfc.js
CHANGED
|
@@ -193,7 +193,9 @@ function create() {
|
|
|
193
193
|
if (!result) {
|
|
194
194
|
return;
|
|
195
195
|
}
|
|
196
|
-
result.items = result.items.filter(item => item.label !== '!DOCTYPE' &&
|
|
196
|
+
result.items = result.items.filter(item => item.label !== '!DOCTYPE' &&
|
|
197
|
+
item.label !== 'Custom Blocks' &&
|
|
198
|
+
item.label !== 'data-');
|
|
197
199
|
const tags = sfcDataProvider?.provideTags();
|
|
198
200
|
const scriptLangs = getLangs('script');
|
|
199
201
|
const scriptItems = result.items.filter(item => item.label === 'script' || item.label === 'script setup');
|
|
@@ -247,14 +247,19 @@ function create(mode, getTsPluginClient) {
|
|
|
247
247
|
return [];
|
|
248
248
|
}
|
|
249
249
|
const { attrs, propInfos, events, directives } = tagInfo;
|
|
250
|
-
const
|
|
251
|
-
|
|
252
|
-
|
|
250
|
+
for (const prop of propInfos) {
|
|
251
|
+
if ((0, language_core_1.hyphenateTag)(prop.name).startsWith('on-vnode-')) {
|
|
252
|
+
prop.name = 'onVue:' + prop.name.slice('onVnode'.length);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
253
255
|
const attributes = [];
|
|
254
|
-
const propsSet = new Set(
|
|
255
|
-
for (const prop of [
|
|
256
|
-
|
|
257
|
-
|
|
256
|
+
const propsSet = new Set(propInfos.map(prop => prop.name));
|
|
257
|
+
for (const prop of [
|
|
258
|
+
...propInfos,
|
|
259
|
+
...attrs.map(attr => ({ name: attr })),
|
|
260
|
+
]) {
|
|
261
|
+
const isGlobal = !propsSet.has(prop.name);
|
|
262
|
+
const name = casing.attr === types_1.AttrNameCasing.Camel ? prop.name : (0, language_core_1.hyphenateAttr)(prop.name);
|
|
258
263
|
const isEvent = (0, language_core_1.hyphenateAttr)(name).startsWith('on-');
|
|
259
264
|
if (isEvent) {
|
|
260
265
|
const propNameBase = name.startsWith('on-')
|
|
@@ -282,6 +287,7 @@ function create(mode, getTsPluginClient) {
|
|
|
282
287
|
attributes.push({
|
|
283
288
|
name: propName,
|
|
284
289
|
description: propKey,
|
|
290
|
+
valueSet: prop.values?.some(value => typeof value === 'string') ? '__deferred__' : undefined,
|
|
285
291
|
}, {
|
|
286
292
|
name: ':' + propName,
|
|
287
293
|
description: propKey,
|
|
@@ -309,10 +315,13 @@ function create(mode, getTsPluginClient) {
|
|
|
309
315
|
});
|
|
310
316
|
}
|
|
311
317
|
const models = [];
|
|
312
|
-
for (const prop of [
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
318
|
+
for (const prop of [
|
|
319
|
+
...propInfos,
|
|
320
|
+
...attrs.map(attr => ({ name: attr })),
|
|
321
|
+
]) {
|
|
322
|
+
if (prop.name.startsWith('onUpdate:')) {
|
|
323
|
+
const isGlobal = !propsSet.has(prop.name);
|
|
324
|
+
models.push([isGlobal, prop.name.slice('onUpdate:'.length)]);
|
|
316
325
|
}
|
|
317
326
|
}
|
|
318
327
|
for (const event of events) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vue/language-service",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.4",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"data",
|
|
@@ -21,19 +21,19 @@
|
|
|
21
21
|
"@volar/language-service": "~2.4.11",
|
|
22
22
|
"@volar/typescript": "~2.4.11",
|
|
23
23
|
"@vue/compiler-dom": "^3.5.0",
|
|
24
|
-
"@vue/language-core": "3.0.0-alpha.
|
|
24
|
+
"@vue/language-core": "3.0.0-alpha.4",
|
|
25
25
|
"@vue/shared": "^3.5.0",
|
|
26
|
-
"@vue/typescript-plugin": "3.0.0-alpha.
|
|
26
|
+
"@vue/typescript-plugin": "3.0.0-alpha.4",
|
|
27
27
|
"alien-signals": "^1.0.3",
|
|
28
28
|
"path-browserify": "^1.0.1",
|
|
29
|
-
"volar-service-css": "0.0.
|
|
30
|
-
"volar-service-emmet": "0.0.
|
|
31
|
-
"volar-service-html": "0.0.
|
|
32
|
-
"volar-service-json": "0.0.
|
|
33
|
-
"volar-service-pug": "0.0.
|
|
34
|
-
"volar-service-pug-beautify": "0.0.
|
|
35
|
-
"volar-service-typescript": "0.0.
|
|
36
|
-
"volar-service-typescript-twoslash-queries": "0.0.
|
|
29
|
+
"volar-service-css": "0.0.64",
|
|
30
|
+
"volar-service-emmet": "0.0.64",
|
|
31
|
+
"volar-service-html": "0.0.64",
|
|
32
|
+
"volar-service-json": "0.0.64",
|
|
33
|
+
"volar-service-pug": "0.0.64",
|
|
34
|
+
"volar-service-pug-beautify": "0.0.64",
|
|
35
|
+
"volar-service-typescript": "0.0.64",
|
|
36
|
+
"volar-service-typescript-twoslash-queries": "0.0.64",
|
|
37
37
|
"vscode-css-languageservice": "^6.3.1",
|
|
38
38
|
"vscode-html-languageservice": "^5.2.0",
|
|
39
39
|
"vscode-languageserver-textdocument": "^1.0.11",
|
|
@@ -45,5 +45,5 @@
|
|
|
45
45
|
"@volar/kit": "~2.4.11",
|
|
46
46
|
"vscode-languageserver-protocol": "^3.17.5"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "1769cd6b94ec9e0cc2681b8dbba904f35856ba1c"
|
|
49
49
|
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { LanguageServiceContext } from '@volar/language-service';
|
|
2
|
-
import type * as vscode from 'vscode-languageserver-protocol';
|
|
3
|
-
import type { URI } from 'vscode-uri';
|
|
4
|
-
import { AttrNameCasing, TagNameCasing } from '../types';
|
|
5
|
-
export declare function convertTagName(context: LanguageServiceContext, uri: URI, casing: TagNameCasing, tsPluginClient: typeof import('@vue/typescript-plugin/lib/client') | undefined): Promise<vscode.TextEdit[] | undefined>;
|
|
6
|
-
export declare function convertAttrName(context: LanguageServiceContext, uri: URI, casing: AttrNameCasing, tsPluginClient?: typeof import('@vue/typescript-plugin/lib/client')): Promise<vscode.TextEdit[] | undefined>;
|
|
7
|
-
export declare function getNameCasing(context: LanguageServiceContext, uri: URI): Promise<{
|
|
8
|
-
tag: TagNameCasing;
|
|
9
|
-
attr: AttrNameCasing;
|
|
10
|
-
}>;
|
|
11
|
-
export declare function detect(context: LanguageServiceContext, uri: URI): Promise<{
|
|
12
|
-
tag: TagNameCasing[];
|
|
13
|
-
attr: AttrNameCasing[];
|
|
14
|
-
}>;
|
|
@@ -1,202 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.convertTagName = convertTagName;
|
|
4
|
-
exports.convertAttrName = convertAttrName;
|
|
5
|
-
exports.getNameCasing = getNameCasing;
|
|
6
|
-
exports.detect = detect;
|
|
7
|
-
const vue = require("@vue/language-core");
|
|
8
|
-
const language_core_1 = require("@vue/language-core");
|
|
9
|
-
const alien_signals_1 = require("alien-signals");
|
|
10
|
-
const types_1 = require("../types");
|
|
11
|
-
async function convertTagName(context, uri, casing, tsPluginClient) {
|
|
12
|
-
const sourceFile = context.language.scripts.get(uri);
|
|
13
|
-
if (!sourceFile) {
|
|
14
|
-
return;
|
|
15
|
-
}
|
|
16
|
-
const root = sourceFile?.generated?.root;
|
|
17
|
-
if (!(root instanceof language_core_1.VueVirtualCode)) {
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
const { template } = root._sfc;
|
|
21
|
-
if (!template) {
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
const document = context.documents.get(sourceFile.id, sourceFile.languageId, sourceFile.snapshot);
|
|
25
|
-
const edits = [];
|
|
26
|
-
const components = await tsPluginClient?.getComponentNames(root.fileName) ?? [];
|
|
27
|
-
const tags = getTemplateTagsAndAttrs(root);
|
|
28
|
-
for (const [tagName, { offsets }] of tags) {
|
|
29
|
-
const componentName = components.find(component => component === tagName || (0, language_core_1.hyphenateTag)(component) === tagName);
|
|
30
|
-
if (componentName) {
|
|
31
|
-
for (const offset of offsets) {
|
|
32
|
-
const start = document.positionAt(template.startTagEnd + offset);
|
|
33
|
-
const end = document.positionAt(template.startTagEnd + offset + tagName.length);
|
|
34
|
-
const range = { start, end };
|
|
35
|
-
if (casing === types_1.TagNameCasing.Kebab && tagName !== (0, language_core_1.hyphenateTag)(componentName)) {
|
|
36
|
-
edits.push({ range, newText: (0, language_core_1.hyphenateTag)(componentName) });
|
|
37
|
-
}
|
|
38
|
-
if (casing === types_1.TagNameCasing.Pascal && tagName !== componentName) {
|
|
39
|
-
edits.push({ range, newText: componentName });
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
return edits;
|
|
45
|
-
}
|
|
46
|
-
async function convertAttrName(context, uri, casing, tsPluginClient) {
|
|
47
|
-
const sourceFile = context.language.scripts.get(uri);
|
|
48
|
-
if (!sourceFile) {
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
const root = sourceFile?.generated?.root;
|
|
52
|
-
if (!(root instanceof language_core_1.VueVirtualCode)) {
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
const { template } = root._sfc;
|
|
56
|
-
if (!template) {
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
const document = context.documents.get(uri, sourceFile.languageId, sourceFile.snapshot);
|
|
60
|
-
const edits = [];
|
|
61
|
-
const components = await tsPluginClient?.getComponentNames(root.fileName) ?? [];
|
|
62
|
-
const tags = getTemplateTagsAndAttrs(root);
|
|
63
|
-
for (const [tagName, { attrs }] of tags) {
|
|
64
|
-
const componentName = components.find(component => component === tagName || (0, language_core_1.hyphenateTag)(component) === tagName);
|
|
65
|
-
if (componentName) {
|
|
66
|
-
const props = (await tsPluginClient?.getComponentProps(root.fileName, componentName) ?? []).map(prop => prop.name);
|
|
67
|
-
for (const [attrName, { offsets }] of attrs) {
|
|
68
|
-
const propName = props.find(prop => prop === attrName || (0, language_core_1.hyphenateAttr)(prop) === attrName);
|
|
69
|
-
if (propName) {
|
|
70
|
-
for (const offset of offsets) {
|
|
71
|
-
const start = document.positionAt(template.startTagEnd + offset);
|
|
72
|
-
const end = document.positionAt(template.startTagEnd + offset + attrName.length);
|
|
73
|
-
const range = { start, end };
|
|
74
|
-
if (casing === types_1.AttrNameCasing.Kebab && attrName !== (0, language_core_1.hyphenateAttr)(propName)) {
|
|
75
|
-
edits.push({ range, newText: (0, language_core_1.hyphenateAttr)(propName) });
|
|
76
|
-
}
|
|
77
|
-
if (casing === types_1.AttrNameCasing.Camel && attrName !== propName) {
|
|
78
|
-
edits.push({ range, newText: propName });
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
return edits;
|
|
86
|
-
}
|
|
87
|
-
async function getNameCasing(context, uri) {
|
|
88
|
-
const detected = await detect(context, uri);
|
|
89
|
-
const [attr, tag] = await Promise.all([
|
|
90
|
-
context.env.getConfiguration?.('vue.complete.casing.props', uri.toString()),
|
|
91
|
-
context.env.getConfiguration?.('vue.complete.casing.tags', uri.toString()),
|
|
92
|
-
]);
|
|
93
|
-
const tagNameCasing = detected.tag.length === 1 && (tag === 'autoPascal' || tag === 'autoKebab') ? detected.tag[0] : (tag === 'autoKebab' || tag === 'kebab') ? types_1.TagNameCasing.Kebab : types_1.TagNameCasing.Pascal;
|
|
94
|
-
const attrNameCasing = detected.attr.length === 1 && (attr === 'autoCamel' || attr === 'autoKebab') ? detected.attr[0] : (attr === 'autoCamel' || attr === 'camel') ? types_1.AttrNameCasing.Camel : types_1.AttrNameCasing.Kebab;
|
|
95
|
-
return {
|
|
96
|
-
tag: tagNameCasing,
|
|
97
|
-
attr: attrNameCasing,
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
async function detect(context, uri) {
|
|
101
|
-
const rootFile = context.language.scripts.get(uri)?.generated?.root;
|
|
102
|
-
if (!(rootFile instanceof language_core_1.VueVirtualCode)) {
|
|
103
|
-
return {
|
|
104
|
-
tag: [],
|
|
105
|
-
attr: [],
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
return {
|
|
109
|
-
tag: await getTagNameCase(rootFile),
|
|
110
|
-
attr: getAttrNameCase(rootFile),
|
|
111
|
-
};
|
|
112
|
-
function getAttrNameCase(file) {
|
|
113
|
-
const tags = getTemplateTagsAndAttrs(file);
|
|
114
|
-
const result = [];
|
|
115
|
-
for (const [_, { attrs }] of tags) {
|
|
116
|
-
for (const [tagName] of attrs) {
|
|
117
|
-
// attrName
|
|
118
|
-
if (tagName !== (0, language_core_1.hyphenateTag)(tagName)) {
|
|
119
|
-
result.push(types_1.AttrNameCasing.Camel);
|
|
120
|
-
break;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
for (const [tagName] of attrs) {
|
|
124
|
-
// attr-name
|
|
125
|
-
if (tagName.includes('-')) {
|
|
126
|
-
result.push(types_1.AttrNameCasing.Kebab);
|
|
127
|
-
break;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
return result;
|
|
132
|
-
}
|
|
133
|
-
function getTagNameCase(file) {
|
|
134
|
-
const result = new Set();
|
|
135
|
-
if (file._sfc.template?.ast) {
|
|
136
|
-
for (const element of vue.forEachElementNode(file._sfc.template.ast)) {
|
|
137
|
-
if (element.tagType === 1) {
|
|
138
|
-
if (element.tag !== (0, language_core_1.hyphenateTag)(element.tag)) {
|
|
139
|
-
// TagName
|
|
140
|
-
result.add(types_1.TagNameCasing.Pascal);
|
|
141
|
-
}
|
|
142
|
-
else {
|
|
143
|
-
// Tagname -> tagname
|
|
144
|
-
// TagName -> tag-name
|
|
145
|
-
result.add(types_1.TagNameCasing.Kebab);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
return [...result];
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
const map = new WeakMap();
|
|
154
|
-
function getTemplateTagsAndAttrs(sourceFile) {
|
|
155
|
-
if (!map.has(sourceFile)) {
|
|
156
|
-
const getter = (0, alien_signals_1.computed)(() => {
|
|
157
|
-
if (!(sourceFile instanceof vue.VueVirtualCode)) {
|
|
158
|
-
return;
|
|
159
|
-
}
|
|
160
|
-
const ast = sourceFile._sfc.template?.ast;
|
|
161
|
-
const tags = new Map();
|
|
162
|
-
if (ast) {
|
|
163
|
-
for (const node of vue.forEachElementNode(ast)) {
|
|
164
|
-
if (!tags.has(node.tag)) {
|
|
165
|
-
tags.set(node.tag, { offsets: [], attrs: new Map() });
|
|
166
|
-
}
|
|
167
|
-
const tag = tags.get(node.tag);
|
|
168
|
-
const startTagHtmlOffset = node.loc.start.offset + node.loc.source.indexOf(node.tag);
|
|
169
|
-
const endTagHtmlOffset = node.loc.start.offset + node.loc.source.lastIndexOf(node.tag);
|
|
170
|
-
tag.offsets.push(startTagHtmlOffset);
|
|
171
|
-
if (!node.isSelfClosing) {
|
|
172
|
-
tag.offsets.push(endTagHtmlOffset);
|
|
173
|
-
}
|
|
174
|
-
for (const prop of node.props) {
|
|
175
|
-
let name;
|
|
176
|
-
let offset;
|
|
177
|
-
if (prop.type === 7
|
|
178
|
-
&& prop.arg?.type === 4
|
|
179
|
-
&& prop.arg.isStatic) {
|
|
180
|
-
name = prop.arg.content;
|
|
181
|
-
offset = prop.arg.loc.start.offset;
|
|
182
|
-
}
|
|
183
|
-
else if (prop.type === 6) {
|
|
184
|
-
name = prop.name;
|
|
185
|
-
offset = prop.loc.start.offset;
|
|
186
|
-
}
|
|
187
|
-
if (name !== undefined && offset !== undefined) {
|
|
188
|
-
if (!tag.attrs.has(name)) {
|
|
189
|
-
tag.attrs.set(name, { offsets: [] });
|
|
190
|
-
}
|
|
191
|
-
tag.attrs.get(name).offsets.push(offset);
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
return tags;
|
|
197
|
-
});
|
|
198
|
-
map.set(sourceFile, getter);
|
|
199
|
-
}
|
|
200
|
-
return map.get(sourceFile).get() ?? new Map();
|
|
201
|
-
}
|
|
202
|
-
//# sourceMappingURL=nameCasing.js.map
|