@vue/typescript-plugin 3.1.2 → 3.1.3
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.js
CHANGED
|
@@ -108,12 +108,12 @@ module.exports = (0, createLanguageServicePlugin_1.createLanguageServicePlugin)(
|
|
|
108
108
|
session.addProtocolHandler('_vue:getElementAttrs', request => {
|
|
109
109
|
const [fileName, tag] = request.arguments;
|
|
110
110
|
const { project } = getProject(fileName);
|
|
111
|
-
return createResponse((0, getElementAttrs_1.getElementAttrs)(ts, project.getLanguageService().getProgram(),
|
|
111
|
+
return createResponse((0, getElementAttrs_1.getElementAttrs)(ts, project.getLanguageService().getProgram(), tag));
|
|
112
112
|
});
|
|
113
113
|
session.addProtocolHandler('_vue:getElementNames', request => {
|
|
114
114
|
const [fileName] = request.arguments;
|
|
115
115
|
const { project } = getProject(fileName);
|
|
116
|
-
return createResponse((0, getElementNames_1.getElementNames)(ts, project.getLanguageService().getProgram()
|
|
116
|
+
return createResponse((0, getElementNames_1.getElementNames)(ts, project.getLanguageService().getProgram()));
|
|
117
117
|
});
|
|
118
118
|
projectService.logger.info('Vue specific commands are successfully added.');
|
|
119
119
|
function createResponse(res) {
|
package/lib/common.js
CHANGED
|
@@ -8,6 +8,8 @@ function createVueLanguageServiceProxy(ts, language, languageService, vueOptions
|
|
|
8
8
|
const proxyCache = new Map();
|
|
9
9
|
const getProxyMethod = (target, p) => {
|
|
10
10
|
switch (p) {
|
|
11
|
+
case 'findReferences':
|
|
12
|
+
return findReferences(ts, language, languageService, asScriptId, target[p]);
|
|
11
13
|
case 'getCompletionsAtPosition':
|
|
12
14
|
return getCompletionsAtPosition(ts, language, asScriptId, vueOptions, target[p]);
|
|
13
15
|
case 'getCompletionEntryDetails':
|
|
@@ -15,7 +17,7 @@ function createVueLanguageServiceProxy(ts, language, languageService, vueOptions
|
|
|
15
17
|
case 'getCodeFixesAtPosition':
|
|
16
18
|
return getCodeFixesAtPosition(target[p]);
|
|
17
19
|
case 'getDefinitionAndBoundSpan':
|
|
18
|
-
return getDefinitionAndBoundSpan(ts, language, asScriptId,
|
|
20
|
+
return getDefinitionAndBoundSpan(ts, language, asScriptId, target[p]);
|
|
19
21
|
}
|
|
20
22
|
};
|
|
21
23
|
return new Proxy(languageService, {
|
|
@@ -34,6 +36,46 @@ function createVueLanguageServiceProxy(ts, language, languageService, vueOptions
|
|
|
34
36
|
},
|
|
35
37
|
});
|
|
36
38
|
}
|
|
39
|
+
function findReferences(ts, language, languageService, asScriptId, findReferences) {
|
|
40
|
+
return (fileName, position) => {
|
|
41
|
+
const result = findReferences(fileName, position);
|
|
42
|
+
const sourceScript = language.scripts.get(asScriptId(fileName));
|
|
43
|
+
const root = sourceScript?.generated?.root;
|
|
44
|
+
if (!(root instanceof language_core_1.VueVirtualCode)) {
|
|
45
|
+
return result;
|
|
46
|
+
}
|
|
47
|
+
const { template } = root.sfc;
|
|
48
|
+
if (template) {
|
|
49
|
+
const textSpan = {
|
|
50
|
+
start: template.start + 1,
|
|
51
|
+
length: 'template'.length,
|
|
52
|
+
};
|
|
53
|
+
if (position >= textSpan.start && position <= textSpan.start + textSpan.length) {
|
|
54
|
+
result?.push({
|
|
55
|
+
definition: {
|
|
56
|
+
fileName,
|
|
57
|
+
textSpan,
|
|
58
|
+
kind: ts.ScriptElementKind.scriptElement,
|
|
59
|
+
name: fileName,
|
|
60
|
+
containerKind: ts.ScriptElementKind.unknown,
|
|
61
|
+
containerName: '',
|
|
62
|
+
displayParts: [],
|
|
63
|
+
},
|
|
64
|
+
references: [
|
|
65
|
+
{
|
|
66
|
+
fileName,
|
|
67
|
+
textSpan,
|
|
68
|
+
isDefinition: true,
|
|
69
|
+
isWriteAccess: false,
|
|
70
|
+
},
|
|
71
|
+
...languageService.getFileReferences(fileName),
|
|
72
|
+
],
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return result;
|
|
77
|
+
};
|
|
78
|
+
}
|
|
37
79
|
function getCompletionsAtPosition(ts, language, asScriptId, vueOptions, getCompletionsAtPosition) {
|
|
38
80
|
return (filePath, position, options, formattingSettings) => {
|
|
39
81
|
const fileName = filePath.replace(windowsPathReg, '/');
|
|
@@ -151,84 +193,56 @@ function getCodeFixesAtPosition(getCodeFixesAtPosition) {
|
|
|
151
193
|
return result;
|
|
152
194
|
};
|
|
153
195
|
}
|
|
154
|
-
function getDefinitionAndBoundSpan(ts, language, asScriptId,
|
|
196
|
+
function getDefinitionAndBoundSpan(ts, language, asScriptId, getDefinitionAndBoundSpan) {
|
|
155
197
|
return (fileName, position) => {
|
|
156
198
|
const result = getDefinitionAndBoundSpan(fileName, position);
|
|
157
|
-
if (!result?.definitions?.length) {
|
|
158
|
-
return result;
|
|
159
|
-
}
|
|
160
|
-
const program = languageService.getProgram();
|
|
161
199
|
const sourceScript = language.scripts.get(asScriptId(fileName));
|
|
162
|
-
|
|
163
|
-
return result;
|
|
164
|
-
}
|
|
165
|
-
const root = sourceScript.generated.root;
|
|
200
|
+
const root = sourceScript?.generated?.root;
|
|
166
201
|
if (!(root instanceof language_core_1.VueVirtualCode)) {
|
|
167
202
|
return result;
|
|
168
203
|
}
|
|
204
|
+
if (!result?.definitions?.length) {
|
|
205
|
+
const { template } = root.sfc;
|
|
206
|
+
if (template) {
|
|
207
|
+
const textSpan = {
|
|
208
|
+
start: template.start + 1,
|
|
209
|
+
length: 'template'.length,
|
|
210
|
+
};
|
|
211
|
+
if (position >= textSpan.start && position <= textSpan.start + textSpan.length) {
|
|
212
|
+
return {
|
|
213
|
+
textSpan,
|
|
214
|
+
definitions: [{
|
|
215
|
+
fileName,
|
|
216
|
+
textSpan,
|
|
217
|
+
kind: ts.ScriptElementKind.scriptElement,
|
|
218
|
+
name: fileName,
|
|
219
|
+
containerKind: ts.ScriptElementKind.unknown,
|
|
220
|
+
containerName: '',
|
|
221
|
+
}],
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
169
227
|
if (!root.sfc.template
|
|
170
228
|
|| position < root.sfc.template.startTagEnd
|
|
171
229
|
|| position > root.sfc.template.endTagStart) {
|
|
172
230
|
return result;
|
|
173
231
|
}
|
|
174
232
|
const definitions = new Set(result.definitions);
|
|
175
|
-
const skippedDefinitions = [];
|
|
176
233
|
// #5275
|
|
177
234
|
if (result.definitions.length >= 2) {
|
|
178
235
|
for (const definition of result.definitions) {
|
|
179
236
|
if (root.sfc.content[definition.textSpan.start - 1] === '@'
|
|
180
237
|
|| root.sfc.content.slice(definition.textSpan.start - 5, definition.textSpan.start) === 'v-on:') {
|
|
181
|
-
|
|
238
|
+
definitions.delete(definition);
|
|
182
239
|
}
|
|
183
240
|
}
|
|
184
241
|
}
|
|
185
|
-
for (const definition of result.definitions) {
|
|
186
|
-
if (vueOptions.extensions.some(ext => definition.fileName.endsWith(ext))) {
|
|
187
|
-
continue;
|
|
188
|
-
}
|
|
189
|
-
const sourceFile = program.getSourceFile(definition.fileName);
|
|
190
|
-
if (!sourceFile) {
|
|
191
|
-
continue;
|
|
192
|
-
}
|
|
193
|
-
visit(sourceFile, definition, sourceFile);
|
|
194
|
-
}
|
|
195
|
-
for (const definition of skippedDefinitions) {
|
|
196
|
-
definitions.delete(definition);
|
|
197
|
-
}
|
|
198
242
|
return {
|
|
199
243
|
definitions: [...definitions],
|
|
200
244
|
textSpan: result.textSpan,
|
|
201
245
|
};
|
|
202
|
-
function visit(node, definition, sourceFile) {
|
|
203
|
-
if (ts.isPropertySignature(node) && node.type) {
|
|
204
|
-
proxy(node.name, node.type, definition, sourceFile);
|
|
205
|
-
}
|
|
206
|
-
else if (ts.isVariableDeclaration(node) && ts.isIdentifier(node.name) && node.type && !node.initializer) {
|
|
207
|
-
proxy(node.name, node.type, definition, sourceFile);
|
|
208
|
-
}
|
|
209
|
-
else {
|
|
210
|
-
ts.forEachChild(node, child => visit(child, definition, sourceFile));
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
function proxy(name, type, definition, sourceFile) {
|
|
214
|
-
const { textSpan, fileName } = definition;
|
|
215
|
-
const start = name.getStart(sourceFile);
|
|
216
|
-
const end = name.getEnd();
|
|
217
|
-
if (start !== textSpan.start || end - start !== textSpan.length) {
|
|
218
|
-
return;
|
|
219
|
-
}
|
|
220
|
-
if (!ts.isIndexedAccessTypeNode(type)) {
|
|
221
|
-
return;
|
|
222
|
-
}
|
|
223
|
-
const pos = type.indexType.getStart(sourceFile);
|
|
224
|
-
const res = getDefinitionAndBoundSpan(fileName, pos);
|
|
225
|
-
if (res?.definitions?.length) {
|
|
226
|
-
for (const definition of res.definitions) {
|
|
227
|
-
definitions.add(definition);
|
|
228
|
-
}
|
|
229
|
-
skippedDefinitions.push(definition);
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
246
|
};
|
|
233
247
|
}
|
|
234
248
|
//# sourceMappingURL=common.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type * as ts from 'typescript';
|
|
2
|
-
export declare function getElementAttrs(ts: typeof import('typescript'), program: ts.Program,
|
|
2
|
+
export declare function getElementAttrs(ts: typeof import('typescript'), program: ts.Program, tag: string): string[];
|
|
@@ -1,18 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getElementAttrs = getElementAttrs;
|
|
4
|
-
|
|
5
|
-
function getElementAttrs(ts, program, fileName, tag) {
|
|
4
|
+
function getElementAttrs(ts, program, tag) {
|
|
6
5
|
const checker = program.getTypeChecker();
|
|
7
|
-
const elements =
|
|
6
|
+
const elements = checker.resolveName('__VLS_intrinsics', undefined, ts.SymbolFlags.Variable, false);
|
|
8
7
|
if (!elements) {
|
|
9
8
|
return [];
|
|
10
9
|
}
|
|
11
|
-
const elementType = elements.
|
|
10
|
+
const elementType = checker.getTypeOfSymbol(elements).getProperty(tag);
|
|
12
11
|
if (!elementType) {
|
|
13
12
|
return [];
|
|
14
13
|
}
|
|
15
|
-
|
|
16
|
-
return attrs.map(c => c.name);
|
|
14
|
+
return checker.getTypeOfSymbol(elementType).getProperties().map(c => c.name);
|
|
17
15
|
}
|
|
18
16
|
//# sourceMappingURL=getElementAttrs.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type * as ts from 'typescript';
|
|
2
|
-
export declare function getElementNames(ts: typeof import('typescript'), program: ts.Program
|
|
2
|
+
export declare function getElementNames(ts: typeof import('typescript'), program: ts.Program): string[];
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getElementNames = getElementNames;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
function getElementNames(ts, program) {
|
|
5
|
+
const checker = program.getTypeChecker();
|
|
6
|
+
const elements = checker.resolveName('__VLS_intrinsics', undefined, ts.SymbolFlags.Variable, false);
|
|
7
|
+
if (!elements) {
|
|
8
|
+
return [];
|
|
9
|
+
}
|
|
10
|
+
return checker.getTypeOfSymbol(elements).getProperties().map(c => c.name);
|
|
11
11
|
}
|
|
12
12
|
//# sourceMappingURL=getElementNames.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vue/typescript-plugin",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.3",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"**/*.js",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"@volar/typescript": "2.4.23",
|
|
17
|
-
"@vue/language-core": "3.1.
|
|
17
|
+
"@vue/language-core": "3.1.3",
|
|
18
18
|
"@vue/shared": "^3.5.0",
|
|
19
19
|
"path-browserify": "^1.0.1"
|
|
20
20
|
},
|
|
@@ -22,5 +22,5 @@
|
|
|
22
22
|
"@types/node": "^22.10.4",
|
|
23
23
|
"@types/path-browserify": "^1.0.1"
|
|
24
24
|
},
|
|
25
|
-
"gitHead": "
|
|
25
|
+
"gitHead": "0d7edee43568f1d90adae6e8fcda0f7f565b3f6a"
|
|
26
26
|
}
|