Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(language-core): inlay hints for <component :is> and <slot :name> #4661

Merged
merged 12 commits into from
Oct 23, 2024
Prev Previous commit
Next Next commit
combine vBindShorthand.ts and types.ts
  • Loading branch information
johnsoncodehk committed Oct 22, 2024
commit 1e84ae7125236d81f9469d7622b78d4378b5fbfc
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
import type * as CompilerDOM from '@vue/compiler-dom';
import type { InlayHintInfo } from "../types";

export function generateVBindShorthandInlayHint(loc: CompilerDOM.SourceLocation, variableName: string): InlayHintInfo {
export interface InlayHintInfo {
blockName: string;
offset: number;
setting: string;
label: string;
tooltip?: string;
paddingRight?: boolean;
paddingLeft?: boolean;
}

export function createVBindShorthandInlayHintInfo(loc: CompilerDOM.SourceLocation, variableName: string): InlayHintInfo {
return {
blockName: 'template',
offset: loc.end.offset,
Expand All @@ -13,4 +22,4 @@ export function generateVBindShorthandInlayHint(loc: CompilerDOM.SourceLocation,
'[More info](https://github.com/vuejs/core/pull/9451)',
].join('\n\n'),
};
};
}
2 changes: 1 addition & 1 deletion packages/language-core/lib/codegen/script/context.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { InlayHintInfo } from '../types';
import { InlayHintInfo } from '../inlayHints';
import { getLocalTypesGenerator } from '../localTypes';
import type { ScriptCodegenOptions } from './index';

Expand Down
2 changes: 1 addition & 1 deletion packages/language-core/lib/codegen/template/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type * as CompilerDOM from '@vue/compiler-dom';
import type { Code, VueCodeInformation } from '../../types';
import { endOfLine, newLine, wrapWith } from '../common';
import type { TemplateCodegenOptions } from './index';
import { InlayHintInfo } from '../types';
import { InlayHintInfo } from '../inlayHints';

const _codeFeatures = {
all: {
Expand Down
4 changes: 2 additions & 2 deletions packages/language-core/lib/codegen/template/element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { generateInterpolation } from './interpolation';
import { generatePropertyAccess } from './propertyAccess';
import { generateTemplateChild } from './templateChild';
import { generateObjectProperty } from './objectProperty';
import { generateVBindShorthandInlayHint } from './vBindShorthand';
import { createVBindShorthandInlayHintInfo } from '../inlayHints';
import { getNodeText } from '../../parsers/scriptSetupRanges';

const colonReg = /:/g;
Expand Down Expand Up @@ -115,7 +115,7 @@ export function* generateComponent(
}
else if (dynamicTagInfo) {
if (dynamicTagInfo.isComponentIsShorthand) {
ctx.inlayHints.push(generateVBindShorthandInlayHint(dynamicTagInfo.exp.loc, 'is'));
ctx.inlayHints.push(createVBindShorthandInlayHintInfo(dynamicTagInfo.exp.loc, 'is'));
}
yield `const ${var_originalComponent} = (`;
yield* generateInterpolation(
Expand Down
4 changes: 2 additions & 2 deletions packages/language-core/lib/codegen/template/elementProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { generateEventArg, generateEventExpression } from './elementEvents';
import type { TemplateCodegenOptions } from './index';
import { generateInterpolation } from './interpolation';
import { generateObjectProperty } from './objectProperty';
import { generateVBindShorthandInlayHint } from './vBindShorthand';
import { createVBindShorthandInlayHintInfo } from '../inlayHints';

export function* generateElementProps(
options: TemplateCodegenOptions,
Expand Down Expand Up @@ -335,7 +335,7 @@ function* generatePropExp(
features
);
if (enableCodeFeatures) {
ctx.inlayHints.push(generateVBindShorthandInlayHint(prop.loc, propVariableName));
ctx.inlayHints.push(createVBindShorthandInlayHintInfo(prop.loc, propVariableName));
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/language-core/lib/codegen/template/slotOutlet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { generateElementChildren } from './elementChildren';
import { generateElementProps } from './elementProps';
import type { TemplateCodegenOptions } from './index';
import { generateInterpolation } from './interpolation';
import { generateVBindShorthandInlayHint } from './vBindShorthand';
import { createVBindShorthandInlayHintInfo } from '../inlayHints';

export function* generateSlotOutlet(
options: TemplateCodegenOptions,
Expand Down Expand Up @@ -83,7 +83,7 @@ export function* generateSlotOutlet(
) {
const isShortHand = nameProp.arg?.loc.start.offset === nameProp.exp.loc.start.offset;
if (isShortHand) {
ctx.inlayHints.push(generateVBindShorthandInlayHint(nameProp.exp.loc, 'name'));
ctx.inlayHints.push(createVBindShorthandInlayHintInfo(nameProp.exp.loc, 'name'));
}
const slotExpVar = ctx.getInternalVariable();
yield `var ${slotExpVar} = `;
Expand Down
9 changes: 0 additions & 9 deletions packages/language-core/lib/codegen/types.ts

This file was deleted.