Skip to content

Commit 777de78

Browse files
authored
fix: fix autocomplete for $props.id() (#1307)
* update autocomplete stuff to current svelte 5 * update autocomplete * lint * fix autocomplete for `$props.id()` * lint * add file type check * fix file check, the types were a lie
1 parent d3ff314 commit 777de78

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

packages/site-kit/src/lib/codemirror/autocompletionDataProvider.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -576,18 +576,28 @@ const is_bindable = (node, context) => {
576576
/**
577577
* @type {import("./types").Test}
578578
*/
579-
const is_props_id = (node) => {
580-
if (node.parent?.name !== 'VariableDeclaration') return false;
581-
if (node.parent?.parent?.name !== 'VariableDeclarator') return false;
582-
if (node.parent?.parent?.parent?.name !== 'Program') return false;
583-
if (node.parent?.firstChild?.name !== 'Identifier') return false;
579+
const is_props_id_call = (node, context, selected) => {
580+
if (!selected.match(/\.svelte$/)) return false;
581+
if (!is_state_call(node, context, selected)) return false;
582+
if (node.parent?.parent?.name !== 'Script') return false;
583+
return true;
584+
};
585+
586+
/**
587+
* @type {import("./types").Test}
588+
*/
589+
const is_props_id = (node, context, selected) => {
590+
if (!selected.match(/\.svelte$/)) return false;
591+
if (!is_state(node, context, selected)) return false;
592+
if (node.parent?.parent?.name !== 'Script') return false;
584593
return true;
585594
};
586595

587596
export const runes = [
588597
{ snippet: '$state(${})', test: is_state },
589598
{ snippet: '$state', test: is_state_call },
590599
{ snippet: '$props()', test: is_props },
600+
{ snippet: '$props.id', test: is_props_id_call },
591601
{ snippet: '$props.id()', test: is_props_id },
592602
{ snippet: '$derived(${});', test: is_state },
593603
{ snippet: '$derived', test: is_state_call },

0 commit comments

Comments
 (0)