Skip to content

perf(language-service): find destructured props only with enabled setting #4815

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

Merged
merged 1 commit into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
perf: find destructured props only with enabled setting
  • Loading branch information
KazariEX committed Sep 5, 2024
commit fa6f0597f3fe9101367b06f301397a6cc9c39efd
2 changes: 1 addition & 1 deletion extensions/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@
"vue.inlayHints.destructuredProps": {
"type": "boolean",
"default": false,
"description": "Show inlay hints for destructured prop."
"description": "Show inlay hints for destructured props."
},
"vue.inlayHints.missingProps": {
"type": "boolean",
Expand Down
27 changes: 16 additions & 11 deletions packages/language-service/lib/plugins/vue-inlayhints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,22 @@ export function create(ts: typeof import('typescript')): LanguageServicePlugin {
const scriptSetupRanges = codegen?.scriptSetupRanges();

if (scriptSetupRanges?.props.destructured && virtualCode.sfc.scriptSetup?.ast) {
for (const [prop, isShorthand] of findDestructuredProps(ts, virtualCode.sfc.scriptSetup.ast, scriptSetupRanges.props.destructured)) {
const name = prop.text;
const end = prop.getEnd();
const pos = isShorthand ? end : end - name.length;
const label = isShorthand ? `: props.${name}` : 'props.';
inlayHints.push({
blockName: 'scriptSetup',
offset: pos,
setting: 'vue.inlayHints.destructuredProps',
label,
});
const setting = 'vue.inlayHints.destructuredProps';
settings[setting] ??= await context.env.getConfiguration?.<boolean>(setting) ?? false;

if (settings[setting]) {
for (const [prop, isShorthand] of findDestructuredProps(ts, virtualCode.sfc.scriptSetup.ast, scriptSetupRanges.props.destructured)) {
const name = prop.text;
const end = prop.getEnd();
const pos = isShorthand ? end : end - name.length;
const label = isShorthand ? `: props.${name}` : 'props.';
inlayHints.push({
blockName: 'scriptSetup',
offset: pos,
setting,
label,
});
}
}
}

Expand Down