@vue/typescript-plugin 2.1.10 → 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 +9 -12
- package/lib/client.js +30 -66
- package/lib/common.js +11 -10
- package/lib/index.d.ts +3 -0
- package/lib/index.js +39 -0
- package/lib/requests/collectExtractProps.js +9 -5
- package/lib/requests/componentInfos.d.ts +7 -4
- package/lib/requests/componentInfos.js +77 -62
- 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/types.d.ts +1 -1
- package/lib/requests/utils.d.ts +8 -0
- package/lib/requests/utils.js +67 -0
- package/lib/server.d.ts +18 -5
- package/lib/server.js +209 -73
- package/lib/utils.d.ts +29 -14
- package/lib/utils.js +192 -188
- package/package.json +5 -5
package/lib/client.d.ts
CHANGED
|
@@ -1,16 +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(
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
export declare
|
|
14
|
-
export declare function getTemplateContextProps(...args: Parameters<typeof import('./requests/componentInfos.js')['getTemplateContextProps']>): Promise<string[] | null | undefined>;
|
|
15
|
-
export declare function getComponentNames(...args: Parameters<typeof import('./requests/componentInfos.js')['getComponentNames']>): Promise<string[] | null | undefined>;
|
|
16
|
-
export declare function getElementAttrs(...args: Parameters<typeof import('./requests/componentInfos.js')['getElementAttrs']>): 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>;
|
|
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
CHANGED
|
@@ -1,78 +1,42 @@
|
|
|
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
|
-
});
|
|
18
|
-
}
|
|
19
|
-
async function getImportPathForFile(...args) {
|
|
20
|
-
return await sendRequest({
|
|
21
|
-
type: 'getImportPathForFile',
|
|
22
|
-
args,
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
async function getPropertiesAtLocation(...args) {
|
|
26
|
-
return await sendRequest({
|
|
27
|
-
type: 'getPropertiesAtLocation',
|
|
28
|
-
args,
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
function getQuickInfoAtPosition(...args) {
|
|
32
|
-
return sendRequest({
|
|
33
|
-
type: 'getQuickInfoAtPosition',
|
|
34
|
-
args,
|
|
35
|
-
});
|
|
36
|
-
}
|
|
7
|
+
exports.collectExtractProps = createRequest('collectExtractProps');
|
|
8
|
+
exports.getImportPathForFile = createRequest('getImportPathForFile');
|
|
9
|
+
exports.getPropertiesAtLocation = createRequest('getPropertiesAtLocation');
|
|
10
|
+
exports.getQuickInfoAtPosition = createRequest('getQuickInfoAtPosition');
|
|
37
11
|
// Component Infos
|
|
38
|
-
function getComponentProps(
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function getComponentEvents(...args) {
|
|
45
|
-
return sendRequest({
|
|
46
|
-
type: 'getComponentEvents',
|
|
47
|
-
args,
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
function getTemplateContextProps(...args) {
|
|
51
|
-
return sendRequest({
|
|
52
|
-
type: 'getTemplateContextProps',
|
|
53
|
-
args,
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
function getComponentNames(...args) {
|
|
57
|
-
return sendRequest({
|
|
58
|
-
type: 'getComponentNames',
|
|
59
|
-
args,
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
function getElementAttrs(...args) {
|
|
63
|
-
return sendRequest({
|
|
64
|
-
type: 'getElementAttrs',
|
|
65
|
-
args,
|
|
66
|
-
});
|
|
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);
|
|
67
18
|
}
|
|
68
|
-
|
|
69
|
-
|
|
19
|
+
exports.getComponentEvents = createRequest('getComponentEvents');
|
|
20
|
+
exports.getComponentDirectives = createRequest('getComponentDirectives');
|
|
21
|
+
async function getComponentNames(fileName) {
|
|
22
|
+
const server = await (0, utils_1.getBestServer)(fileName);
|
|
70
23
|
if (!server) {
|
|
71
|
-
console.warn('[Vue Named Pipe Client] No server found for', request.args[0]);
|
|
72
24
|
return;
|
|
73
25
|
}
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
|
|
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
|
+
};
|
|
77
41
|
}
|
|
78
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();
|
|
@@ -42,8 +42,8 @@ function getCompletionsAtPosition(vueOptions, getCompletionsAtPosition) {
|
|
|
42
42
|
const result = getCompletionsAtPosition(fileName, position, options, formattingSettings);
|
|
43
43
|
if (result) {
|
|
44
44
|
// filter __VLS_
|
|
45
|
-
result.entries = result.entries.filter(entry => entry.name.
|
|
46
|
-
&&
|
|
45
|
+
result.entries = result.entries.filter(entry => !entry.name.includes('__VLS_')
|
|
46
|
+
&& !entry.labelDetails?.description?.includes('__VLS_'));
|
|
47
47
|
// modify label
|
|
48
48
|
for (const item of result.entries) {
|
|
49
49
|
if (item.source) {
|
|
@@ -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) {
|
|
@@ -124,7 +124,7 @@ function getCodeFixesAtPosition(getCodeFixesAtPosition) {
|
|
|
124
124
|
return (...args) => {
|
|
125
125
|
let result = getCodeFixesAtPosition(...args);
|
|
126
126
|
// filter __VLS_
|
|
127
|
-
result = result.filter(entry => entry.description.
|
|
127
|
+
result = result.filter(entry => !entry.description.includes('__VLS_'));
|
|
128
128
|
return result;
|
|
129
129
|
};
|
|
130
130
|
}
|
|
@@ -170,11 +170,12 @@ function getEncodedSemanticClassifications(ts, language, languageService, asScri
|
|
|
170
170
|
return (filePath, span, format) => {
|
|
171
171
|
const fileName = filePath.replace(windowsPathReg, '/');
|
|
172
172
|
const result = getEncodedSemanticClassifications(fileName, span, format);
|
|
173
|
-
const
|
|
174
|
-
|
|
175
|
-
|
|
173
|
+
const sourceScript = language.scripts.get(asScriptId(fileName));
|
|
174
|
+
const root = sourceScript?.generated?.root;
|
|
175
|
+
if (root instanceof language_core_1.VueVirtualCode) {
|
|
176
|
+
const { template } = root._sfc;
|
|
176
177
|
if (template) {
|
|
177
|
-
for (const componentSpan of getComponentSpans.call({ typescript: ts, languageService },
|
|
178
|
+
for (const componentSpan of getComponentSpans.call({ typescript: ts, languageService }, root, template, {
|
|
178
179
|
start: span.start - template.startTagEnd,
|
|
179
180
|
length: span.length,
|
|
180
181
|
})) {
|
|
@@ -189,7 +190,7 @@ function getEncodedSemanticClassifications(ts, language, languageService, asScri
|
|
|
189
190
|
function getComponentSpans(vueCode, template, spanTemplateRange) {
|
|
190
191
|
const { typescript: ts, languageService } = this;
|
|
191
192
|
const result = [];
|
|
192
|
-
const validComponentNames = (0,
|
|
193
|
+
const validComponentNames = (0, getComponentNames_1._getComponentNames)(ts, languageService, vueCode);
|
|
193
194
|
const components = new Set([
|
|
194
195
|
...validComponentNames,
|
|
195
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
|
|
@@ -4,17 +4,21 @@ exports.collectExtractProps = collectExtractProps;
|
|
|
4
4
|
const language_core_1 = require("@vue/language-core");
|
|
5
5
|
function collectExtractProps(fileName, templateCodeRange) {
|
|
6
6
|
const { typescript: ts, languageService, language, isTsPlugin, getFileId } = this;
|
|
7
|
-
const
|
|
8
|
-
if (!
|
|
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)) {
|
|
9
13
|
return;
|
|
10
14
|
}
|
|
11
15
|
const result = new Map();
|
|
12
16
|
const program = languageService.getProgram();
|
|
13
17
|
const sourceFile = program.getSourceFile(fileName);
|
|
14
18
|
const checker = program.getTypeChecker();
|
|
15
|
-
const script =
|
|
19
|
+
const script = sourceScript.generated?.languagePlugin.typescript?.getServiceScript(root);
|
|
16
20
|
const maps = script ? [...language.maps.forEach(script.code)].map(([_sourceScript, map]) => map) : [];
|
|
17
|
-
const sfc =
|
|
21
|
+
const sfc = root._sfc;
|
|
18
22
|
sourceFile.forEachChild(function visit(node) {
|
|
19
23
|
if (ts.isPropertyAccessExpression(node)
|
|
20
24
|
&& ts.isIdentifier(node.expression)
|
|
@@ -23,7 +27,7 @@ function collectExtractProps(fileName, templateCodeRange) {
|
|
|
23
27
|
const { name } = node;
|
|
24
28
|
for (const map of maps) {
|
|
25
29
|
let mapped = false;
|
|
26
|
-
for (const source of map.toSourceLocation(name.getEnd() - (isTsPlugin ?
|
|
30
|
+
for (const source of map.toSourceLocation(name.getEnd() - (isTsPlugin ? sourceScript.snapshot.getLength() : 0))) {
|
|
27
31
|
if (source[0] >= sfc.template.startTagEnd + templateCodeRange[0]
|
|
28
32
|
&& source[0] <= sfc.template.startTagEnd + templateCodeRange[1]
|
|
29
33
|
&& (0, language_core_1.isSemanticTokensEnabled)(source[1].data)) {
|
|
@@ -1,12 +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
|
-
|
|
7
|
-
|
|
6
|
+
required?: boolean;
|
|
7
|
+
deprecated?: boolean;
|
|
8
|
+
commentMarkdown?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare function getComponentProps(this: RequestContext, fileName: string, tag: string): ComponentPropInfo[] | undefined;
|
|
8
11
|
export declare function getComponentEvents(this: RequestContext, fileName: string, tag: string): string[] | undefined;
|
|
9
|
-
export declare function
|
|
12
|
+
export declare function getComponentDirectives(this: RequestContext, fileName: string): string[] | undefined;
|
|
10
13
|
export declare function getComponentNames(this: RequestContext, fileName: string): string[] | undefined;
|
|
11
14
|
export declare function _getComponentNames(ts: typeof import('typescript'), tsLs: ts.LanguageService, vueCode: vue.VueVirtualCode): string[];
|
|
12
15
|
export declare function getElementAttrs(this: RequestContext, fileName: string, tagName: string): string[] | undefined;
|
|
@@ -2,13 +2,14 @@
|
|
|
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
|
-
|
|
11
|
+
const path = require("node:path");
|
|
12
|
+
function getComponentProps(fileName, tag) {
|
|
12
13
|
const { typescript: ts, language, languageService, getFileId } = this;
|
|
13
14
|
const volarFile = language.scripts.get(getFileId(fileName));
|
|
14
15
|
if (!(volarFile?.generated?.root instanceof vue.VueVirtualCode)) {
|
|
@@ -21,25 +22,10 @@ function getComponentProps(fileName, tag, requiredOnly = false) {
|
|
|
21
22
|
if (!components) {
|
|
22
23
|
return [];
|
|
23
24
|
}
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
if (!componentSymbol) {
|
|
27
|
-
componentSymbol = components.type.getProperty((0, shared_1.camelize)(name[0]))
|
|
28
|
-
?? components.type.getProperty((0, shared_1.capitalize)((0, shared_1.camelize)(name[0])));
|
|
29
|
-
}
|
|
30
|
-
if (!componentSymbol) {
|
|
25
|
+
const componentType = getComponentType(ts, languageService, vueCode, components, fileName, tag);
|
|
26
|
+
if (!componentType) {
|
|
31
27
|
return [];
|
|
32
28
|
}
|
|
33
|
-
let componentType = checker.getTypeOfSymbolAtLocation(componentSymbol, components.node);
|
|
34
|
-
for (let i = 1; i < name.length; i++) {
|
|
35
|
-
componentSymbol = componentType.getProperty(name[i]);
|
|
36
|
-
if (componentSymbol) {
|
|
37
|
-
componentType = checker.getTypeOfSymbolAtLocation(componentSymbol, components.node);
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
return [];
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
29
|
const result = new Map();
|
|
44
30
|
for (const sig of componentType.getCallSignatures()) {
|
|
45
31
|
const propParam = sig.parameters[0];
|
|
@@ -47,11 +33,15 @@ function getComponentProps(fileName, tag, requiredOnly = false) {
|
|
|
47
33
|
const propsType = checker.getTypeOfSymbolAtLocation(propParam, components.node);
|
|
48
34
|
const props = propsType.getProperties();
|
|
49
35
|
for (const prop of props) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
36
|
+
const name = prop.name;
|
|
37
|
+
const required = !(prop.flags & ts.SymbolFlags.Optional) || undefined;
|
|
38
|
+
const { content: commentMarkdown, deprecated } = generateCommentMarkdown(prop.getDocumentationComment(checker), prop.getJsDocTags());
|
|
39
|
+
result.set(name, {
|
|
40
|
+
name,
|
|
41
|
+
required,
|
|
42
|
+
deprecated,
|
|
43
|
+
commentMarkdown
|
|
44
|
+
});
|
|
55
45
|
}
|
|
56
46
|
}
|
|
57
47
|
}
|
|
@@ -65,11 +55,15 @@ function getComponentProps(fileName, tag, requiredOnly = false) {
|
|
|
65
55
|
if (prop.flags & ts.SymbolFlags.Method) { // #2443
|
|
66
56
|
continue;
|
|
67
57
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
58
|
+
const name = prop.name;
|
|
59
|
+
const required = !(prop.flags & ts.SymbolFlags.Optional) || undefined;
|
|
60
|
+
const { content: commentMarkdown, deprecated } = generateCommentMarkdown(prop.getDocumentationComment(checker), prop.getJsDocTags());
|
|
61
|
+
result.set(name, {
|
|
62
|
+
name,
|
|
63
|
+
required,
|
|
64
|
+
deprecated,
|
|
65
|
+
commentMarkdown
|
|
66
|
+
});
|
|
73
67
|
}
|
|
74
68
|
}
|
|
75
69
|
}
|
|
@@ -88,25 +82,10 @@ function getComponentEvents(fileName, tag) {
|
|
|
88
82
|
if (!components) {
|
|
89
83
|
return [];
|
|
90
84
|
}
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
if (!componentSymbol) {
|
|
94
|
-
componentSymbol = components.type.getProperty((0, shared_1.camelize)(name[0]))
|
|
95
|
-
?? components.type.getProperty((0, shared_1.capitalize)((0, shared_1.camelize)(name[0])));
|
|
96
|
-
}
|
|
97
|
-
if (!componentSymbol) {
|
|
85
|
+
const componentType = getComponentType(ts, languageService, vueCode, components, fileName, tag);
|
|
86
|
+
if (!componentType) {
|
|
98
87
|
return [];
|
|
99
88
|
}
|
|
100
|
-
let componentType = checker.getTypeOfSymbolAtLocation(componentSymbol, components.node);
|
|
101
|
-
for (let i = 1; i < name.length; i++) {
|
|
102
|
-
componentSymbol = componentType.getProperty(name[i]);
|
|
103
|
-
if (componentSymbol) {
|
|
104
|
-
componentType = checker.getTypeOfSymbolAtLocation(componentSymbol, components.node);
|
|
105
|
-
}
|
|
106
|
-
else {
|
|
107
|
-
return [];
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
89
|
const result = new Set();
|
|
111
90
|
// for (const sig of componentType.getCallSignatures()) {
|
|
112
91
|
// const emitParam = sig.parameters[1];
|
|
@@ -132,17 +111,21 @@ function getComponentEvents(fileName, tag) {
|
|
|
132
111
|
}
|
|
133
112
|
return [...result];
|
|
134
113
|
}
|
|
135
|
-
function
|
|
114
|
+
function getComponentDirectives(fileName) {
|
|
136
115
|
const { typescript: ts, language, languageService, getFileId } = this;
|
|
137
116
|
const volarFile = language.scripts.get(getFileId(fileName));
|
|
138
117
|
if (!(volarFile?.generated?.root instanceof vue.VueVirtualCode)) {
|
|
139
118
|
return;
|
|
140
119
|
}
|
|
141
120
|
const vueCode = volarFile.generated.root;
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
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));
|
|
146
129
|
}
|
|
147
130
|
function getComponentNames(fileName) {
|
|
148
131
|
const { typescript: ts, language, languageService, getFileId } = this;
|
|
@@ -151,20 +134,17 @@ function getComponentNames(fileName) {
|
|
|
151
134
|
return;
|
|
152
135
|
}
|
|
153
136
|
const vueCode = volarFile.generated.root;
|
|
154
|
-
return
|
|
155
|
-
?.type
|
|
156
|
-
?.getProperties()
|
|
157
|
-
.map(c => c.name)
|
|
158
|
-
.filter(entry => entry.indexOf('$') === -1 && !entry.startsWith('_'))
|
|
159
|
-
?? [];
|
|
137
|
+
return _getComponentNames(ts, languageService, vueCode);
|
|
160
138
|
}
|
|
161
139
|
function _getComponentNames(ts, tsLs, vueCode) {
|
|
162
|
-
|
|
140
|
+
const names = getVariableType(ts, tsLs, vueCode, '__VLS_components')
|
|
163
141
|
?.type
|
|
164
142
|
?.getProperties()
|
|
165
143
|
.map(c => c.name)
|
|
166
|
-
.filter(entry => entry.
|
|
144
|
+
.filter(entry => !entry.includes('$') && !entry.startsWith('_'))
|
|
167
145
|
?? [];
|
|
146
|
+
names.push(getSelfComponentName(vueCode.fileName));
|
|
147
|
+
return names;
|
|
168
148
|
}
|
|
169
149
|
function getElementAttrs(fileName, tagName) {
|
|
170
150
|
const { typescript: ts, language, languageService, getFileId } = this;
|
|
@@ -175,7 +155,9 @@ function getElementAttrs(fileName, tagName) {
|
|
|
175
155
|
const program = languageService.getProgram();
|
|
176
156
|
let tsSourceFile;
|
|
177
157
|
if (tsSourceFile = program.getSourceFile(fileName)) {
|
|
178
|
-
const typeNode = tsSourceFile.statements
|
|
158
|
+
const typeNode = tsSourceFile.statements
|
|
159
|
+
.filter(ts.isTypeAliasDeclaration)
|
|
160
|
+
.find(node => node.name.getText() === '__VLS_IntrinsicElementsCompletion');
|
|
179
161
|
const checker = program.getTypeChecker();
|
|
180
162
|
if (checker && typeNode) {
|
|
181
163
|
const type = checker.getTypeFromTypeNode(typeNode.type);
|
|
@@ -188,6 +170,31 @@ function getElementAttrs(fileName, tagName) {
|
|
|
188
170
|
}
|
|
189
171
|
return [];
|
|
190
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
|
+
}
|
|
191
198
|
function getVariableType(ts, languageService, vueCode, name) {
|
|
192
199
|
const program = languageService.getProgram();
|
|
193
200
|
let tsSourceFile;
|
|
@@ -202,6 +209,10 @@ function getVariableType(ts, languageService, vueCode, name) {
|
|
|
202
209
|
}
|
|
203
210
|
}
|
|
204
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
|
+
}
|
|
205
216
|
function searchVariableDeclarationNode(ts, sourceFile, name) {
|
|
206
217
|
let componentsNode;
|
|
207
218
|
walk(sourceFile);
|
|
@@ -221,8 +232,12 @@ function searchVariableDeclarationNode(ts, sourceFile, name) {
|
|
|
221
232
|
function generateCommentMarkdown(parts, jsDocTags) {
|
|
222
233
|
const parsedComment = _symbolDisplayPartsToMarkdown(parts);
|
|
223
234
|
const parsedJsDoc = _jsDocTagInfoToMarkdown(jsDocTags);
|
|
224
|
-
|
|
225
|
-
|
|
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
|
+
};
|
|
226
241
|
}
|
|
227
242
|
function _symbolDisplayPartsToMarkdown(parts) {
|
|
228
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
|