@vue/typescript-plugin 3.0.3 → 3.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +14 -10
- package/lib/common.d.ts +1 -1
- package/lib/common.js +10 -10
- package/lib/requests/collectExtractProps.d.ts +4 -2
- package/lib/requests/collectExtractProps.js +8 -11
- package/lib/requests/getComponentDirectives.d.ts +1 -1
- package/lib/requests/getComponentDirectives.js +6 -6
- package/lib/requests/getComponentEvents.d.ts +1 -1
- package/lib/requests/getComponentEvents.js +7 -7
- package/lib/requests/getComponentNames.d.ts +1 -4
- package/lib/requests/getComponentNames.js +7 -11
- package/lib/requests/getComponentProps.d.ts +2 -2
- package/lib/requests/getComponentProps.js +12 -12
- package/lib/requests/getComponentSlots.d.ts +2 -0
- package/lib/requests/getComponentSlots.js +24 -0
- package/lib/requests/getElementAttrs.d.ts +1 -1
- package/lib/requests/getElementAttrs.js +6 -6
- package/lib/requests/getElementNames.d.ts +1 -4
- package/lib/requests/getElementNames.js +6 -10
- package/lib/requests/getImportPathForFile.d.ts +3 -1
- package/lib/requests/getImportPathForFile.js +5 -5
- package/lib/requests/getMissingPropsDiagnostics.d.ts +10 -0
- package/lib/requests/getMissingPropsDiagnostics.js +40 -0
- package/lib/requests/getPropertiesAtLocation.d.ts +1 -1
- package/lib/requests/getPropertiesAtLocation.js +24 -24
- package/lib/requests/index.d.ts +17 -14
- package/lib/requests/resolveModuleName.d.ts +4 -0
- package/lib/requests/resolveModuleName.js +28 -0
- package/lib/requests/types.d.ts +2 -4
- package/package.json +4 -4
package/index.js
CHANGED
|
@@ -7,6 +7,7 @@ const getComponentDirectives_1 = require("./lib/requests/getComponentDirectives"
|
|
|
7
7
|
const getComponentEvents_1 = require("./lib/requests/getComponentEvents");
|
|
8
8
|
const getComponentNames_1 = require("./lib/requests/getComponentNames");
|
|
9
9
|
const getComponentProps_1 = require("./lib/requests/getComponentProps");
|
|
10
|
+
const getComponentSlots_1 = require("./lib/requests/getComponentSlots");
|
|
10
11
|
const getElementAttrs_1 = require("./lib/requests/getElementAttrs");
|
|
11
12
|
const getElementNames_1 = require("./lib/requests/getElementNames");
|
|
12
13
|
const getImportPathForFile_1 = require("./lib/requests/getImportPathForFile");
|
|
@@ -22,7 +23,7 @@ module.exports = (0, createLanguageServicePlugin_1.createLanguageServicePlugin)(
|
|
|
22
23
|
languagePlugins: [languagePlugin],
|
|
23
24
|
setup: language => {
|
|
24
25
|
project2Service.set(info.project, [language, info.languageServiceHost, info.languageService]);
|
|
25
|
-
info.languageService = (0, common_1.createVueLanguageServiceProxy)(ts, language, info.languageService, vueOptions
|
|
26
|
+
info.languageService = (0, common_1.createVueLanguageServiceProxy)(ts, language, info.languageService, vueOptions);
|
|
26
27
|
// #3963
|
|
27
28
|
const timer = setInterval(() => {
|
|
28
29
|
if (info.project['program']) {
|
|
@@ -86,6 +87,16 @@ module.exports = (0, createLanguageServicePlugin_1.createLanguageServicePlugin)(
|
|
|
86
87
|
response: getPropertiesAtLocation_1.getPropertiesAtLocation.apply(getRequestContext(args[0]), args),
|
|
87
88
|
};
|
|
88
89
|
});
|
|
90
|
+
session.addProtocolHandler('_vue:getComponentDirectives', ({ arguments: args }) => {
|
|
91
|
+
return {
|
|
92
|
+
response: getComponentDirectives_1.getComponentDirectives.apply(getRequestContext(args[0]), args),
|
|
93
|
+
};
|
|
94
|
+
});
|
|
95
|
+
session.addProtocolHandler('_vue:getComponentEvents', ({ arguments: args }) => {
|
|
96
|
+
return {
|
|
97
|
+
response: getComponentEvents_1.getComponentEvents.apply(getRequestContext(args[0]), args),
|
|
98
|
+
};
|
|
99
|
+
});
|
|
89
100
|
session.addProtocolHandler('_vue:getComponentNames', ({ arguments: args }) => {
|
|
90
101
|
return {
|
|
91
102
|
response: getComponentNames_1.getComponentNames.apply(getRequestContext(args[0]), args) ?? [],
|
|
@@ -96,14 +107,9 @@ module.exports = (0, createLanguageServicePlugin_1.createLanguageServicePlugin)(
|
|
|
96
107
|
response: getComponentProps_1.getComponentProps.apply(getRequestContext(args[0]), args),
|
|
97
108
|
};
|
|
98
109
|
});
|
|
99
|
-
session.addProtocolHandler('_vue:
|
|
100
|
-
return {
|
|
101
|
-
response: getComponentEvents_1.getComponentEvents.apply(getRequestContext(args[0]), args),
|
|
102
|
-
};
|
|
103
|
-
});
|
|
104
|
-
session.addProtocolHandler('_vue:getComponentDirectives', ({ arguments: args }) => {
|
|
110
|
+
session.addProtocolHandler('_vue:getComponentSlots', ({ arguments: args }) => {
|
|
105
111
|
return {
|
|
106
|
-
response:
|
|
112
|
+
response: getComponentSlots_1.getComponentSlots.apply(getRequestContext(args[0]), args),
|
|
107
113
|
};
|
|
108
114
|
});
|
|
109
115
|
session.addProtocolHandler('_vue:getElementAttrs', ({ arguments: args }) => {
|
|
@@ -132,8 +138,6 @@ module.exports = (0, createLanguageServicePlugin_1.createLanguageServicePlugin)(
|
|
|
132
138
|
languageService: service[2],
|
|
133
139
|
languageServiceHost: service[1],
|
|
134
140
|
language: service[0],
|
|
135
|
-
isTsPlugin: true,
|
|
136
|
-
asScriptId: (fileName) => fileName,
|
|
137
141
|
};
|
|
138
142
|
}
|
|
139
143
|
});
|
package/lib/common.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { type Language, type VueCompilerOptions } from '@vue/language-core';
|
|
2
2
|
import type * as ts from 'typescript';
|
|
3
|
-
export declare function createVueLanguageServiceProxy
|
|
3
|
+
export declare function createVueLanguageServiceProxy(ts: typeof import('typescript'), language: Language<string>, languageService: ts.LanguageService, vueOptions: VueCompilerOptions): ts.LanguageService;
|
package/lib/common.js
CHANGED
|
@@ -4,18 +4,18 @@ exports.createVueLanguageServiceProxy = createVueLanguageServiceProxy;
|
|
|
4
4
|
const language_core_1 = require("@vue/language-core");
|
|
5
5
|
const shared_1 = require("@vue/shared");
|
|
6
6
|
const windowsPathReg = /\\/g;
|
|
7
|
-
function createVueLanguageServiceProxy(ts, language, languageService, vueOptions
|
|
7
|
+
function createVueLanguageServiceProxy(ts, language, languageService, vueOptions) {
|
|
8
8
|
const proxyCache = new Map();
|
|
9
9
|
const getProxyMethod = (target, p) => {
|
|
10
10
|
switch (p) {
|
|
11
11
|
case 'getCompletionsAtPosition':
|
|
12
|
-
return getCompletionsAtPosition(ts, language, vueOptions,
|
|
12
|
+
return getCompletionsAtPosition(ts, language, vueOptions, target[p]);
|
|
13
13
|
case 'getCompletionEntryDetails':
|
|
14
|
-
return getCompletionEntryDetails(language,
|
|
14
|
+
return getCompletionEntryDetails(language, target[p]);
|
|
15
15
|
case 'getCodeFixesAtPosition':
|
|
16
16
|
return getCodeFixesAtPosition(target[p]);
|
|
17
17
|
case 'getDefinitionAndBoundSpan':
|
|
18
|
-
return getDefinitionAndBoundSpan(ts, language, languageService, vueOptions,
|
|
18
|
+
return getDefinitionAndBoundSpan(ts, language, languageService, vueOptions, target[p]);
|
|
19
19
|
}
|
|
20
20
|
};
|
|
21
21
|
return new Proxy(languageService, {
|
|
@@ -36,7 +36,7 @@ function createVueLanguageServiceProxy(ts, language, languageService, vueOptions
|
|
|
36
36
|
},
|
|
37
37
|
});
|
|
38
38
|
}
|
|
39
|
-
function getCompletionsAtPosition(ts, language, vueOptions,
|
|
39
|
+
function getCompletionsAtPosition(ts, language, vueOptions, getCompletionsAtPosition) {
|
|
40
40
|
return (filePath, position, options, formattingSettings) => {
|
|
41
41
|
const fileName = filePath.replace(windowsPathReg, '/');
|
|
42
42
|
const result = getCompletionsAtPosition(fileName, position, options, formattingSettings);
|
|
@@ -45,7 +45,7 @@ function getCompletionsAtPosition(ts, language, vueOptions, asScriptId, getCompl
|
|
|
45
45
|
result.entries = result.entries.filter(entry => !entry.name.includes('__VLS_')
|
|
46
46
|
&& !entry.labelDetails?.description?.includes('__VLS_'));
|
|
47
47
|
// filter global variables in template and styles
|
|
48
|
-
const sourceScript = language.scripts.get(
|
|
48
|
+
const sourceScript = language.scripts.get(fileName);
|
|
49
49
|
const root = sourceScript?.generated?.root;
|
|
50
50
|
if (root instanceof language_core_1.VueVirtualCode) {
|
|
51
51
|
const blocks = [
|
|
@@ -105,7 +105,7 @@ function getCompletionsAtPosition(ts, language, vueOptions, asScriptId, getCompl
|
|
|
105
105
|
return result;
|
|
106
106
|
};
|
|
107
107
|
}
|
|
108
|
-
function getCompletionEntryDetails(language,
|
|
108
|
+
function getCompletionEntryDetails(language, getCompletionEntryDetails) {
|
|
109
109
|
return (...args) => {
|
|
110
110
|
const details = getCompletionEntryDetails(...args);
|
|
111
111
|
// modify import statement
|
|
@@ -125,7 +125,7 @@ function getCompletionEntryDetails(language, asScriptId, getCompletionEntryDetai
|
|
|
125
125
|
if (args[6]?.__isAutoImport) {
|
|
126
126
|
// @ts-expect-error
|
|
127
127
|
const { fileName } = args[6].__isAutoImport;
|
|
128
|
-
const sourceScript = language.scripts.get(
|
|
128
|
+
const sourceScript = language.scripts.get(fileName);
|
|
129
129
|
if (sourceScript?.generated?.root instanceof language_core_1.VueVirtualCode) {
|
|
130
130
|
const sfc = sourceScript.generated.root.vueSfc;
|
|
131
131
|
if (!sfc?.descriptor.script && !sfc?.descriptor.scriptSetup) {
|
|
@@ -153,14 +153,14 @@ function getCodeFixesAtPosition(getCodeFixesAtPosition) {
|
|
|
153
153
|
return result;
|
|
154
154
|
};
|
|
155
155
|
}
|
|
156
|
-
function getDefinitionAndBoundSpan(ts, language, languageService, vueOptions,
|
|
156
|
+
function getDefinitionAndBoundSpan(ts, language, languageService, vueOptions, getDefinitionAndBoundSpan) {
|
|
157
157
|
return (fileName, position) => {
|
|
158
158
|
const result = getDefinitionAndBoundSpan(fileName, position);
|
|
159
159
|
if (!result?.definitions?.length) {
|
|
160
160
|
return result;
|
|
161
161
|
}
|
|
162
162
|
const program = languageService.getProgram();
|
|
163
|
-
const sourceScript = language.scripts.get(
|
|
163
|
+
const sourceScript = language.scripts.get(fileName);
|
|
164
164
|
if (!sourceScript?.generated) {
|
|
165
165
|
return result;
|
|
166
166
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { RequestContext } from './types';
|
|
2
|
-
|
|
2
|
+
interface ExtractPropsInfo {
|
|
3
3
|
name: string;
|
|
4
4
|
type: string;
|
|
5
5
|
model: boolean;
|
|
6
|
-
}
|
|
6
|
+
}
|
|
7
|
+
export declare function collectExtractProps(this: RequestContext, fileName: string, templateCodeRange: [number, number]): ExtractPropsInfo[];
|
|
8
|
+
export {};
|
|
@@ -3,21 +3,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.collectExtractProps = collectExtractProps;
|
|
4
4
|
const language_core_1 = require("@vue/language-core");
|
|
5
5
|
function collectExtractProps(fileName, templateCodeRange) {
|
|
6
|
-
const { typescript: ts, languageService, language
|
|
7
|
-
const sourceScript = language.scripts.get(
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const root = sourceScript.generated.root;
|
|
12
|
-
if (!(root instanceof language_core_1.VueVirtualCode)) {
|
|
13
|
-
return;
|
|
6
|
+
const { typescript: ts, languageService, language } = this;
|
|
7
|
+
const sourceScript = language.scripts.get(fileName);
|
|
8
|
+
const root = sourceScript?.generated?.root;
|
|
9
|
+
if (!sourceScript?.generated || !(root instanceof language_core_1.VueVirtualCode)) {
|
|
10
|
+
return [];
|
|
14
11
|
}
|
|
15
12
|
const result = new Map();
|
|
16
13
|
const program = languageService.getProgram();
|
|
17
14
|
const sourceFile = program.getSourceFile(fileName);
|
|
18
15
|
const checker = program.getTypeChecker();
|
|
19
|
-
const script = sourceScript.generated
|
|
20
|
-
const maps = script ? [...language.maps.forEach(script.code)].map(([
|
|
16
|
+
const script = sourceScript.generated.languagePlugin.typescript?.getServiceScript(root);
|
|
17
|
+
const maps = script ? [...language.maps.forEach(script.code)].map(([, map]) => map) : [];
|
|
21
18
|
const { sfc } = root;
|
|
22
19
|
sourceFile.forEachChild(function visit(node) {
|
|
23
20
|
if (ts.isPropertyAccessExpression(node)
|
|
@@ -27,7 +24,7 @@ function collectExtractProps(fileName, templateCodeRange) {
|
|
|
27
24
|
const { name } = node;
|
|
28
25
|
for (const map of maps) {
|
|
29
26
|
let mapped = false;
|
|
30
|
-
for (const source of map.toSourceLocation(name.getEnd() -
|
|
27
|
+
for (const source of map.toSourceLocation(name.getEnd() - sourceScript.snapshot.getLength())) {
|
|
31
28
|
if (source[0] >= sfc.template.startTagEnd + templateCodeRange[0]
|
|
32
29
|
&& source[0] <= sfc.template.startTagEnd + templateCodeRange[1]
|
|
33
30
|
&& (0, language_core_1.isSemanticTokensEnabled)(source[1].data)) {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { RequestContext } from './types';
|
|
2
|
-
export declare function getComponentDirectives(this: RequestContext, fileName: string): string[]
|
|
2
|
+
export declare function getComponentDirectives(this: RequestContext, fileName: string): string[];
|
|
@@ -12,13 +12,13 @@ const builtInDirectives = new Set([
|
|
|
12
12
|
'vSlot',
|
|
13
13
|
]);
|
|
14
14
|
function getComponentDirectives(fileName) {
|
|
15
|
-
const { typescript: ts, language, languageService
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
const { typescript: ts, language, languageService } = this;
|
|
16
|
+
const sourceScript = language.scripts.get(fileName);
|
|
17
|
+
const root = sourceScript?.generated?.root;
|
|
18
|
+
if (!sourceScript?.generated || !(root instanceof language_core_1.VueVirtualCode)) {
|
|
19
|
+
return [];
|
|
19
20
|
}
|
|
20
|
-
const
|
|
21
|
-
const directives = (0, utils_1.getVariableType)(ts, languageService, vueCode, '__VLS_directives');
|
|
21
|
+
const directives = (0, utils_1.getVariableType)(ts, languageService, root, '__VLS_directives');
|
|
22
22
|
if (!directives) {
|
|
23
23
|
return [];
|
|
24
24
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { RequestContext } from './types';
|
|
2
|
-
export declare function getComponentEvents(this: RequestContext, fileName: string, tag: string): string[]
|
|
2
|
+
export declare function getComponentEvents(this: RequestContext, fileName: string, tag: string): string[];
|
|
@@ -4,19 +4,19 @@ exports.getComponentEvents = getComponentEvents;
|
|
|
4
4
|
const language_core_1 = require("@vue/language-core");
|
|
5
5
|
const utils_1 = require("./utils");
|
|
6
6
|
function getComponentEvents(fileName, tag) {
|
|
7
|
-
const { typescript: ts, language, languageService
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
const { typescript: ts, language, languageService } = this;
|
|
8
|
+
const sourceScript = language.scripts.get(fileName);
|
|
9
|
+
const root = sourceScript?.generated?.root;
|
|
10
|
+
if (!sourceScript?.generated || !(root instanceof language_core_1.VueVirtualCode)) {
|
|
11
|
+
return [];
|
|
11
12
|
}
|
|
12
|
-
const vueCode = volarFile.generated.root;
|
|
13
13
|
const program = languageService.getProgram();
|
|
14
14
|
const checker = program.getTypeChecker();
|
|
15
|
-
const components = (0, utils_1.getVariableType)(ts, languageService,
|
|
15
|
+
const components = (0, utils_1.getVariableType)(ts, languageService, root, '__VLS_components');
|
|
16
16
|
if (!components) {
|
|
17
17
|
return [];
|
|
18
18
|
}
|
|
19
|
-
const componentType = (0, utils_1.getComponentType)(ts, languageService,
|
|
19
|
+
const componentType = (0, utils_1.getComponentType)(ts, languageService, root, components, fileName, tag);
|
|
20
20
|
if (!componentType) {
|
|
21
21
|
return [];
|
|
22
22
|
}
|
|
@@ -1,5 +1,2 @@
|
|
|
1
|
-
import { VueVirtualCode } from '@vue/language-core';
|
|
2
|
-
import type * as ts from 'typescript';
|
|
3
1
|
import type { RequestContext } from './types';
|
|
4
|
-
export declare function getComponentNames(this: RequestContext, fileName: string): string[]
|
|
5
|
-
export declare function _getComponentNames(ts: typeof import('typescript'), tsLs: ts.LanguageService, vueCode: VueVirtualCode): string[];
|
|
2
|
+
export declare function getComponentNames(this: RequestContext, fileName: string): string[];
|
|
@@ -1,26 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getComponentNames = getComponentNames;
|
|
4
|
-
exports._getComponentNames = _getComponentNames;
|
|
5
4
|
const language_core_1 = require("@vue/language-core");
|
|
6
5
|
const utils_1 = require("./utils");
|
|
7
6
|
function getComponentNames(fileName) {
|
|
8
|
-
const { typescript: ts, language, languageService
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
const { typescript: ts, language, languageService } = this;
|
|
8
|
+
const sourceScript = language.scripts.get(fileName);
|
|
9
|
+
const root = sourceScript?.generated?.root;
|
|
10
|
+
if (!sourceScript?.generated || !(root instanceof language_core_1.VueVirtualCode)) {
|
|
11
|
+
return [];
|
|
12
12
|
}
|
|
13
|
-
const
|
|
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')
|
|
13
|
+
const names = (0, utils_1.getVariableType)(ts, languageService, root, '__VLS_components')
|
|
18
14
|
?.type
|
|
19
15
|
?.getProperties()
|
|
20
16
|
.map(c => c.name)
|
|
21
17
|
.filter(entry => !entry.includes('$') && !entry.startsWith('_'))
|
|
22
18
|
?? [];
|
|
23
|
-
names.push((0, utils_1.getSelfComponentName)(
|
|
19
|
+
names.push((0, utils_1.getSelfComponentName)(fileName));
|
|
24
20
|
return names;
|
|
25
21
|
}
|
|
26
22
|
//# sourceMappingURL=getComponentNames.js.map
|
|
@@ -4,7 +4,7 @@ export interface ComponentPropInfo {
|
|
|
4
4
|
required?: boolean;
|
|
5
5
|
deprecated?: boolean;
|
|
6
6
|
isAttribute?: boolean;
|
|
7
|
-
|
|
7
|
+
documentation?: string;
|
|
8
8
|
values?: string[];
|
|
9
9
|
}
|
|
10
|
-
export declare function getComponentProps(this: RequestContext, fileName: string, tag: string): ComponentPropInfo[]
|
|
10
|
+
export declare function getComponentProps(this: RequestContext, fileName: string, tag: string): ComponentPropInfo[];
|
|
@@ -4,17 +4,17 @@ exports.getComponentProps = getComponentProps;
|
|
|
4
4
|
const language_core_1 = require("@vue/language-core");
|
|
5
5
|
const utils_1 = require("./utils");
|
|
6
6
|
function getComponentProps(fileName, tag) {
|
|
7
|
-
const { typescript: ts, language, languageService
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
const { typescript: ts, language, languageService } = this;
|
|
8
|
+
const sourceScript = language.scripts.get(fileName);
|
|
9
|
+
const root = sourceScript?.generated?.root;
|
|
10
|
+
if (!sourceScript?.generated || !(root instanceof language_core_1.VueVirtualCode)) {
|
|
11
|
+
return [];
|
|
11
12
|
}
|
|
12
|
-
const
|
|
13
|
-
const components = (0, utils_1.getVariableType)(ts, languageService, vueCode, '__VLS_components');
|
|
13
|
+
const components = (0, utils_1.getVariableType)(ts, languageService, root, '__VLS_components');
|
|
14
14
|
if (!components) {
|
|
15
15
|
return [];
|
|
16
16
|
}
|
|
17
|
-
const componentType = (0, utils_1.getComponentType)(ts, languageService,
|
|
17
|
+
const componentType = (0, utils_1.getComponentType)(ts, languageService, root, components, fileName, tag);
|
|
18
18
|
if (!componentType) {
|
|
19
19
|
return [];
|
|
20
20
|
}
|
|
@@ -49,7 +49,7 @@ function getComponentProps(fileName, tag) {
|
|
|
49
49
|
}
|
|
50
50
|
const name = prop.name;
|
|
51
51
|
const required = !(prop.flags & ts.SymbolFlags.Optional) || undefined;
|
|
52
|
-
const {
|
|
52
|
+
const { documentation, deprecated, } = generateDocumentation(prop.getDocumentationComment(checker), prop.getJsDocTags());
|
|
53
53
|
const values = [];
|
|
54
54
|
const type = checker.getTypeOfSymbol(prop);
|
|
55
55
|
const subTypes = type.types;
|
|
@@ -79,18 +79,18 @@ function getComponentProps(fileName, tag) {
|
|
|
79
79
|
required,
|
|
80
80
|
deprecated,
|
|
81
81
|
isAttribute,
|
|
82
|
-
|
|
82
|
+
documentation,
|
|
83
83
|
values,
|
|
84
84
|
});
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
|
-
function
|
|
87
|
+
function generateDocumentation(parts, jsDocTags) {
|
|
88
88
|
const parsedComment = _symbolDisplayPartsToMarkdown(parts);
|
|
89
89
|
const parsedJsDoc = _jsDocTagInfoToMarkdown(jsDocTags);
|
|
90
|
-
const
|
|
90
|
+
const documentation = [parsedComment, parsedJsDoc].filter(str => !!str).join('\n\n');
|
|
91
91
|
const deprecated = jsDocTags.some(tag => tag.name === 'deprecated');
|
|
92
92
|
return {
|
|
93
|
-
|
|
93
|
+
documentation,
|
|
94
94
|
deprecated,
|
|
95
95
|
};
|
|
96
96
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getComponentSlots = getComponentSlots;
|
|
4
|
+
const language_core_1 = require("@vue/language-core");
|
|
5
|
+
const utils_1 = require("./utils");
|
|
6
|
+
function getComponentSlots(fileName) {
|
|
7
|
+
const { typescript: ts, language, languageService } = this;
|
|
8
|
+
const sourceScript = language.scripts.get(fileName);
|
|
9
|
+
const root = sourceScript?.generated?.root;
|
|
10
|
+
if (!sourceScript?.generated || !(root instanceof language_core_1.VueVirtualCode)) {
|
|
11
|
+
return [];
|
|
12
|
+
}
|
|
13
|
+
const codegen = language_core_1.tsCodegen.get(root.sfc);
|
|
14
|
+
if (!codegen) {
|
|
15
|
+
return [];
|
|
16
|
+
}
|
|
17
|
+
const assignName = codegen.getSetupSlotsAssignName() ?? `__VLS_slots`;
|
|
18
|
+
const slots = (0, utils_1.getVariableType)(ts, languageService, root, assignName);
|
|
19
|
+
if (!slots) {
|
|
20
|
+
return [];
|
|
21
|
+
}
|
|
22
|
+
return slots.type.getProperties().map(({ name }) => name);
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=getComponentSlots.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { RequestContext } from './types';
|
|
2
|
-
export declare function getElementAttrs(this: RequestContext, fileName: string, tagName: string): string[]
|
|
2
|
+
export declare function getElementAttrs(this: RequestContext, fileName: string, tagName: string): string[];
|
|
@@ -4,15 +4,15 @@ exports.getElementAttrs = getElementAttrs;
|
|
|
4
4
|
const language_core_1 = require("@vue/language-core");
|
|
5
5
|
const utils_1 = require("./utils");
|
|
6
6
|
function getElementAttrs(fileName, tagName) {
|
|
7
|
-
const { typescript: ts, language, languageService
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
const { typescript: ts, language, languageService } = this;
|
|
8
|
+
const sourceScript = language.scripts.get(fileName);
|
|
9
|
+
const root = sourceScript?.generated?.root;
|
|
10
|
+
if (!sourceScript?.generated || !(root instanceof language_core_1.VueVirtualCode)) {
|
|
11
|
+
return [];
|
|
11
12
|
}
|
|
12
|
-
const vueCode = volarFile.generated.root;
|
|
13
13
|
const program = languageService.getProgram();
|
|
14
14
|
const checker = program.getTypeChecker();
|
|
15
|
-
const elements = (0, utils_1.getVariableType)(ts, languageService,
|
|
15
|
+
const elements = (0, utils_1.getVariableType)(ts, languageService, root, '__VLS_elements');
|
|
16
16
|
if (!elements) {
|
|
17
17
|
return [];
|
|
18
18
|
}
|
|
@@ -1,5 +1,2 @@
|
|
|
1
|
-
import { VueVirtualCode } from '@vue/language-core';
|
|
2
|
-
import type * as ts from 'typescript';
|
|
3
1
|
import type { RequestContext } from './types';
|
|
4
|
-
export declare function getElementNames(this: RequestContext, fileName: string): string[]
|
|
5
|
-
export declare function _getElementNames(ts: typeof import('typescript'), tsLs: ts.LanguageService, vueCode: VueVirtualCode): string[];
|
|
2
|
+
export declare function getElementNames(this: RequestContext, fileName: string): string[];
|
|
@@ -1,20 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getElementNames = getElementNames;
|
|
4
|
-
exports._getElementNames = _getElementNames;
|
|
5
4
|
const language_core_1 = require("@vue/language-core");
|
|
6
5
|
const utils_1 = require("./utils");
|
|
7
6
|
function getElementNames(fileName) {
|
|
8
|
-
const { typescript: ts, language, languageService
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
const { typescript: ts, language, languageService } = this;
|
|
8
|
+
const sourceScript = language.scripts.get(fileName);
|
|
9
|
+
const root = sourceScript?.generated?.root;
|
|
10
|
+
if (!sourceScript?.generated || !(root instanceof language_core_1.VueVirtualCode)) {
|
|
11
|
+
return [];
|
|
12
12
|
}
|
|
13
|
-
|
|
14
|
-
return _getElementNames(ts, languageService, vueCode);
|
|
15
|
-
}
|
|
16
|
-
function _getElementNames(ts, tsLs, vueCode) {
|
|
17
|
-
return (0, utils_1.getVariableType)(ts, tsLs, vueCode, '__VLS_elements')
|
|
13
|
+
return (0, utils_1.getVariableType)(ts, languageService, root, '__VLS_elements')
|
|
18
14
|
?.type
|
|
19
15
|
?.getProperties()
|
|
20
16
|
.map(c => c.name)
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import type * as ts from 'typescript';
|
|
2
2
|
import type { RequestContext } from './types';
|
|
3
|
-
export declare function getImportPathForFile(this: RequestContext, fileName: string, incomingFileName: string, preferences: ts.UserPreferences):
|
|
3
|
+
export declare function getImportPathForFile(this: RequestContext, fileName: string, incomingFileName: string, preferences: ts.UserPreferences): {
|
|
4
|
+
path?: string;
|
|
5
|
+
};
|
|
@@ -7,13 +7,13 @@ function getImportPathForFile(fileName, incomingFileName, preferences) {
|
|
|
7
7
|
const incomingFile = program?.getSourceFile(incomingFileName);
|
|
8
8
|
const sourceFile = program?.getSourceFile(fileName);
|
|
9
9
|
if (!program || !sourceFile || !incomingFile) {
|
|
10
|
-
return;
|
|
10
|
+
return {};
|
|
11
11
|
}
|
|
12
12
|
const getModuleSpecifiersWithCacheInfo = ts.moduleSpecifiers.getModuleSpecifiersWithCacheInfo;
|
|
13
13
|
const resolutionHost = ts.createModuleSpecifierResolutionHost(program, languageServiceHost);
|
|
14
|
-
const moduleSpecifiers = getModuleSpecifiersWithCacheInfo(incomingFile.symbol, program.getTypeChecker(), languageServiceHost.getCompilationSettings(), sourceFile, resolutionHost, preferences);
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
14
|
+
const { moduleSpecifiers } = getModuleSpecifiersWithCacheInfo(incomingFile.symbol, program.getTypeChecker(), languageServiceHost.getCompilationSettings(), sourceFile, resolutionHost, preferences);
|
|
15
|
+
return {
|
|
16
|
+
path: moduleSpecifiers[0],
|
|
17
|
+
};
|
|
18
18
|
}
|
|
19
19
|
//# sourceMappingURL=getImportPathForFile.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { RequestContext } from './types';
|
|
2
|
+
export interface ComponentPropInfo {
|
|
3
|
+
name: string;
|
|
4
|
+
required?: boolean;
|
|
5
|
+
deprecated?: boolean;
|
|
6
|
+
isAttribute?: boolean;
|
|
7
|
+
commentMarkdown?: string;
|
|
8
|
+
values?: string[];
|
|
9
|
+
}
|
|
10
|
+
export declare function getMissingPropsDiagnostics(this: RequestContext, fileName: string): undefined;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getMissingPropsDiagnostics = getMissingPropsDiagnostics;
|
|
4
|
+
const language_core_1 = require("@vue/language-core");
|
|
5
|
+
function getMissingPropsDiagnostics(fileName) {
|
|
6
|
+
const { typescript: ts, language, languageService, asScriptId } = this;
|
|
7
|
+
const volarFile = language.scripts.get(asScriptId(fileName));
|
|
8
|
+
if (!(volarFile?.generated?.root instanceof language_core_1.VueVirtualCode)) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
const vueCode = volarFile.generated.root;
|
|
12
|
+
const program = languageService.getProgram();
|
|
13
|
+
const sourceFile = program.getSourceFile(vueCode.fileName);
|
|
14
|
+
if (!sourceFile) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const checker = program.getTypeChecker();
|
|
18
|
+
ts.forEachChild(sourceFile, function visit(node) {
|
|
19
|
+
if (ts.isVariableDeclaration(node)
|
|
20
|
+
&& node.initializer
|
|
21
|
+
&& ts.isCallExpression(node.initializer)
|
|
22
|
+
&& ts.isIdentifier(node.initializer.expression)
|
|
23
|
+
&& /^__VLS_\d+$/.test(node.initializer.expression.text)) {
|
|
24
|
+
const firstArg = node.initializer.arguments[0];
|
|
25
|
+
const type = checker.getTypeAtLocation(firstArg);
|
|
26
|
+
const contextualType = checker.getContextualType(firstArg);
|
|
27
|
+
if (contextualType) {
|
|
28
|
+
const subtype = contextualType.isUnion()
|
|
29
|
+
? contextualType.types.find(subtype => checker.isTypeAssignableTo(subtype, type))
|
|
30
|
+
: contextualType;
|
|
31
|
+
void subtype;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
ts.forEachChild(node, visit);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=getMissingPropsDiagnostics.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { RequestContext } from './types';
|
|
2
|
-
export declare function getPropertiesAtLocation(this: RequestContext, fileName: string, position: number): string[]
|
|
2
|
+
export declare function getPropertiesAtLocation(this: RequestContext, fileName: string, position: number): string[];
|
|
@@ -4,42 +4,42 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
4
4
|
exports.getPropertiesAtLocation = getPropertiesAtLocation;
|
|
5
5
|
const language_core_1 = require("@vue/language-core");
|
|
6
6
|
function getPropertiesAtLocation(fileName, position) {
|
|
7
|
-
const { languageService, language, typescript: ts
|
|
7
|
+
const { languageService, language, typescript: ts } = this;
|
|
8
8
|
// mapping
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
if (mapped) {
|
|
9
|
+
const sourceScript = language.scripts.get(fileName);
|
|
10
|
+
const root = sourceScript?.generated?.root;
|
|
11
|
+
if (!sourceScript?.generated || !(root instanceof language_core_1.VueVirtualCode)) {
|
|
12
|
+
return [];
|
|
13
|
+
}
|
|
14
|
+
const virtualScript = sourceScript.generated.languagePlugin.typescript?.getServiceScript(root);
|
|
15
|
+
if (!virtualScript) {
|
|
16
|
+
return [];
|
|
17
|
+
}
|
|
18
|
+
let mapped = false;
|
|
19
|
+
for (const [_sourceScript, map] of language.maps.forEach(virtualScript.code)) {
|
|
20
|
+
for (const [position2, mapping] of map.toGeneratedLocation(position)) {
|
|
21
|
+
if ((0, language_core_1.isCompletionEnabled)(mapping.data)) {
|
|
22
|
+
position = position2;
|
|
23
|
+
mapped = true;
|
|
25
24
|
break;
|
|
26
25
|
}
|
|
27
26
|
}
|
|
28
|
-
if (
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
if (isTsPlugin) {
|
|
32
|
-
position += file.snapshot.getLength();
|
|
27
|
+
if (mapped) {
|
|
28
|
+
break;
|
|
33
29
|
}
|
|
34
30
|
}
|
|
31
|
+
if (!mapped) {
|
|
32
|
+
return [];
|
|
33
|
+
}
|
|
34
|
+
position += sourceScript.snapshot.getLength();
|
|
35
35
|
const program = languageService.getProgram();
|
|
36
36
|
const sourceFile = program.getSourceFile(fileName);
|
|
37
37
|
if (!sourceFile) {
|
|
38
|
-
return;
|
|
38
|
+
return [];
|
|
39
39
|
}
|
|
40
40
|
const node = findPositionIdentifier(sourceFile, sourceFile, position);
|
|
41
41
|
if (!node) {
|
|
42
|
-
return;
|
|
42
|
+
return [];
|
|
43
43
|
}
|
|
44
44
|
const checker = program.getTypeChecker();
|
|
45
45
|
const type = checker.getTypeAtLocation(node);
|
package/lib/requests/index.d.ts
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
import type * as ts from 'typescript';
|
|
2
|
-
type
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
getComponentEvents:
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
2
|
+
type Request<T extends (...args: any) => any> = (...args: Parameters<T>) => MaybePromise<ReturnType<T> | null | undefined>;
|
|
3
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
4
|
+
export interface Requests {
|
|
5
|
+
collectExtractProps: Request<typeof import('./collectExtractProps.js')['collectExtractProps']>;
|
|
6
|
+
getImportPathForFile: Request<typeof import('./getImportPathForFile.js')['getImportPathForFile']>;
|
|
7
|
+
getPropertiesAtLocation: Request<typeof import('./getPropertiesAtLocation.js')['getPropertiesAtLocation']>;
|
|
8
|
+
getComponentDirectives: Request<typeof import('./getComponentDirectives.js')['getComponentDirectives']>;
|
|
9
|
+
getComponentEvents: Request<typeof import('./getComponentEvents.js')['getComponentEvents']>;
|
|
10
|
+
getComponentNames: Request<typeof import('./getComponentNames.js')['getComponentNames']>;
|
|
11
|
+
getComponentProps: Request<typeof import('./getComponentProps.js')['getComponentProps']>;
|
|
12
|
+
getComponentSlots: Request<typeof import('./getComponentSlots.js')['getComponentSlots']>;
|
|
13
|
+
getElementAttrs: Request<typeof import('./getElementAttrs.js')['getElementAttrs']>;
|
|
14
|
+
getElementNames: Request<typeof import('./getElementNames.js')['getElementNames']>;
|
|
15
|
+
getDocumentHighlights: Request<(fileName: string, position: number) => ts.DocumentHighlights[]>;
|
|
16
|
+
getEncodedSemanticClassifications: Request<(fileName: string, span: ts.TextSpan) => ts.Classifications>;
|
|
17
|
+
getQuickInfoAtPosition: Request<(fileName: string, position: ts.LineAndCharacter) => string>;
|
|
18
|
+
}
|
|
16
19
|
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveModuleName = resolveModuleName;
|
|
4
|
+
function resolveModuleName(fileName, moduleName) {
|
|
5
|
+
const { typescript: ts, languageServiceHost } = this;
|
|
6
|
+
const compilerOptions = languageServiceHost.getCompilationSettings();
|
|
7
|
+
const ext = moduleName.split('.').pop();
|
|
8
|
+
const result = ts.resolveModuleName(moduleName, fileName, {
|
|
9
|
+
...compilerOptions,
|
|
10
|
+
allowArbitraryExtensions: true,
|
|
11
|
+
}, {
|
|
12
|
+
fileExists(fileName) {
|
|
13
|
+
fileName = transformFileName(fileName, ext);
|
|
14
|
+
return languageServiceHost.fileExists(fileName);
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
const resolveFileName = result.resolvedModule?.resolvedFileName;
|
|
18
|
+
return {
|
|
19
|
+
name: resolveFileName ? transformFileName(resolveFileName, ext) : undefined,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
function transformFileName(fileName, ext) {
|
|
23
|
+
if (ext && fileName.endsWith(`.d.${ext}.ts`)) {
|
|
24
|
+
return fileName.slice(0, -`.d.${ext}.ts`.length) + `.${ext}`;
|
|
25
|
+
}
|
|
26
|
+
return fileName;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=resolveModuleName.js.map
|
package/lib/requests/types.d.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import type { Language } from '@vue/language-core';
|
|
2
2
|
import type * as ts from 'typescript';
|
|
3
|
-
export interface RequestContext
|
|
3
|
+
export interface RequestContext {
|
|
4
4
|
typescript: typeof ts;
|
|
5
5
|
languageService: ts.LanguageService;
|
|
6
6
|
languageServiceHost: ts.LanguageServiceHost;
|
|
7
|
-
language: Language<
|
|
8
|
-
isTsPlugin: boolean;
|
|
9
|
-
asScriptId: (fileName: string) => T;
|
|
7
|
+
language: Language<string>;
|
|
10
8
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vue/typescript-plugin",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.5",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"**/*.js",
|
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
"directory": "packages/typescript-plugin"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@volar/typescript": "2.4.
|
|
17
|
-
"@vue/language-core": "3.0.
|
|
16
|
+
"@volar/typescript": "2.4.22",
|
|
17
|
+
"@vue/language-core": "3.0.5",
|
|
18
18
|
"@vue/shared": "^3.5.0",
|
|
19
19
|
"path-browserify": "^1.0.1"
|
|
20
20
|
},
|
|
@@ -22,5 +22,5 @@
|
|
|
22
22
|
"@types/node": "^22.10.4",
|
|
23
23
|
"@types/path-browserify": "^1.0.1"
|
|
24
24
|
},
|
|
25
|
-
"gitHead": "
|
|
25
|
+
"gitHead": "036b6b1882179d35586e16f2a5cba5150e5d18e6"
|
|
26
26
|
}
|