@vue/typescript-plugin 3.0.0 → 3.0.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/index.js +6 -0
- package/lib/common.js +2 -61
- package/lib/requests/getComponentHighlights.d.ts +1 -0
- package/lib/requests/getComponentHighlights.js +3 -0
- package/lib/requests/getSemanticClassfications.d.ts +3 -0
- package/lib/requests/getSemanticClassfications.js +8 -0
- package/lib/requests/getVariableProperties.d.ts +10 -0
- package/lib/requests/getVariableProperties.js +16 -0
- package/lib/requests/index.d.ts +3 -4
- package/package.json +4 -4
package/index.js
CHANGED
|
@@ -15,6 +15,9 @@ const windowsPathReg = /\\/g;
|
|
|
15
15
|
const project2Service = new WeakMap();
|
|
16
16
|
module.exports = (0, createLanguageServicePlugin_1.createLanguageServicePlugin)((ts, info) => {
|
|
17
17
|
const vueOptions = getVueCompilerOptions();
|
|
18
|
+
if (vueOptions.globalTypesPath) {
|
|
19
|
+
ts.sys.writeFile(vueOptions.globalTypesPath, vue.generateGlobalTypes(vueOptions));
|
|
20
|
+
}
|
|
18
21
|
const languagePlugin = vue.createVueLanguagePlugin(ts, info.languageServiceHost.getCompilationSettings(), vueOptions, id => id);
|
|
19
22
|
addVueCommands();
|
|
20
23
|
return {
|
|
@@ -64,6 +67,9 @@ module.exports = (0, createLanguageServicePlugin_1.createLanguageServicePlugin)(
|
|
|
64
67
|
session.addProtocolHandler('_vue:documentHighlights-full', ({ arguments: args }) => {
|
|
65
68
|
return session.handlers.get('documentHighlights-full')?.({ arguments: args });
|
|
66
69
|
});
|
|
70
|
+
session.addProtocolHandler('_vue:encodedSemanticClassifications-full', ({ arguments: args }) => {
|
|
71
|
+
return session.handlers.get('encodedSemanticClassifications-full')?.({ arguments: args });
|
|
72
|
+
});
|
|
67
73
|
session.addProtocolHandler('_vue:quickinfo', ({ arguments: args }) => {
|
|
68
74
|
return session.handlers.get('quickinfo')?.({ arguments: args });
|
|
69
75
|
});
|
package/lib/common.js
CHANGED
|
@@ -3,8 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.createVueLanguageServiceProxy = createVueLanguageServiceProxy;
|
|
4
4
|
const language_core_1 = require("@vue/language-core");
|
|
5
5
|
const shared_1 = require("@vue/shared");
|
|
6
|
-
const getComponentNames_1 = require("./requests/getComponentNames");
|
|
7
|
-
const getElementNames_1 = require("./requests/getElementNames");
|
|
8
6
|
const windowsPathReg = /\\/g;
|
|
9
7
|
function createVueLanguageServiceProxy(ts, language, languageService, vueOptions, asScriptId) {
|
|
10
8
|
const proxyCache = new Map();
|
|
@@ -18,9 +16,6 @@ function createVueLanguageServiceProxy(ts, language, languageService, vueOptions
|
|
|
18
16
|
return getCodeFixesAtPosition(target[p]);
|
|
19
17
|
case 'getDefinitionAndBoundSpan':
|
|
20
18
|
return getDefinitionAndBoundSpan(ts, language, languageService, vueOptions, asScriptId, target[p]);
|
|
21
|
-
// TS plugin only
|
|
22
|
-
case 'getEncodedSemanticClassifications':
|
|
23
|
-
return getEncodedSemanticClassifications(ts, language, target, asScriptId, target[p]);
|
|
24
19
|
}
|
|
25
20
|
};
|
|
26
21
|
return new Proxy(languageService, {
|
|
@@ -62,13 +57,14 @@ function getCompletionsAtPosition(ts, language, vueOptions, asScriptId, getCompl
|
|
|
62
57
|
block.endTagStart,
|
|
63
58
|
]);
|
|
64
59
|
if (ranges.some(([start, end]) => position >= start && position <= end)) {
|
|
60
|
+
const globalKinds = new Set(['var', 'function', 'module']);
|
|
65
61
|
const globalsOrKeywords = ts.Completions.SortText.GlobalsOrKeywords;
|
|
66
62
|
const sortTexts = new Set([
|
|
67
63
|
globalsOrKeywords,
|
|
68
64
|
'z' + globalsOrKeywords,
|
|
69
65
|
globalsOrKeywords + '1',
|
|
70
66
|
]);
|
|
71
|
-
result.entries = result.entries.filter(entry => !(entry.kind === 'const' && entry.name in vueOptions.macros) && (
|
|
67
|
+
result.entries = result.entries.filter(entry => !(entry.kind === 'const' && entry.name in vueOptions.macros) && (!globalKinds.has(entry.kind)
|
|
72
68
|
|| !sortTexts.has(entry.sortText)
|
|
73
69
|
|| (0, shared_1.isGloballyAllowed)(entry.name)));
|
|
74
70
|
}
|
|
@@ -237,59 +233,4 @@ function getDefinitionAndBoundSpan(ts, language, languageService, vueOptions, as
|
|
|
237
233
|
}
|
|
238
234
|
};
|
|
239
235
|
}
|
|
240
|
-
function getEncodedSemanticClassifications(ts, language, languageService, asScriptId, getEncodedSemanticClassifications) {
|
|
241
|
-
return (filePath, span, format) => {
|
|
242
|
-
const fileName = filePath.replace(windowsPathReg, '/');
|
|
243
|
-
const result = getEncodedSemanticClassifications(fileName, span, format);
|
|
244
|
-
const sourceScript = language.scripts.get(asScriptId(fileName));
|
|
245
|
-
const root = sourceScript?.generated?.root;
|
|
246
|
-
if (root instanceof language_core_1.VueVirtualCode) {
|
|
247
|
-
const { template } = root.sfc;
|
|
248
|
-
if (template) {
|
|
249
|
-
for (const componentSpan of getComponentSpans.call({ typescript: ts, languageService }, root, template, {
|
|
250
|
-
start: span.start - template.startTagEnd,
|
|
251
|
-
length: span.length,
|
|
252
|
-
})) {
|
|
253
|
-
result.spans.push(componentSpan.start + template.startTagEnd, componentSpan.length, 256);
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
return result;
|
|
258
|
-
};
|
|
259
|
-
}
|
|
260
|
-
function getComponentSpans(vueCode, template, spanTemplateRange) {
|
|
261
|
-
const { typescript: ts, languageService } = this;
|
|
262
|
-
const result = [];
|
|
263
|
-
const validComponentNames = (0, getComponentNames_1._getComponentNames)(ts, languageService, vueCode);
|
|
264
|
-
const elements = new Set((0, getElementNames_1._getElementNames)(ts, languageService, vueCode));
|
|
265
|
-
const components = new Set([
|
|
266
|
-
...validComponentNames,
|
|
267
|
-
...validComponentNames.map(language_core_1.hyphenateTag),
|
|
268
|
-
]);
|
|
269
|
-
if (template.ast) {
|
|
270
|
-
for (const node of (0, language_core_1.forEachElementNode)(template.ast)) {
|
|
271
|
-
if (node.loc.end.offset <= spanTemplateRange.start
|
|
272
|
-
|| node.loc.start.offset >= (spanTemplateRange.start + spanTemplateRange.length)) {
|
|
273
|
-
continue;
|
|
274
|
-
}
|
|
275
|
-
if (components.has(node.tag) && !elements.has(node.tag)) {
|
|
276
|
-
let start = node.loc.start.offset;
|
|
277
|
-
if (template.lang === 'html') {
|
|
278
|
-
start += '<'.length;
|
|
279
|
-
}
|
|
280
|
-
result.push({
|
|
281
|
-
start,
|
|
282
|
-
length: node.tag.length,
|
|
283
|
-
});
|
|
284
|
-
if (template.lang === 'html' && !node.isSelfClosing) {
|
|
285
|
-
result.push({
|
|
286
|
-
start: node.loc.start.offset + node.loc.source.lastIndexOf(node.tag),
|
|
287
|
-
length: node.tag.length,
|
|
288
|
-
});
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
return result;
|
|
294
|
-
}
|
|
295
236
|
//# sourceMappingURL=common.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getSemanticClassifications = getSemanticClassifications;
|
|
4
|
+
function getSemanticClassifications(fileName, span) {
|
|
5
|
+
const { languageService, typescript: ts } = this;
|
|
6
|
+
return languageService.getSemanticClassifications(fileName, span, ts.SemanticClassificationFormat.TwentyTwenty);
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=getSemanticClassfications.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 getVariableProperties(this: RequestContext, fileName: string, variableName: string): string[] | undefined;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getVariableProperties = getVariableProperties;
|
|
4
|
+
const language_core_1 = require("@vue/language-core");
|
|
5
|
+
const utils_1 = require("./utils");
|
|
6
|
+
function getVariableProperties(fileName, variableName) {
|
|
7
|
+
const { typescript: ts, language, languageService, asScriptId } = this;
|
|
8
|
+
const volarFile = language.scripts.get(asScriptId(fileName));
|
|
9
|
+
if (!(volarFile?.generated?.root instanceof language_core_1.VueVirtualCode)) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
const vueCode = volarFile.generated.root;
|
|
13
|
+
const variable = (0, utils_1.getVariableType)(ts, languageService, vueCode, variableName);
|
|
14
|
+
return variable?.type.getProperties().map(prop => prop.name);
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=getVariableProperties.js.map
|
package/lib/requests/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type * as ts from 'typescript';
|
|
1
2
|
type ToRequest<T extends (...args: any) => any> = (...args: Parameters<T>) => Promise<ReturnType<T> | null | undefined>;
|
|
2
3
|
export type Requests = {
|
|
3
4
|
collectExtractProps: ToRequest<typeof import('./collectExtractProps.js')['collectExtractProps']>;
|
|
@@ -9,9 +10,7 @@ export type Requests = {
|
|
|
9
10
|
getComponentDirectives: ToRequest<typeof import('./getComponentDirectives.js')['getComponentDirectives']>;
|
|
10
11
|
getElementAttrs: ToRequest<typeof import('./getElementAttrs.js')['getElementAttrs']>;
|
|
11
12
|
getElementNames: ToRequest<typeof import('./getElementNames.js')['getElementNames']>;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
character: number;
|
|
15
|
-
}) => string>;
|
|
13
|
+
getEncodedSemanticClassifications: ToRequest<(fileName: string, span: ts.TextSpan) => ts.Classifications>;
|
|
14
|
+
getQuickInfoAtPosition: ToRequest<(fileName: string, position: ts.LineAndCharacter) => string>;
|
|
16
15
|
};
|
|
17
16
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vue/typescript-plugin",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.2",
|
|
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.19",
|
|
17
|
+
"@vue/language-core": "3.0.2",
|
|
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": "7343119e9ca4f6a54f63b57f448f15df4b592a9a"
|
|
26
26
|
}
|