@vue/typescript-plugin 2.0.16 → 2.0.18
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 +1 -1
- package/lib/common.d.ts +1 -1
- package/lib/common.js +66 -3
- package/lib/requests/collectExtractProps.d.ts +2 -9
- package/lib/requests/componentInfos.d.ts +2 -6
- package/lib/requests/getImportPathForFile.d.ts +2 -5
- package/lib/requests/getPropertiesAtLocation.d.ts +2 -9
- package/lib/requests/getQuickInfoAtPosition.d.ts +2 -4
- package/lib/requests/types.d.ts +10 -0
- package/lib/requests/types.js +3 -0
- package/lib/server.d.ts +1 -1
- package/lib/server.js +0 -1
- package/package.json +4 -4
package/index.js
CHANGED
|
@@ -42,7 +42,7 @@ function createLanguageServicePlugin() {
|
|
|
42
42
|
projectExternalFileExtensions.set(info.project, extensions);
|
|
43
43
|
server_1.projects.set(info.project, { info, language, vueOptions });
|
|
44
44
|
(0, decorateLanguageService_1.decorateLanguageService)(language, info.languageService);
|
|
45
|
-
(0, common_1.decorateLanguageServiceForVue)(language, info.languageService, vueOptions, ts, true);
|
|
45
|
+
(0, common_1.decorateLanguageServiceForVue)(language, info.languageService, vueOptions, ts, true, fileName => fileName);
|
|
46
46
|
(0, decorateLanguageServiceHost_1.decorateLanguageServiceHost)(ts, language, info.languageServiceHost);
|
|
47
47
|
(0, server_1.startNamedPipeServer)(ts, info.project.projectKind, info.project.getCurrentDirectory());
|
|
48
48
|
// #3963
|
package/lib/common.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as vue from '@vue/language-core';
|
|
2
2
|
import type * as ts from 'typescript';
|
|
3
|
-
export declare function decorateLanguageServiceForVue(language: vue.Language, languageService: ts.LanguageService, vueOptions: vue.VueCompilerOptions, ts: typeof import('typescript'), isTsPlugin: boolean): void;
|
|
3
|
+
export declare function decorateLanguageServiceForVue(language: vue.Language, languageService: ts.LanguageService, vueOptions: vue.VueCompilerOptions, ts: typeof import('typescript'), isTsPlugin: boolean, getScriptId: (fileName: string) => string): void;
|
|
4
4
|
export declare function getComponentSpans(this: {
|
|
5
5
|
typescript: typeof import('typescript');
|
|
6
6
|
languageService: ts.LanguageService;
|
package/lib/common.js
CHANGED
|
@@ -4,8 +4,8 @@ exports.getComponentSpans = exports.decorateLanguageServiceForVue = void 0;
|
|
|
4
4
|
const vue = require("@vue/language-core");
|
|
5
5
|
const shared_1 = require("@vue/shared");
|
|
6
6
|
const componentInfos_1 = require("./requests/componentInfos");
|
|
7
|
-
function decorateLanguageServiceForVue(language, languageService, vueOptions, ts, isTsPlugin) {
|
|
8
|
-
const { getCompletionsAtPosition, getCompletionEntryDetails, getCodeFixesAtPosition, getEncodedSemanticClassifications, } = languageService;
|
|
7
|
+
function decorateLanguageServiceForVue(language, languageService, vueOptions, ts, isTsPlugin, getScriptId) {
|
|
8
|
+
const { getCompletionsAtPosition, getCompletionEntryDetails, getCodeFixesAtPosition, getEncodedSemanticClassifications, getQuickInfoAtPosition, } = languageService;
|
|
9
9
|
languageService.getCompletionsAtPosition = (fileName, position, options, formattingSettings) => {
|
|
10
10
|
const result = getCompletionsAtPosition(fileName, position, options, formattingSettings);
|
|
11
11
|
if (result) {
|
|
@@ -36,6 +36,12 @@ function decorateLanguageServiceForVue(language, languageService, vueOptions, ts
|
|
|
36
36
|
break;
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
|
+
if (item.data) {
|
|
40
|
+
// @ts-expect-error
|
|
41
|
+
item.data.__isAutoImport = {
|
|
42
|
+
fileName,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
39
45
|
}
|
|
40
46
|
}
|
|
41
47
|
}
|
|
@@ -56,6 +62,27 @@ function decorateLanguageServiceForVue(language, languageService, vueOptions, ts
|
|
|
56
62
|
}
|
|
57
63
|
}
|
|
58
64
|
}
|
|
65
|
+
// @ts-expect-error
|
|
66
|
+
if (args[6]?.__isAutoImport) {
|
|
67
|
+
// @ts-expect-error
|
|
68
|
+
const { fileName } = args[6]?.__isAutoImport;
|
|
69
|
+
const sourceScript = language.scripts.get(getScriptId(fileName));
|
|
70
|
+
if (sourceScript?.generated?.root instanceof vue.VueVirtualCode) {
|
|
71
|
+
const sfc = sourceScript.generated.root.getVueSfc();
|
|
72
|
+
if (!sfc?.descriptor.script && !sfc?.descriptor.scriptSetup) {
|
|
73
|
+
for (const codeAction of details?.codeActions ?? []) {
|
|
74
|
+
for (const change of codeAction.changes) {
|
|
75
|
+
for (const textChange of change.textChanges) {
|
|
76
|
+
textChange.newText = `<script setup lang="ts">${textChange.newText}</script>\n\n`;
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
59
86
|
return details;
|
|
60
87
|
};
|
|
61
88
|
languageService.getCodeFixesAtPosition = (...args) => {
|
|
@@ -64,10 +91,46 @@ function decorateLanguageServiceForVue(language, languageService, vueOptions, ts
|
|
|
64
91
|
result = result.filter(entry => entry.description.indexOf('__VLS_') === -1);
|
|
65
92
|
return result;
|
|
66
93
|
};
|
|
94
|
+
languageService.getQuickInfoAtPosition = (...args) => {
|
|
95
|
+
const result = getQuickInfoAtPosition(...args);
|
|
96
|
+
if (result && result.documentation?.length === 1 && result.documentation[0].text.startsWith('__VLS_emit,')) {
|
|
97
|
+
const [_, emitVarName, eventName] = result.documentation[0].text.split(',');
|
|
98
|
+
const program = languageService.getProgram();
|
|
99
|
+
const typeChecker = program.getTypeChecker();
|
|
100
|
+
const sourceFile = program.getSourceFile(args[0]);
|
|
101
|
+
result.documentation = undefined;
|
|
102
|
+
let symbolNode;
|
|
103
|
+
sourceFile?.forEachChild(function visit(node) {
|
|
104
|
+
if (ts.isIdentifier(node) && node.text === emitVarName) {
|
|
105
|
+
symbolNode = node;
|
|
106
|
+
}
|
|
107
|
+
if (symbolNode) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
ts.forEachChild(node, visit);
|
|
111
|
+
});
|
|
112
|
+
if (symbolNode) {
|
|
113
|
+
const emitSymbol = typeChecker.getSymbolAtLocation(symbolNode);
|
|
114
|
+
if (emitSymbol) {
|
|
115
|
+
const type = typeChecker.getTypeOfSymbolAtLocation(emitSymbol, symbolNode);
|
|
116
|
+
const calls = type.getCallSignatures();
|
|
117
|
+
for (const call of calls) {
|
|
118
|
+
const callEventName = typeChecker.getTypeOfSymbolAtLocation(call.parameters[0], symbolNode).value;
|
|
119
|
+
call.getJsDocTags();
|
|
120
|
+
if (callEventName === eventName) {
|
|
121
|
+
result.documentation = call.getDocumentationComment(typeChecker);
|
|
122
|
+
result.tags = call.getJsDocTags();
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return result;
|
|
129
|
+
};
|
|
67
130
|
if (isTsPlugin) {
|
|
68
131
|
languageService.getEncodedSemanticClassifications = (fileName, span, format) => {
|
|
69
132
|
const result = getEncodedSemanticClassifications(fileName, span, format);
|
|
70
|
-
const file = language.scripts.get(fileName);
|
|
133
|
+
const file = language.scripts.get(getScriptId(fileName));
|
|
71
134
|
if (file?.generated?.root instanceof vue.VueVirtualCode) {
|
|
72
135
|
const { template } = file.generated.root.sfc;
|
|
73
136
|
if (template) {
|
|
@@ -1,12 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export declare function collectExtractProps(this: {
|
|
4
|
-
typescript: typeof import('typescript');
|
|
5
|
-
languageService: ts.LanguageService;
|
|
6
|
-
language: Language;
|
|
7
|
-
isTsPlugin: boolean;
|
|
8
|
-
getFileId: (fileName: string) => string;
|
|
9
|
-
}, fileName: string, templateCodeRange: [number, number]): {
|
|
1
|
+
import type { RequestContext } from './types';
|
|
2
|
+
export declare function collectExtractProps(this: RequestContext, fileName: string, templateCodeRange: [number, number]): {
|
|
10
3
|
name: string;
|
|
11
4
|
type: string;
|
|
12
5
|
model: boolean;
|
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
import * as vue from '@vue/language-core';
|
|
2
2
|
import type * as ts from 'typescript';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
languageService: ts.LanguageService;
|
|
6
|
-
language: vue.Language;
|
|
7
|
-
getFileId: (fileName: string) => string;
|
|
8
|
-
}, fileName: string, tag: string, requiredOnly?: boolean): string[] | undefined;
|
|
3
|
+
import type { RequestContext } from './types';
|
|
4
|
+
export declare function getComponentProps(this: RequestContext, fileName: string, tag: string, requiredOnly?: boolean): string[] | undefined;
|
|
9
5
|
export declare function getComponentEvents(this: {
|
|
10
6
|
typescript: typeof import('typescript');
|
|
11
7
|
languageService: ts.LanguageService;
|
|
@@ -1,6 +1,3 @@
|
|
|
1
1
|
import type * as ts from 'typescript';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
languageService: ts.LanguageService;
|
|
5
|
-
languageServiceHost: ts.LanguageServiceHost;
|
|
6
|
-
}, fileName: string, incomingFileName: string, preferences: ts.UserPreferences): string | undefined;
|
|
2
|
+
import type { RequestContext } from './types';
|
|
3
|
+
export declare function getImportPathForFile(this: RequestContext, fileName: string, incomingFileName: string, preferences: ts.UserPreferences): string | undefined;
|
|
@@ -1,9 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export declare function getPropertiesAtLocation(this: {
|
|
4
|
-
typescript: typeof import('typescript');
|
|
5
|
-
languageService: ts.LanguageService;
|
|
6
|
-
language: Language;
|
|
7
|
-
isTsPlugin: boolean;
|
|
8
|
-
getFileId: (fileName: string) => string;
|
|
9
|
-
}, fileName: string, position: number): string[] | undefined;
|
|
1
|
+
import type { RequestContext } from './types';
|
|
2
|
+
export declare function getPropertiesAtLocation(this: RequestContext, fileName: string, position: number): string[] | undefined;
|
|
@@ -1,4 +1,2 @@
|
|
|
1
|
-
import type
|
|
2
|
-
export declare function getQuickInfoAtPosition(this:
|
|
3
|
-
languageService: ts.LanguageService;
|
|
4
|
-
}, fileName: string, position: number): ts.QuickInfo | undefined;
|
|
1
|
+
import type { RequestContext } from './types';
|
|
2
|
+
export declare function getQuickInfoAtPosition(this: RequestContext, fileName: string, position: number): import("typescript").QuickInfo | undefined;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Language } from '@vue/language-core';
|
|
2
|
+
import type * as ts from 'typescript';
|
|
3
|
+
export interface RequestContext {
|
|
4
|
+
typescript: typeof import('typescript');
|
|
5
|
+
languageService: ts.LanguageService;
|
|
6
|
+
languageServiceHost: ts.LanguageServiceHost;
|
|
7
|
+
language: Language;
|
|
8
|
+
isTsPlugin: boolean;
|
|
9
|
+
getFileId: (fileName: string) => string;
|
|
10
|
+
}
|
package/lib/server.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type * as ts from 'typescript';
|
|
2
1
|
import type { Language, VueCompilerOptions } from '@vue/language-core';
|
|
2
|
+
import type * as ts from 'typescript';
|
|
3
3
|
export interface Request {
|
|
4
4
|
type: 'projectInfoForFile' | 'collectExtractProps' | 'getImportPathForFile' | 'getPropertiesAtLocation' | 'getQuickInfoAtPosition' | 'getComponentProps' | 'getComponentEvents' | 'getTemplateContextProps' | 'getComponentNames' | 'getElementAttrs';
|
|
5
5
|
args: [fileName: string, ...rest: any];
|
package/lib/server.js
CHANGED
|
@@ -38,7 +38,6 @@ function startNamedPipeServer(ts, serverKind, currentDirectory) {
|
|
|
38
38
|
languageService: project.info.languageService,
|
|
39
39
|
languageServiceHost: project.info.languageServiceHost,
|
|
40
40
|
language: project.language,
|
|
41
|
-
vueOptions: project.vueOptions,
|
|
42
41
|
isTsPlugin: true,
|
|
43
42
|
getFileId: (fileName) => fileName,
|
|
44
43
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vue/typescript-plugin",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.18",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"**/*.js",
|
|
@@ -12,12 +12,12 @@
|
|
|
12
12
|
"directory": "packages/typescript-plugin"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@volar/typescript": "~2.2.
|
|
16
|
-
"@vue/language-core": "2.0.
|
|
15
|
+
"@volar/typescript": "~2.2.4",
|
|
16
|
+
"@vue/language-core": "2.0.18",
|
|
17
17
|
"@vue/shared": "^3.4.0"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
20
|
"@types/node": "latest"
|
|
21
21
|
},
|
|
22
|
-
"gitHead": "
|
|
22
|
+
"gitHead": "7aac2805f03b17e4c624335f509d502002bb75a8"
|
|
23
23
|
}
|