@vue/language-service 1.9.0-alpha.2 → 2.0.0
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/data/template/en.json +2 -2
- package/data/template/fr.json +1 -1
- package/data/template/ja.json +2 -2
- package/data/template/ko.json +13 -13
- package/data/template/pt.json +18 -18
- package/data/template/zh-cn.json +3 -3
- package/package.json +18 -18
- package/out/helpers.d.ts +0 -17
- package/out/helpers.js +0 -235
- package/out/ideFeatures/dragImport.d.ts +0 -9
- package/out/ideFeatures/dragImport.js +0 -50
- package/out/ideFeatures/nameCasing.d.ts +0 -16
- package/out/ideFeatures/nameCasing.js +0 -158
- package/out/index.d.ts +0 -8
- package/out/index.js +0 -26
- package/out/languageService.d.ts +0 -9
- package/out/languageService.js +0 -239
- package/out/plugins/data.d.ts +0 -5
- package/out/plugins/data.js +0 -91
- package/out/plugins/vue-autoinsert-dotvalue.d.ts +0 -7
- package/out/plugins/vue-autoinsert-dotvalue.js +0 -161
- package/out/plugins/vue-autoinsert-parentheses.d.ts +0 -3
- package/out/plugins/vue-autoinsert-parentheses.js +0 -61
- package/out/plugins/vue-autoinsert-space.d.ts +0 -3
- package/out/plugins/vue-autoinsert-space.js +0 -32
- package/out/plugins/vue-codelens-references.d.ts +0 -3
- package/out/plugins/vue-codelens-references.js +0 -54
- package/out/plugins/vue-directive-comments.d.ts +0 -3
- package/out/plugins/vue-directive-comments.js +0 -57
- package/out/plugins/vue-extract-file.d.ts +0 -9
- package/out/plugins/vue-extract-file.js +0 -293
- package/out/plugins/vue-template.d.ts +0 -12
- package/out/plugins/vue-template.js +0 -548
- package/out/plugins/vue-toggle-v-bind-codeaction.d.ts +0 -3
- package/out/plugins/vue-toggle-v-bind-codeaction.js +0 -126
- package/out/plugins/vue-twoslash-queries.d.ts +0 -3
- package/out/plugins/vue-twoslash-queries.js +0 -60
- package/out/plugins/vue-visualize-hidden-callback-param.d.ts +0 -3
- package/out/plugins/vue-visualize-hidden-callback-param.js +0 -43
- package/out/plugins/vue.d.ts +0 -8
- package/out/plugins/vue.js +0 -169
- package/out/types.d.ts +0 -11
- package/out/types.js +0 -31
package/out/helpers.js
DELETED
|
@@ -1,235 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getTemplateTagsAndAttrs = exports.getElementAttrs = exports.getComponentNames = exports.getTemplateCtx = exports.getEventsOfTag = exports.getPropsByTag = void 0;
|
|
4
|
-
const vue = require("@vue/language-core");
|
|
5
|
-
const embedded = require("@volar/language-core");
|
|
6
|
-
const computeds_1 = require("computeds");
|
|
7
|
-
const language_core_1 = require("@vue/language-core");
|
|
8
|
-
const shared_1 = require("@vue/shared");
|
|
9
|
-
function getPropsByTag(ts, tsLs, sourceFile, tag, vueCompilerOptions, requiredOnly = false) {
|
|
10
|
-
const checker = tsLs.getProgram().getTypeChecker();
|
|
11
|
-
const components = getVariableType(ts, tsLs, sourceFile, '__VLS_components');
|
|
12
|
-
if (!components)
|
|
13
|
-
return [];
|
|
14
|
-
const name = tag.split('.');
|
|
15
|
-
let componentSymbol = components.type.getProperty(name[0]);
|
|
16
|
-
if (!componentSymbol && !vueCompilerOptions.nativeTags.includes(name[0])) {
|
|
17
|
-
componentSymbol = components.type.getProperty((0, shared_1.camelize)(name[0]))
|
|
18
|
-
?? components.type.getProperty((0, shared_1.capitalize)((0, shared_1.camelize)(name[0])));
|
|
19
|
-
}
|
|
20
|
-
if (!componentSymbol)
|
|
21
|
-
return [];
|
|
22
|
-
let componentType = checker.getTypeOfSymbolAtLocation(componentSymbol, components.node);
|
|
23
|
-
for (let i = 1; i < name.length; i++) {
|
|
24
|
-
componentSymbol = componentType.getProperty(name[i]);
|
|
25
|
-
if (componentSymbol) {
|
|
26
|
-
componentType = checker.getTypeOfSymbolAtLocation(componentSymbol, components.node);
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
return [];
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
const result = new Set();
|
|
33
|
-
for (const sig of componentType.getCallSignatures()) {
|
|
34
|
-
const propParam = sig.parameters[0];
|
|
35
|
-
if (propParam) {
|
|
36
|
-
const propsType = checker.getTypeOfSymbolAtLocation(propParam, components.node);
|
|
37
|
-
const props = propsType.getProperties();
|
|
38
|
-
for (const prop of props) {
|
|
39
|
-
if (!requiredOnly || !(prop.flags & ts.SymbolFlags.Optional)) {
|
|
40
|
-
result.add(prop.name);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
for (const sig of componentType.getConstructSignatures()) {
|
|
46
|
-
const instanceType = sig.getReturnType();
|
|
47
|
-
const propsSymbol = instanceType.getProperty('$props');
|
|
48
|
-
if (propsSymbol) {
|
|
49
|
-
const propsType = checker.getTypeOfSymbolAtLocation(propsSymbol, components.node);
|
|
50
|
-
const props = propsType.getProperties();
|
|
51
|
-
for (const prop of props) {
|
|
52
|
-
if (prop.flags & ts.SymbolFlags.Method) { // #2443
|
|
53
|
-
continue;
|
|
54
|
-
}
|
|
55
|
-
if (!requiredOnly || !(prop.flags & ts.SymbolFlags.Optional)) {
|
|
56
|
-
result.add(prop.name);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return [...result];
|
|
62
|
-
}
|
|
63
|
-
exports.getPropsByTag = getPropsByTag;
|
|
64
|
-
function getEventsOfTag(ts, tsLs, sourceFile, tag, vueCompilerOptions) {
|
|
65
|
-
const checker = tsLs.getProgram().getTypeChecker();
|
|
66
|
-
const components = getVariableType(ts, tsLs, sourceFile, '__VLS_components');
|
|
67
|
-
if (!components)
|
|
68
|
-
return [];
|
|
69
|
-
const name = tag.split('.');
|
|
70
|
-
let componentSymbol = components.type.getProperty(name[0]);
|
|
71
|
-
if (!componentSymbol && !vueCompilerOptions.nativeTags.includes(name[0])) {
|
|
72
|
-
componentSymbol = components.type.getProperty((0, shared_1.camelize)(name[0]))
|
|
73
|
-
?? components.type.getProperty((0, shared_1.capitalize)((0, shared_1.camelize)(name[0])));
|
|
74
|
-
}
|
|
75
|
-
if (!componentSymbol)
|
|
76
|
-
return [];
|
|
77
|
-
let componentType = checker.getTypeOfSymbolAtLocation(componentSymbol, components.node);
|
|
78
|
-
for (let i = 1; i < name.length; i++) {
|
|
79
|
-
componentSymbol = componentType.getProperty(name[i]);
|
|
80
|
-
if (componentSymbol) {
|
|
81
|
-
componentType = checker.getTypeOfSymbolAtLocation(componentSymbol, components.node);
|
|
82
|
-
}
|
|
83
|
-
else {
|
|
84
|
-
return [];
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
const result = new Set();
|
|
88
|
-
// for (const sig of componentType.getCallSignatures()) {
|
|
89
|
-
// const emitParam = sig.parameters[1];
|
|
90
|
-
// if (emitParam) {
|
|
91
|
-
// // TODO
|
|
92
|
-
// }
|
|
93
|
-
// }
|
|
94
|
-
for (const sig of componentType.getConstructSignatures()) {
|
|
95
|
-
const instanceType = sig.getReturnType();
|
|
96
|
-
const emitSymbol = instanceType.getProperty('$emit');
|
|
97
|
-
if (emitSymbol) {
|
|
98
|
-
const emitType = checker.getTypeOfSymbolAtLocation(emitSymbol, components.node);
|
|
99
|
-
for (const call of emitType.getCallSignatures()) {
|
|
100
|
-
const eventNameParamSymbol = call.parameters[0];
|
|
101
|
-
if (eventNameParamSymbol) {
|
|
102
|
-
const eventNameParamType = checker.getTypeOfSymbolAtLocation(eventNameParamSymbol, components.node);
|
|
103
|
-
if (eventNameParamType.isStringLiteral()) {
|
|
104
|
-
result.add(eventNameParamType.value);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
return [...result];
|
|
111
|
-
}
|
|
112
|
-
exports.getEventsOfTag = getEventsOfTag;
|
|
113
|
-
function getTemplateCtx(ts, tsLs, sourceFile) {
|
|
114
|
-
return getVariableType(ts, tsLs, sourceFile, '__VLS_ctx')
|
|
115
|
-
?.type
|
|
116
|
-
?.getProperties()
|
|
117
|
-
.map(c => c.name);
|
|
118
|
-
}
|
|
119
|
-
exports.getTemplateCtx = getTemplateCtx;
|
|
120
|
-
function getComponentNames(ts, tsLs, sourceFile, vueCompilerOptions) {
|
|
121
|
-
return getVariableType(ts, tsLs, sourceFile, '__VLS_components')
|
|
122
|
-
?.type
|
|
123
|
-
?.getProperties()
|
|
124
|
-
.map(c => c.name)
|
|
125
|
-
.filter(entry => entry.indexOf('$') === -1 && !entry.startsWith('_'))
|
|
126
|
-
.filter(entry => !vueCompilerOptions.nativeTags.includes(entry))
|
|
127
|
-
?? [];
|
|
128
|
-
}
|
|
129
|
-
exports.getComponentNames = getComponentNames;
|
|
130
|
-
function getElementAttrs(ts, tsLs, tsLsHost, tagName) {
|
|
131
|
-
const sharedTypesFileName = tsLsHost.getCurrentDirectory() + '/' + language_core_1.sharedTypes.baseName;
|
|
132
|
-
let tsSourceFile;
|
|
133
|
-
if (tsSourceFile = tsLs.getProgram()?.getSourceFile(sharedTypesFileName)) {
|
|
134
|
-
const typeNode = tsSourceFile.statements.find((node) => ts.isTypeAliasDeclaration(node) && node.name.getText() === '__VLS_IntrinsicElements');
|
|
135
|
-
const checker = tsLs.getProgram()?.getTypeChecker();
|
|
136
|
-
if (checker && typeNode) {
|
|
137
|
-
const type = checker.getTypeFromTypeNode(typeNode.type);
|
|
138
|
-
const el = type.getProperty(tagName);
|
|
139
|
-
if (el) {
|
|
140
|
-
const attrs = checker.getTypeOfSymbolAtLocation(el, typeNode).getProperties();
|
|
141
|
-
return attrs.map(c => c.name);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
return [];
|
|
146
|
-
}
|
|
147
|
-
exports.getElementAttrs = getElementAttrs;
|
|
148
|
-
function getVariableType(ts, tsLs, sourceFile, name) {
|
|
149
|
-
if (!(sourceFile instanceof vue.VueFile)) {
|
|
150
|
-
return;
|
|
151
|
-
}
|
|
152
|
-
let file;
|
|
153
|
-
let tsSourceFile;
|
|
154
|
-
embedded.forEachEmbeddedFile(sourceFile, embedded => {
|
|
155
|
-
if (embedded.fileName === sourceFile.mainScriptName) {
|
|
156
|
-
file = embedded;
|
|
157
|
-
}
|
|
158
|
-
});
|
|
159
|
-
if (file && (tsSourceFile = tsLs.getProgram()?.getSourceFile(file.fileName))) {
|
|
160
|
-
const node = searchVariableDeclarationNode(ts, tsSourceFile, name);
|
|
161
|
-
const checker = tsLs.getProgram()?.getTypeChecker();
|
|
162
|
-
if (checker && node) {
|
|
163
|
-
return {
|
|
164
|
-
node: node,
|
|
165
|
-
type: checker.getTypeAtLocation(node),
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
function searchVariableDeclarationNode(ts, sourceFile, name) {
|
|
171
|
-
let componentsNode;
|
|
172
|
-
walk(sourceFile);
|
|
173
|
-
return componentsNode;
|
|
174
|
-
function walk(node) {
|
|
175
|
-
if (componentsNode) {
|
|
176
|
-
return;
|
|
177
|
-
}
|
|
178
|
-
else if (ts.isVariableDeclaration(node) && node.name.getText() === name) {
|
|
179
|
-
componentsNode = node;
|
|
180
|
-
}
|
|
181
|
-
else {
|
|
182
|
-
node.forEachChild(walk);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
const map = new WeakMap();
|
|
187
|
-
function getTemplateTagsAndAttrs(sourceFile) {
|
|
188
|
-
if (!map.has(sourceFile)) {
|
|
189
|
-
const getter = (0, computeds_1.computed)(() => {
|
|
190
|
-
if (!(sourceFile instanceof vue.VueFile))
|
|
191
|
-
return;
|
|
192
|
-
const ast = sourceFile.sfc.template?.ast;
|
|
193
|
-
const tags = new Map();
|
|
194
|
-
if (ast) {
|
|
195
|
-
vue.walkElementNodes(ast, node => {
|
|
196
|
-
if (!tags.has(node.tag)) {
|
|
197
|
-
tags.set(node.tag, { offsets: [], attrs: new Map() });
|
|
198
|
-
}
|
|
199
|
-
const tag = tags.get(node.tag);
|
|
200
|
-
const startTagHtmlOffset = node.loc.start.offset + node.loc.source.indexOf(node.tag);
|
|
201
|
-
const endTagHtmlOffset = node.loc.start.offset + node.loc.source.lastIndexOf(node.tag);
|
|
202
|
-
tag.offsets.push(startTagHtmlOffset);
|
|
203
|
-
if (!node.isSelfClosing) {
|
|
204
|
-
tag.offsets.push(endTagHtmlOffset);
|
|
205
|
-
}
|
|
206
|
-
for (const prop of node.props) {
|
|
207
|
-
let name;
|
|
208
|
-
let offset;
|
|
209
|
-
if (prop.type === 7
|
|
210
|
-
&& prop.arg?.type === 4
|
|
211
|
-
&& prop.arg.isStatic) {
|
|
212
|
-
name = prop.arg.content;
|
|
213
|
-
offset = prop.arg.loc.start.offset;
|
|
214
|
-
}
|
|
215
|
-
else if (prop.type === 6) {
|
|
216
|
-
name = prop.name;
|
|
217
|
-
offset = prop.loc.start.offset;
|
|
218
|
-
}
|
|
219
|
-
if (name !== undefined && offset !== undefined) {
|
|
220
|
-
if (!tag.attrs.has(name)) {
|
|
221
|
-
tag.attrs.set(name, { offsets: [] });
|
|
222
|
-
}
|
|
223
|
-
tag.attrs.get(name).offsets.push(offset);
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
});
|
|
227
|
-
}
|
|
228
|
-
return tags;
|
|
229
|
-
});
|
|
230
|
-
map.set(sourceFile, getter);
|
|
231
|
-
}
|
|
232
|
-
return map.get(sourceFile)() ?? new Map();
|
|
233
|
-
}
|
|
234
|
-
exports.getTemplateTagsAndAttrs = getTemplateTagsAndAttrs;
|
|
235
|
-
//# sourceMappingURL=helpers.js.map
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { ServiceContext } from '@volar/language-service';
|
|
2
|
-
import type * as vscode from 'vscode-languageserver-protocol';
|
|
3
|
-
import { TagNameCasing } from '../types';
|
|
4
|
-
export declare function getDragImportEdits(ts: typeof import('typescript/lib/tsserverlibrary'), ctx: ServiceContext, uri: string, importUri: string, casing: TagNameCasing): {
|
|
5
|
-
insertText: string;
|
|
6
|
-
insertTextFormat: vscode.InsertTextFormat;
|
|
7
|
-
additionalEdits: vscode.TextEdit[];
|
|
8
|
-
} | undefined;
|
|
9
|
-
//# sourceMappingURL=dragImport.d.ts.map
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getDragImportEdits = void 0;
|
|
4
|
-
const shared_1 = require("@vue/shared");
|
|
5
|
-
const path = require("path-browserify");
|
|
6
|
-
const vue_extract_file_1 = require("../plugins/vue-extract-file");
|
|
7
|
-
const types_1 = require("../types");
|
|
8
|
-
function getDragImportEdits(ts, ctx, uri, importUri, casing) {
|
|
9
|
-
let baseName = importUri.substring(importUri.lastIndexOf('/') + 1);
|
|
10
|
-
baseName = baseName.substring(0, baseName.lastIndexOf('.'));
|
|
11
|
-
const newName = (0, shared_1.capitalize)((0, shared_1.camelize)(baseName));
|
|
12
|
-
const document = ctx.getTextDocument(uri);
|
|
13
|
-
const [vueFile] = ctx.documents.getVirtualFileByUri(document.uri);
|
|
14
|
-
const { sfc } = vueFile;
|
|
15
|
-
const script = sfc.scriptSetup ?? sfc.script;
|
|
16
|
-
if (!sfc.template || !script)
|
|
17
|
-
return;
|
|
18
|
-
const lastImportNode = (0, vue_extract_file_1.getLastImportNode)(ts, script.ast);
|
|
19
|
-
const edits = [
|
|
20
|
-
{
|
|
21
|
-
range: lastImportNode ? {
|
|
22
|
-
start: document.positionAt(script.startTagEnd + lastImportNode.end),
|
|
23
|
-
end: document.positionAt(script.startTagEnd + lastImportNode.end),
|
|
24
|
-
} : {
|
|
25
|
-
start: document.positionAt(script.startTagEnd),
|
|
26
|
-
end: document.positionAt(script.startTagEnd),
|
|
27
|
-
},
|
|
28
|
-
newText: `\nimport ${newName} from './${path.relative(path.dirname(uri), importUri) || importUri.substring(importUri.lastIndexOf('/') + 1)}'`,
|
|
29
|
-
},
|
|
30
|
-
];
|
|
31
|
-
if (sfc.script) {
|
|
32
|
-
const edit = (0, vue_extract_file_1.createAddComponentToOptionEdit)(ts, sfc.script.ast, newName);
|
|
33
|
-
if (edit) {
|
|
34
|
-
edits.push({
|
|
35
|
-
range: {
|
|
36
|
-
start: document.positionAt(sfc.script.startTagEnd + edit.range.start),
|
|
37
|
-
end: document.positionAt(sfc.script.startTagEnd + edit.range.end),
|
|
38
|
-
},
|
|
39
|
-
newText: edit.newText,
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
return {
|
|
44
|
-
insertText: `<${casing === types_1.TagNameCasing.Kebab ? (0, shared_1.hyphenate)(newName) : newName}$0 />`,
|
|
45
|
-
insertTextFormat: 2,
|
|
46
|
-
additionalEdits: edits,
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
exports.getDragImportEdits = getDragImportEdits;
|
|
50
|
-
//# sourceMappingURL=dragImport.js.map
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { ServiceContext } from '@volar/language-service';
|
|
2
|
-
import { VueCompilerOptions } from '@vue/language-core';
|
|
3
|
-
import type { Provide } from 'volar-service-typescript';
|
|
4
|
-
import type * as vscode from 'vscode-languageserver-protocol';
|
|
5
|
-
import { AttrNameCasing, TagNameCasing } from '../types';
|
|
6
|
-
export declare function convertTagName(ts: typeof import('typescript/lib/tsserverlibrary'), context: ServiceContext<Provide>, uri: string, casing: TagNameCasing, vueCompilerOptions: VueCompilerOptions): Promise<vscode.TextEdit[] | undefined>;
|
|
7
|
-
export declare function convertAttrName(ts: typeof import('typescript/lib/tsserverlibrary'), context: ServiceContext, uri: string, casing: AttrNameCasing, vueCompilerOptions: VueCompilerOptions): Promise<vscode.TextEdit[] | undefined>;
|
|
8
|
-
export declare function getNameCasing(ts: typeof import('typescript/lib/tsserverlibrary'), context: ServiceContext, uri: string, vueCompilerOptions: VueCompilerOptions): Promise<{
|
|
9
|
-
tag: TagNameCasing;
|
|
10
|
-
attr: AttrNameCasing;
|
|
11
|
-
}>;
|
|
12
|
-
export declare function detect(ts: typeof import('typescript/lib/tsserverlibrary'), context: ServiceContext, uri: string, vueCompilerOptions: VueCompilerOptions): {
|
|
13
|
-
tag: TagNameCasing[];
|
|
14
|
-
attr: AttrNameCasing[];
|
|
15
|
-
};
|
|
16
|
-
//# sourceMappingURL=nameCasing.d.ts.map
|
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.detect = exports.getNameCasing = exports.convertAttrName = exports.convertTagName = void 0;
|
|
4
|
-
const language_core_1 = require("@vue/language-core");
|
|
5
|
-
const helpers_1 = require("../helpers");
|
|
6
|
-
const types_1 = require("../types");
|
|
7
|
-
async function convertTagName(ts, context, uri, casing, vueCompilerOptions) {
|
|
8
|
-
const rootFile = context.documents.getSourceByUri(uri)?.root;
|
|
9
|
-
if (!(rootFile instanceof language_core_1.VueFile))
|
|
10
|
-
return;
|
|
11
|
-
const desc = rootFile.sfc;
|
|
12
|
-
if (!desc.template)
|
|
13
|
-
return;
|
|
14
|
-
const languageService = context.inject('typescript/languageService');
|
|
15
|
-
const template = desc.template;
|
|
16
|
-
const document = context.documents.getDocumentByFileName(rootFile.snapshot, rootFile.fileName);
|
|
17
|
-
const edits = [];
|
|
18
|
-
const components = (0, helpers_1.getComponentNames)(ts, languageService, rootFile, vueCompilerOptions);
|
|
19
|
-
const tags = (0, helpers_1.getTemplateTagsAndAttrs)(rootFile);
|
|
20
|
-
for (const [tagName, { offsets }] of tags) {
|
|
21
|
-
const componentName = components.find(component => component === tagName || (0, language_core_1.hyphenateTag)(component) === tagName);
|
|
22
|
-
if (componentName) {
|
|
23
|
-
for (const offset of offsets) {
|
|
24
|
-
const start = document.positionAt(template.startTagEnd + offset);
|
|
25
|
-
const end = document.positionAt(template.startTagEnd + offset + tagName.length);
|
|
26
|
-
const range = { start, end };
|
|
27
|
-
if (casing === types_1.TagNameCasing.Kebab && tagName !== (0, language_core_1.hyphenateTag)(componentName)) {
|
|
28
|
-
edits.push({ range, newText: (0, language_core_1.hyphenateTag)(componentName) });
|
|
29
|
-
}
|
|
30
|
-
if (casing === types_1.TagNameCasing.Pascal && tagName !== componentName) {
|
|
31
|
-
edits.push({ range, newText: componentName });
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return edits;
|
|
37
|
-
}
|
|
38
|
-
exports.convertTagName = convertTagName;
|
|
39
|
-
async function convertAttrName(ts, context, uri, casing, vueCompilerOptions) {
|
|
40
|
-
const rootFile = context.documents.getSourceByUri(uri)?.root;
|
|
41
|
-
if (!(rootFile instanceof language_core_1.VueFile))
|
|
42
|
-
return;
|
|
43
|
-
const desc = rootFile.sfc;
|
|
44
|
-
if (!desc.template)
|
|
45
|
-
return;
|
|
46
|
-
const languageService = context.inject('typescript/languageService');
|
|
47
|
-
const template = desc.template;
|
|
48
|
-
const document = context.documents.getDocumentByFileName(rootFile.snapshot, rootFile.fileName);
|
|
49
|
-
const edits = [];
|
|
50
|
-
const components = (0, helpers_1.getComponentNames)(ts, languageService, rootFile, vueCompilerOptions);
|
|
51
|
-
const tags = (0, helpers_1.getTemplateTagsAndAttrs)(rootFile);
|
|
52
|
-
for (const [tagName, { attrs }] of tags) {
|
|
53
|
-
const componentName = components.find(component => component === tagName || (0, language_core_1.hyphenateTag)(component) === tagName);
|
|
54
|
-
if (componentName) {
|
|
55
|
-
const props = (0, helpers_1.getPropsByTag)(ts, languageService, rootFile, componentName, vueCompilerOptions);
|
|
56
|
-
for (const [attrName, { offsets }] of attrs) {
|
|
57
|
-
const propName = props.find(prop => prop === attrName || (0, language_core_1.hyphenateAttr)(prop) === attrName);
|
|
58
|
-
if (propName) {
|
|
59
|
-
for (const offset of offsets) {
|
|
60
|
-
const start = document.positionAt(template.startTagEnd + offset);
|
|
61
|
-
const end = document.positionAt(template.startTagEnd + offset + attrName.length);
|
|
62
|
-
const range = { start, end };
|
|
63
|
-
if (casing === types_1.AttrNameCasing.Kebab && attrName !== (0, language_core_1.hyphenateAttr)(propName)) {
|
|
64
|
-
edits.push({ range, newText: (0, language_core_1.hyphenateAttr)(propName) });
|
|
65
|
-
}
|
|
66
|
-
if (casing === types_1.AttrNameCasing.Camel && attrName !== propName) {
|
|
67
|
-
edits.push({ range, newText: propName });
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
return edits;
|
|
75
|
-
}
|
|
76
|
-
exports.convertAttrName = convertAttrName;
|
|
77
|
-
async function getNameCasing(ts, context, uri, vueCompilerOptions) {
|
|
78
|
-
const detected = detect(ts, context, uri, vueCompilerOptions);
|
|
79
|
-
const [attr, tag] = await Promise.all([
|
|
80
|
-
context.env.getConfiguration?.('vue.complete.casing.props', uri),
|
|
81
|
-
context.env.getConfiguration?.('vue.complete.casing.tags', uri),
|
|
82
|
-
]);
|
|
83
|
-
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;
|
|
84
|
-
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;
|
|
85
|
-
return {
|
|
86
|
-
tag: tagNameCasing,
|
|
87
|
-
attr: attrNameCasing,
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
exports.getNameCasing = getNameCasing;
|
|
91
|
-
function detect(ts, context, uri, vueCompilerOptions) {
|
|
92
|
-
const rootFile = context.documents.getSourceByUri(uri)?.root;
|
|
93
|
-
if (!(rootFile instanceof language_core_1.VueFile)) {
|
|
94
|
-
return {
|
|
95
|
-
tag: [],
|
|
96
|
-
attr: [],
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
const languageService = context.inject('typescript/languageService');
|
|
100
|
-
return {
|
|
101
|
-
tag: getTagNameCase(rootFile),
|
|
102
|
-
attr: getAttrNameCase(rootFile),
|
|
103
|
-
};
|
|
104
|
-
function getAttrNameCase(file) {
|
|
105
|
-
const tags = (0, helpers_1.getTemplateTagsAndAttrs)(file);
|
|
106
|
-
const result = [];
|
|
107
|
-
for (const [_, { attrs }] of tags) {
|
|
108
|
-
for (const [tagName] of attrs) {
|
|
109
|
-
// attrName
|
|
110
|
-
if (tagName !== (0, language_core_1.hyphenateTag)(tagName)) {
|
|
111
|
-
result.push(types_1.AttrNameCasing.Camel);
|
|
112
|
-
break;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
for (const [tagName] of attrs) {
|
|
116
|
-
// attr-name
|
|
117
|
-
if (tagName.indexOf('-') >= 0) {
|
|
118
|
-
result.push(types_1.AttrNameCasing.Kebab);
|
|
119
|
-
break;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
return result;
|
|
124
|
-
}
|
|
125
|
-
function getTagNameCase(file) {
|
|
126
|
-
const components = (0, helpers_1.getComponentNames)(ts, languageService, file, vueCompilerOptions);
|
|
127
|
-
const tagNames = (0, helpers_1.getTemplateTagsAndAttrs)(file);
|
|
128
|
-
const result = [];
|
|
129
|
-
let anyComponentUsed = false;
|
|
130
|
-
for (const component of components) {
|
|
131
|
-
if (tagNames.has(component) || tagNames.has((0, language_core_1.hyphenateTag)(component))) {
|
|
132
|
-
anyComponentUsed = true;
|
|
133
|
-
break;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
if (!anyComponentUsed) {
|
|
137
|
-
return []; // not sure component style, because do not have any component using in <template> for check
|
|
138
|
-
}
|
|
139
|
-
for (const [tagName] of tagNames) {
|
|
140
|
-
// TagName
|
|
141
|
-
if (tagName !== (0, language_core_1.hyphenateTag)(tagName)) {
|
|
142
|
-
result.push(types_1.TagNameCasing.Pascal);
|
|
143
|
-
break;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
for (const component of components) {
|
|
147
|
-
// Tagname -> tagname
|
|
148
|
-
// TagName -> tag-name
|
|
149
|
-
if (component !== (0, language_core_1.hyphenateTag)(component) && tagNames.has((0, language_core_1.hyphenateTag)(component))) {
|
|
150
|
-
result.push(types_1.TagNameCasing.Kebab);
|
|
151
|
-
break;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
return result;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
exports.detect = detect;
|
|
158
|
-
//# sourceMappingURL=nameCasing.js.map
|
package/out/index.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export * from '@volar/language-service';
|
|
2
|
-
export * from '@vue/language-core';
|
|
3
|
-
export * from './ideFeatures/nameCasing';
|
|
4
|
-
export * from './ideFeatures/dragImport';
|
|
5
|
-
export * from './languageService';
|
|
6
|
-
export { TagNameCasing, AttrNameCasing } from './types';
|
|
7
|
-
export { Provide } from './plugins/vue';
|
|
8
|
-
//# sourceMappingURL=index.d.ts.map
|
package/out/index.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.AttrNameCasing = exports.TagNameCasing = void 0;
|
|
18
|
-
__exportStar(require("@volar/language-service"), exports);
|
|
19
|
-
__exportStar(require("@vue/language-core"), exports);
|
|
20
|
-
__exportStar(require("./ideFeatures/nameCasing"), exports);
|
|
21
|
-
__exportStar(require("./ideFeatures/dragImport"), exports);
|
|
22
|
-
__exportStar(require("./languageService"), exports);
|
|
23
|
-
var types_1 = require("./types");
|
|
24
|
-
Object.defineProperty(exports, "TagNameCasing", { enumerable: true, get: function () { return types_1.TagNameCasing; } });
|
|
25
|
-
Object.defineProperty(exports, "AttrNameCasing", { enumerable: true, get: function () { return types_1.AttrNameCasing; } });
|
|
26
|
-
//# sourceMappingURL=index.js.map
|
package/out/languageService.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { Config } from '@volar/language-service';
|
|
2
|
-
import type * as ts from 'typescript/lib/tsserverlibrary';
|
|
3
|
-
import { VueCompilerOptions } from './types';
|
|
4
|
-
import * as JsonService from 'volar-service-json';
|
|
5
|
-
export interface Settings {
|
|
6
|
-
json?: Parameters<typeof JsonService['create']>[0];
|
|
7
|
-
}
|
|
8
|
-
export declare function resolveConfig(ts: typeof import('typescript/lib/tsserverlibrary'), config: Config, compilerOptions?: ts.CompilerOptions, vueCompilerOptions?: Partial<VueCompilerOptions>, codegenStack?: boolean): Config;
|
|
9
|
-
//# sourceMappingURL=languageService.d.ts.map
|