@vue/typescript-plugin 2.2.8 → 3.0.0-alpha.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/index.d.ts +2 -2
- package/index.js +102 -9
- package/lib/common.d.ts +1 -3
- package/lib/common.js +75 -2
- package/lib/requests/getElementAttrs.js +14 -17
- package/lib/requests/getElementNames.d.ts +5 -0
- package/lib/requests/getElementNames.js +23 -0
- package/lib/requests/getPropertiesAtLocation.js +1 -0
- package/lib/requests/index.d.ts +14 -0
- package/lib/requests/index.js +3 -0
- package/lib/requests/utils.js +8 -8
- package/package.json +3 -3
- package/lib/client.d.ts +0 -13
- package/lib/client.js +0 -42
- 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
- package/lib/server.d.ts +0 -25
- package/lib/server.js +0 -260
- package/lib/utils.d.ts +0 -31
- package/lib/utils.js +0 -250
package/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type * as ts from 'typescript';
|
|
2
|
-
declare const
|
|
3
|
-
export =
|
|
2
|
+
declare const _default: ts.server.PluginModuleFactory;
|
|
3
|
+
export = _default;
|
package/index.js
CHANGED
|
@@ -2,21 +2,27 @@
|
|
|
2
2
|
const createLanguageServicePlugin_1 = require("@volar/typescript/lib/quickstart/createLanguageServicePlugin");
|
|
3
3
|
const vue = require("@vue/language-core");
|
|
4
4
|
const common_1 = require("./lib/common");
|
|
5
|
-
const
|
|
5
|
+
const collectExtractProps_1 = require("./lib/requests/collectExtractProps");
|
|
6
|
+
const getComponentDirectives_1 = require("./lib/requests/getComponentDirectives");
|
|
7
|
+
const getComponentEvents_1 = require("./lib/requests/getComponentEvents");
|
|
8
|
+
const getComponentNames_1 = require("./lib/requests/getComponentNames");
|
|
9
|
+
const getComponentProps_1 = require("./lib/requests/getComponentProps");
|
|
10
|
+
const getElementAttrs_1 = require("./lib/requests/getElementAttrs");
|
|
11
|
+
const getElementNames_1 = require("./lib/requests/getElementNames");
|
|
12
|
+
const getImportPathForFile_1 = require("./lib/requests/getImportPathForFile");
|
|
13
|
+
const getPropertiesAtLocation_1 = require("./lib/requests/getPropertiesAtLocation");
|
|
14
|
+
const getQuickInfoAtPosition_1 = require("./lib/requests/getQuickInfoAtPosition");
|
|
6
15
|
const windowsPathReg = /\\/g;
|
|
7
|
-
const
|
|
8
|
-
|
|
16
|
+
const project2Service = new WeakMap();
|
|
17
|
+
module.exports = (0, createLanguageServicePlugin_1.createLanguageServicePlugin)((ts, info) => {
|
|
9
18
|
const vueOptions = getVueCompilerOptions();
|
|
10
19
|
const languagePlugin = vue.createVueLanguagePlugin(ts, info.languageServiceHost.getCompilationSettings(), vueOptions, id => id);
|
|
11
|
-
|
|
20
|
+
addVueCommands();
|
|
12
21
|
return {
|
|
13
22
|
languagePlugins: [languagePlugin],
|
|
14
23
|
setup: language => {
|
|
24
|
+
project2Service.set(info.project, [language, info.languageServiceHost, info.languageService]);
|
|
15
25
|
info.languageService = (0, common_1.proxyLanguageServiceForVue)(ts, language, info.languageService, vueOptions, fileName => fileName);
|
|
16
|
-
if (info.project.projectKind === ts.server.ProjectKind.Configured
|
|
17
|
-
|| info.project.projectKind === ts.server.ProjectKind.Inferred) {
|
|
18
|
-
(0, server_1.startNamedPipeServer)(ts, info, language, info.project.projectKind);
|
|
19
|
-
}
|
|
20
26
|
// #3963
|
|
21
27
|
const timer = setInterval(() => {
|
|
22
28
|
if (info.project['program']) {
|
|
@@ -35,6 +41,93 @@ const plugin = (0, createLanguageServicePlugin_1.createLanguageServicePlugin)((t
|
|
|
35
41
|
return vue.createParsedCommandLineByJson(ts, ts.sys, info.languageServiceHost.getCurrentDirectory(), {}).vueOptions;
|
|
36
42
|
}
|
|
37
43
|
}
|
|
44
|
+
// https://github.com/JetBrains/intellij-plugins/blob/6435723ad88fa296b41144162ebe3b8513f4949b/Angular/src-js/angular-service/src/index.ts#L69
|
|
45
|
+
function addVueCommands() {
|
|
46
|
+
const projectService = info.project.projectService;
|
|
47
|
+
projectService.logger.info("Vue: called handler processing " + info.project.projectKind);
|
|
48
|
+
const session = info.session;
|
|
49
|
+
if (session == undefined) {
|
|
50
|
+
projectService.logger.info("Vue: there is no session in info.");
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
if (session.addProtocolHandler == undefined) {
|
|
54
|
+
// addProtocolHandler was introduced in TS 4.4 or 4.5 in 2021, see https://github.com/microsoft/TypeScript/issues/43893
|
|
55
|
+
projectService.logger.info("Vue: there is no addProtocolHandler method.");
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if (session.vueCommandsAdded) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
session.vueCommandsAdded = true;
|
|
62
|
+
session.addProtocolHandler('vue:collectExtractProps', ({ arguments: args }) => {
|
|
63
|
+
return {
|
|
64
|
+
response: collectExtractProps_1.collectExtractProps.apply(getRequestContext(args[0]), args),
|
|
65
|
+
};
|
|
66
|
+
});
|
|
67
|
+
session.addProtocolHandler('vue:getImportPathForFile', ({ arguments: args }) => {
|
|
68
|
+
return {
|
|
69
|
+
response: getImportPathForFile_1.getImportPathForFile.apply(getRequestContext(args[0]), args),
|
|
70
|
+
};
|
|
71
|
+
});
|
|
72
|
+
session.addProtocolHandler('vue:getPropertiesAtLocation', ({ arguments: args }) => {
|
|
73
|
+
return {
|
|
74
|
+
response: getPropertiesAtLocation_1.getPropertiesAtLocation.apply(getRequestContext(args[0]), args),
|
|
75
|
+
};
|
|
76
|
+
});
|
|
77
|
+
session.addProtocolHandler('vue:getQuickInfoAtPosition', ({ arguments: args }) => {
|
|
78
|
+
return {
|
|
79
|
+
response: getQuickInfoAtPosition_1.getQuickInfoAtPosition.apply(getRequestContext(args[0]), args),
|
|
80
|
+
};
|
|
81
|
+
});
|
|
82
|
+
session.addProtocolHandler('vue:getComponentNames', ({ arguments: args }) => {
|
|
83
|
+
return {
|
|
84
|
+
response: getComponentNames_1.getComponentNames.apply(getRequestContext(args[0]), args) ?? [],
|
|
85
|
+
};
|
|
86
|
+
});
|
|
87
|
+
session.addProtocolHandler('vue:getComponentProps', ({ arguments: args }) => {
|
|
88
|
+
return {
|
|
89
|
+
response: getComponentProps_1.getComponentProps.apply(getRequestContext(args[0]), args),
|
|
90
|
+
};
|
|
91
|
+
});
|
|
92
|
+
session.addProtocolHandler('vue:getComponentEvents', ({ arguments: args }) => {
|
|
93
|
+
return {
|
|
94
|
+
response: getComponentEvents_1.getComponentEvents.apply(getRequestContext(args[0]), args),
|
|
95
|
+
};
|
|
96
|
+
});
|
|
97
|
+
session.addProtocolHandler('vue:getComponentDirectives', ({ arguments: args }) => {
|
|
98
|
+
return {
|
|
99
|
+
response: getComponentDirectives_1.getComponentDirectives.apply(getRequestContext(args[0]), args),
|
|
100
|
+
};
|
|
101
|
+
});
|
|
102
|
+
session.addProtocolHandler('vue:getElementAttrs', ({ arguments: args }) => {
|
|
103
|
+
return {
|
|
104
|
+
response: getElementAttrs_1.getElementAttrs.apply(getRequestContext(args[0]), args),
|
|
105
|
+
};
|
|
106
|
+
});
|
|
107
|
+
session.addProtocolHandler('vue:getElementNames', ({ arguments: args }) => {
|
|
108
|
+
return {
|
|
109
|
+
response: getElementNames_1.getElementNames.apply(getRequestContext(args[0]), args),
|
|
110
|
+
};
|
|
111
|
+
});
|
|
112
|
+
projectService.logger.info('Vue specific commands are successfully added.');
|
|
113
|
+
}
|
|
114
|
+
function getRequestContext(fileName) {
|
|
115
|
+
const fileAndProject = info.session.getFileAndProject({
|
|
116
|
+
file: fileName,
|
|
117
|
+
projectFileName: undefined,
|
|
118
|
+
});
|
|
119
|
+
const service = project2Service.get(fileAndProject.project);
|
|
120
|
+
if (!service) {
|
|
121
|
+
throw 'No RequestContext';
|
|
122
|
+
}
|
|
123
|
+
return {
|
|
124
|
+
typescript: ts,
|
|
125
|
+
languageService: service[2],
|
|
126
|
+
languageServiceHost: service[1],
|
|
127
|
+
language: service[0],
|
|
128
|
+
isTsPlugin: true,
|
|
129
|
+
getFileId: (fileName) => fileName,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
38
132
|
});
|
|
39
|
-
module.exports = plugin;
|
|
40
133
|
//# sourceMappingURL=index.js.map
|
package/lib/common.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { Language, VueCompilerOptions
|
|
1
|
+
import { Language, VueCompilerOptions } from '@vue/language-core';
|
|
2
2
|
import type * as ts from 'typescript';
|
|
3
|
-
import type { RequestContext } from './requests/types';
|
|
4
3
|
export declare function proxyLanguageServiceForVue<T>(ts: typeof import('typescript'), language: Language<T>, languageService: ts.LanguageService, vueOptions: VueCompilerOptions, asScriptId: (fileName: string) => T): ts.LanguageService;
|
|
5
|
-
export declare function getComponentSpans(this: Pick<RequestContext, 'typescript' | 'languageService'>, vueCode: VueVirtualCode, template: NonNullable<VueVirtualCode['_sfc']['template']>, spanTemplateRange: ts.TextSpan): ts.TextSpan[];
|
package/lib/common.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.proxyLanguageServiceForVue = proxyLanguageServiceForVue;
|
|
4
|
-
exports.getComponentSpans = getComponentSpans;
|
|
5
4
|
const language_core_1 = require("@vue/language-core");
|
|
6
5
|
const shared_1 = require("@vue/shared");
|
|
7
6
|
const getComponentNames_1 = require("./requests/getComponentNames");
|
|
7
|
+
const getElementNames_1 = require("./requests/getElementNames");
|
|
8
8
|
const windowsPathReg = /\\/g;
|
|
9
9
|
function proxyLanguageServiceForVue(ts, language, languageService, vueOptions, asScriptId) {
|
|
10
10
|
const proxyCache = new Map();
|
|
@@ -13,6 +13,7 @@ function proxyLanguageServiceForVue(ts, language, languageService, vueOptions, a
|
|
|
13
13
|
case 'getCompletionsAtPosition': return getCompletionsAtPosition(vueOptions, target[p]);
|
|
14
14
|
case 'getCompletionEntryDetails': return getCompletionEntryDetails(language, asScriptId, target[p]);
|
|
15
15
|
case 'getCodeFixesAtPosition': return getCodeFixesAtPosition(target[p]);
|
|
16
|
+
case 'getDefinitionAndBoundSpan': return getDefinitionAndBoundSpan(ts, language, languageService, vueOptions, asScriptId, target[p]);
|
|
16
17
|
case 'getQuickInfoAtPosition': return getQuickInfoAtPosition(ts, target, target[p]);
|
|
17
18
|
// TS plugin only
|
|
18
19
|
case 'getEncodedSemanticClassifications': return getEncodedSemanticClassifications(ts, language, target, asScriptId, target[p]);
|
|
@@ -128,6 +129,77 @@ function getCodeFixesAtPosition(getCodeFixesAtPosition) {
|
|
|
128
129
|
return result;
|
|
129
130
|
};
|
|
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
|
+
for (const definition of result.definitions) {
|
|
155
|
+
if (vueOptions.extensions.some(ext => definition.fileName.endsWith(ext))) {
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
const sourceFile = program.getSourceFile(definition.fileName);
|
|
159
|
+
if (!sourceFile) {
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
visit(sourceFile, definition, sourceFile);
|
|
163
|
+
}
|
|
164
|
+
for (const definition of skippedDefinitions) {
|
|
165
|
+
definitions.delete(definition);
|
|
166
|
+
}
|
|
167
|
+
return {
|
|
168
|
+
definitions: [...definitions],
|
|
169
|
+
textSpan: result.textSpan,
|
|
170
|
+
};
|
|
171
|
+
function visit(node, definition, sourceFile) {
|
|
172
|
+
if (ts.isPropertySignature(node) && node.type) {
|
|
173
|
+
proxy(node.name, node.type, definition, sourceFile);
|
|
174
|
+
}
|
|
175
|
+
else if (ts.isVariableDeclaration(node) && ts.isIdentifier(node.name) && node.type && !node.initializer) {
|
|
176
|
+
proxy(node.name, node.type, definition, sourceFile);
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
ts.forEachChild(node, child => visit(child, definition, sourceFile));
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
function proxy(name, type, definition, sourceFile) {
|
|
183
|
+
const { textSpan, fileName } = definition;
|
|
184
|
+
const start = name.getStart(sourceFile);
|
|
185
|
+
const end = name.getEnd();
|
|
186
|
+
if (start !== textSpan.start || end - start !== textSpan.length) {
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
if (!ts.isIndexedAccessTypeNode(type)) {
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
const pos = type.indexType.getStart(sourceFile);
|
|
193
|
+
const res = getDefinitionAndBoundSpan(fileName, pos);
|
|
194
|
+
if (res?.definitions?.length) {
|
|
195
|
+
for (const definition of res.definitions) {
|
|
196
|
+
definitions.add(definition);
|
|
197
|
+
}
|
|
198
|
+
skippedDefinitions.push(definition);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
}
|
|
131
203
|
function getQuickInfoAtPosition(ts, languageService, getQuickInfoAtPosition) {
|
|
132
204
|
return (...args) => {
|
|
133
205
|
const result = getQuickInfoAtPosition(...args);
|
|
@@ -191,6 +263,7 @@ function getComponentSpans(vueCode, template, spanTemplateRange) {
|
|
|
191
263
|
const { typescript: ts, languageService } = this;
|
|
192
264
|
const result = [];
|
|
193
265
|
const validComponentNames = (0, getComponentNames_1._getComponentNames)(ts, languageService, vueCode);
|
|
266
|
+
const elements = new Set((0, getElementNames_1._getElementNames)(ts, languageService, vueCode));
|
|
194
267
|
const components = new Set([
|
|
195
268
|
...validComponentNames,
|
|
196
269
|
...validComponentNames.map(language_core_1.hyphenateTag),
|
|
@@ -200,7 +273,7 @@ function getComponentSpans(vueCode, template, spanTemplateRange) {
|
|
|
200
273
|
if (node.loc.end.offset <= spanTemplateRange.start || node.loc.start.offset >= (spanTemplateRange.start + spanTemplateRange.length)) {
|
|
201
274
|
continue;
|
|
202
275
|
}
|
|
203
|
-
if (components.has(node.tag)) {
|
|
276
|
+
if (components.has(node.tag) && !elements.has(node.tag)) {
|
|
204
277
|
let start = node.loc.start.offset;
|
|
205
278
|
if (template.lang === 'html') {
|
|
206
279
|
start += '<'.length;
|
|
@@ -1,29 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getElementAttrs = getElementAttrs;
|
|
4
|
-
const
|
|
4
|
+
const language_core_1 = require("@vue/language-core");
|
|
5
|
+
const utils_1 = require("./utils");
|
|
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
|
}
|
|
12
|
+
const vueCode = volarFile.generated.root;
|
|
11
13
|
const program = languageService.getProgram();
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
.filter(ts.isTypeAliasDeclaration)
|
|
17
|
-
.find(node => node.name.getText() === '__VLS_IntrinsicElementsCompletion');
|
|
18
|
-
if (checker && typeNode) {
|
|
19
|
-
const type = checker.getTypeFromTypeNode(typeNode.type);
|
|
20
|
-
const el = type.getProperty(tagName);
|
|
21
|
-
if (el) {
|
|
22
|
-
const attrs = checker.getTypeOfSymbolAtLocation(el, typeNode).getProperties();
|
|
23
|
-
return attrs.map(c => c.name);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
14
|
+
const checker = program.getTypeChecker();
|
|
15
|
+
const elements = (0, utils_1.getVariableType)(ts, languageService, vueCode, '__VLS_elements');
|
|
16
|
+
if (!elements) {
|
|
17
|
+
return [];
|
|
26
18
|
}
|
|
27
|
-
|
|
19
|
+
const elementType = elements.type.getProperty(tagName);
|
|
20
|
+
if (!elementType) {
|
|
21
|
+
return [];
|
|
22
|
+
}
|
|
23
|
+
const attrs = checker.getTypeOfSymbol(elementType).getProperties();
|
|
24
|
+
return attrs.map(c => c.name);
|
|
28
25
|
}
|
|
29
26
|
//# 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,14 @@
|
|
|
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
|
+
getQuickInfoAtPosition: ToRequest<typeof import('./getQuickInfoAtPosition.js')['getQuickInfoAtPosition']>;
|
|
7
|
+
getComponentNames: ToRequest<typeof import('./getComponentNames.js')['getComponentNames']>;
|
|
8
|
+
getComponentProps: ToRequest<typeof import('./getComponentProps.js')['getComponentProps']>;
|
|
9
|
+
getComponentEvents: ToRequest<typeof import('./getComponentEvents.js')['getComponentEvents']>;
|
|
10
|
+
getComponentDirectives: ToRequest<typeof import('./getComponentDirectives.js')['getComponentDirectives']>;
|
|
11
|
+
getElementAttrs: ToRequest<typeof import('./getElementAttrs.js')['getElementAttrs']>;
|
|
12
|
+
getElementNames: ToRequest<typeof import('./getElementNames.js')['getElementNames']>;
|
|
13
|
+
};
|
|
14
|
+
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": "
|
|
3
|
+
"version": "3.0.0-alpha.0",
|
|
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": "
|
|
17
|
+
"@vue/language-core": "3.0.0-alpha.0",
|
|
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": "4b49cbe09097e482def4603b90f6c3b93bb2e913"
|
|
24
24
|
}
|
package/lib/client.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export declare const collectExtractProps: (fileName: string, templateCodeRange: [number, number]) => Promise<{
|
|
2
|
-
name: string;
|
|
3
|
-
type: string;
|
|
4
|
-
model: boolean;
|
|
5
|
-
}[] | null | undefined>;
|
|
6
|
-
export declare const getImportPathForFile: (fileName: string, incomingFileName: string, preferences: import("typescript").UserPreferences) => Promise<string | null | undefined>;
|
|
7
|
-
export declare const getPropertiesAtLocation: (fileName: string, position: number) => Promise<string[] | null | undefined>;
|
|
8
|
-
export declare const getQuickInfoAtPosition: (fileName: string, position: number) => Promise<string | null | undefined>;
|
|
9
|
-
export declare function getComponentProps(fileName: string, componentName: string): Promise<import("./requests/getComponentProps").ComponentPropInfo[] | null | undefined>;
|
|
10
|
-
export declare const getComponentEvents: (fileName: string, tag: string) => Promise<string[] | null | undefined>;
|
|
11
|
-
export declare const getComponentDirectives: (fileName: string) => Promise<string[] | null | undefined>;
|
|
12
|
-
export declare function getComponentNames(fileName: string): Promise<string[] | undefined>;
|
|
13
|
-
export declare const getElementAttrs: (fileName: string, tagName: string) => Promise<string[] | null | undefined>;
|
package/lib/client.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getElementAttrs = exports.getComponentDirectives = exports.getComponentEvents = exports.getQuickInfoAtPosition = exports.getPropertiesAtLocation = exports.getImportPathForFile = exports.collectExtractProps = void 0;
|
|
4
|
-
exports.getComponentProps = getComponentProps;
|
|
5
|
-
exports.getComponentNames = getComponentNames;
|
|
6
|
-
const utils_1 = require("./utils");
|
|
7
|
-
exports.collectExtractProps = createRequest('collectExtractProps');
|
|
8
|
-
exports.getImportPathForFile = createRequest('getImportPathForFile');
|
|
9
|
-
exports.getPropertiesAtLocation = createRequest('getPropertiesAtLocation');
|
|
10
|
-
exports.getQuickInfoAtPosition = createRequest('getQuickInfoAtPosition');
|
|
11
|
-
// Component Infos
|
|
12
|
-
async function getComponentProps(fileName, componentName) {
|
|
13
|
-
const server = await (0, utils_1.getBestServer)(fileName);
|
|
14
|
-
if (!server) {
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
return await server.getComponentProps(fileName, componentName);
|
|
18
|
-
}
|
|
19
|
-
exports.getComponentEvents = createRequest('getComponentEvents');
|
|
20
|
-
exports.getComponentDirectives = createRequest('getComponentDirectives');
|
|
21
|
-
async function getComponentNames(fileName) {
|
|
22
|
-
const server = await (0, utils_1.getBestServer)(fileName);
|
|
23
|
-
if (!server) {
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
const componentAndProps = server.componentNamesAndProps.get(fileName);
|
|
27
|
-
if (!componentAndProps) {
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
return Object.keys(componentAndProps);
|
|
31
|
-
}
|
|
32
|
-
exports.getElementAttrs = createRequest('getElementAttrs');
|
|
33
|
-
function createRequest(requestType) {
|
|
34
|
-
return async function (...[fileName, ...rest]) {
|
|
35
|
-
const server = await (0, utils_1.getBestServer)(fileName);
|
|
36
|
-
if (!server) {
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
return server.sendRequest(requestType, fileName, ...rest);
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
//# sourceMappingURL=client.js.map
|
|
@@ -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;
|