@vue/typescript-plugin 2.0.23-alpha.1 → 2.0.24
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 +3 -3
- package/lib/common.js +67 -29
- package/package.json +4 -4
package/index.js
CHANGED
|
@@ -19,7 +19,7 @@ const plugin = (0, createLanguageServicePlugin_1.createLanguageServicePlugin)((t
|
|
|
19
19
|
languagePlugins: [languagePlugin],
|
|
20
20
|
setup: language => {
|
|
21
21
|
server_1.projects.set(info.project, { info, language, vueOptions });
|
|
22
|
-
(0, common_1.
|
|
22
|
+
info.languageService = (0, common_1.proxyLanguageServiceForVue)(ts, language, info.languageService, vueOptions, fileName => fileName);
|
|
23
23
|
(0, server_1.startNamedPipeServer)(ts, info.project.projectKind, info.project.getCurrentDirectory());
|
|
24
24
|
// #3963
|
|
25
25
|
const timer = setInterval(() => {
|
package/lib/common.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Language, VueCompilerOptions, VueVirtualCode } from '@vue/language-core';
|
|
2
2
|
import type * as ts from 'typescript';
|
|
3
3
|
import type { RequestContext } from './requests/types';
|
|
4
|
-
export declare function
|
|
5
|
-
export declare function getComponentSpans(this: Pick<RequestContext, 'typescript' | 'languageService'>, vueCode:
|
|
4
|
+
export declare function proxyLanguageServiceForVue<T>(ts: typeof import('typescript'), language: Language<T>, languageService: ts.LanguageService, vueOptions: VueCompilerOptions, asScriptId: (fileName: string) => T): ts.LanguageService;
|
|
5
|
+
export declare function getComponentSpans(this: Pick<RequestContext, 'typescript' | 'languageService'>, vueCode: VueVirtualCode, template: NonNullable<VueVirtualCode['sfc']['template']>, spanTemplateRange: ts.TextSpan): ts.TextSpan[];
|
package/lib/common.js
CHANGED
|
@@ -1,13 +1,44 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.proxyLanguageServiceForVue = proxyLanguageServiceForVue;
|
|
4
4
|
exports.getComponentSpans = getComponentSpans;
|
|
5
|
-
const
|
|
5
|
+
const language_core_1 = require("@vue/language-core");
|
|
6
6
|
const shared_1 = require("@vue/shared");
|
|
7
7
|
const componentInfos_1 = require("./requests/componentInfos");
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
const windowsPathReg = /\\/g;
|
|
9
|
+
function proxyLanguageServiceForVue(ts, language, languageService, vueOptions, asScriptId) {
|
|
10
|
+
const proxyCache = new Map();
|
|
11
|
+
const getProxyMethod = (target, p) => {
|
|
12
|
+
switch (p) {
|
|
13
|
+
case 'getCompletionsAtPosition': return getCompletionsAtPosition(vueOptions, target[p]);
|
|
14
|
+
case 'getCompletionEntryDetails': return getCompletionEntryDetails(language, asScriptId, target[p]);
|
|
15
|
+
case 'getCodeFixesAtPosition': return getCodeFixesAtPosition(target[p]);
|
|
16
|
+
case 'getQuickInfoAtPosition': return getQuickInfoAtPosition(ts, target, target[p]);
|
|
17
|
+
// TS plugin only
|
|
18
|
+
case 'getEncodedSemanticClassifications': return getEncodedSemanticClassifications(ts, language, target, asScriptId, target[p]);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
return new Proxy(languageService, {
|
|
22
|
+
get(target, p, receiver) {
|
|
23
|
+
if (getProxyMethod) {
|
|
24
|
+
if (!proxyCache.has(p)) {
|
|
25
|
+
proxyCache.set(p, getProxyMethod(target, p));
|
|
26
|
+
}
|
|
27
|
+
const proxyMethod = proxyCache.get(p);
|
|
28
|
+
if (proxyMethod) {
|
|
29
|
+
return proxyMethod;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return Reflect.get(target, p, receiver);
|
|
33
|
+
},
|
|
34
|
+
set(target, p, value, receiver) {
|
|
35
|
+
return Reflect.set(target, p, value, receiver);
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
function getCompletionsAtPosition(vueOptions, getCompletionsAtPosition) {
|
|
40
|
+
return (filePath, position, options, formattingSettings) => {
|
|
41
|
+
const fileName = filePath.replace(windowsPathReg, '/');
|
|
11
42
|
const result = getCompletionsAtPosition(fileName, position, options, formattingSettings);
|
|
12
43
|
if (result) {
|
|
13
44
|
// filter __VLS_
|
|
@@ -48,7 +79,9 @@ function decorateLanguageServiceForVue(language, languageService, vueOptions, ts
|
|
|
48
79
|
}
|
|
49
80
|
return result;
|
|
50
81
|
};
|
|
51
|
-
|
|
82
|
+
}
|
|
83
|
+
function getCompletionEntryDetails(language, asScriptId, getCompletionEntryDetails) {
|
|
84
|
+
return (...args) => {
|
|
52
85
|
const details = getCompletionEntryDetails(...args);
|
|
53
86
|
// modify import statement
|
|
54
87
|
// @ts-expect-error
|
|
@@ -67,8 +100,8 @@ function decorateLanguageServiceForVue(language, languageService, vueOptions, ts
|
|
|
67
100
|
if (args[6]?.__isAutoImport) {
|
|
68
101
|
// @ts-expect-error
|
|
69
102
|
const { fileName } = args[6]?.__isAutoImport;
|
|
70
|
-
const sourceScript = language.scripts.get(
|
|
71
|
-
if (sourceScript?.generated?.root instanceof
|
|
103
|
+
const sourceScript = language.scripts.get(asScriptId(fileName));
|
|
104
|
+
if (sourceScript?.generated?.root instanceof language_core_1.VueVirtualCode) {
|
|
72
105
|
const sfc = sourceScript.generated.root.getVueSfc();
|
|
73
106
|
if (!sfc?.descriptor.script && !sfc?.descriptor.scriptSetup) {
|
|
74
107
|
for (const codeAction of details?.codeActions ?? []) {
|
|
@@ -86,13 +119,17 @@ function decorateLanguageServiceForVue(language, languageService, vueOptions, ts
|
|
|
86
119
|
}
|
|
87
120
|
return details;
|
|
88
121
|
};
|
|
89
|
-
|
|
122
|
+
}
|
|
123
|
+
function getCodeFixesAtPosition(getCodeFixesAtPosition) {
|
|
124
|
+
return (...args) => {
|
|
90
125
|
let result = getCodeFixesAtPosition(...args);
|
|
91
126
|
// filter __VLS_
|
|
92
127
|
result = result.filter(entry => entry.description.indexOf('__VLS_') === -1);
|
|
93
128
|
return result;
|
|
94
129
|
};
|
|
95
|
-
|
|
130
|
+
}
|
|
131
|
+
function getQuickInfoAtPosition(ts, languageService, getQuickInfoAtPosition) {
|
|
132
|
+
return (...args) => {
|
|
96
133
|
const result = getQuickInfoAtPosition(...args);
|
|
97
134
|
if (result && result.documentation?.length === 1 && result.documentation[0].text.startsWith('__VLS_emit,')) {
|
|
98
135
|
const [_, emitVarName, eventName] = result.documentation[0].text.split(',');
|
|
@@ -128,25 +165,26 @@ function decorateLanguageServiceForVue(language, languageService, vueOptions, ts
|
|
|
128
165
|
}
|
|
129
166
|
return result;
|
|
130
167
|
};
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
168
|
+
}
|
|
169
|
+
function getEncodedSemanticClassifications(ts, language, languageService, asScriptId, getEncodedSemanticClassifications) {
|
|
170
|
+
return (filePath, span, format) => {
|
|
171
|
+
const fileName = filePath.replace(windowsPathReg, '/');
|
|
172
|
+
const result = getEncodedSemanticClassifications(fileName, span, format);
|
|
173
|
+
const file = language.scripts.get(asScriptId(fileName));
|
|
174
|
+
if (file?.generated?.root instanceof language_core_1.VueVirtualCode) {
|
|
175
|
+
const { template } = file.generated.root.sfc;
|
|
176
|
+
if (template) {
|
|
177
|
+
for (const componentSpan of getComponentSpans.call({ typescript: ts, languageService }, file.generated.root, template, {
|
|
178
|
+
start: span.start - template.startTagEnd,
|
|
179
|
+
length: span.length,
|
|
180
|
+
})) {
|
|
181
|
+
result.spans.push(componentSpan.start + template.startTagEnd, componentSpan.length, 256 // class
|
|
182
|
+
);
|
|
145
183
|
}
|
|
146
184
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
}
|
|
185
|
+
}
|
|
186
|
+
return result;
|
|
187
|
+
};
|
|
150
188
|
}
|
|
151
189
|
function getComponentSpans(vueCode, template, spanTemplateRange) {
|
|
152
190
|
const { typescript: ts, languageService } = this;
|
|
@@ -154,10 +192,10 @@ function getComponentSpans(vueCode, template, spanTemplateRange) {
|
|
|
154
192
|
const validComponentNames = (0, componentInfos_1._getComponentNames)(ts, languageService, vueCode);
|
|
155
193
|
const components = new Set([
|
|
156
194
|
...validComponentNames,
|
|
157
|
-
...validComponentNames.map(
|
|
195
|
+
...validComponentNames.map(language_core_1.hyphenateTag),
|
|
158
196
|
]);
|
|
159
197
|
if (template.ast) {
|
|
160
|
-
for (const node of
|
|
198
|
+
for (const node of (0, language_core_1.forEachElementNode)(template.ast)) {
|
|
161
199
|
if (node.loc.end.offset <= spanTemplateRange.start || node.loc.start.offset >= (spanTemplateRange.start + spanTemplateRange.length)) {
|
|
162
200
|
continue;
|
|
163
201
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vue/typescript-plugin",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.24",
|
|
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.4.0-alpha.
|
|
16
|
-
"@vue/language-core": "2.0.
|
|
15
|
+
"@volar/typescript": "~2.4.0-alpha.2",
|
|
16
|
+
"@vue/language-core": "2.0.24",
|
|
17
17
|
"@vue/shared": "^3.4.0"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
20
|
"@types/node": "latest"
|
|
21
21
|
},
|
|
22
|
-
"gitHead": "
|
|
22
|
+
"gitHead": "bca79db09e413ef29c17b910271c123a7a68806f"
|
|
23
23
|
}
|