@vue/language-service 3.0.0-alpha.6 → 3.0.0-beta.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 +4 -7
- package/index.js +4 -181
- package/lib/nameCasing.d.ts +9 -9
- package/lib/nameCasing.js +100 -174
- package/lib/plugins/css.js +54 -42
- package/lib/plugins/utils.d.ts +1 -1
- package/lib/plugins/vue-compiler-dom-errors.d.ts +1 -1
- package/lib/plugins/vue-document-drop.d.ts +1 -1
- package/lib/plugins/vue-document-drop.js +3 -3
- package/lib/plugins/vue-document-links.js +63 -31
- package/lib/plugins/vue-inlayhints.d.ts +1 -1
- package/lib/plugins/vue-inlayhints.js +2 -3
- package/lib/plugins/vue-missing-props-hints.d.ts +1 -2
- package/lib/plugins/vue-missing-props-hints.js +3 -5
- package/lib/plugins/vue-template.d.ts +1 -2
- package/lib/plugins/vue-template.js +66 -82
- package/package.json +9 -13
- package/lib/ideFeatures/nameCasing.d.ts +0 -14
- package/lib/ideFeatures/nameCasing.js +0 -202
- package/lib/types.d.ts +0 -18
- package/lib/types.js +0 -39
package/index.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
export * from '@volar/language-service';
|
|
2
|
-
export * from '@
|
|
3
|
-
export * from './lib/nameCasing';
|
|
4
|
-
export * from './lib/types';
|
|
2
|
+
export * from '@volar/language-service/lib/utils/featureWorkers';
|
|
5
3
|
import type { LanguageServicePlugin } from '@volar/language-service';
|
|
6
|
-
import {
|
|
4
|
+
import type { VueCompilerOptions } from '@vue/language-core';
|
|
5
|
+
import type * as ts from 'typescript';
|
|
7
6
|
declare module '@volar/language-service' {
|
|
8
7
|
interface ProjectContext {
|
|
9
8
|
vue?: {
|
|
@@ -11,8 +10,6 @@ declare module '@volar/language-service' {
|
|
|
11
10
|
};
|
|
12
11
|
}
|
|
13
12
|
}
|
|
14
|
-
export declare function
|
|
15
|
-
import type * as ts from 'typescript';
|
|
16
|
-
export declare function getHybridModeLanguageServicePlugins(ts: typeof import('typescript'), tsPluginClient: (import('@vue/typescript-plugin/lib/requests').Requests & {
|
|
13
|
+
export declare function createVueLanguageServicePlugins(ts: typeof import('typescript'), tsPluginClient: (import('@vue/typescript-plugin/lib/requests').Requests & {
|
|
17
14
|
getDocumentHighlights: (fileName: string, position: number) => Promise<ts.DocumentHighlights[] | null>;
|
|
18
15
|
}) | undefined): LanguageServicePlugin<any>[];
|
package/index.js
CHANGED
|
@@ -15,17 +15,13 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
16
16
|
};
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.
|
|
19
|
-
exports.getHybridModeLanguageServicePlugins = getHybridModeLanguageServicePlugins;
|
|
18
|
+
exports.createVueLanguageServicePlugins = createVueLanguageServicePlugins;
|
|
20
19
|
__exportStar(require("@volar/language-service"), exports);
|
|
21
|
-
|
|
22
|
-
__exportStar(require("
|
|
23
|
-
__exportStar(require("./lib/types"), exports);
|
|
24
|
-
const types_1 = require("./lib/types");
|
|
20
|
+
// for @vue/language-server usage
|
|
21
|
+
__exportStar(require("@volar/language-service/lib/utils/featureWorkers"), exports);
|
|
25
22
|
const volar_service_emmet_1 = require("volar-service-emmet");
|
|
26
23
|
const volar_service_json_1 = require("volar-service-json");
|
|
27
24
|
const volar_service_pug_beautify_1 = require("volar-service-pug-beautify");
|
|
28
|
-
const volar_service_typescript_1 = require("volar-service-typescript");
|
|
29
25
|
const volar_service_typescript_twoslash_queries_1 = require("volar-service-typescript-twoslash-queries");
|
|
30
26
|
const docCommentTemplate_1 = require("volar-service-typescript/lib/plugins/docCommentTemplate");
|
|
31
27
|
const syntactic_1 = require("volar-service-typescript/lib/plugins/syntactic");
|
|
@@ -44,130 +40,7 @@ const vue_missing_props_hints_1 = require("./lib/plugins/vue-missing-props-hints
|
|
|
44
40
|
const vue_sfc_1 = require("./lib/plugins/vue-sfc");
|
|
45
41
|
const vue_template_1 = require("./lib/plugins/vue-template");
|
|
46
42
|
const vue_twoslash_queries_1 = require("./lib/plugins/vue-twoslash-queries");
|
|
47
|
-
|
|
48
|
-
const common_1 = require("@vue/typescript-plugin/lib/common");
|
|
49
|
-
const collectExtractProps_1 = require("@vue/typescript-plugin/lib/requests/collectExtractProps");
|
|
50
|
-
const getComponentDirectives_1 = require("@vue/typescript-plugin/lib/requests/getComponentDirectives");
|
|
51
|
-
const getComponentEvents_1 = require("@vue/typescript-plugin/lib/requests/getComponentEvents");
|
|
52
|
-
const getComponentNames_1 = require("@vue/typescript-plugin/lib/requests/getComponentNames");
|
|
53
|
-
const getComponentProps_1 = require("@vue/typescript-plugin/lib/requests/getComponentProps");
|
|
54
|
-
const getElementAttrs_1 = require("@vue/typescript-plugin/lib/requests/getElementAttrs");
|
|
55
|
-
const getElementNames_1 = require("@vue/typescript-plugin/lib/requests/getElementNames");
|
|
56
|
-
const getImportPathForFile_1 = require("@vue/typescript-plugin/lib/requests/getImportPathForFile");
|
|
57
|
-
const getPropertiesAtLocation_1 = require("@vue/typescript-plugin/lib/requests/getPropertiesAtLocation");
|
|
58
|
-
const vscode_uri_1 = require("vscode-uri");
|
|
59
|
-
const nameCasing_1 = require("./lib/nameCasing");
|
|
60
|
-
function getFullLanguageServicePlugins(ts) {
|
|
61
|
-
const plugins = [
|
|
62
|
-
...(0, volar_service_typescript_1.create)(ts),
|
|
63
|
-
...getCommonLanguageServicePlugins(ts, getTsPluginClientForLSP),
|
|
64
|
-
];
|
|
65
|
-
for (let i = 0; i < plugins.length; i++) {
|
|
66
|
-
const plugin = plugins[i];
|
|
67
|
-
if (plugin.name === 'typescript-semantic') {
|
|
68
|
-
plugins[i] = {
|
|
69
|
-
...plugin,
|
|
70
|
-
create(context) {
|
|
71
|
-
const created = plugin.create(context);
|
|
72
|
-
if (!context.project.typescript) {
|
|
73
|
-
return created;
|
|
74
|
-
}
|
|
75
|
-
const languageService = created.provide['typescript/languageService']();
|
|
76
|
-
if (context.project.vue) {
|
|
77
|
-
const proxy = (0, common_1.proxyLanguageServiceForVue)(ts, context.language, languageService, context.project.vue.compilerOptions, s => context.project.typescript?.uriConverter.asUri(s));
|
|
78
|
-
languageService.getCompletionsAtPosition = proxy.getCompletionsAtPosition;
|
|
79
|
-
languageService.getCompletionEntryDetails = proxy.getCompletionEntryDetails;
|
|
80
|
-
languageService.getCodeFixesAtPosition = proxy.getCodeFixesAtPosition;
|
|
81
|
-
languageService.getDefinitionAndBoundSpan = proxy.getDefinitionAndBoundSpan;
|
|
82
|
-
languageService.getQuickInfoAtPosition = proxy.getQuickInfoAtPosition;
|
|
83
|
-
}
|
|
84
|
-
return created;
|
|
85
|
-
},
|
|
86
|
-
};
|
|
87
|
-
break;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
return plugins;
|
|
91
|
-
function getTsPluginClientForLSP(context) {
|
|
92
|
-
if (!context.project.typescript) {
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
const languageService = context.inject('typescript/languageService');
|
|
96
|
-
if (!languageService) {
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
const requestContext = {
|
|
100
|
-
typescript: ts,
|
|
101
|
-
language: context.language,
|
|
102
|
-
languageService,
|
|
103
|
-
languageServiceHost: context.project.typescript.languageServiceHost,
|
|
104
|
-
isTsPlugin: false,
|
|
105
|
-
getFileId: s => context.project.typescript.uriConverter.asUri(s),
|
|
106
|
-
};
|
|
107
|
-
return {
|
|
108
|
-
async collectExtractProps(...args) {
|
|
109
|
-
return collectExtractProps_1.collectExtractProps.apply(requestContext, args);
|
|
110
|
-
},
|
|
111
|
-
async getPropertiesAtLocation(...args) {
|
|
112
|
-
return getPropertiesAtLocation_1.getPropertiesAtLocation.apply(requestContext, args);
|
|
113
|
-
},
|
|
114
|
-
async getImportPathForFile(...args) {
|
|
115
|
-
return getImportPathForFile_1.getImportPathForFile.apply(requestContext, args);
|
|
116
|
-
},
|
|
117
|
-
async getComponentEvents(...args) {
|
|
118
|
-
return getComponentEvents_1.getComponentEvents.apply(requestContext, args);
|
|
119
|
-
},
|
|
120
|
-
async getComponentDirectives(...args) {
|
|
121
|
-
return getComponentDirectives_1.getComponentDirectives.apply(requestContext, args);
|
|
122
|
-
},
|
|
123
|
-
async getComponentNames(...args) {
|
|
124
|
-
return getComponentNames_1.getComponentNames.apply(requestContext, args);
|
|
125
|
-
},
|
|
126
|
-
async getComponentProps(...args) {
|
|
127
|
-
return getComponentProps_1.getComponentProps.apply(requestContext, args);
|
|
128
|
-
},
|
|
129
|
-
async getElementAttrs(...args) {
|
|
130
|
-
return getElementAttrs_1.getElementAttrs.apply(requestContext, args);
|
|
131
|
-
},
|
|
132
|
-
async getElementNames(...args) {
|
|
133
|
-
return getElementNames_1.getElementNames.apply(requestContext, args);
|
|
134
|
-
},
|
|
135
|
-
async getQuickInfoAtPosition(fileName, position) {
|
|
136
|
-
const languageService = context.getLanguageService();
|
|
137
|
-
const uri = context.project.typescript.uriConverter.asUri(fileName);
|
|
138
|
-
const sourceScript = context.language.scripts.get(uri);
|
|
139
|
-
if (!sourceScript) {
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
const hover = await languageService.getHover(uri, position);
|
|
143
|
-
let text = '';
|
|
144
|
-
if (typeof hover?.contents === 'string') {
|
|
145
|
-
text = hover.contents;
|
|
146
|
-
}
|
|
147
|
-
else if (Array.isArray(hover?.contents)) {
|
|
148
|
-
text = hover.contents.map(c => typeof c === 'string' ? c : c.value).join('\n');
|
|
149
|
-
}
|
|
150
|
-
else if (hover) {
|
|
151
|
-
text = hover.contents.value;
|
|
152
|
-
}
|
|
153
|
-
text = text.replace(/```typescript/g, '');
|
|
154
|
-
text = text.replace(/```/g, '');
|
|
155
|
-
text = text.replace(/---/g, '');
|
|
156
|
-
text = text.trim();
|
|
157
|
-
while (true) {
|
|
158
|
-
const newText = text.replace(/\n\n/g, '\n');
|
|
159
|
-
if (newText === text) {
|
|
160
|
-
break;
|
|
161
|
-
}
|
|
162
|
-
text = newText;
|
|
163
|
-
}
|
|
164
|
-
text = text.replace(/\n/g, ' | ');
|
|
165
|
-
return text;
|
|
166
|
-
},
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
function getHybridModeLanguageServicePlugins(ts, tsPluginClient) {
|
|
43
|
+
function createVueLanguageServicePlugins(ts, tsPluginClient) {
|
|
171
44
|
const plugins = [
|
|
172
45
|
(0, syntactic_1.create)(ts),
|
|
173
46
|
(0, docCommentTemplate_1.create)(ts),
|
|
@@ -208,56 +81,6 @@ function getCommonLanguageServicePlugins(ts, getTsPluginClient) {
|
|
|
208
81
|
'postcss': 'scss',
|
|
209
82
|
},
|
|
210
83
|
}),
|
|
211
|
-
{
|
|
212
|
-
name: 'vue-parse-sfc',
|
|
213
|
-
capabilities: {
|
|
214
|
-
executeCommandProvider: {
|
|
215
|
-
commands: [types_1.commands.parseSfc],
|
|
216
|
-
},
|
|
217
|
-
},
|
|
218
|
-
create() {
|
|
219
|
-
return {
|
|
220
|
-
executeCommand(_command, [source]) {
|
|
221
|
-
return (0, language_core_1.parse)(source);
|
|
222
|
-
},
|
|
223
|
-
};
|
|
224
|
-
},
|
|
225
|
-
},
|
|
226
|
-
{
|
|
227
|
-
name: 'vue-name-casing',
|
|
228
|
-
capabilities: {
|
|
229
|
-
executeCommandProvider: {
|
|
230
|
-
commands: [
|
|
231
|
-
types_1.commands.detectNameCasing,
|
|
232
|
-
types_1.commands.convertTagsToKebabCase,
|
|
233
|
-
types_1.commands.convertTagsToPascalCase,
|
|
234
|
-
types_1.commands.convertPropsToKebabCase,
|
|
235
|
-
types_1.commands.convertPropsToCamelCase,
|
|
236
|
-
],
|
|
237
|
-
}
|
|
238
|
-
},
|
|
239
|
-
create(context) {
|
|
240
|
-
return {
|
|
241
|
-
executeCommand(command, [uri]) {
|
|
242
|
-
if (command === types_1.commands.detectNameCasing) {
|
|
243
|
-
return (0, nameCasing_1.detect)(context, vscode_uri_1.URI.parse(uri));
|
|
244
|
-
}
|
|
245
|
-
else if (command === types_1.commands.convertTagsToKebabCase) {
|
|
246
|
-
return (0, nameCasing_1.convertTagName)(context, vscode_uri_1.URI.parse(uri), types_1.TagNameCasing.Kebab, getTsPluginClient(context));
|
|
247
|
-
}
|
|
248
|
-
else if (command === types_1.commands.convertTagsToPascalCase) {
|
|
249
|
-
return (0, nameCasing_1.convertTagName)(context, vscode_uri_1.URI.parse(uri), types_1.TagNameCasing.Pascal, getTsPluginClient(context));
|
|
250
|
-
}
|
|
251
|
-
else if (command === types_1.commands.convertPropsToKebabCase) {
|
|
252
|
-
return (0, nameCasing_1.convertAttrName)(context, vscode_uri_1.URI.parse(uri), types_1.AttrNameCasing.Kebab, getTsPluginClient(context));
|
|
253
|
-
}
|
|
254
|
-
else if (command === types_1.commands.convertPropsToCamelCase) {
|
|
255
|
-
return (0, nameCasing_1.convertAttrName)(context, vscode_uri_1.URI.parse(uri), types_1.AttrNameCasing.Camel, getTsPluginClient(context));
|
|
256
|
-
}
|
|
257
|
-
},
|
|
258
|
-
};
|
|
259
|
-
},
|
|
260
|
-
}
|
|
261
84
|
];
|
|
262
85
|
}
|
|
263
86
|
//# sourceMappingURL=index.js.map
|
package/lib/nameCasing.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import type { LanguageServiceContext } from '@volar/language-service';
|
|
2
|
-
import type * as vscode from 'vscode-languageserver-protocol';
|
|
3
2
|
import type { URI } from 'vscode-uri';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
export declare enum TagNameCasing {
|
|
4
|
+
Kebab = 0,
|
|
5
|
+
Pascal = 1
|
|
6
|
+
}
|
|
7
|
+
export declare enum AttrNameCasing {
|
|
8
|
+
Kebab = 0,
|
|
9
|
+
Camel = 1
|
|
10
|
+
}
|
|
11
|
+
export declare function checkCasing(context: LanguageServiceContext, uri: URI): Promise<{
|
|
8
12
|
tag: TagNameCasing;
|
|
9
13
|
attr: AttrNameCasing;
|
|
10
14
|
}>;
|
|
11
|
-
export declare function detect(context: LanguageServiceContext, uri: URI): Promise<{
|
|
12
|
-
tag: TagNameCasing[];
|
|
13
|
-
attr: AttrNameCasing[];
|
|
14
|
-
}>;
|
package/lib/nameCasing.js
CHANGED
|
@@ -1,201 +1,127 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.
|
|
5
|
-
exports.getNameCasing = getNameCasing;
|
|
6
|
-
exports.detect = detect;
|
|
3
|
+
exports.AttrNameCasing = exports.TagNameCasing = void 0;
|
|
4
|
+
exports.checkCasing = checkCasing;
|
|
7
5
|
const language_core_1 = require("@vue/language-core");
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
if (!template) {
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
const document = context.documents.get(sourceFile.id, sourceFile.languageId, sourceFile.snapshot);
|
|
24
|
-
const edits = [];
|
|
25
|
-
const components = await tsPluginClient?.getComponentNames(root.fileName) ?? [];
|
|
26
|
-
const tags = getTemplateTagsAndAttrs(root);
|
|
27
|
-
for (const [tagName, { offsets }] of tags) {
|
|
28
|
-
const componentName = components.find(component => component === tagName || (0, language_core_1.hyphenateTag)(component) === tagName);
|
|
29
|
-
if (componentName) {
|
|
30
|
-
for (const offset of offsets) {
|
|
31
|
-
const start = document.positionAt(template.startTagEnd + offset);
|
|
32
|
-
const end = document.positionAt(template.startTagEnd + offset + tagName.length);
|
|
33
|
-
const range = { start, end };
|
|
34
|
-
if (casing === types_1.TagNameCasing.Kebab && tagName !== (0, language_core_1.hyphenateTag)(componentName)) {
|
|
35
|
-
edits.push({ range, newText: (0, language_core_1.hyphenateTag)(componentName) });
|
|
36
|
-
}
|
|
37
|
-
if (casing === types_1.TagNameCasing.Pascal && tagName !== componentName) {
|
|
38
|
-
edits.push({ range, newText: componentName });
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
return edits;
|
|
44
|
-
}
|
|
45
|
-
async function convertAttrName(context, uri, casing, tsPluginClient) {
|
|
46
|
-
const sourceFile = context.language.scripts.get(uri);
|
|
47
|
-
if (!sourceFile) {
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
const root = sourceFile?.generated?.root;
|
|
51
|
-
if (!(root instanceof language_core_1.VueVirtualCode)) {
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
const { template } = root.sfc;
|
|
55
|
-
if (!template) {
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
const document = context.documents.get(uri, sourceFile.languageId, sourceFile.snapshot);
|
|
59
|
-
const edits = [];
|
|
60
|
-
const components = await tsPluginClient?.getComponentNames(root.fileName) ?? [];
|
|
61
|
-
const tags = getTemplateTagsAndAttrs(root);
|
|
62
|
-
for (const [tagName, { attrs }] of tags) {
|
|
63
|
-
const componentName = components.find(component => component === tagName || (0, language_core_1.hyphenateTag)(component) === tagName);
|
|
64
|
-
if (componentName) {
|
|
65
|
-
const props = (await tsPluginClient?.getComponentProps(root.fileName, componentName) ?? []).map(prop => prop.name);
|
|
66
|
-
for (const [attrName, { offsets }] of attrs) {
|
|
67
|
-
const propName = props.find(prop => prop === attrName || (0, language_core_1.hyphenateAttr)(prop) === attrName);
|
|
68
|
-
if (propName) {
|
|
69
|
-
for (const offset of offsets) {
|
|
70
|
-
const start = document.positionAt(template.startTagEnd + offset);
|
|
71
|
-
const end = document.positionAt(template.startTagEnd + offset + attrName.length);
|
|
72
|
-
const range = { start, end };
|
|
73
|
-
if (casing === types_1.AttrNameCasing.Kebab && attrName !== (0, language_core_1.hyphenateAttr)(propName)) {
|
|
74
|
-
edits.push({ range, newText: (0, language_core_1.hyphenateAttr)(propName) });
|
|
75
|
-
}
|
|
76
|
-
if (casing === types_1.AttrNameCasing.Camel && attrName !== propName) {
|
|
77
|
-
edits.push({ range, newText: propName });
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
return edits;
|
|
85
|
-
}
|
|
86
|
-
async function getNameCasing(context, uri) {
|
|
87
|
-
const detected = await detect(context, uri);
|
|
6
|
+
var TagNameCasing;
|
|
7
|
+
(function (TagNameCasing) {
|
|
8
|
+
TagNameCasing[TagNameCasing["Kebab"] = 0] = "Kebab";
|
|
9
|
+
TagNameCasing[TagNameCasing["Pascal"] = 1] = "Pascal";
|
|
10
|
+
})(TagNameCasing || (exports.TagNameCasing = TagNameCasing = {}));
|
|
11
|
+
var AttrNameCasing;
|
|
12
|
+
(function (AttrNameCasing) {
|
|
13
|
+
AttrNameCasing[AttrNameCasing["Kebab"] = 0] = "Kebab";
|
|
14
|
+
AttrNameCasing[AttrNameCasing["Camel"] = 1] = "Camel";
|
|
15
|
+
})(AttrNameCasing || (exports.AttrNameCasing = AttrNameCasing = {}));
|
|
16
|
+
async function checkCasing(context, uri) {
|
|
17
|
+
const detected = detect(context, uri);
|
|
88
18
|
const [attr, tag] = await Promise.all([
|
|
89
19
|
context.env.getConfiguration?.('vue.complete.casing.props', uri.toString()),
|
|
90
20
|
context.env.getConfiguration?.('vue.complete.casing.tags', uri.toString()),
|
|
91
21
|
]);
|
|
92
|
-
const tagNameCasing = detected.tag.length === 1 && (tag === 'autoPascal' || tag === 'autoKebab')
|
|
93
|
-
|
|
22
|
+
const tagNameCasing = detected.tag.length === 1 && (tag === 'autoPascal' || tag === 'autoKebab')
|
|
23
|
+
? detected.tag[0]
|
|
24
|
+
: (tag === 'autoKebab' || tag === 'kebab')
|
|
25
|
+
? TagNameCasing.Kebab
|
|
26
|
+
: TagNameCasing.Pascal;
|
|
27
|
+
const attrNameCasing = detected.attr.length === 1 && (attr === 'autoCamel' || attr === 'autoKebab')
|
|
28
|
+
? detected.attr[0]
|
|
29
|
+
: (attr === 'autoCamel' || attr === 'camel')
|
|
30
|
+
? AttrNameCasing.Camel
|
|
31
|
+
: AttrNameCasing.Kebab;
|
|
94
32
|
return {
|
|
95
33
|
tag: tagNameCasing,
|
|
96
34
|
attr: attrNameCasing,
|
|
97
35
|
};
|
|
98
36
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
attr: [],
|
|
105
|
-
};
|
|
37
|
+
const cache = new WeakMap();
|
|
38
|
+
function detect(context, uri) {
|
|
39
|
+
const root = context.language.scripts.get(uri)?.generated?.root;
|
|
40
|
+
if (!(root instanceof language_core_1.VueVirtualCode)) {
|
|
41
|
+
return { tag: [], attr: [] };
|
|
106
42
|
}
|
|
107
43
|
return {
|
|
108
|
-
tag:
|
|
109
|
-
attr:
|
|
44
|
+
tag: detectTagCasing(root),
|
|
45
|
+
attr: detectAttrCasing(root),
|
|
110
46
|
};
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
47
|
+
}
|
|
48
|
+
function detectAttrCasing(code) {
|
|
49
|
+
let tags;
|
|
50
|
+
if (cache.has(code)) {
|
|
51
|
+
tags = cache.get(code);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
cache.set(code, tags = collectTags(code));
|
|
55
|
+
}
|
|
56
|
+
const result = new Set();
|
|
57
|
+
for (const [, attrs] of tags ?? []) {
|
|
58
|
+
for (const attr of attrs) {
|
|
59
|
+
// attrName
|
|
60
|
+
if (attr !== (0, language_core_1.hyphenateTag)(attr)) {
|
|
61
|
+
result.add(AttrNameCasing.Camel);
|
|
62
|
+
break;
|
|
121
63
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
64
|
+
}
|
|
65
|
+
for (const attr of attrs) {
|
|
66
|
+
// attr-name
|
|
67
|
+
if (attr.includes('-')) {
|
|
68
|
+
result.add(AttrNameCasing.Kebab);
|
|
69
|
+
break;
|
|
128
70
|
}
|
|
129
71
|
}
|
|
130
|
-
return result;
|
|
131
72
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
73
|
+
return [...result];
|
|
74
|
+
}
|
|
75
|
+
function detectTagCasing(code) {
|
|
76
|
+
let tags;
|
|
77
|
+
if (cache.has(code)) {
|
|
78
|
+
tags = cache.get(code);
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
cache.set(code, tags = collectTags(code));
|
|
82
|
+
}
|
|
83
|
+
const result = new Set();
|
|
84
|
+
for (const [tag] of tags ?? []) {
|
|
85
|
+
if (tag !== (0, language_core_1.hyphenateTag)(tag)) {
|
|
86
|
+
// TagName
|
|
87
|
+
result.add(TagNameCasing.Pascal);
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
// tag-name
|
|
91
|
+
result.add(TagNameCasing.Kebab);
|
|
148
92
|
}
|
|
149
|
-
return [...result];
|
|
150
93
|
}
|
|
94
|
+
return [...result];
|
|
151
95
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
96
|
+
function collectTags(root) {
|
|
97
|
+
if (!(root instanceof language_core_1.VueVirtualCode)) {
|
|
98
|
+
return undefined;
|
|
99
|
+
}
|
|
100
|
+
const ast = root.sfc.template?.ast;
|
|
101
|
+
if (!ast) {
|
|
102
|
+
return undefined;
|
|
103
|
+
}
|
|
104
|
+
const tags = new Map();
|
|
105
|
+
for (const node of (0, language_core_1.forEachElementNode)(ast)) {
|
|
106
|
+
let tag = tags.get(node.tag);
|
|
107
|
+
if (!tag) {
|
|
108
|
+
tags.set(node.tag, tag = []);
|
|
109
|
+
}
|
|
110
|
+
for (const prop of node.props) {
|
|
111
|
+
let name;
|
|
112
|
+
if (prop.type === 7
|
|
113
|
+
&& prop.arg?.type === 4
|
|
114
|
+
&& prop.arg.isStatic) {
|
|
115
|
+
name = prop.arg.content;
|
|
158
116
|
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
if (ast) {
|
|
162
|
-
for (const node of (0, language_core_1.forEachElementNode)(ast)) {
|
|
163
|
-
if (!tags.has(node.tag)) {
|
|
164
|
-
tags.set(node.tag, { offsets: [], attrs: new Map() });
|
|
165
|
-
}
|
|
166
|
-
const tag = tags.get(node.tag);
|
|
167
|
-
const startTagHtmlOffset = node.loc.start.offset + node.loc.source.indexOf(node.tag);
|
|
168
|
-
const endTagHtmlOffset = node.loc.start.offset + node.loc.source.lastIndexOf(node.tag);
|
|
169
|
-
tag.offsets.push(startTagHtmlOffset);
|
|
170
|
-
if (!node.isSelfClosing) {
|
|
171
|
-
tag.offsets.push(endTagHtmlOffset);
|
|
172
|
-
}
|
|
173
|
-
for (const prop of node.props) {
|
|
174
|
-
let name;
|
|
175
|
-
let offset;
|
|
176
|
-
if (prop.type === 7
|
|
177
|
-
&& prop.arg?.type === 4
|
|
178
|
-
&& prop.arg.isStatic) {
|
|
179
|
-
name = prop.arg.content;
|
|
180
|
-
offset = prop.arg.loc.start.offset;
|
|
181
|
-
}
|
|
182
|
-
else if (prop.type === 6) {
|
|
183
|
-
name = prop.name;
|
|
184
|
-
offset = prop.loc.start.offset;
|
|
185
|
-
}
|
|
186
|
-
if (name !== undefined && offset !== undefined) {
|
|
187
|
-
if (!tag.attrs.has(name)) {
|
|
188
|
-
tag.attrs.set(name, { offsets: [] });
|
|
189
|
-
}
|
|
190
|
-
tag.attrs.get(name).offsets.push(offset);
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
}
|
|
117
|
+
else if (prop.type === 6) {
|
|
118
|
+
name = prop.name;
|
|
194
119
|
}
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
120
|
+
if (name !== undefined) {
|
|
121
|
+
tag.push(name);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
198
124
|
}
|
|
199
|
-
return
|
|
125
|
+
return tags;
|
|
200
126
|
}
|
|
201
127
|
//# sourceMappingURL=nameCasing.js.map
|