Skip to content

Commit

Permalink
perf: find destructured props only with enabled setting
Browse files Browse the repository at this point in the history
  • Loading branch information
KazariEX committed Sep 5, 2024
1 parent 1dafe62 commit fa6f059
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
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

0 comments on commit fa6f059

Please sign in to comment.