@vue/typescript-plugin 2.2.8 → 2.2.10
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/commands.d.ts +3 -0
- package/lib/commands.js +136 -0
- package/lib/common.js +75 -1
- package/lib/proxy.d.ts +3 -0
- package/lib/proxy.js +305 -0
- package/lib/requests/getDefineSlots.d.ts +2 -0
- package/lib/requests/getDefineSlots.js +16 -0
- package/lib/requests/getElementAttrs.d.ts +3 -0
- package/lib/requests/getElementAttrs.js +21 -5
- package/lib/requests/getElementNames.d.ts +5 -0
- package/lib/requests/getElementNames.js +23 -0
- package/lib/requests/index.d.ts +17 -0
- package/lib/requests/index.js +3 -0
- package/lib/requests/utils.js +8 -8
- package/package.json +3 -3
- package/lib/requests/componentInfos.d.ts +0 -13
- package/lib/requests/componentInfos.js +0 -249
- package/lib/requests/getComponentInfo.d.ts +0 -5
- package/lib/requests/getComponentInfo.js +0 -23
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { type Language } from '@vue/language-core';
|
|
2
|
+
import type * as ts from 'typescript';
|
|
3
|
+
export declare function addVueCommands(ts: typeof import('typescript'), info: ts.server.PluginCreateInfo, project2Service: Map<ts.server.Project, [Language, ts.LanguageServiceHost, ts.LanguageService]>): void;
|
package/lib/commands.js
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addVueCommands = addVueCommands;
|
|
4
|
+
const language_core_1 = require("@vue/language-core");
|
|
5
|
+
const collectExtractProps_1 = require("./requests/collectExtractProps");
|
|
6
|
+
const getComponentDirectives_1 = require("./requests/getComponentDirectives");
|
|
7
|
+
const getComponentEvents_1 = require("./requests/getComponentEvents");
|
|
8
|
+
const getComponentNames_1 = require("./requests/getComponentNames");
|
|
9
|
+
const getComponentProps_1 = require("./requests/getComponentProps");
|
|
10
|
+
const getElementAttrs_1 = require("./requests/getElementAttrs");
|
|
11
|
+
const getElementNames_1 = require("./requests/getElementNames");
|
|
12
|
+
const getImportPathForFile_1 = require("./requests/getImportPathForFile");
|
|
13
|
+
const getPropertiesAtLocation_1 = require("./requests/getPropertiesAtLocation");
|
|
14
|
+
// https://github.com/JetBrains/intellij-plugins/blob/6435723ad88fa296b41144162ebe3b8513f4949b/Angular/src-js/angular-service/src/index.ts#L69
|
|
15
|
+
function addVueCommands(ts, info, project2Service) {
|
|
16
|
+
const projectService = info.project.projectService;
|
|
17
|
+
projectService.logger.info("Vue: called handler processing " + info.project.projectKind);
|
|
18
|
+
const session = info.session;
|
|
19
|
+
if (session == undefined) {
|
|
20
|
+
projectService.logger.info("Vue: there is no session in info.");
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
if (session.addProtocolHandler == undefined) {
|
|
24
|
+
// addProtocolHandler was introduced in TS 4.4 or 4.5 in 2021, see https://github.com/microsoft/TypeScript/issues/43893
|
|
25
|
+
projectService.logger.info("Vue: there is no addProtocolHandler method.");
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if (session.vueCommandsAdded) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
session.vueCommandsAdded = true;
|
|
32
|
+
const isCaseSensitive = info.languageServiceHost.useCaseSensitiveFileNames?.() ?? false;
|
|
33
|
+
let lastProjectVersion;
|
|
34
|
+
let scriptInfos = new language_core_1.FileMap(isCaseSensitive);
|
|
35
|
+
session.addProtocolHandler('vue:isProjectUpdated', () => {
|
|
36
|
+
const projectVersion = info.project.getProjectVersion();
|
|
37
|
+
if (projectVersion === lastProjectVersion) {
|
|
38
|
+
return { response: 'no' };
|
|
39
|
+
}
|
|
40
|
+
lastProjectVersion = projectVersion;
|
|
41
|
+
const [, [language, languageServiceHost]] = [...project2Service].find(([project]) => project.projectKind === ts.server.ProjectKind.Configured);
|
|
42
|
+
const fileNames = languageServiceHost.getScriptFileNames();
|
|
43
|
+
const infos = new language_core_1.FileMap(isCaseSensitive);
|
|
44
|
+
let isAnyScriptVersionChanged = false;
|
|
45
|
+
let isAnyScriptSnapshotChanged = false;
|
|
46
|
+
for (const file of fileNames) {
|
|
47
|
+
const scriptVersion = languageServiceHost.getScriptVersion(file);
|
|
48
|
+
const scriptInfo = scriptInfos.get(file) ?? { version: "" };
|
|
49
|
+
infos.set(file, scriptInfo);
|
|
50
|
+
if (scriptInfo.version === scriptVersion) {
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
scriptInfo.version = scriptVersion;
|
|
54
|
+
isAnyScriptVersionChanged = true;
|
|
55
|
+
const volarFile = language.scripts.get(file);
|
|
56
|
+
const root = volarFile?.generated?.root;
|
|
57
|
+
const serviceScript = volarFile?.generated?.languagePlugin.typescript?.getServiceScript(root);
|
|
58
|
+
if (!serviceScript) {
|
|
59
|
+
isAnyScriptSnapshotChanged = true;
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
const { snapshot } = serviceScript.code;
|
|
63
|
+
if (scriptInfo.snapshot !== snapshot) {
|
|
64
|
+
scriptInfo.snapshot = snapshot;
|
|
65
|
+
isAnyScriptSnapshotChanged = true;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
scriptInfos = infos;
|
|
69
|
+
return { response: isAnyScriptSnapshotChanged || !isAnyScriptVersionChanged ? 'yes' : 'no' };
|
|
70
|
+
});
|
|
71
|
+
session.addProtocolHandler('vue:collectExtractProps', ({ arguments: args }) => {
|
|
72
|
+
return {
|
|
73
|
+
response: collectExtractProps_1.collectExtractProps.apply(getRequestContext(args[0]), args),
|
|
74
|
+
};
|
|
75
|
+
});
|
|
76
|
+
session.addProtocolHandler('vue:getImportPathForFile', ({ arguments: args }) => {
|
|
77
|
+
return {
|
|
78
|
+
response: getImportPathForFile_1.getImportPathForFile.apply(getRequestContext(args[0]), args),
|
|
79
|
+
};
|
|
80
|
+
});
|
|
81
|
+
session.addProtocolHandler('vue:getPropertiesAtLocation', ({ arguments: args }) => {
|
|
82
|
+
return {
|
|
83
|
+
response: getPropertiesAtLocation_1.getPropertiesAtLocation.apply(getRequestContext(args[0]), args),
|
|
84
|
+
};
|
|
85
|
+
});
|
|
86
|
+
session.addProtocolHandler('vue:getComponentNames', ({ arguments: args }) => {
|
|
87
|
+
return {
|
|
88
|
+
response: getComponentNames_1.getComponentNames.apply(getRequestContext(args[0]), args),
|
|
89
|
+
};
|
|
90
|
+
});
|
|
91
|
+
session.addProtocolHandler('vue:getComponentProps', ({ arguments: args }) => {
|
|
92
|
+
return {
|
|
93
|
+
response: getComponentProps_1.getComponentProps.apply(getRequestContext(args[0]), args),
|
|
94
|
+
};
|
|
95
|
+
});
|
|
96
|
+
session.addProtocolHandler('vue:getComponentEvents', ({ arguments: args }) => {
|
|
97
|
+
return {
|
|
98
|
+
response: getComponentEvents_1.getComponentEvents.apply(getRequestContext(args[0]), args),
|
|
99
|
+
};
|
|
100
|
+
});
|
|
101
|
+
session.addProtocolHandler('vue:getComponentDirectives', ({ arguments: args }) => {
|
|
102
|
+
return {
|
|
103
|
+
response: getComponentDirectives_1.getComponentDirectives.apply(getRequestContext(args[0]), args),
|
|
104
|
+
};
|
|
105
|
+
});
|
|
106
|
+
session.addProtocolHandler('vue:getElementAttrs', ({ arguments: args }) => {
|
|
107
|
+
return {
|
|
108
|
+
response: getElementAttrs_1.getElementAttrs.apply(getRequestContext(args[0]), args),
|
|
109
|
+
};
|
|
110
|
+
});
|
|
111
|
+
session.addProtocolHandler('vue:getElementNames', ({ arguments: args }) => {
|
|
112
|
+
return {
|
|
113
|
+
response: getElementNames_1.getElementNames.apply(getRequestContext(args[0]), args),
|
|
114
|
+
};
|
|
115
|
+
});
|
|
116
|
+
projectService.logger.info('Vue specific commands are successfully added.');
|
|
117
|
+
function getRequestContext(fileName) {
|
|
118
|
+
const fileAndProject = info.session.getFileAndProject({
|
|
119
|
+
file: fileName,
|
|
120
|
+
projectFileName: undefined,
|
|
121
|
+
});
|
|
122
|
+
const service = project2Service.get(fileAndProject.project);
|
|
123
|
+
if (!service) {
|
|
124
|
+
throw 'No RequestContext';
|
|
125
|
+
}
|
|
126
|
+
return {
|
|
127
|
+
typescript: ts,
|
|
128
|
+
languageService: service[2],
|
|
129
|
+
languageServiceHost: service[1],
|
|
130
|
+
language: service[0],
|
|
131
|
+
isTsPlugin: true,
|
|
132
|
+
getFileId: (fileName) => fileName,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
//# sourceMappingURL=commands.js.map
|
package/lib/common.js
CHANGED
|
@@ -5,6 +5,7 @@ exports.getComponentSpans = getComponentSpans;
|
|
|
5
5
|
const language_core_1 = require("@vue/language-core");
|
|
6
6
|
const shared_1 = require("@vue/shared");
|
|
7
7
|
const getComponentNames_1 = require("./requests/getComponentNames");
|
|
8
|
+
const getElementAttrs_1 = require("./requests/getElementAttrs");
|
|
8
9
|
const windowsPathReg = /\\/g;
|
|
9
10
|
function proxyLanguageServiceForVue(ts, language, languageService, vueOptions, asScriptId) {
|
|
10
11
|
const proxyCache = new Map();
|
|
@@ -13,6 +14,7 @@ function proxyLanguageServiceForVue(ts, language, languageService, vueOptions, a
|
|
|
13
14
|
case 'getCompletionsAtPosition': return getCompletionsAtPosition(vueOptions, target[p]);
|
|
14
15
|
case 'getCompletionEntryDetails': return getCompletionEntryDetails(language, asScriptId, target[p]);
|
|
15
16
|
case 'getCodeFixesAtPosition': return getCodeFixesAtPosition(target[p]);
|
|
17
|
+
case 'getDefinitionAndBoundSpan': return getDefinitionAndBoundSpan(ts, language, languageService, vueOptions, asScriptId, target[p]);
|
|
16
18
|
case 'getQuickInfoAtPosition': return getQuickInfoAtPosition(ts, target, target[p]);
|
|
17
19
|
// TS plugin only
|
|
18
20
|
case 'getEncodedSemanticClassifications': return getEncodedSemanticClassifications(ts, language, target, asScriptId, target[p]);
|
|
@@ -128,6 +130,77 @@ function getCodeFixesAtPosition(getCodeFixesAtPosition) {
|
|
|
128
130
|
return result;
|
|
129
131
|
};
|
|
130
132
|
}
|
|
133
|
+
function getDefinitionAndBoundSpan(ts, language, languageService, vueOptions, asScriptId, getDefinitionAndBoundSpan) {
|
|
134
|
+
return (fileName, position) => {
|
|
135
|
+
const result = getDefinitionAndBoundSpan(fileName, position);
|
|
136
|
+
if (!result?.definitions?.length) {
|
|
137
|
+
return result;
|
|
138
|
+
}
|
|
139
|
+
const program = languageService.getProgram();
|
|
140
|
+
const sourceScript = language.scripts.get(asScriptId(fileName));
|
|
141
|
+
if (!sourceScript?.generated) {
|
|
142
|
+
return result;
|
|
143
|
+
}
|
|
144
|
+
const root = sourceScript.generated.root;
|
|
145
|
+
if (!(root instanceof language_core_1.VueVirtualCode)) {
|
|
146
|
+
return result;
|
|
147
|
+
}
|
|
148
|
+
if (!root.sfc.template
|
|
149
|
+
|| position < root.sfc.template.startTagEnd
|
|
150
|
+
|| position > root.sfc.template.endTagStart) {
|
|
151
|
+
return result;
|
|
152
|
+
}
|
|
153
|
+
const definitions = new Set(result.definitions);
|
|
154
|
+
const skippedDefinitions = [];
|
|
155
|
+
for (const definition of result.definitions) {
|
|
156
|
+
if (vueOptions.extensions.some(ext => definition.fileName.endsWith(ext))) {
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
const sourceFile = program.getSourceFile(definition.fileName);
|
|
160
|
+
if (!sourceFile) {
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
visit(sourceFile, definition, sourceFile);
|
|
164
|
+
}
|
|
165
|
+
for (const definition of skippedDefinitions) {
|
|
166
|
+
definitions.delete(definition);
|
|
167
|
+
}
|
|
168
|
+
return {
|
|
169
|
+
definitions: [...definitions],
|
|
170
|
+
textSpan: result.textSpan,
|
|
171
|
+
};
|
|
172
|
+
function visit(node, definition, sourceFile) {
|
|
173
|
+
if (ts.isPropertySignature(node) && node.type) {
|
|
174
|
+
proxy(node.name, node.type, definition, sourceFile);
|
|
175
|
+
}
|
|
176
|
+
else if (ts.isVariableDeclaration(node) && ts.isIdentifier(node.name) && node.type && !node.initializer) {
|
|
177
|
+
proxy(node.name, node.type, definition, sourceFile);
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
ts.forEachChild(node, child => visit(child, definition, sourceFile));
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
function proxy(name, type, definition, sourceFile) {
|
|
184
|
+
const { textSpan, fileName } = definition;
|
|
185
|
+
const start = name.getStart(sourceFile);
|
|
186
|
+
const end = name.getEnd();
|
|
187
|
+
if (start !== textSpan.start || end - start !== textSpan.length) {
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
if (!ts.isIndexedAccessTypeNode(type)) {
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
const pos = type.indexType.getStart(sourceFile);
|
|
194
|
+
const res = getDefinitionAndBoundSpan(fileName, pos);
|
|
195
|
+
if (res?.definitions?.length) {
|
|
196
|
+
for (const definition of res.definitions) {
|
|
197
|
+
definitions.add(definition);
|
|
198
|
+
}
|
|
199
|
+
skippedDefinitions.push(definition);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
}
|
|
131
204
|
function getQuickInfoAtPosition(ts, languageService, getQuickInfoAtPosition) {
|
|
132
205
|
return (...args) => {
|
|
133
206
|
const result = getQuickInfoAtPosition(...args);
|
|
@@ -191,6 +264,7 @@ function getComponentSpans(vueCode, template, spanTemplateRange) {
|
|
|
191
264
|
const { typescript: ts, languageService } = this;
|
|
192
265
|
const result = [];
|
|
193
266
|
const validComponentNames = (0, getComponentNames_1._getComponentNames)(ts, languageService, vueCode);
|
|
267
|
+
const elements = new Set((0, getElementAttrs_1._getElementNames)(ts, languageService, vueCode));
|
|
194
268
|
const components = new Set([
|
|
195
269
|
...validComponentNames,
|
|
196
270
|
...validComponentNames.map(language_core_1.hyphenateTag),
|
|
@@ -200,7 +274,7 @@ function getComponentSpans(vueCode, template, spanTemplateRange) {
|
|
|
200
274
|
if (node.loc.end.offset <= spanTemplateRange.start || node.loc.start.offset >= (spanTemplateRange.start + spanTemplateRange.length)) {
|
|
201
275
|
continue;
|
|
202
276
|
}
|
|
203
|
-
if (components.has(node.tag)) {
|
|
277
|
+
if (components.has(node.tag) && !elements.has(node.tag)) {
|
|
204
278
|
let start = node.loc.start.offset;
|
|
205
279
|
if (template.lang === 'html') {
|
|
206
280
|
start += '<'.length;
|
package/lib/proxy.d.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { Language, VueCompilerOptions } from '@vue/language-core';
|
|
2
|
+
import type * as ts from 'typescript';
|
|
3
|
+
export declare function proxyLanguageServiceForVue<T>(ts: typeof import('typescript'), language: Language<T>, languageService: ts.LanguageService, vueOptions: VueCompilerOptions, asScriptId: (fileName: string) => T): ts.LanguageService;
|
package/lib/proxy.js
ADDED
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.proxyLanguageServiceForVue = proxyLanguageServiceForVue;
|
|
4
|
+
const language_core_1 = require("@vue/language-core");
|
|
5
|
+
const shared_1 = require("@vue/shared");
|
|
6
|
+
const getComponentNames_1 = require("./requests/getComponentNames");
|
|
7
|
+
const getElementNames_1 = require("./requests/getElementNames");
|
|
8
|
+
const windowsPathReg = /\\/g;
|
|
9
|
+
function proxyLanguageServiceForVue(ts, language, languageService, vueOptions, asScriptId) {
|
|
10
|
+
const proxyCache = new Map();
|
|
11
|
+
const getProxyMethod = (target, p) => {
|
|
12
|
+
switch (p) {
|
|
13
|
+
case 'getCompletionsAtPosition': return getCompletionsAtPosition(vueOptions, target[p]);
|
|
14
|
+
case 'getCompletionEntryDetails': return getCompletionEntryDetails(language, asScriptId, target[p]);
|
|
15
|
+
case 'getCodeFixesAtPosition': return getCodeFixesAtPosition(target[p]);
|
|
16
|
+
case 'getDefinitionAndBoundSpan': return getDefinitionAndBoundSpan(ts, language, languageService, vueOptions, asScriptId, target[p]);
|
|
17
|
+
case 'getQuickInfoAtPosition': return getQuickInfoAtPosition(ts, target, target[p]);
|
|
18
|
+
// TS plugin only
|
|
19
|
+
case 'getEncodedSemanticClassifications': return getEncodedSemanticClassifications(ts, language, target, asScriptId, target[p]);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
return new Proxy(languageService, {
|
|
23
|
+
get(target, p, receiver) {
|
|
24
|
+
if (getProxyMethod) {
|
|
25
|
+
if (!proxyCache.has(p)) {
|
|
26
|
+
proxyCache.set(p, getProxyMethod(target, p));
|
|
27
|
+
}
|
|
28
|
+
const proxyMethod = proxyCache.get(p);
|
|
29
|
+
if (proxyMethod) {
|
|
30
|
+
return proxyMethod;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return Reflect.get(target, p, receiver);
|
|
34
|
+
},
|
|
35
|
+
set(target, p, value, receiver) {
|
|
36
|
+
return Reflect.set(target, p, value, receiver);
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
function getCompletionsAtPosition(vueOptions, getCompletionsAtPosition) {
|
|
41
|
+
return (filePath, position, options, formattingSettings) => {
|
|
42
|
+
const fileName = filePath.replace(windowsPathReg, '/');
|
|
43
|
+
const result = getCompletionsAtPosition(fileName, position, options, formattingSettings);
|
|
44
|
+
if (result) {
|
|
45
|
+
// filter __VLS_
|
|
46
|
+
result.entries = result.entries.filter(entry => !entry.name.includes('__VLS_')
|
|
47
|
+
&& !entry.labelDetails?.description?.includes('__VLS_'));
|
|
48
|
+
// modify label
|
|
49
|
+
for (const item of result.entries) {
|
|
50
|
+
if (item.source) {
|
|
51
|
+
const originalName = item.name;
|
|
52
|
+
for (const vueExt of vueOptions.extensions) {
|
|
53
|
+
const suffix = (0, shared_1.capitalize)(vueExt.slice(1)); // .vue -> Vue
|
|
54
|
+
if (item.source.endsWith(vueExt) && item.name.endsWith(suffix)) {
|
|
55
|
+
item.name = (0, shared_1.capitalize)(item.name.slice(0, -suffix.length));
|
|
56
|
+
if (item.insertText) {
|
|
57
|
+
// #2286
|
|
58
|
+
item.insertText = item.insertText.replace(`${suffix}$1`, '$1');
|
|
59
|
+
}
|
|
60
|
+
if (item.data) {
|
|
61
|
+
// @ts-expect-error
|
|
62
|
+
item.data.__isComponentAutoImport = {
|
|
63
|
+
ext: vueExt,
|
|
64
|
+
suffix,
|
|
65
|
+
originalName,
|
|
66
|
+
newName: item.insertText,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (item.data) {
|
|
73
|
+
// @ts-expect-error
|
|
74
|
+
item.data.__isAutoImport = {
|
|
75
|
+
fileName,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return result;
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
function getCompletionEntryDetails(language, asScriptId, getCompletionEntryDetails) {
|
|
85
|
+
return (...args) => {
|
|
86
|
+
const details = getCompletionEntryDetails(...args);
|
|
87
|
+
// modify import statement
|
|
88
|
+
// @ts-expect-error
|
|
89
|
+
if (args[6]?.__isComponentAutoImport) {
|
|
90
|
+
// @ts-expect-error
|
|
91
|
+
const { ext, suffix, originalName, newName } = args[6]?.__isComponentAutoImport;
|
|
92
|
+
for (const codeAction of details?.codeActions ?? []) {
|
|
93
|
+
for (const change of codeAction.changes) {
|
|
94
|
+
for (const textChange of change.textChanges) {
|
|
95
|
+
textChange.newText = textChange.newText.replace('import ' + originalName + ' from ', 'import ' + newName + ' from ');
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
// @ts-expect-error
|
|
101
|
+
if (args[6]?.__isAutoImport) {
|
|
102
|
+
// @ts-expect-error
|
|
103
|
+
const { fileName } = args[6]?.__isAutoImport;
|
|
104
|
+
const sourceScript = language.scripts.get(asScriptId(fileName));
|
|
105
|
+
if (sourceScript?.generated?.root instanceof language_core_1.VueVirtualCode) {
|
|
106
|
+
const sfc = sourceScript.generated.root.vueSfc;
|
|
107
|
+
if (!sfc?.descriptor.script && !sfc?.descriptor.scriptSetup) {
|
|
108
|
+
for (const codeAction of details?.codeActions ?? []) {
|
|
109
|
+
for (const change of codeAction.changes) {
|
|
110
|
+
for (const textChange of change.textChanges) {
|
|
111
|
+
textChange.newText = `<script setup lang="ts">${textChange.newText}</script>\n\n`;
|
|
112
|
+
break;
|
|
113
|
+
}
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return details;
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
function getCodeFixesAtPosition(getCodeFixesAtPosition) {
|
|
125
|
+
return (...args) => {
|
|
126
|
+
let result = getCodeFixesAtPosition(...args);
|
|
127
|
+
// filter __VLS_
|
|
128
|
+
result = result.filter(entry => !entry.description.includes('__VLS_'));
|
|
129
|
+
return result;
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
function getDefinitionAndBoundSpan(ts, language, languageService, vueOptions, asScriptId, getDefinitionAndBoundSpan) {
|
|
133
|
+
return (fileName, position) => {
|
|
134
|
+
const result = getDefinitionAndBoundSpan(fileName, position);
|
|
135
|
+
if (!result?.definitions?.length) {
|
|
136
|
+
return result;
|
|
137
|
+
}
|
|
138
|
+
const program = languageService.getProgram();
|
|
139
|
+
const sourceScript = language.scripts.get(asScriptId(fileName));
|
|
140
|
+
if (!sourceScript?.generated) {
|
|
141
|
+
return result;
|
|
142
|
+
}
|
|
143
|
+
const root = sourceScript.generated.root;
|
|
144
|
+
if (!(root instanceof language_core_1.VueVirtualCode)) {
|
|
145
|
+
return result;
|
|
146
|
+
}
|
|
147
|
+
if (!root.sfc.template
|
|
148
|
+
|| position < root.sfc.template.startTagEnd
|
|
149
|
+
|| position > root.sfc.template.endTagStart) {
|
|
150
|
+
return result;
|
|
151
|
+
}
|
|
152
|
+
const definitions = new Set(result.definitions);
|
|
153
|
+
const skippedDefinitions = [];
|
|
154
|
+
// #5275
|
|
155
|
+
if (result.definitions.length >= 2) {
|
|
156
|
+
for (const definition of result.definitions) {
|
|
157
|
+
if (root.sfc.content[definition.textSpan.start - 1] === '@'
|
|
158
|
+
|| root.sfc.content.slice(definition.textSpan.start - 5, definition.textSpan.start) === 'v-on:') {
|
|
159
|
+
skippedDefinitions.push(definition);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
for (const definition of result.definitions) {
|
|
164
|
+
if (vueOptions.extensions.some(ext => definition.fileName.endsWith(ext))) {
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
const sourceFile = program.getSourceFile(definition.fileName);
|
|
168
|
+
if (!sourceFile) {
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
visit(sourceFile, definition, sourceFile);
|
|
172
|
+
}
|
|
173
|
+
for (const definition of skippedDefinitions) {
|
|
174
|
+
definitions.delete(definition);
|
|
175
|
+
}
|
|
176
|
+
return {
|
|
177
|
+
definitions: [...definitions],
|
|
178
|
+
textSpan: result.textSpan,
|
|
179
|
+
};
|
|
180
|
+
function visit(node, definition, sourceFile) {
|
|
181
|
+
if (ts.isPropertySignature(node) && node.type) {
|
|
182
|
+
proxy(node.name, node.type, definition, sourceFile);
|
|
183
|
+
}
|
|
184
|
+
else if (ts.isVariableDeclaration(node) && ts.isIdentifier(node.name) && node.type && !node.initializer) {
|
|
185
|
+
proxy(node.name, node.type, definition, sourceFile);
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
ts.forEachChild(node, child => visit(child, definition, sourceFile));
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
function proxy(name, type, definition, sourceFile) {
|
|
192
|
+
const { textSpan, fileName } = definition;
|
|
193
|
+
const start = name.getStart(sourceFile);
|
|
194
|
+
const end = name.getEnd();
|
|
195
|
+
if (start !== textSpan.start || end - start !== textSpan.length) {
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
if (!ts.isIndexedAccessTypeNode(type)) {
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
const pos = type.indexType.getStart(sourceFile);
|
|
202
|
+
const res = getDefinitionAndBoundSpan(fileName, pos);
|
|
203
|
+
if (res?.definitions?.length) {
|
|
204
|
+
for (const definition of res.definitions) {
|
|
205
|
+
definitions.add(definition);
|
|
206
|
+
}
|
|
207
|
+
skippedDefinitions.push(definition);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
function getQuickInfoAtPosition(ts, languageService, getQuickInfoAtPosition) {
|
|
213
|
+
return (...args) => {
|
|
214
|
+
const result = getQuickInfoAtPosition(...args);
|
|
215
|
+
if (result && result.documentation?.length === 1 && result.documentation[0].text.startsWith('__VLS_emit,')) {
|
|
216
|
+
const [_, emitVarName, eventName] = result.documentation[0].text.split(',');
|
|
217
|
+
const program = languageService.getProgram();
|
|
218
|
+
const typeChecker = program.getTypeChecker();
|
|
219
|
+
const sourceFile = program.getSourceFile(args[0]);
|
|
220
|
+
result.documentation = undefined;
|
|
221
|
+
let symbolNode;
|
|
222
|
+
sourceFile?.forEachChild(function visit(node) {
|
|
223
|
+
if (ts.isIdentifier(node) && node.text === emitVarName) {
|
|
224
|
+
symbolNode = node;
|
|
225
|
+
}
|
|
226
|
+
if (symbolNode) {
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
ts.forEachChild(node, visit);
|
|
230
|
+
});
|
|
231
|
+
if (symbolNode) {
|
|
232
|
+
const emitSymbol = typeChecker.getSymbolAtLocation(symbolNode);
|
|
233
|
+
if (emitSymbol) {
|
|
234
|
+
const type = typeChecker.getTypeOfSymbolAtLocation(emitSymbol, symbolNode);
|
|
235
|
+
const calls = type.getCallSignatures();
|
|
236
|
+
for (const call of calls) {
|
|
237
|
+
const callEventName = typeChecker.getTypeOfSymbolAtLocation(call.parameters[0], symbolNode).value;
|
|
238
|
+
call.getJsDocTags();
|
|
239
|
+
if (callEventName === eventName) {
|
|
240
|
+
result.documentation = call.getDocumentationComment(typeChecker);
|
|
241
|
+
result.tags = call.getJsDocTags();
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
return result;
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
function getEncodedSemanticClassifications(ts, language, languageService, asScriptId, getEncodedSemanticClassifications) {
|
|
251
|
+
return (filePath, span, format) => {
|
|
252
|
+
const fileName = filePath.replace(windowsPathReg, '/');
|
|
253
|
+
const result = getEncodedSemanticClassifications(fileName, span, format);
|
|
254
|
+
const sourceScript = language.scripts.get(asScriptId(fileName));
|
|
255
|
+
const root = sourceScript?.generated?.root;
|
|
256
|
+
if (root instanceof language_core_1.VueVirtualCode) {
|
|
257
|
+
const { template } = root.sfc;
|
|
258
|
+
if (template) {
|
|
259
|
+
for (const componentSpan of getComponentSpans.call({ typescript: ts, languageService }, root, template, {
|
|
260
|
+
start: span.start - template.startTagEnd,
|
|
261
|
+
length: span.length,
|
|
262
|
+
})) {
|
|
263
|
+
result.spans.push(componentSpan.start + template.startTagEnd, componentSpan.length, 256 // class
|
|
264
|
+
);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
return result;
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
function getComponentSpans(vueCode, template, spanTemplateRange) {
|
|
272
|
+
const { typescript: ts, languageService } = this;
|
|
273
|
+
const result = [];
|
|
274
|
+
const validComponentNames = (0, getComponentNames_1._getComponentNames)(ts, languageService, vueCode);
|
|
275
|
+
const elements = new Set((0, getElementNames_1._getElementNames)(ts, languageService, vueCode));
|
|
276
|
+
const components = new Set([
|
|
277
|
+
...validComponentNames,
|
|
278
|
+
...validComponentNames.map(language_core_1.hyphenateTag),
|
|
279
|
+
]);
|
|
280
|
+
if (template.ast) {
|
|
281
|
+
for (const node of (0, language_core_1.forEachElementNode)(template.ast)) {
|
|
282
|
+
if (node.loc.end.offset <= spanTemplateRange.start || node.loc.start.offset >= (spanTemplateRange.start + spanTemplateRange.length)) {
|
|
283
|
+
continue;
|
|
284
|
+
}
|
|
285
|
+
if (components.has(node.tag) && !elements.has(node.tag)) {
|
|
286
|
+
let start = node.loc.start.offset;
|
|
287
|
+
if (template.lang === 'html') {
|
|
288
|
+
start += '<'.length;
|
|
289
|
+
}
|
|
290
|
+
result.push({
|
|
291
|
+
start,
|
|
292
|
+
length: node.tag.length,
|
|
293
|
+
});
|
|
294
|
+
if (template.lang === 'html' && !node.isSelfClosing) {
|
|
295
|
+
result.push({
|
|
296
|
+
start: node.loc.start.offset + node.loc.source.lastIndexOf(node.tag),
|
|
297
|
+
length: node.tag.length,
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
return result;
|
|
304
|
+
}
|
|
305
|
+
//# sourceMappingURL=proxy.js.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getDefineSlots = getDefineSlots;
|
|
4
|
+
const language_core_1 = require("@vue/language-core");
|
|
5
|
+
const utils_1 = require("./utils");
|
|
6
|
+
function getDefineSlots(fileName) {
|
|
7
|
+
const { typescript: ts, language, languageService, getFileId } = this;
|
|
8
|
+
const volarFile = language.scripts.get(getFileId(fileName));
|
|
9
|
+
if (!(volarFile?.generated?.root instanceof language_core_1.VueVirtualCode)) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
const vueCode = volarFile.generated.root;
|
|
13
|
+
const slots = (0, utils_1.getTypeAliasType)(ts, languageService, vueCode, '__VLS_Slots');
|
|
14
|
+
return slots?.type.getProperties().map(prop => prop.getName());
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=getDefineSlots.js.map
|
|
@@ -1,2 +1,5 @@
|
|
|
1
|
+
import { VueVirtualCode } from '@vue/language-core';
|
|
2
|
+
import type * as ts from 'typescript';
|
|
1
3
|
import type { RequestContext } from './types';
|
|
2
4
|
export declare function getElementAttrs(this: RequestContext, fileName: string, tagName: string): string[] | undefined;
|
|
5
|
+
export declare function _getElementNames(ts: typeof import('typescript'), tsLs: ts.LanguageService, vueCode: VueVirtualCode): string[];
|
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getElementAttrs = getElementAttrs;
|
|
4
|
-
|
|
4
|
+
exports._getElementNames = _getElementNames;
|
|
5
|
+
const language_core_1 = require("@vue/language-core");
|
|
5
6
|
function getElementAttrs(fileName, tagName) {
|
|
6
7
|
const { typescript: ts, language, languageService, getFileId } = this;
|
|
7
8
|
const volarFile = language.scripts.get(getFileId(fileName));
|
|
8
|
-
if (!(volarFile?.generated?.root instanceof
|
|
9
|
+
if (!(volarFile?.generated?.root instanceof language_core_1.VueVirtualCode)) {
|
|
9
10
|
return;
|
|
10
11
|
}
|
|
11
12
|
const program = languageService.getProgram();
|
|
12
|
-
|
|
13
|
-
if (tsSourceFile
|
|
13
|
+
const tsSourceFile = program.getSourceFile(fileName);
|
|
14
|
+
if (tsSourceFile) {
|
|
14
15
|
const checker = program.getTypeChecker();
|
|
15
16
|
const typeNode = tsSourceFile.statements
|
|
16
17
|
.filter(ts.isTypeAliasDeclaration)
|
|
17
18
|
.find(node => node.name.getText() === '__VLS_IntrinsicElementsCompletion');
|
|
18
|
-
if (
|
|
19
|
+
if (typeNode) {
|
|
19
20
|
const type = checker.getTypeFromTypeNode(typeNode.type);
|
|
20
21
|
const el = type.getProperty(tagName);
|
|
21
22
|
if (el) {
|
|
@@ -26,4 +27,19 @@ function getElementAttrs(fileName, tagName) {
|
|
|
26
27
|
}
|
|
27
28
|
return [];
|
|
28
29
|
}
|
|
30
|
+
function _getElementNames(ts, tsLs, vueCode) {
|
|
31
|
+
const program = tsLs.getProgram();
|
|
32
|
+
const tsSourceFile = program.getSourceFile(vueCode.fileName);
|
|
33
|
+
if (tsSourceFile) {
|
|
34
|
+
const checker = program.getTypeChecker();
|
|
35
|
+
const typeNode = tsSourceFile.statements
|
|
36
|
+
.filter(ts.isTypeAliasDeclaration)
|
|
37
|
+
.find(node => node.name.getText() === '__VLS_IntrinsicElementsCompletion');
|
|
38
|
+
if (typeNode) {
|
|
39
|
+
const type = checker.getTypeFromTypeNode(typeNode.type);
|
|
40
|
+
return type.getProperties().map(c => c.name);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return [];
|
|
44
|
+
}
|
|
29
45
|
//# sourceMappingURL=getElementAttrs.js.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { VueVirtualCode } from '@vue/language-core';
|
|
2
|
+
import type * as ts from 'typescript';
|
|
3
|
+
import type { RequestContext } from './types';
|
|
4
|
+
export declare function getElementNames(this: RequestContext, fileName: string): string[] | undefined;
|
|
5
|
+
export declare function _getElementNames(ts: typeof import('typescript'), tsLs: ts.LanguageService, vueCode: VueVirtualCode): string[];
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getElementNames = getElementNames;
|
|
4
|
+
exports._getElementNames = _getElementNames;
|
|
5
|
+
const language_core_1 = require("@vue/language-core");
|
|
6
|
+
const utils_1 = require("./utils");
|
|
7
|
+
function getElementNames(fileName) {
|
|
8
|
+
const { typescript: ts, language, languageService, getFileId } = this;
|
|
9
|
+
const volarFile = language.scripts.get(getFileId(fileName));
|
|
10
|
+
if (!(volarFile?.generated?.root instanceof language_core_1.VueVirtualCode)) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const vueCode = volarFile.generated.root;
|
|
14
|
+
return _getElementNames(ts, languageService, vueCode);
|
|
15
|
+
}
|
|
16
|
+
function _getElementNames(ts, tsLs, vueCode) {
|
|
17
|
+
return (0, utils_1.getVariableType)(ts, tsLs, vueCode, '__VLS_elements')
|
|
18
|
+
?.type
|
|
19
|
+
?.getProperties()
|
|
20
|
+
.map(c => c.name)
|
|
21
|
+
?? [];
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=getElementNames.js.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
type ToRequest<T extends (...args: any) => any> = (...args: Parameters<T>) => Promise<ReturnType<T> | null | undefined>;
|
|
2
|
+
export type Requests = {
|
|
3
|
+
collectExtractProps: ToRequest<typeof import('./collectExtractProps.js')['collectExtractProps']>;
|
|
4
|
+
getImportPathForFile: ToRequest<typeof import('./getImportPathForFile.js')['getImportPathForFile']>;
|
|
5
|
+
getPropertiesAtLocation: ToRequest<typeof import('./getPropertiesAtLocation.js')['getPropertiesAtLocation']>;
|
|
6
|
+
getComponentNames: ToRequest<typeof import('./getComponentNames.js')['getComponentNames']>;
|
|
7
|
+
getComponentProps: ToRequest<typeof import('./getComponentProps.js')['getComponentProps']>;
|
|
8
|
+
getComponentEvents: ToRequest<typeof import('./getComponentEvents.js')['getComponentEvents']>;
|
|
9
|
+
getComponentDirectives: ToRequest<typeof import('./getComponentDirectives.js')['getComponentDirectives']>;
|
|
10
|
+
getElementAttrs: ToRequest<typeof import('./getElementAttrs.js')['getElementAttrs']>;
|
|
11
|
+
getElementNames: ToRequest<typeof import('./getElementNames.js')['getElementNames']>;
|
|
12
|
+
getQuickInfoAtPosition: ToRequest<(fileName: string, position: {
|
|
13
|
+
line: number;
|
|
14
|
+
character: number;
|
|
15
|
+
}) => string>;
|
|
16
|
+
};
|
|
17
|
+
export {};
|
package/lib/requests/utils.js
CHANGED
|
@@ -36,11 +36,11 @@ function getSelfComponentName(fileName) {
|
|
|
36
36
|
}
|
|
37
37
|
function getVariableType(ts, languageService, vueCode, name) {
|
|
38
38
|
const program = languageService.getProgram();
|
|
39
|
-
|
|
40
|
-
if (tsSourceFile
|
|
41
|
-
const node = searchVariableDeclarationNode(ts, tsSourceFile, name);
|
|
39
|
+
const tsSourceFile = program.getSourceFile(vueCode.fileName);
|
|
40
|
+
if (tsSourceFile) {
|
|
42
41
|
const checker = program.getTypeChecker();
|
|
43
|
-
|
|
42
|
+
const node = searchVariableDeclarationNode(ts, tsSourceFile, name);
|
|
43
|
+
if (node) {
|
|
44
44
|
return {
|
|
45
45
|
node: node,
|
|
46
46
|
type: checker.getTypeAtLocation(node),
|
|
@@ -49,15 +49,15 @@ function getVariableType(ts, languageService, vueCode, name) {
|
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
function searchVariableDeclarationNode(ts, sourceFile, name) {
|
|
52
|
-
let
|
|
52
|
+
let result;
|
|
53
53
|
walk(sourceFile);
|
|
54
|
-
return
|
|
54
|
+
return result;
|
|
55
55
|
function walk(node) {
|
|
56
|
-
if (
|
|
56
|
+
if (result) {
|
|
57
57
|
return;
|
|
58
58
|
}
|
|
59
59
|
else if (ts.isVariableDeclaration(node) && node.name.getText() === name) {
|
|
60
|
-
|
|
60
|
+
result = node;
|
|
61
61
|
}
|
|
62
62
|
else {
|
|
63
63
|
node.forEachChild(walk);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vue/typescript-plugin",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.10",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"**/*.js",
|
|
@@ -14,11 +14,11 @@
|
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"@volar/typescript": "~2.4.11",
|
|
17
|
-
"@vue/language-core": "2.2.
|
|
17
|
+
"@vue/language-core": "2.2.10",
|
|
18
18
|
"@vue/shared": "^3.5.0"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"@types/node": "^22.10.4"
|
|
22
22
|
},
|
|
23
|
-
"gitHead": "
|
|
23
|
+
"gitHead": "0422c03ffa4958431c9cd3cd19ae51f726c30b07"
|
|
24
24
|
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import * as vue from '@vue/language-core';
|
|
2
|
-
import type * as ts from 'typescript';
|
|
3
|
-
import type { RequestContext } from './types';
|
|
4
|
-
export declare function getComponentProps(this: RequestContext, fileName: string, tag: string): {
|
|
5
|
-
name: string;
|
|
6
|
-
required?: true;
|
|
7
|
-
commentMarkdown?: string;
|
|
8
|
-
}[] | undefined;
|
|
9
|
-
export declare function getComponentEvents(this: RequestContext, fileName: string, tag: string): string[] | undefined;
|
|
10
|
-
export declare function getTemplateContextProps(this: RequestContext, fileName: string): string[] | undefined;
|
|
11
|
-
export declare function getComponentNames(this: RequestContext, fileName: string): string[] | undefined;
|
|
12
|
-
export declare function _getComponentNames(ts: typeof import('typescript'), tsLs: ts.LanguageService, vueCode: vue.VueVirtualCode): string[];
|
|
13
|
-
export declare function getElementAttrs(this: RequestContext, fileName: string, tagName: string): string[] | undefined;
|
|
@@ -1,249 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getComponentProps = getComponentProps;
|
|
4
|
-
exports.getComponentEvents = getComponentEvents;
|
|
5
|
-
exports.getTemplateContextProps = getTemplateContextProps;
|
|
6
|
-
exports.getComponentNames = getComponentNames;
|
|
7
|
-
exports._getComponentNames = _getComponentNames;
|
|
8
|
-
exports.getElementAttrs = getElementAttrs;
|
|
9
|
-
const vue = require("@vue/language-core");
|
|
10
|
-
const shared_1 = require("@vue/shared");
|
|
11
|
-
function getComponentProps(fileName, tag) {
|
|
12
|
-
const { typescript: ts, language, languageService, getFileId } = this;
|
|
13
|
-
const volarFile = language.scripts.get(getFileId(fileName));
|
|
14
|
-
if (!(volarFile?.generated?.root instanceof vue.VueVirtualCode)) {
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
const vueCode = volarFile.generated.root;
|
|
18
|
-
const program = languageService.getProgram();
|
|
19
|
-
const checker = program.getTypeChecker();
|
|
20
|
-
const components = getVariableType(ts, languageService, vueCode, '__VLS_components');
|
|
21
|
-
if (!components) {
|
|
22
|
-
return [];
|
|
23
|
-
}
|
|
24
|
-
const name = tag.split('.');
|
|
25
|
-
let componentSymbol = components.type.getProperty(name[0])
|
|
26
|
-
?? components.type.getProperty((0, shared_1.camelize)(name[0]))
|
|
27
|
-
?? components.type.getProperty((0, shared_1.capitalize)((0, shared_1.camelize)(name[0])));
|
|
28
|
-
if (!componentSymbol) {
|
|
29
|
-
return [];
|
|
30
|
-
}
|
|
31
|
-
let componentType = checker.getTypeOfSymbolAtLocation(componentSymbol, components.node);
|
|
32
|
-
for (let i = 1; i < name.length; i++) {
|
|
33
|
-
componentSymbol = componentType.getProperty(name[i]);
|
|
34
|
-
if (componentSymbol) {
|
|
35
|
-
componentType = checker.getTypeOfSymbolAtLocation(componentSymbol, components.node);
|
|
36
|
-
}
|
|
37
|
-
else {
|
|
38
|
-
return [];
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
const result = new Map();
|
|
42
|
-
for (const sig of componentType.getCallSignatures()) {
|
|
43
|
-
const propParam = sig.parameters[0];
|
|
44
|
-
if (propParam) {
|
|
45
|
-
const propsType = checker.getTypeOfSymbolAtLocation(propParam, components.node);
|
|
46
|
-
const props = propsType.getProperties();
|
|
47
|
-
for (const prop of props) {
|
|
48
|
-
const name = prop.name;
|
|
49
|
-
const required = !(prop.flags & ts.SymbolFlags.Optional) || undefined;
|
|
50
|
-
const commentMarkdown = generateCommentMarkdown(prop.getDocumentationComment(checker), prop.getJsDocTags()) || undefined;
|
|
51
|
-
result.set(name, { name, required, commentMarkdown });
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
for (const sig of componentType.getConstructSignatures()) {
|
|
56
|
-
const instanceType = sig.getReturnType();
|
|
57
|
-
const propsSymbol = instanceType.getProperty('$props');
|
|
58
|
-
if (propsSymbol) {
|
|
59
|
-
const propsType = checker.getTypeOfSymbolAtLocation(propsSymbol, components.node);
|
|
60
|
-
const props = propsType.getProperties();
|
|
61
|
-
for (const prop of props) {
|
|
62
|
-
if (prop.flags & ts.SymbolFlags.Method) { // #2443
|
|
63
|
-
continue;
|
|
64
|
-
}
|
|
65
|
-
const name = prop.name;
|
|
66
|
-
const required = !(prop.flags & ts.SymbolFlags.Optional) || undefined;
|
|
67
|
-
const commentMarkdown = generateCommentMarkdown(prop.getDocumentationComment(checker), prop.getJsDocTags()) || undefined;
|
|
68
|
-
result.set(name, { name, required, commentMarkdown });
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
return [...result.values()];
|
|
73
|
-
}
|
|
74
|
-
function getComponentEvents(fileName, tag) {
|
|
75
|
-
const { typescript: ts, language, languageService, getFileId } = this;
|
|
76
|
-
const volarFile = language.scripts.get(getFileId(fileName));
|
|
77
|
-
if (!(volarFile?.generated?.root instanceof vue.VueVirtualCode)) {
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
const vueCode = volarFile.generated.root;
|
|
81
|
-
const program = languageService.getProgram();
|
|
82
|
-
const checker = program.getTypeChecker();
|
|
83
|
-
const components = getVariableType(ts, languageService, vueCode, '__VLS_components');
|
|
84
|
-
if (!components) {
|
|
85
|
-
return [];
|
|
86
|
-
}
|
|
87
|
-
const name = tag.split('.');
|
|
88
|
-
let componentSymbol = components.type.getProperty(name[0]);
|
|
89
|
-
if (!componentSymbol) {
|
|
90
|
-
componentSymbol = components.type.getProperty((0, shared_1.camelize)(name[0]))
|
|
91
|
-
?? components.type.getProperty((0, shared_1.capitalize)((0, shared_1.camelize)(name[0])));
|
|
92
|
-
}
|
|
93
|
-
if (!componentSymbol) {
|
|
94
|
-
return [];
|
|
95
|
-
}
|
|
96
|
-
let componentType = checker.getTypeOfSymbolAtLocation(componentSymbol, components.node);
|
|
97
|
-
for (let i = 1; i < name.length; i++) {
|
|
98
|
-
componentSymbol = componentType.getProperty(name[i]);
|
|
99
|
-
if (componentSymbol) {
|
|
100
|
-
componentType = checker.getTypeOfSymbolAtLocation(componentSymbol, components.node);
|
|
101
|
-
}
|
|
102
|
-
else {
|
|
103
|
-
return [];
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
const result = new Set();
|
|
107
|
-
// for (const sig of componentType.getCallSignatures()) {
|
|
108
|
-
// const emitParam = sig.parameters[1];
|
|
109
|
-
// if (emitParam) {
|
|
110
|
-
// // TODO
|
|
111
|
-
// }
|
|
112
|
-
// }
|
|
113
|
-
for (const sig of componentType.getConstructSignatures()) {
|
|
114
|
-
const instanceType = sig.getReturnType();
|
|
115
|
-
const emitSymbol = instanceType.getProperty('$emit');
|
|
116
|
-
if (emitSymbol) {
|
|
117
|
-
const emitType = checker.getTypeOfSymbolAtLocation(emitSymbol, components.node);
|
|
118
|
-
for (const call of emitType.getCallSignatures()) {
|
|
119
|
-
const eventNameParamSymbol = call.parameters[0];
|
|
120
|
-
if (eventNameParamSymbol) {
|
|
121
|
-
const eventNameParamType = checker.getTypeOfSymbolAtLocation(eventNameParamSymbol, components.node);
|
|
122
|
-
if (eventNameParamType.isStringLiteral()) {
|
|
123
|
-
result.add(eventNameParamType.value);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
return [...result];
|
|
130
|
-
}
|
|
131
|
-
function getTemplateContextProps(fileName) {
|
|
132
|
-
const { typescript: ts, language, languageService, getFileId } = this;
|
|
133
|
-
const volarFile = language.scripts.get(getFileId(fileName));
|
|
134
|
-
if (!(volarFile?.generated?.root instanceof vue.VueVirtualCode)) {
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
const vueCode = volarFile.generated.root;
|
|
138
|
-
return getVariableType(ts, languageService, vueCode, '__VLS_ctx')
|
|
139
|
-
?.type
|
|
140
|
-
?.getProperties()
|
|
141
|
-
.map(c => c.name);
|
|
142
|
-
}
|
|
143
|
-
function getComponentNames(fileName) {
|
|
144
|
-
const { typescript: ts, language, languageService, getFileId } = this;
|
|
145
|
-
const volarFile = language.scripts.get(getFileId(fileName));
|
|
146
|
-
if (!(volarFile?.generated?.root instanceof vue.VueVirtualCode)) {
|
|
147
|
-
return;
|
|
148
|
-
}
|
|
149
|
-
const vueCode = volarFile.generated.root;
|
|
150
|
-
return getVariableType(ts, languageService, vueCode, '__VLS_components')
|
|
151
|
-
?.type
|
|
152
|
-
?.getProperties()
|
|
153
|
-
.map(c => c.name)
|
|
154
|
-
.filter(entry => !entry.includes('$') && !entry.startsWith('_'))
|
|
155
|
-
?? [];
|
|
156
|
-
}
|
|
157
|
-
function _getComponentNames(ts, tsLs, vueCode) {
|
|
158
|
-
return getVariableType(ts, tsLs, vueCode, '__VLS_components')
|
|
159
|
-
?.type
|
|
160
|
-
?.getProperties()
|
|
161
|
-
.map(c => c.name)
|
|
162
|
-
.filter(entry => !entry.includes('$') && !entry.startsWith('_'))
|
|
163
|
-
?? [];
|
|
164
|
-
}
|
|
165
|
-
function getElementAttrs(fileName, tagName) {
|
|
166
|
-
const { typescript: ts, language, languageService, getFileId } = this;
|
|
167
|
-
const volarFile = language.scripts.get(getFileId(fileName));
|
|
168
|
-
if (!(volarFile?.generated?.root instanceof vue.VueVirtualCode)) {
|
|
169
|
-
return;
|
|
170
|
-
}
|
|
171
|
-
const program = languageService.getProgram();
|
|
172
|
-
let tsSourceFile;
|
|
173
|
-
if (tsSourceFile = program.getSourceFile(fileName)) {
|
|
174
|
-
const typeNode = tsSourceFile.statements.find((node) => ts.isTypeAliasDeclaration(node) && node.name.getText() === '__VLS_IntrinsicElementsCompletion');
|
|
175
|
-
const checker = program.getTypeChecker();
|
|
176
|
-
if (checker && typeNode) {
|
|
177
|
-
const type = checker.getTypeFromTypeNode(typeNode.type);
|
|
178
|
-
const el = type.getProperty(tagName);
|
|
179
|
-
if (el) {
|
|
180
|
-
const attrs = checker.getTypeOfSymbolAtLocation(el, typeNode).getProperties();
|
|
181
|
-
return attrs.map(c => c.name);
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
return [];
|
|
186
|
-
}
|
|
187
|
-
function getVariableType(ts, languageService, vueCode, name) {
|
|
188
|
-
const program = languageService.getProgram();
|
|
189
|
-
let tsSourceFile;
|
|
190
|
-
if (tsSourceFile = program.getSourceFile(vueCode.fileName)) {
|
|
191
|
-
const node = searchVariableDeclarationNode(ts, tsSourceFile, name);
|
|
192
|
-
const checker = program.getTypeChecker();
|
|
193
|
-
if (checker && node) {
|
|
194
|
-
return {
|
|
195
|
-
node: node,
|
|
196
|
-
type: checker.getTypeAtLocation(node),
|
|
197
|
-
};
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
function searchVariableDeclarationNode(ts, sourceFile, name) {
|
|
202
|
-
let componentsNode;
|
|
203
|
-
walk(sourceFile);
|
|
204
|
-
return componentsNode;
|
|
205
|
-
function walk(node) {
|
|
206
|
-
if (componentsNode) {
|
|
207
|
-
return;
|
|
208
|
-
}
|
|
209
|
-
else if (ts.isVariableDeclaration(node) && node.name.getText() === name) {
|
|
210
|
-
componentsNode = node;
|
|
211
|
-
}
|
|
212
|
-
else {
|
|
213
|
-
node.forEachChild(walk);
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
function generateCommentMarkdown(parts, jsDocTags) {
|
|
218
|
-
const parsedComment = _symbolDisplayPartsToMarkdown(parts);
|
|
219
|
-
const parsedJsDoc = _jsDocTagInfoToMarkdown(jsDocTags);
|
|
220
|
-
let result = [parsedComment, parsedJsDoc].filter(str => !!str).join('\n\n');
|
|
221
|
-
return result;
|
|
222
|
-
}
|
|
223
|
-
function _symbolDisplayPartsToMarkdown(parts) {
|
|
224
|
-
return parts.map(part => {
|
|
225
|
-
switch (part.kind) {
|
|
226
|
-
case 'keyword':
|
|
227
|
-
return `\`${part.text}\``;
|
|
228
|
-
case 'functionName':
|
|
229
|
-
return `**${part.text}**`;
|
|
230
|
-
default:
|
|
231
|
-
return part.text;
|
|
232
|
-
}
|
|
233
|
-
}).join('');
|
|
234
|
-
}
|
|
235
|
-
function _jsDocTagInfoToMarkdown(jsDocTags) {
|
|
236
|
-
return jsDocTags.map(tag => {
|
|
237
|
-
const tagName = `*@${tag.name}*`;
|
|
238
|
-
const tagText = tag.text?.map(t => {
|
|
239
|
-
if (t.kind === 'parameterName') {
|
|
240
|
-
return `\`${t.text}\``;
|
|
241
|
-
}
|
|
242
|
-
else {
|
|
243
|
-
return t.text;
|
|
244
|
-
}
|
|
245
|
-
}).join('') || '';
|
|
246
|
-
return `${tagName} ${tagText}`;
|
|
247
|
-
}).join('\n\n');
|
|
248
|
-
}
|
|
249
|
-
//# sourceMappingURL=componentInfos.js.map
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getComponentInfo = getComponentInfo;
|
|
4
|
-
const shared_1 = require("@vue/shared");
|
|
5
|
-
const getComponentEvents_1 = require("./getComponentEvents");
|
|
6
|
-
const getComponentProps_1 = require("./getComponentProps");
|
|
7
|
-
const globalProperties = [
|
|
8
|
-
'key',
|
|
9
|
-
'ref',
|
|
10
|
-
'ref_for',
|
|
11
|
-
'ref_key',
|
|
12
|
-
'class',
|
|
13
|
-
'style'
|
|
14
|
-
];
|
|
15
|
-
function getComponentInfo(fileName, tag) {
|
|
16
|
-
const props = getComponentProps_1.getComponentProps.call(this, fileName, tag, true)?.filter(({ name }) => !globalProperties.includes(name) && !(0, shared_1.hyphenate)(name).startsWith('on-vnode-'));
|
|
17
|
-
const events = getComponentEvents_1.getComponentEvents.call(this, fileName, tag);
|
|
18
|
-
return {
|
|
19
|
-
props,
|
|
20
|
-
events,
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
//# sourceMappingURL=getComponentInfo.js.map
|