Skip to content

Commit eb06045

Browse files
committed
Merge branch 'master' into pr/4878
2 parents 233b7fb + e6e8ae5 commit eb06045

File tree

80 files changed

+1617
-1327
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+1617
-1327
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,15 @@ lspconfig.tsserver.setup {
9797
},
9898
},
9999
},
100+
}
100101

101102
lspconfig.volar.setup {
102103
init_options = {
103104
vue = {
104105
hybridMode = false,
105106
},
106107
},
107-
},
108+
}
108109
```
109110

110111
### nvim-cmp integration

extensions/vscode/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@
551551
"devDependencies": {
552552
"@types/semver": "^7.5.3",
553553
"@types/vscode": "^1.82.0",
554-
"@volar/vscode": "~2.4.1",
554+
"@volar/vscode": "~2.4.7",
555555
"@vscode/vsce": "latest",
556556
"@vue/language-core": "2.1.6",
557557
"@vue/language-server": "2.1.6",

extensions/vscode/tsconfig.json

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
"compilerOptions": {
44
"outDir": "out",
55
"rootDir": "src",
6+
"module": "CommonJS",
7+
"moduleResolution": "Node"
68
},
79
"include": [ "src" ],
810
"references": [

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
"@lerna-lite/publish": "latest",
2626
"@tsslint/cli": "latest",
2727
"@tsslint/config": "latest",
28-
"@volar/language-service": "~2.4.1",
2928
"typescript": "latest",
3029
"vite": "latest",
3130
"vitest": "latest"

packages/component-meta/lib/base.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ function createSchemaResolvers(
540540
function resolveSlotProperties(prop: ts.Symbol): SlotMeta {
541541
const propType = typeChecker.getNonNullableType(typeChecker.getTypeOfSymbolAtLocation(prop, symbolNode));
542542
const signatures = propType.getCallSignatures();
543-
const paramType = signatures[0].parameters[0];
543+
const paramType = signatures[0]?.parameters[0];
544544
const subtype = paramType ? typeChecker.getTypeOfSymbolAtLocation(paramType, symbolNode) : typeChecker.getAnyType();
545545
let schema: PropertyMetaSchema;
546546
let declarations: Declaration[];
@@ -721,7 +721,7 @@ function readVueComponentDefaultProps(
721721

722722
function scriptSetupWorker() {
723723

724-
const descriptor = vueSourceFile.sfc;
724+
const descriptor = vueSourceFile._sfc;
725725
const scriptSetupRanges = descriptor.scriptSetup ? vue.parseScriptSetupRanges(ts, descriptor.scriptSetup.ast, vueCompilerOptions) : undefined;
726726

727727
if (descriptor.scriptSetup && scriptSetupRanges?.props.withDefaults?.arg) {
@@ -772,7 +772,7 @@ function readVueComponentDefaultProps(
772772

773773
function scriptWorker() {
774774

775-
const descriptor = vueSourceFile.sfc;
775+
const descriptor = vueSourceFile._sfc;
776776

777777
if (descriptor.script) {
778778
const scriptResult = readTsComponentDefaultProps(descriptor.script.lang, descriptor.script.content, 'default', printer, ts);

packages/component-meta/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66
"**/*.js",
77
"**/*.d.ts"
88
],
9+
"sideEffects": false,
910
"repository": {
1011
"type": "git",
1112
"url": "https://github.com/vuejs/language-tools.git",
1213
"directory": "packages/component-meta"
1314
},
1415
"dependencies": {
15-
"@volar/typescript": "~2.4.1",
16+
"@volar/typescript": "~2.4.7",
1617
"@vue/language-core": "2.1.6",
1718
"path-browserify": "^1.0.1",
1819
"vue-component-type-helpers": "2.1.6"

packages/component-type-helpers/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"**/*.js",
77
"**/*.d.ts"
88
],
9+
"sideEffects": false,
910
"repository": {
1011
"type": "git",
1112
"url": "https://github.com/vuejs/language-tools.git",

packages/language-core/lib/codegen/globalTypes.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ export function generateGlobalTypes(lib: string, target: number, strictTemplates
8787
'__ctx' extends keyof __VLS_PickNotAny<K, {}> ? K extends { __ctx?: infer Ctx } ? Ctx : never : any
8888
, T extends (props: any, ctx: infer Ctx) => any ? Ctx : any
8989
>>;
90+
type __VLS_UseTemplateRef<T> = Readonly<import('${lib}').ShallowRef<T | null>>;
9091
9192
function __VLS_getVForSourceType(source: number): [number, number, number][];
9293
function __VLS_getVForSourceType(source: string): [string, number, number][];
@@ -115,9 +116,11 @@ export function generateGlobalTypes(lib: string, target: number, strictTemplates
115116
function __VLS_getSlotParams<T>(slot: T): Parameters<__VLS_PickNotAny<NonNullable<T>, (...args: any[]) => any>>;
116117
// @ts-ignore
117118
function __VLS_getSlotParam<T>(slot: T): Parameters<__VLS_PickNotAny<NonNullable<T>, (...args: any[]) => any>>[0];
118-
function __VLS_directiveAsFunction<T extends import('${lib}').Directive>(dir: T): T extends (...args: any) => any
119-
? T | __VLS_unknownDirective
120-
: NonNullable<(T & Record<string, __VLS_unknownDirective>)['created' | 'beforeMount' | 'mounted' | 'beforeUpdate' | 'updated' | 'beforeUnmount' | 'unmounted']>;
119+
function __VLS_asFunctionalDirective<T>(dir: T): T extends import('${lib}').ObjectDirective
120+
? NonNullable<T['created' | 'beforeMount' | 'mounted' | 'beforeUpdate' | 'updated' | 'beforeUnmount' | 'unmounted']>
121+
: T extends (...args: any) => any
122+
? T
123+
: __VLS_unknownDirective;
121124
function __VLS_withScope<T, K>(ctx: T, scope: K): ctx is T & K;
122125
function __VLS_nonNullable<T>(t: T): T extends null | undefined ? never : T;
123126
function __VLS_asFunctionalComponent<T, K = T extends new (...args: any) => any ? InstanceType<T> : unknown>(t: T, instance?: K):
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import type * as CompilerDOM from '@vue/compiler-dom';
2+
3+
export interface InlayHintInfo {
4+
blockName: string;
5+
offset: number;
6+
setting: string;
7+
label: string;
8+
tooltip?: string;
9+
paddingRight?: boolean;
10+
paddingLeft?: boolean;
11+
}
12+
13+
export function createVBindShorthandInlayHintInfo(loc: CompilerDOM.SourceLocation, variableName: string): InlayHintInfo {
14+
return {
15+
blockName: 'template',
16+
offset: loc.end.offset,
17+
setting: 'vue.inlayHints.vBindShorthand',
18+
label: `="${variableName}"`,
19+
tooltip: [
20+
`This is a shorthand for \`${loc.source}="${variableName}"\`.`,
21+
'To hide this hint, set `vue.inlayHints.vBindShorthand` to `false` in IDE settings.',
22+
'[More info](https://github.com/vuejs/core/pull/9451)',
23+
].join('\n\n'),
24+
};
25+
}

packages/language-core/lib/codegen/script/component.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export function* generateComponent(
3030
yield `}${endOfLine}`;
3131
yield `},${newLine}`;
3232
if (!ctx.bypassDefineComponent) {
33-
const emitOptionCodes = [...generateEmitsOption(options, scriptSetup, scriptSetupRanges)];
33+
const emitOptionCodes = [...generateEmitsOption(options, scriptSetupRanges)];
3434
for (const code of emitOptionCodes) {
3535
yield code;
3636
}
@@ -63,7 +63,6 @@ export function* generateComponentSetupReturns(scriptSetupRanges: ScriptSetupRan
6363

6464
export function* generateEmitsOption(
6565
options: ScriptCodegenOptions,
66-
scriptSetup: NonNullable<Sfc['scriptSetup']>,
6766
scriptSetupRanges: ScriptSetupRanges
6867
): Generator<Code> {
6968
const codes: {
@@ -74,16 +73,16 @@ export function* generateEmitsOption(
7473
}[] = [];
7574
if (scriptSetupRanges.defineProp.some(p => p.isModel)) {
7675
codes.push({
77-
optionExp: `{} as __VLS_NormalizeEmits<__VLS_ModelEmitsType>`,
78-
typeOptionType: `__VLS_ModelEmitsType`,
76+
optionExp: `{} as __VLS_NormalizeEmits<typeof __VLS_modelEmit>`,
77+
typeOptionType: `__VLS_ModelEmit`,
7978
});
8079
}
8180
if (scriptSetupRanges.emits.define) {
8281
const { typeArg, hasUnionTypeArg } = scriptSetupRanges.emits.define;
8382
codes.push({
8483
optionExp: `{} as __VLS_NormalizeEmits<typeof ${scriptSetupRanges.emits.name ?? '__VLS_emit'}>`,
8584
typeOptionType: typeArg && !hasUnionTypeArg
86-
? scriptSetup.content.slice(typeArg.start, typeArg.end)
85+
? `__VLS_Emit`
8786
: undefined,
8887
});
8988
}

packages/language-core/lib/codegen/script/componentSelf.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export function* generateComponentSelf(
4848
yield `}${endOfLine}`; // return {
4949
yield `},${newLine}`; // setup() {
5050
if (options.sfc.scriptSetup && options.scriptSetupRanges && !ctx.bypassDefineComponent) {
51-
const emitOptionCodes = [...generateEmitsOption(options, options.sfc.scriptSetup, options.scriptSetupRanges)];
51+
const emitOptionCodes = [...generateEmitsOption(options, options.scriptSetupRanges)];
5252
for (const code of emitOptionCodes) {
5353
yield code;
5454
}

packages/language-core/lib/codegen/script/context.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { InlayHintInfo } from '../types';
1+
import { InlayHintInfo } from '../inlayHints';
22
import { getLocalTypesGenerator } from '../localTypes';
33
import type { ScriptCodegenOptions } from './index';
44

packages/language-core/lib/codegen/script/index.ts

+20-7
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import type { Code, Sfc, VueCodeInformation, VueCompilerOptions } from '../../ty
66
import { endOfLine, generateSfcBlockSection, newLine } from '../common';
77
import { generateGlobalTypes } from '../globalTypes';
88
import type { TemplateCodegenContext } from '../template/context';
9-
import { createScriptCodegenContext, ScriptCodegenContext } from './context';
109
import { generateComponentSelf } from './componentSelf';
10+
import { createScriptCodegenContext, ScriptCodegenContext } from './context';
1111
import { generateScriptSetup, generateScriptSetupImports } from './scriptSetup';
1212
import { generateSrc } from './src';
1313
import { generateStyleModulesType } from './styleModulesType';
@@ -56,7 +56,13 @@ export function* generateScript(options: ScriptCodegenOptions): Generator<Code,
5656
const ctx = createScriptCodegenContext(options);
5757

5858
if (options.vueCompilerOptions.__setupedGlobalTypes) {
59-
yield `/// <reference types=".vue-global-types/${options.vueCompilerOptions.lib}_${options.vueCompilerOptions.target}_${options.vueCompilerOptions.strictTemplates}.d.ts" />${newLine}`;
59+
const globalTypes = options.vueCompilerOptions.__setupedGlobalTypes;
60+
if (typeof globalTypes === 'object') {
61+
yield `/// <reference types="${globalTypes.absolutePath}" />${newLine}`;
62+
}
63+
else {
64+
yield `/// <reference types=".vue-global-types/${options.vueCompilerOptions.lib}_${options.vueCompilerOptions.target}_${options.vueCompilerOptions.strictTemplates}.d.ts" />${newLine}`;
65+
}
6066
}
6167
else {
6268
yield `/* placeholder */`;
@@ -79,6 +85,7 @@ export function* generateScript(options: ScriptCodegenOptions): Generator<Code,
7985
}
8086
else {
8187
yield generateSfcBlockSection(options.sfc.script, 0, options.sfc.script.content.length, codeFeatures.all);
88+
yield* generateScriptSectionPartiallyEnding(options.sfc.script.name, options.sfc.script.content.length, '#3632/both.vue');
8289
yield* generateScriptSetup(options, ctx, options.sfc.scriptSetup, options.scriptSetupRanges);
8390
}
8491
}
@@ -117,7 +124,7 @@ export function* generateScript(options: ScriptCodegenOptions): Generator<Code,
117124
yield `__VLS_template = () => {${newLine}`;
118125
const templateCodegenCtx = yield* generateTemplate(options, ctx);
119126
yield* generateComponentSelf(options, ctx, templateCodegenCtx);
120-
yield `},${newLine}`;
127+
yield `}${endOfLine}`;
121128
yield generateSfcBlockSection(options.sfc.script, classBlockEnd, options.sfc.script.content.length, codeFeatures.all);
122129
}
123130
}
@@ -131,12 +138,12 @@ export function* generateScript(options: ScriptCodegenOptions): Generator<Code,
131138
yield* generateScriptSetup(options, ctx, options.sfc.scriptSetup, options.scriptSetupRanges);
132139
}
133140

134-
yield `;`;
141+
if (options.sfc.script) {
142+
yield* generateScriptSectionPartiallyEnding(options.sfc.script.name, options.sfc.script.content.length, '#3632/script.vue');
143+
}
135144
if (options.sfc.scriptSetup) {
136-
// #4569
137-
yield ['', 'scriptSetup', options.sfc.scriptSetup.content.length, codeFeatures.verification];
145+
yield* generateScriptSectionPartiallyEnding(options.sfc.scriptSetup.name, options.sfc.scriptSetup.content.length, '#4569/main.vue');
138146
}
139-
yield newLine;
140147

141148
if (!ctx.generatedTemplate) {
142149
yield `function __VLS_template() {${newLine}`;
@@ -163,6 +170,12 @@ export function* generateScript(options: ScriptCodegenOptions): Generator<Code,
163170
return ctx;
164171
}
165172

173+
export function* generateScriptSectionPartiallyEnding(source: string, end: number, mark: string): Generator<Code> {
174+
yield `;`;
175+
yield ['', source, end, codeFeatures.verification];
176+
yield `/* PartiallyEnd: ${mark} */${newLine}`;
177+
}
178+
166179
function* generateDefineProp(
167180
options: ScriptCodegenOptions,
168181
scriptSetup: NonNullable<Sfc['scriptSetup']>

0 commit comments

Comments
 (0)