@vue/typescript-plugin 3.2.1 → 3.2.3
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/common.js +110 -14
- package/package.json +4 -4
package/lib/common.js
CHANGED
|
@@ -10,27 +10,29 @@ const language_core_1 = require("@vue/language-core");
|
|
|
10
10
|
const shared_1 = require("@vue/shared");
|
|
11
11
|
const windowsPathReg = /\\/g;
|
|
12
12
|
function preprocessLanguageService(languageService, getLanguage) {
|
|
13
|
-
const { getQuickInfoAtPosition, getSuggestionDiagnostics, getCompletionsAtPosition, getCodeFixesAtPosition, } = languageService;
|
|
13
|
+
const { getQuickInfoAtPosition, getSuggestionDiagnostics, getCompletionsAtPosition, getCodeFixesAtPosition, findRenameLocations, } = languageService;
|
|
14
14
|
languageService.getQuickInfoAtPosition = (fileName, position, ...rests) => {
|
|
15
15
|
const result = getQuickInfoAtPosition(fileName, position, ...rests);
|
|
16
|
-
if (!result) {
|
|
16
|
+
if (!result || result.tags?.length) {
|
|
17
17
|
return result;
|
|
18
18
|
}
|
|
19
19
|
const language = getLanguage();
|
|
20
20
|
if (!language) {
|
|
21
21
|
return result;
|
|
22
22
|
}
|
|
23
|
-
const [serviceScript,
|
|
23
|
+
const [serviceScript, , sourceScript] = (0, utils_1.getServiceScript)(language, fileName);
|
|
24
24
|
if (!serviceScript || !(sourceScript?.generated?.root instanceof language_core_1.VueVirtualCode)) {
|
|
25
25
|
return result;
|
|
26
26
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
27
|
+
const codegen = language_core_1.tsCodegen.get(sourceScript.generated.root.sfc);
|
|
28
|
+
const leadingOffset = sourceScript.snapshot.getLength();
|
|
29
|
+
for (const sourceRange of (0, transform_1.toSourceRanges)(sourceScript, language, serviceScript, result.textSpan.start, result.textSpan.start + result.textSpan.length, true, () => true)) {
|
|
30
|
+
const generateRange2 = (0, transform_1.toGeneratedRange)(language, serviceScript, sourceScript, sourceRange[1], sourceRange[2], (data) => !!data.__importCompletion);
|
|
31
|
+
if (generateRange2 !== undefined) {
|
|
32
|
+
const variableName = serviceScript.code.snapshot.getText(generateRange2[0] - leadingOffset, generateRange2[1] - leadingOffset);
|
|
33
|
+
if (codegen?.getSetupExposed().has(variableName)) {
|
|
34
|
+
const extraInfo = getQuickInfoAtPosition(fileName, generateRange2[0], ...rests);
|
|
35
|
+
result.tags = extraInfo?.tags;
|
|
34
36
|
}
|
|
35
37
|
}
|
|
36
38
|
}
|
|
@@ -42,17 +44,22 @@ function preprocessLanguageService(languageService, getLanguage) {
|
|
|
42
44
|
if (!language) {
|
|
43
45
|
return result;
|
|
44
46
|
}
|
|
45
|
-
const [serviceScript,
|
|
47
|
+
const [serviceScript, , sourceScript] = (0, utils_1.getServiceScript)(language, fileName);
|
|
46
48
|
if (!serviceScript || !(sourceScript?.generated?.root instanceof language_core_1.VueVirtualCode)) {
|
|
47
49
|
return result;
|
|
48
50
|
}
|
|
51
|
+
const codegen = language_core_1.tsCodegen.get(sourceScript.generated.root.sfc);
|
|
52
|
+
const leadingOffset = sourceScript.snapshot.getLength();
|
|
49
53
|
for (const diagnostic of result) {
|
|
50
54
|
for (const sourceRange of (0, transform_1.toSourceRanges)(sourceScript, language, serviceScript, diagnostic.start, diagnostic.start + diagnostic.length, true, (data) => !!data.__importCompletion)) {
|
|
51
55
|
const generateRange2 = (0, transform_1.toGeneratedRange)(language, serviceScript, sourceScript, sourceRange[1], sourceRange[2], (data) => !data.__importCompletion);
|
|
52
56
|
if (generateRange2 !== undefined) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
57
|
+
const variableName = serviceScript.code.snapshot.getText(generateRange2[0] - leadingOffset, generateRange2[1] - leadingOffset);
|
|
58
|
+
if (codegen?.getSetupExposed().has(variableName)) {
|
|
59
|
+
diagnostic.start = generateRange2[0];
|
|
60
|
+
diagnostic.length = generateRange2[1] - generateRange2[0];
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
56
63
|
}
|
|
57
64
|
}
|
|
58
65
|
}
|
|
@@ -122,6 +129,95 @@ function preprocessLanguageService(languageService, getLanguage) {
|
|
|
122
129
|
}
|
|
123
130
|
return result;
|
|
124
131
|
};
|
|
132
|
+
languageService.findRenameLocations = (fileName, position, ...rests) => {
|
|
133
|
+
// @ts-expect-error
|
|
134
|
+
const result = findRenameLocations(fileName, position, ...rests);
|
|
135
|
+
if (!result?.length) {
|
|
136
|
+
return result;
|
|
137
|
+
}
|
|
138
|
+
const language = getLanguage();
|
|
139
|
+
if (!language) {
|
|
140
|
+
return result;
|
|
141
|
+
}
|
|
142
|
+
const [serviceScript, _targetScript, sourceScript] = (0, utils_1.getServiceScript)(language, fileName);
|
|
143
|
+
if (!serviceScript || !(sourceScript?.generated?.root instanceof language_core_1.VueVirtualCode)) {
|
|
144
|
+
return result;
|
|
145
|
+
}
|
|
146
|
+
const map = language.maps.get(serviceScript.code, sourceScript);
|
|
147
|
+
const leadingOffset = sourceScript.snapshot.getLength();
|
|
148
|
+
const isShorthand = (data) => !!data.__shorthandExpression;
|
|
149
|
+
// { foo: __VLS_ctx.foo }
|
|
150
|
+
// ^^^ ^^^
|
|
151
|
+
// if the rename is triggered directly on the shorthand,
|
|
152
|
+
// skip the entire request on the generated property name
|
|
153
|
+
if ([...map.toSourceLocation(position - leadingOffset, isShorthand)].length === 0) {
|
|
154
|
+
for (const [offset] of map.toSourceLocation(position - leadingOffset, () => true)) {
|
|
155
|
+
for (const _ of map.toGeneratedLocation(offset, isShorthand)) {
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
const preferAlias = typeof rests[2] === 'boolean'
|
|
161
|
+
? rests[2]
|
|
162
|
+
: rests[2]?.providePrefixAndSuffixTextForRename ?? true;
|
|
163
|
+
if (!preferAlias) {
|
|
164
|
+
return result;
|
|
165
|
+
}
|
|
166
|
+
const locations = [...result];
|
|
167
|
+
outer: for (let i = 0; i < locations.length; i++) {
|
|
168
|
+
const { textSpan } = locations[i];
|
|
169
|
+
const generatedLeft = textSpan.start - leadingOffset;
|
|
170
|
+
const generatedRight = textSpan.start + textSpan.length - leadingOffset;
|
|
171
|
+
// { foo: __VLS_ctx.foo }
|
|
172
|
+
// ^^^
|
|
173
|
+
for (const [start, end, { data }] of map.toSourceRange(generatedLeft, generatedRight, true, isShorthand)) {
|
|
174
|
+
locations.splice(i, 1, {
|
|
175
|
+
...locations[i],
|
|
176
|
+
...getPrefixAndSuffixForShorthandRename(data.__shorthandExpression, 'right', sourceScript.snapshot.getText(start, end)),
|
|
177
|
+
});
|
|
178
|
+
continue outer;
|
|
179
|
+
}
|
|
180
|
+
// { foo: __VLS_ctx.foo }
|
|
181
|
+
// ^^^
|
|
182
|
+
for (const [start, end] of map.toSourceRange(generatedLeft, generatedRight, true, () => true)) {
|
|
183
|
+
for (const [, , { data }] of map.toGeneratedRange(start, end, true, isShorthand)) {
|
|
184
|
+
locations.splice(i, 1, {
|
|
185
|
+
...locations[i],
|
|
186
|
+
...getPrefixAndSuffixForShorthandRename(data.__shorthandExpression, 'left', sourceScript.snapshot.getText(start, end)),
|
|
187
|
+
});
|
|
188
|
+
continue outer;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
return locations;
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
function getPrefixAndSuffixForShorthandRename(type, target, originalText) {
|
|
196
|
+
if (type === 'html') {
|
|
197
|
+
if (target === 'left') {
|
|
198
|
+
return {
|
|
199
|
+
suffixText: `="${(0, shared_1.camelize)(originalText)}"`,
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
return {
|
|
204
|
+
prefixText: `${originalText}="`,
|
|
205
|
+
suffixText: `"`,
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
else {
|
|
210
|
+
if (target === 'left') {
|
|
211
|
+
return {
|
|
212
|
+
suffixText: `: ${originalText}`,
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
216
|
+
return {
|
|
217
|
+
prefixText: `${originalText}: `,
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
}
|
|
125
221
|
}
|
|
126
222
|
function postprocessLanguageService(ts, language, languageService, vueOptions, asScriptId) {
|
|
127
223
|
const proxyCache = new Map();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vue/typescript-plugin",
|
|
3
|
-
"version": "3.2.
|
|
3
|
+
"version": "3.2.3",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"**/*.js",
|
|
@@ -14,14 +14,14 @@
|
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"@volar/typescript": "2.4.27",
|
|
17
|
-
"@vue/language-core": "3.2.
|
|
17
|
+
"@vue/language-core": "3.2.3",
|
|
18
18
|
"@vue/shared": "^3.5.0",
|
|
19
19
|
"path-browserify": "^1.0.1",
|
|
20
|
-
"vue-component-meta": "3.2.
|
|
20
|
+
"vue-component-meta": "3.2.3"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@types/node": "^22.10.4",
|
|
24
24
|
"@types/path-browserify": "^1.0.1"
|
|
25
25
|
},
|
|
26
|
-
"gitHead": "
|
|
26
|
+
"gitHead": "efc6882ab62a518b41ab5c8dc1d762c41c862ebc"
|
|
27
27
|
}
|