@vue/typescript-plugin 2.2.0 → 2.2.2
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/client.d.ts +8 -12
- package/lib/client.js +16 -34
- package/lib/common.js +3 -3
- package/lib/index.d.ts +3 -0
- package/lib/index.js +39 -0
- package/lib/requests/componentInfos.d.ts +6 -4
- package/lib/requests/componentInfos.js +71 -52
- package/lib/requests/getComponentDirectives.d.ts +2 -0
- package/lib/requests/getComponentDirectives.js +22 -0
- package/lib/requests/getComponentEvents.d.ts +2 -0
- package/lib/requests/getComponentEvents.js +48 -0
- package/lib/requests/getComponentNames.d.ts +5 -0
- package/lib/requests/getComponentNames.js +26 -0
- package/lib/requests/getComponentProps.d.ts +9 -0
- package/lib/requests/getComponentProps.js +102 -0
- package/lib/requests/getElementAttrs.d.ts +2 -0
- package/lib/requests/getElementAttrs.js +29 -0
- package/lib/requests/getSlotNames.d.ts +6 -0
- package/lib/requests/getSlotNames.js +30 -0
- package/lib/requests/goToDefinition.d.ts +2 -0
- package/lib/requests/goToDefinition.js +26 -0
- package/lib/requests/utils.d.ts +8 -0
- package/lib/requests/utils.js +67 -0
- package/lib/server.d.ts +1 -1
- package/lib/server.js +13 -9
- package/lib/utils.d.ts +3 -10
- package/package.json +4 -4
package/lib/client.d.ts
CHANGED
|
@@ -1,17 +1,13 @@
|
|
|
1
|
-
export declare
|
|
1
|
+
export declare const collectExtractProps: (fileName: string, templateCodeRange: [number, number]) => Promise<{
|
|
2
2
|
name: string;
|
|
3
3
|
type: string;
|
|
4
4
|
model: boolean;
|
|
5
5
|
}[] | null | undefined>;
|
|
6
|
-
export declare
|
|
7
|
-
export declare
|
|
8
|
-
export declare
|
|
9
|
-
export declare function getComponentProps(fileName: string, componentName: string): Promise<
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
commentMarkdown?: string;
|
|
13
|
-
}[] | null | undefined>;
|
|
14
|
-
export declare function getComponentEvents(...args: Parameters<typeof import('./requests/componentInfos.js')['getComponentEvents']>): Promise<string[] | null | undefined>;
|
|
15
|
-
export declare function getTemplateContextProps(...args: Parameters<typeof import('./requests/componentInfos.js')['getTemplateContextProps']>): Promise<string[] | 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>;
|
|
16
12
|
export declare function getComponentNames(fileName: string): Promise<string[] | undefined>;
|
|
17
|
-
export declare
|
|
13
|
+
export declare const getElementAttrs: (fileName: string, tagName: string) => Promise<string[] | null | undefined>;
|
package/lib/client.js
CHANGED
|
@@ -1,27 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.collectExtractProps =
|
|
4
|
-
exports.getImportPathForFile = getImportPathForFile;
|
|
5
|
-
exports.getPropertiesAtLocation = getPropertiesAtLocation;
|
|
6
|
-
exports.getQuickInfoAtPosition = getQuickInfoAtPosition;
|
|
3
|
+
exports.getElementAttrs = exports.getComponentDirectives = exports.getComponentEvents = exports.getQuickInfoAtPosition = exports.getPropertiesAtLocation = exports.getImportPathForFile = exports.collectExtractProps = void 0;
|
|
7
4
|
exports.getComponentProps = getComponentProps;
|
|
8
|
-
exports.getComponentEvents = getComponentEvents;
|
|
9
|
-
exports.getTemplateContextProps = getTemplateContextProps;
|
|
10
5
|
exports.getComponentNames = getComponentNames;
|
|
11
|
-
exports.getElementAttrs = getElementAttrs;
|
|
12
6
|
const utils_1 = require("./utils");
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
return await sendRequest('getImportPathForFile', ...args);
|
|
18
|
-
}
|
|
19
|
-
async function getPropertiesAtLocation(...args) {
|
|
20
|
-
return await sendRequest('getPropertiesAtLocation', ...args);
|
|
21
|
-
}
|
|
22
|
-
function getQuickInfoAtPosition(...args) {
|
|
23
|
-
return sendRequest('getQuickInfoAtPosition', ...args);
|
|
24
|
-
}
|
|
7
|
+
exports.collectExtractProps = createRequest('collectExtractProps');
|
|
8
|
+
exports.getImportPathForFile = createRequest('getImportPathForFile');
|
|
9
|
+
exports.getPropertiesAtLocation = createRequest('getPropertiesAtLocation');
|
|
10
|
+
exports.getQuickInfoAtPosition = createRequest('getQuickInfoAtPosition');
|
|
25
11
|
// Component Infos
|
|
26
12
|
async function getComponentProps(fileName, componentName) {
|
|
27
13
|
const server = await (0, utils_1.getBestServer)(fileName);
|
|
@@ -30,12 +16,8 @@ async function getComponentProps(fileName, componentName) {
|
|
|
30
16
|
}
|
|
31
17
|
return await server.getComponentProps(fileName, componentName);
|
|
32
18
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
function getTemplateContextProps(...args) {
|
|
37
|
-
return sendRequest('getTemplateContextProps', ...args);
|
|
38
|
-
}
|
|
19
|
+
exports.getComponentEvents = createRequest('getComponentEvents');
|
|
20
|
+
exports.getComponentDirectives = createRequest('getComponentDirectives');
|
|
39
21
|
async function getComponentNames(fileName) {
|
|
40
22
|
const server = await (0, utils_1.getBestServer)(fileName);
|
|
41
23
|
if (!server) {
|
|
@@ -47,14 +29,14 @@ async function getComponentNames(fileName) {
|
|
|
47
29
|
}
|
|
48
30
|
return Object.keys(componentAndProps);
|
|
49
31
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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
|
+
};
|
|
59
41
|
}
|
|
60
42
|
//# sourceMappingURL=client.js.map
|
package/lib/common.js
CHANGED
|
@@ -4,7 +4,7 @@ exports.proxyLanguageServiceForVue = proxyLanguageServiceForVue;
|
|
|
4
4
|
exports.getComponentSpans = getComponentSpans;
|
|
5
5
|
const language_core_1 = require("@vue/language-core");
|
|
6
6
|
const shared_1 = require("@vue/shared");
|
|
7
|
-
const
|
|
7
|
+
const getComponentNames_1 = require("./requests/getComponentNames");
|
|
8
8
|
const windowsPathReg = /\\/g;
|
|
9
9
|
function proxyLanguageServiceForVue(ts, language, languageService, vueOptions, asScriptId) {
|
|
10
10
|
const proxyCache = new Map();
|
|
@@ -102,7 +102,7 @@ function getCompletionEntryDetails(language, asScriptId, getCompletionEntryDetai
|
|
|
102
102
|
const { fileName } = args[6]?.__isAutoImport;
|
|
103
103
|
const sourceScript = language.scripts.get(asScriptId(fileName));
|
|
104
104
|
if (sourceScript?.generated?.root instanceof language_core_1.VueVirtualCode) {
|
|
105
|
-
const sfc = sourceScript.generated.root._vueSfc
|
|
105
|
+
const sfc = sourceScript.generated.root._vueSfc();
|
|
106
106
|
if (!sfc?.descriptor.script && !sfc?.descriptor.scriptSetup) {
|
|
107
107
|
for (const codeAction of details?.codeActions ?? []) {
|
|
108
108
|
for (const change of codeAction.changes) {
|
|
@@ -190,7 +190,7 @@ function getEncodedSemanticClassifications(ts, language, languageService, asScri
|
|
|
190
190
|
function getComponentSpans(vueCode, template, spanTemplateRange) {
|
|
191
191
|
const { typescript: ts, languageService } = this;
|
|
192
192
|
const result = [];
|
|
193
|
-
const validComponentNames = (0,
|
|
193
|
+
const validComponentNames = (0, getComponentNames_1._getComponentNames)(ts, languageService, vueCode);
|
|
194
194
|
const components = new Set([
|
|
195
195
|
...validComponentNames,
|
|
196
196
|
...validComponentNames.map(language_core_1.hyphenateTag),
|
package/lib/index.d.ts
ADDED
package/lib/index.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { createLanguageServicePlugin } from '@volar/typescript/lib/quickstart/createLanguageServicePlugin';
|
|
2
|
+
import * as vue from '@vue/language-core';
|
|
3
|
+
import { proxyLanguageServiceForVue } from './common';
|
|
4
|
+
import { startNamedPipeServer } from './server';
|
|
5
|
+
const windowsPathReg = /\\/g;
|
|
6
|
+
const vueCompilerOptions = new WeakMap();
|
|
7
|
+
const plugin = createLanguageServicePlugin((ts, info) => {
|
|
8
|
+
const vueOptions = getVueCompilerOptions();
|
|
9
|
+
const languagePlugin = vue.createVueLanguagePlugin(ts, info.languageServiceHost.getCompilationSettings(), vueOptions, id => id);
|
|
10
|
+
vueCompilerOptions.set(info.project, vueOptions);
|
|
11
|
+
return {
|
|
12
|
+
languagePlugins: [languagePlugin],
|
|
13
|
+
setup: language => {
|
|
14
|
+
info.languageService = proxyLanguageServiceForVue(ts, language, info.languageService, vueOptions, fileName => fileName);
|
|
15
|
+
if (info.project.projectKind === ts.server.ProjectKind.Configured
|
|
16
|
+
|| info.project.projectKind === ts.server.ProjectKind.Inferred) {
|
|
17
|
+
startNamedPipeServer(ts, info, language, info.project.projectKind);
|
|
18
|
+
}
|
|
19
|
+
// #3963
|
|
20
|
+
const timer = setInterval(() => {
|
|
21
|
+
if (info.project['program']) {
|
|
22
|
+
clearInterval(timer);
|
|
23
|
+
info.project['program'].__vue__ = { language };
|
|
24
|
+
}
|
|
25
|
+
}, 50);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
function getVueCompilerOptions() {
|
|
29
|
+
if (info.project.projectKind === ts.server.ProjectKind.Configured) {
|
|
30
|
+
const tsconfig = info.project.getProjectName();
|
|
31
|
+
return vue.createParsedCommandLine(ts, ts.sys, tsconfig.replace(windowsPathReg, '/')).vueOptions;
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
return vue.createParsedCommandLineByJson(ts, ts.sys, info.languageServiceHost.getCurrentDirectory(), {}).vueOptions;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
export default plugin;
|
|
39
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import * as vue from '@vue/language-core';
|
|
2
2
|
import type * as ts from 'typescript';
|
|
3
3
|
import type { RequestContext } from './types';
|
|
4
|
-
export
|
|
4
|
+
export interface ComponentPropInfo {
|
|
5
5
|
name: string;
|
|
6
|
-
required?:
|
|
6
|
+
required?: boolean;
|
|
7
|
+
deprecated?: boolean;
|
|
7
8
|
commentMarkdown?: string;
|
|
8
|
-
}
|
|
9
|
+
}
|
|
10
|
+
export declare function getComponentProps(this: RequestContext, fileName: string, tag: string): ComponentPropInfo[] | undefined;
|
|
9
11
|
export declare function getComponentEvents(this: RequestContext, fileName: string, tag: string): string[] | undefined;
|
|
10
|
-
export declare function
|
|
12
|
+
export declare function getComponentDirectives(this: RequestContext, fileName: string): string[] | undefined;
|
|
11
13
|
export declare function getComponentNames(this: RequestContext, fileName: string): string[] | undefined;
|
|
12
14
|
export declare function _getComponentNames(ts: typeof import('typescript'), tsLs: ts.LanguageService, vueCode: vue.VueVirtualCode): string[];
|
|
13
15
|
export declare function getElementAttrs(this: RequestContext, fileName: string, tagName: string): string[] | undefined;
|
|
@@ -2,12 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getComponentProps = getComponentProps;
|
|
4
4
|
exports.getComponentEvents = getComponentEvents;
|
|
5
|
-
exports.
|
|
5
|
+
exports.getComponentDirectives = getComponentDirectives;
|
|
6
6
|
exports.getComponentNames = getComponentNames;
|
|
7
7
|
exports._getComponentNames = _getComponentNames;
|
|
8
8
|
exports.getElementAttrs = getElementAttrs;
|
|
9
9
|
const vue = require("@vue/language-core");
|
|
10
10
|
const shared_1 = require("@vue/shared");
|
|
11
|
+
const path = require("node:path");
|
|
11
12
|
function getComponentProps(fileName, tag) {
|
|
12
13
|
const { typescript: ts, language, languageService, getFileId } = this;
|
|
13
14
|
const volarFile = language.scripts.get(getFileId(fileName));
|
|
@@ -21,23 +22,10 @@ function getComponentProps(fileName, tag) {
|
|
|
21
22
|
if (!components) {
|
|
22
23
|
return [];
|
|
23
24
|
}
|
|
24
|
-
const
|
|
25
|
-
|
|
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) {
|
|
25
|
+
const componentType = getComponentType(ts, languageService, vueCode, components, fileName, tag);
|
|
26
|
+
if (!componentType) {
|
|
29
27
|
return [];
|
|
30
28
|
}
|
|
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
29
|
const result = new Map();
|
|
42
30
|
for (const sig of componentType.getCallSignatures()) {
|
|
43
31
|
const propParam = sig.parameters[0];
|
|
@@ -47,8 +35,13 @@ function getComponentProps(fileName, tag) {
|
|
|
47
35
|
for (const prop of props) {
|
|
48
36
|
const name = prop.name;
|
|
49
37
|
const required = !(prop.flags & ts.SymbolFlags.Optional) || undefined;
|
|
50
|
-
const commentMarkdown = generateCommentMarkdown(prop.getDocumentationComment(checker), prop.getJsDocTags())
|
|
51
|
-
result.set(name, {
|
|
38
|
+
const { content: commentMarkdown, deprecated } = generateCommentMarkdown(prop.getDocumentationComment(checker), prop.getJsDocTags());
|
|
39
|
+
result.set(name, {
|
|
40
|
+
name,
|
|
41
|
+
required,
|
|
42
|
+
deprecated,
|
|
43
|
+
commentMarkdown
|
|
44
|
+
});
|
|
52
45
|
}
|
|
53
46
|
}
|
|
54
47
|
}
|
|
@@ -64,8 +57,13 @@ function getComponentProps(fileName, tag) {
|
|
|
64
57
|
}
|
|
65
58
|
const name = prop.name;
|
|
66
59
|
const required = !(prop.flags & ts.SymbolFlags.Optional) || undefined;
|
|
67
|
-
const commentMarkdown = generateCommentMarkdown(prop.getDocumentationComment(checker), prop.getJsDocTags())
|
|
68
|
-
result.set(name, {
|
|
60
|
+
const { content: commentMarkdown, deprecated } = generateCommentMarkdown(prop.getDocumentationComment(checker), prop.getJsDocTags());
|
|
61
|
+
result.set(name, {
|
|
62
|
+
name,
|
|
63
|
+
required,
|
|
64
|
+
deprecated,
|
|
65
|
+
commentMarkdown
|
|
66
|
+
});
|
|
69
67
|
}
|
|
70
68
|
}
|
|
71
69
|
}
|
|
@@ -84,25 +82,10 @@ function getComponentEvents(fileName, tag) {
|
|
|
84
82
|
if (!components) {
|
|
85
83
|
return [];
|
|
86
84
|
}
|
|
87
|
-
const
|
|
88
|
-
|
|
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) {
|
|
85
|
+
const componentType = getComponentType(ts, languageService, vueCode, components, fileName, tag);
|
|
86
|
+
if (!componentType) {
|
|
94
87
|
return [];
|
|
95
88
|
}
|
|
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
89
|
const result = new Set();
|
|
107
90
|
// for (const sig of componentType.getCallSignatures()) {
|
|
108
91
|
// const emitParam = sig.parameters[1];
|
|
@@ -128,17 +111,21 @@ function getComponentEvents(fileName, tag) {
|
|
|
128
111
|
}
|
|
129
112
|
return [...result];
|
|
130
113
|
}
|
|
131
|
-
function
|
|
114
|
+
function getComponentDirectives(fileName) {
|
|
132
115
|
const { typescript: ts, language, languageService, getFileId } = this;
|
|
133
116
|
const volarFile = language.scripts.get(getFileId(fileName));
|
|
134
117
|
if (!(volarFile?.generated?.root instanceof vue.VueVirtualCode)) {
|
|
135
118
|
return;
|
|
136
119
|
}
|
|
137
120
|
const vueCode = volarFile.generated.root;
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
121
|
+
const directives = getVariableType(ts, languageService, vueCode, '__VLS_directives');
|
|
122
|
+
if (!directives) {
|
|
123
|
+
return [];
|
|
124
|
+
}
|
|
125
|
+
return directives.type.getProperties()
|
|
126
|
+
.map(({ name }) => name)
|
|
127
|
+
.filter(name => name.startsWith('v') && name.length >= 2 && name[1] === name[1].toUpperCase())
|
|
128
|
+
.filter(name => !['vBind', 'vIf', 'vOn', 'VOnce', 'vShow', 'VSlot'].includes(name));
|
|
142
129
|
}
|
|
143
130
|
function getComponentNames(fileName) {
|
|
144
131
|
const { typescript: ts, language, languageService, getFileId } = this;
|
|
@@ -147,20 +134,17 @@ function getComponentNames(fileName) {
|
|
|
147
134
|
return;
|
|
148
135
|
}
|
|
149
136
|
const vueCode = volarFile.generated.root;
|
|
150
|
-
return
|
|
151
|
-
?.type
|
|
152
|
-
?.getProperties()
|
|
153
|
-
.map(c => c.name)
|
|
154
|
-
.filter(entry => !entry.includes('$') && !entry.startsWith('_'))
|
|
155
|
-
?? [];
|
|
137
|
+
return _getComponentNames(ts, languageService, vueCode);
|
|
156
138
|
}
|
|
157
139
|
function _getComponentNames(ts, tsLs, vueCode) {
|
|
158
|
-
|
|
140
|
+
const names = getVariableType(ts, tsLs, vueCode, '__VLS_components')
|
|
159
141
|
?.type
|
|
160
142
|
?.getProperties()
|
|
161
143
|
.map(c => c.name)
|
|
162
144
|
.filter(entry => !entry.includes('$') && !entry.startsWith('_'))
|
|
163
145
|
?? [];
|
|
146
|
+
names.push(getSelfComponentName(vueCode.fileName));
|
|
147
|
+
return names;
|
|
164
148
|
}
|
|
165
149
|
function getElementAttrs(fileName, tagName) {
|
|
166
150
|
const { typescript: ts, language, languageService, getFileId } = this;
|
|
@@ -171,7 +155,9 @@ function getElementAttrs(fileName, tagName) {
|
|
|
171
155
|
const program = languageService.getProgram();
|
|
172
156
|
let tsSourceFile;
|
|
173
157
|
if (tsSourceFile = program.getSourceFile(fileName)) {
|
|
174
|
-
const typeNode = tsSourceFile.statements
|
|
158
|
+
const typeNode = tsSourceFile.statements
|
|
159
|
+
.filter(ts.isTypeAliasDeclaration)
|
|
160
|
+
.find(node => node.name.getText() === '__VLS_IntrinsicElementsCompletion');
|
|
175
161
|
const checker = program.getTypeChecker();
|
|
176
162
|
if (checker && typeNode) {
|
|
177
163
|
const type = checker.getTypeFromTypeNode(typeNode.type);
|
|
@@ -184,6 +170,31 @@ function getElementAttrs(fileName, tagName) {
|
|
|
184
170
|
}
|
|
185
171
|
return [];
|
|
186
172
|
}
|
|
173
|
+
function getComponentType(ts, languageService, vueCode, components, fileName, tag) {
|
|
174
|
+
const program = languageService.getProgram();
|
|
175
|
+
const checker = program.getTypeChecker();
|
|
176
|
+
const name = tag.split('.');
|
|
177
|
+
let componentSymbol = components.type.getProperty(name[0])
|
|
178
|
+
?? components.type.getProperty((0, shared_1.camelize)(name[0]))
|
|
179
|
+
?? components.type.getProperty((0, shared_1.capitalize)((0, shared_1.camelize)(name[0])));
|
|
180
|
+
let componentType;
|
|
181
|
+
if (!componentSymbol) {
|
|
182
|
+
const name = getSelfComponentName(fileName);
|
|
183
|
+
if (name === (0, shared_1.capitalize)((0, shared_1.camelize)(tag))) {
|
|
184
|
+
componentType = getVariableType(ts, languageService, vueCode, '__VLS_self')?.type;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
componentType = checker.getTypeOfSymbolAtLocation(componentSymbol, components.node);
|
|
189
|
+
for (let i = 1; i < name.length; i++) {
|
|
190
|
+
componentSymbol = componentType.getProperty(name[i]);
|
|
191
|
+
if (componentSymbol) {
|
|
192
|
+
componentType = checker.getTypeOfSymbolAtLocation(componentSymbol, components.node);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
return componentType;
|
|
197
|
+
}
|
|
187
198
|
function getVariableType(ts, languageService, vueCode, name) {
|
|
188
199
|
const program = languageService.getProgram();
|
|
189
200
|
let tsSourceFile;
|
|
@@ -198,6 +209,10 @@ function getVariableType(ts, languageService, vueCode, name) {
|
|
|
198
209
|
}
|
|
199
210
|
}
|
|
200
211
|
}
|
|
212
|
+
function getSelfComponentName(fileName) {
|
|
213
|
+
const baseName = path.basename(fileName);
|
|
214
|
+
return (0, shared_1.capitalize)((0, shared_1.camelize)(baseName.slice(0, baseName.lastIndexOf('.'))));
|
|
215
|
+
}
|
|
201
216
|
function searchVariableDeclarationNode(ts, sourceFile, name) {
|
|
202
217
|
let componentsNode;
|
|
203
218
|
walk(sourceFile);
|
|
@@ -217,8 +232,12 @@ function searchVariableDeclarationNode(ts, sourceFile, name) {
|
|
|
217
232
|
function generateCommentMarkdown(parts, jsDocTags) {
|
|
218
233
|
const parsedComment = _symbolDisplayPartsToMarkdown(parts);
|
|
219
234
|
const parsedJsDoc = _jsDocTagInfoToMarkdown(jsDocTags);
|
|
220
|
-
|
|
221
|
-
|
|
235
|
+
const content = [parsedComment, parsedJsDoc].filter(str => !!str).join('\n\n');
|
|
236
|
+
const deprecated = jsDocTags.some(tag => tag.name === 'deprecated');
|
|
237
|
+
return {
|
|
238
|
+
content,
|
|
239
|
+
deprecated
|
|
240
|
+
};
|
|
222
241
|
}
|
|
223
242
|
function _symbolDisplayPartsToMarkdown(parts) {
|
|
224
243
|
return parts.map(part => {
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getComponentDirectives = getComponentDirectives;
|
|
4
|
+
const language_core_1 = require("@vue/language-core");
|
|
5
|
+
const utils_1 = require("./utils");
|
|
6
|
+
function getComponentDirectives(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 directives = (0, utils_1.getVariableType)(ts, languageService, vueCode, '__VLS_directives');
|
|
14
|
+
if (!directives) {
|
|
15
|
+
return [];
|
|
16
|
+
}
|
|
17
|
+
return directives.type.getProperties()
|
|
18
|
+
.map(({ name }) => name)
|
|
19
|
+
.filter(name => name.startsWith('v') && name.length >= 2 && name[1] === name[1].toUpperCase())
|
|
20
|
+
.filter(name => !['vBind', 'vIf', 'vOn', 'VOnce', 'vShow', 'VSlot'].includes(name));
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=getComponentDirectives.js.map
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getComponentEvents = getComponentEvents;
|
|
4
|
+
const language_core_1 = require("@vue/language-core");
|
|
5
|
+
const utils_1 = require("./utils");
|
|
6
|
+
function getComponentEvents(fileName, tag) {
|
|
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 program = languageService.getProgram();
|
|
14
|
+
const checker = program.getTypeChecker();
|
|
15
|
+
const components = (0, utils_1.getVariableType)(ts, languageService, vueCode, '__VLS_components');
|
|
16
|
+
if (!components) {
|
|
17
|
+
return [];
|
|
18
|
+
}
|
|
19
|
+
const componentType = (0, utils_1.getComponentType)(ts, languageService, vueCode, components, fileName, tag);
|
|
20
|
+
if (!componentType) {
|
|
21
|
+
return [];
|
|
22
|
+
}
|
|
23
|
+
const result = new Set();
|
|
24
|
+
// for (const sig of componentType.getCallSignatures()) {
|
|
25
|
+
// const emitParam = sig.parameters[1];
|
|
26
|
+
// if (emitParam) {
|
|
27
|
+
// // TODO
|
|
28
|
+
// }
|
|
29
|
+
// }
|
|
30
|
+
for (const sig of componentType.getConstructSignatures()) {
|
|
31
|
+
const instanceType = sig.getReturnType();
|
|
32
|
+
const emitSymbol = instanceType.getProperty('$emit');
|
|
33
|
+
if (emitSymbol) {
|
|
34
|
+
const emitType = checker.getTypeOfSymbolAtLocation(emitSymbol, components.node);
|
|
35
|
+
for (const call of emitType.getCallSignatures()) {
|
|
36
|
+
const eventNameParamSymbol = call.parameters[0];
|
|
37
|
+
if (eventNameParamSymbol) {
|
|
38
|
+
const eventNameParamType = checker.getTypeOfSymbolAtLocation(eventNameParamSymbol, components.node);
|
|
39
|
+
if (eventNameParamType.isStringLiteral()) {
|
|
40
|
+
result.add(eventNameParamType.value);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return [...result];
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=getComponentEvents.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 getComponentNames(this: RequestContext, fileName: string): string[] | undefined;
|
|
5
|
+
export declare function _getComponentNames(ts: typeof import('typescript'), tsLs: ts.LanguageService, vueCode: VueVirtualCode): string[];
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getComponentNames = getComponentNames;
|
|
4
|
+
exports._getComponentNames = _getComponentNames;
|
|
5
|
+
const language_core_1 = require("@vue/language-core");
|
|
6
|
+
const utils_1 = require("./utils");
|
|
7
|
+
function getComponentNames(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 _getComponentNames(ts, languageService, vueCode);
|
|
15
|
+
}
|
|
16
|
+
function _getComponentNames(ts, tsLs, vueCode) {
|
|
17
|
+
const names = (0, utils_1.getVariableType)(ts, tsLs, vueCode, '__VLS_components')
|
|
18
|
+
?.type
|
|
19
|
+
?.getProperties()
|
|
20
|
+
.map(c => c.name)
|
|
21
|
+
.filter(entry => !entry.includes('$') && !entry.startsWith('_'))
|
|
22
|
+
?? [];
|
|
23
|
+
names.push((0, utils_1.getSelfComponentName)(vueCode.fileName));
|
|
24
|
+
return names;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=getComponentNames.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { RequestContext } from './types';
|
|
2
|
+
export interface ComponentPropInfo {
|
|
3
|
+
name: string;
|
|
4
|
+
required?: boolean;
|
|
5
|
+
deprecated?: boolean;
|
|
6
|
+
commentMarkdown?: string;
|
|
7
|
+
values?: string[];
|
|
8
|
+
}
|
|
9
|
+
export declare function getComponentProps(this: RequestContext, fileName: string, tag: string): ComponentPropInfo[] | undefined;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getComponentProps = getComponentProps;
|
|
4
|
+
const language_core_1 = require("@vue/language-core");
|
|
5
|
+
const utils_1 = require("./utils");
|
|
6
|
+
function getComponentProps(fileName, tag) {
|
|
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 program = languageService.getProgram();
|
|
14
|
+
const checker = program.getTypeChecker();
|
|
15
|
+
const components = (0, utils_1.getVariableType)(ts, languageService, vueCode, '__VLS_components');
|
|
16
|
+
if (!components) {
|
|
17
|
+
return [];
|
|
18
|
+
}
|
|
19
|
+
const componentType = (0, utils_1.getComponentType)(ts, languageService, vueCode, components, fileName, tag);
|
|
20
|
+
if (!componentType) {
|
|
21
|
+
return [];
|
|
22
|
+
}
|
|
23
|
+
const result = new Map();
|
|
24
|
+
for (const sig of componentType.getCallSignatures()) {
|
|
25
|
+
const propParam = sig.parameters[0];
|
|
26
|
+
if (propParam) {
|
|
27
|
+
const propsType = checker.getTypeOfSymbolAtLocation(propParam, components.node);
|
|
28
|
+
const props = propsType.getProperties();
|
|
29
|
+
for (const prop of props) {
|
|
30
|
+
const name = prop.name;
|
|
31
|
+
const required = !(prop.flags & ts.SymbolFlags.Optional) || undefined;
|
|
32
|
+
const { content: commentMarkdown, deprecated } = generateCommentMarkdown(prop.getDocumentationComment(checker), prop.getJsDocTags());
|
|
33
|
+
result.set(name, {
|
|
34
|
+
name,
|
|
35
|
+
required,
|
|
36
|
+
deprecated,
|
|
37
|
+
commentMarkdown
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
for (const sig of componentType.getConstructSignatures()) {
|
|
43
|
+
const instanceType = sig.getReturnType();
|
|
44
|
+
const propsSymbol = instanceType.getProperty('$props');
|
|
45
|
+
if (propsSymbol) {
|
|
46
|
+
const propsType = checker.getTypeOfSymbolAtLocation(propsSymbol, components.node);
|
|
47
|
+
const props = propsType.getProperties();
|
|
48
|
+
for (const prop of props) {
|
|
49
|
+
if (prop.flags & ts.SymbolFlags.Method) { // #2443
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
const name = prop.name;
|
|
53
|
+
const required = !(prop.flags & ts.SymbolFlags.Optional) || undefined;
|
|
54
|
+
const { content: commentMarkdown, deprecated } = generateCommentMarkdown(prop.getDocumentationComment(checker), prop.getJsDocTags());
|
|
55
|
+
result.set(name, {
|
|
56
|
+
name,
|
|
57
|
+
required,
|
|
58
|
+
deprecated,
|
|
59
|
+
commentMarkdown
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return [...result.values()];
|
|
65
|
+
}
|
|
66
|
+
function generateCommentMarkdown(parts, jsDocTags) {
|
|
67
|
+
const parsedComment = _symbolDisplayPartsToMarkdown(parts);
|
|
68
|
+
const parsedJsDoc = _jsDocTagInfoToMarkdown(jsDocTags);
|
|
69
|
+
const content = [parsedComment, parsedJsDoc].filter(str => !!str).join('\n\n');
|
|
70
|
+
const deprecated = jsDocTags.some(tag => tag.name === 'deprecated');
|
|
71
|
+
return {
|
|
72
|
+
content,
|
|
73
|
+
deprecated
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
function _symbolDisplayPartsToMarkdown(parts) {
|
|
77
|
+
return parts.map(part => {
|
|
78
|
+
switch (part.kind) {
|
|
79
|
+
case 'keyword':
|
|
80
|
+
return `\`${part.text}\``;
|
|
81
|
+
case 'functionName':
|
|
82
|
+
return `**${part.text}**`;
|
|
83
|
+
default:
|
|
84
|
+
return part.text;
|
|
85
|
+
}
|
|
86
|
+
}).join('');
|
|
87
|
+
}
|
|
88
|
+
function _jsDocTagInfoToMarkdown(jsDocTags) {
|
|
89
|
+
return jsDocTags.map(tag => {
|
|
90
|
+
const tagName = `*@${tag.name}*`;
|
|
91
|
+
const tagText = tag.text?.map(t => {
|
|
92
|
+
if (t.kind === 'parameterName') {
|
|
93
|
+
return `\`${t.text}\``;
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
return t.text;
|
|
97
|
+
}
|
|
98
|
+
}).join('') || '';
|
|
99
|
+
return `${tagName} ${tagText}`;
|
|
100
|
+
}).join('\n\n');
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=getComponentProps.js.map
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getElementAttrs = getElementAttrs;
|
|
4
|
+
const vue = require("@vue/language-core");
|
|
5
|
+
function getElementAttrs(fileName, tagName) {
|
|
6
|
+
const { typescript: ts, language, languageService, getFileId } = this;
|
|
7
|
+
const volarFile = language.scripts.get(getFileId(fileName));
|
|
8
|
+
if (!(volarFile?.generated?.root instanceof vue.VueVirtualCode)) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
const program = languageService.getProgram();
|
|
12
|
+
let tsSourceFile;
|
|
13
|
+
if (tsSourceFile = program.getSourceFile(fileName)) {
|
|
14
|
+
const checker = program.getTypeChecker();
|
|
15
|
+
const typeNode = tsSourceFile.statements
|
|
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
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return [];
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=getElementAttrs.js.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getSlotNames = getSlotNames;
|
|
4
|
+
const language_core_1 = require("@vue/language-core");
|
|
5
|
+
function getSlotNames(fileName) {
|
|
6
|
+
const { typescript: ts, language, languageService, getFileId } = this;
|
|
7
|
+
const sourceScript = language.scripts.get(getFileId(fileName));
|
|
8
|
+
if (!sourceScript?.generated) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
const root = sourceScript.generated.root;
|
|
12
|
+
if (!(root instanceof language_core_1.VueVirtualCode)) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
const program = languageService.getProgram();
|
|
16
|
+
const tsSourceFile = program.getSourceFile(fileName);
|
|
17
|
+
if (!tsSourceFile) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const checker = program.getTypeChecker();
|
|
21
|
+
const typeNode = tsSourceFile.statements
|
|
22
|
+
.filter(ts.isTypeAliasDeclaration)
|
|
23
|
+
.find(node => node.name.getText() === '__VLS_Slots');
|
|
24
|
+
if (typeNode) {
|
|
25
|
+
const attrs = checker.getTypeFromTypeNode(typeNode.type).getProperties();
|
|
26
|
+
return attrs.map(attr => attr.name);
|
|
27
|
+
}
|
|
28
|
+
return [];
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=getSlotNames.js.map
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.goToDefinition = goToDefinition;
|
|
4
|
+
const vue = require("@vue/language-core");
|
|
5
|
+
const componentInfos_1 = require("./componentInfos");
|
|
6
|
+
function goToDefinition(fileName, tag) {
|
|
7
|
+
const { typescript: ts, language, languageService, getFileId } = this;
|
|
8
|
+
const volarFile = language.scripts.get(getFileId(fileName));
|
|
9
|
+
if (!(volarFile?.generated?.root instanceof vue.VueVirtualCode)) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
const vueCode = volarFile.generated.root;
|
|
13
|
+
const components = (0, componentInfos_1.getVariableType)(ts, languageService, vueCode, '__VLS_components');
|
|
14
|
+
if (!components) {
|
|
15
|
+
return '';
|
|
16
|
+
}
|
|
17
|
+
const componentType = (0, componentInfos_1.getComponentType)(ts, languageService, vueCode, components, fileName, tag);
|
|
18
|
+
if (!componentType) {
|
|
19
|
+
return '';
|
|
20
|
+
}
|
|
21
|
+
const decls = componentType.symbol.declarations ?? [];
|
|
22
|
+
for (const decl of decls) {
|
|
23
|
+
return decl.getSourceFile().fileName;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=goToDefinition.js.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { VueVirtualCode } from '@vue/language-core';
|
|
2
|
+
import type * as ts from 'typescript';
|
|
3
|
+
export declare function getComponentType(ts: typeof import('typescript'), languageService: ts.LanguageService, vueCode: VueVirtualCode, components: NonNullable<ReturnType<typeof getVariableType>>, fileName: string, tag: string): ts.Type | undefined;
|
|
4
|
+
export declare function getSelfComponentName(fileName: string): Capitalize<string>;
|
|
5
|
+
export declare function getVariableType(ts: typeof import('typescript'), languageService: ts.LanguageService, vueCode: VueVirtualCode, name: string): {
|
|
6
|
+
node: ts.Node;
|
|
7
|
+
type: ts.Type;
|
|
8
|
+
} | undefined;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getComponentType = getComponentType;
|
|
4
|
+
exports.getSelfComponentName = getSelfComponentName;
|
|
5
|
+
exports.getVariableType = getVariableType;
|
|
6
|
+
const shared_1 = require("@vue/shared");
|
|
7
|
+
const path = require("node:path");
|
|
8
|
+
function getComponentType(ts, languageService, vueCode, components, fileName, tag) {
|
|
9
|
+
const program = languageService.getProgram();
|
|
10
|
+
const checker = program.getTypeChecker();
|
|
11
|
+
const name = tag.split('.');
|
|
12
|
+
let componentSymbol = components.type.getProperty(name[0])
|
|
13
|
+
?? components.type.getProperty((0, shared_1.camelize)(name[0]))
|
|
14
|
+
?? components.type.getProperty((0, shared_1.capitalize)((0, shared_1.camelize)(name[0])));
|
|
15
|
+
let componentType;
|
|
16
|
+
if (!componentSymbol) {
|
|
17
|
+
const name = getSelfComponentName(fileName);
|
|
18
|
+
if (name === (0, shared_1.capitalize)((0, shared_1.camelize)(tag))) {
|
|
19
|
+
componentType = getVariableType(ts, languageService, vueCode, '__VLS_self')?.type;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
componentType = checker.getTypeOfSymbolAtLocation(componentSymbol, components.node);
|
|
24
|
+
for (let i = 1; i < name.length; i++) {
|
|
25
|
+
componentSymbol = componentType.getProperty(name[i]);
|
|
26
|
+
if (componentSymbol) {
|
|
27
|
+
componentType = checker.getTypeOfSymbolAtLocation(componentSymbol, components.node);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return componentType;
|
|
32
|
+
}
|
|
33
|
+
function getSelfComponentName(fileName) {
|
|
34
|
+
const baseName = path.basename(fileName);
|
|
35
|
+
return (0, shared_1.capitalize)((0, shared_1.camelize)(baseName.slice(0, baseName.lastIndexOf('.'))));
|
|
36
|
+
}
|
|
37
|
+
function getVariableType(ts, languageService, vueCode, name) {
|
|
38
|
+
const program = languageService.getProgram();
|
|
39
|
+
let tsSourceFile;
|
|
40
|
+
if (tsSourceFile = program.getSourceFile(vueCode.fileName)) {
|
|
41
|
+
const node = searchVariableDeclarationNode(ts, tsSourceFile, name);
|
|
42
|
+
const checker = program.getTypeChecker();
|
|
43
|
+
if (checker && node) {
|
|
44
|
+
return {
|
|
45
|
+
node: node,
|
|
46
|
+
type: checker.getTypeAtLocation(node),
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function searchVariableDeclarationNode(ts, sourceFile, name) {
|
|
52
|
+
let componentsNode;
|
|
53
|
+
walk(sourceFile);
|
|
54
|
+
return componentsNode;
|
|
55
|
+
function walk(node) {
|
|
56
|
+
if (componentsNode) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
else if (ts.isVariableDeclaration(node) && node.name.getText() === name) {
|
|
60
|
+
componentsNode = node;
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
node.forEachChild(walk);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=utils.js.map
|
package/lib/server.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Language } from '@vue/language-core';
|
|
2
2
|
import type * as ts from 'typescript';
|
|
3
|
-
export type RequestType = 'containsFile' | 'projectInfo' | 'collectExtractProps' | 'getImportPathForFile' | 'getPropertiesAtLocation' | 'getQuickInfoAtPosition' | 'subscribeComponentProps' | 'getComponentEvents' | '
|
|
3
|
+
export type RequestType = 'containsFile' | 'projectInfo' | 'collectExtractProps' | 'getImportPathForFile' | 'getPropertiesAtLocation' | 'getQuickInfoAtPosition' | 'subscribeComponentProps' | 'getComponentEvents' | 'getComponentDirectives' | 'getElementAttrs';
|
|
4
4
|
export type NotificationType = 'componentNamesUpdated' | 'componentPropsUpdated';
|
|
5
5
|
export type RequestData = [
|
|
6
6
|
seq: number,
|
package/lib/server.js
CHANGED
|
@@ -5,7 +5,11 @@ const language_core_1 = require("@vue/language-core");
|
|
|
5
5
|
const fs = require("node:fs");
|
|
6
6
|
const net = require("node:net");
|
|
7
7
|
const collectExtractProps_1 = require("./requests/collectExtractProps");
|
|
8
|
-
const
|
|
8
|
+
const getComponentDirectives_1 = require("./requests/getComponentDirectives");
|
|
9
|
+
const getComponentEvents_1 = require("./requests/getComponentEvents");
|
|
10
|
+
const getComponentNames_1 = require("./requests/getComponentNames");
|
|
11
|
+
const getComponentProps_1 = require("./requests/getComponentProps");
|
|
12
|
+
const getElementAttrs_1 = require("./requests/getElementAttrs");
|
|
9
13
|
const getImportPathForFile_1 = require("./requests/getImportPathForFile");
|
|
10
14
|
const getPropertiesAtLocation_1 = require("./requests/getPropertiesAtLocation");
|
|
11
15
|
const getQuickInfoAtPosition_1 = require("./requests/getQuickInfoAtPosition");
|
|
@@ -51,7 +55,7 @@ async function startNamedPipeServer(ts, info, language, projectKind) {
|
|
|
51
55
|
});
|
|
52
56
|
connection.on('error', err => console.error('[Vue Named Pipe Server]', err.message));
|
|
53
57
|
for (const [fileName, [componentNames, componentProps]] of currentData) {
|
|
54
|
-
notify(connection, 'componentNamesUpdated', fileName,
|
|
58
|
+
notify(connection, 'componentNamesUpdated', fileName, componentNames);
|
|
55
59
|
for (const [name, props] of Object.entries(componentProps)) {
|
|
56
60
|
notify(connection, 'componentPropsUpdated', fileName, [name, props]);
|
|
57
61
|
}
|
|
@@ -100,7 +104,7 @@ async function startNamedPipeServer(ts, info, language, projectKind) {
|
|
|
100
104
|
currentData.set(scriptInfo.fileName, data);
|
|
101
105
|
}
|
|
102
106
|
const [oldComponentNames, componentProps] = data;
|
|
103
|
-
const newComponentNames =
|
|
107
|
+
const newComponentNames = getComponentNames_1.getComponentNames.apply(requestContext, [scriptInfo.fileName]) ?? [];
|
|
104
108
|
if (JSON.stringify(oldComponentNames) !== JSON.stringify(newComponentNames)) {
|
|
105
109
|
data[0] = newComponentNames;
|
|
106
110
|
for (const connection of connections) {
|
|
@@ -112,7 +116,7 @@ async function startNamedPipeServer(ts, info, language, projectKind) {
|
|
|
112
116
|
if (token?.isCancellationRequested()) {
|
|
113
117
|
break;
|
|
114
118
|
}
|
|
115
|
-
const newProps =
|
|
119
|
+
const newProps = getComponentProps_1.getComponentProps.apply(requestContext, [scriptInfo.fileName, name]) ?? [];
|
|
116
120
|
if (JSON.stringify(props) !== JSON.stringify(newProps)) {
|
|
117
121
|
componentProps[name] = newProps;
|
|
118
122
|
for (const connection of connections) {
|
|
@@ -171,7 +175,7 @@ async function startNamedPipeServer(ts, info, language, projectKind) {
|
|
|
171
175
|
}
|
|
172
176
|
else if (requestType === 'subscribeComponentProps') {
|
|
173
177
|
const tag = args[1];
|
|
174
|
-
const props =
|
|
178
|
+
const props = getComponentProps_1.getComponentProps.apply(requestContext, [fileName, tag]) ?? [];
|
|
175
179
|
let data = currentData.get(fileName);
|
|
176
180
|
if (!data) {
|
|
177
181
|
data = [[], {}];
|
|
@@ -181,13 +185,13 @@ async function startNamedPipeServer(ts, info, language, projectKind) {
|
|
|
181
185
|
return props;
|
|
182
186
|
}
|
|
183
187
|
else if (requestType === 'getComponentEvents') {
|
|
184
|
-
return
|
|
188
|
+
return getComponentEvents_1.getComponentEvents.apply(requestContext, args);
|
|
185
189
|
}
|
|
186
|
-
else if (requestType === '
|
|
187
|
-
return
|
|
190
|
+
else if (requestType === 'getComponentDirectives') {
|
|
191
|
+
return getComponentDirectives_1.getComponentDirectives.apply(requestContext, args);
|
|
188
192
|
}
|
|
189
193
|
else if (requestType === 'getElementAttrs') {
|
|
190
|
-
return
|
|
194
|
+
return getElementAttrs_1.getElementAttrs.apply(requestContext, args);
|
|
191
195
|
}
|
|
192
196
|
console.warn('[Vue Named Pipe Server] Unknown request:', requestType);
|
|
193
197
|
debugger;
|
package/lib/utils.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { FileMap } from '@vue/language-core';
|
|
2
2
|
import * as net from 'node:net';
|
|
3
3
|
import type * as ts from 'typescript';
|
|
4
|
+
import type { ComponentPropInfo } from './requests/getComponentProps';
|
|
4
5
|
import type { NotificationData, ProjectInfo, RequestData } from './server';
|
|
5
6
|
export { TypeScriptProjectHost } from '@volar/typescript';
|
|
6
7
|
export declare function getServerPath(kind: ts.server.ProjectKind, id: number): string;
|
|
@@ -9,18 +10,10 @@ declare class NamedPipeServer {
|
|
|
9
10
|
connecting: boolean;
|
|
10
11
|
projectInfo?: ProjectInfo;
|
|
11
12
|
containsFileCache: Map<string, Promise<boolean | null | undefined>>;
|
|
12
|
-
componentNamesAndProps: FileMap<Record<string,
|
|
13
|
-
name: string;
|
|
14
|
-
required?: true;
|
|
15
|
-
commentMarkdown?: string;
|
|
16
|
-
}[] | null>>;
|
|
13
|
+
componentNamesAndProps: FileMap<Record<string, ComponentPropInfo[] | null>>;
|
|
17
14
|
constructor(kind: ts.server.ProjectKind, id: number);
|
|
18
15
|
containsFile(fileName: string): Promise<boolean | null | undefined> | undefined;
|
|
19
|
-
getComponentProps(fileName: string, tag: string): Promise<
|
|
20
|
-
name: string;
|
|
21
|
-
required?: true;
|
|
22
|
-
commentMarkdown?: string;
|
|
23
|
-
}[] | null | undefined>;
|
|
16
|
+
getComponentProps(fileName: string, tag: string): Promise<ComponentPropInfo[] | null | undefined>;
|
|
24
17
|
update(): void;
|
|
25
18
|
connect(): void;
|
|
26
19
|
close(): void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vue/typescript-plugin",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.2",
|
|
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.2",
|
|
18
18
|
"@vue/shared": "^3.5.0"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
|
-
"@types/node": "
|
|
21
|
+
"@types/node": "^22.10.4"
|
|
22
22
|
},
|
|
23
|
-
"gitHead": "
|
|
23
|
+
"gitHead": "30757908b67f40f779c36795665163634fb81868"
|
|
24
24
|
}
|