Skip to content

Commit 92bac84

Browse files
committed
handle $inspect(...).with(...) special case
1 parent ff4258c commit 92bac84

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

sites/svelte-5-preview/src/lib/autocomplete.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,28 @@ export function autocomplete(context) {
135135
}
136136

137137
if (node.name === 'VariableName' || node.name === 'PropertyName' || node.name === '.') {
138+
// special case — `$inspect(...).with(...)` is the only rune that 'returns'
139+
// an 'object' with a 'method'
140+
if (node.name === 'PropertyName' || node.name === '.') {
141+
if (
142+
node.parent?.name === 'MemberExpression' &&
143+
node.parent.firstChild?.name === 'CallExpression' &&
144+
node.parent.firstChild.firstChild?.name === 'VariableName' &&
145+
context.state.sliceDoc(
146+
node.parent.firstChild.firstChild.from,
147+
node.parent.firstChild.firstChild.to
148+
) === '$inspect'
149+
) {
150+
const open = context.matchBefore(/\.\w*/);
151+
if (!open) return null;
152+
153+
return {
154+
from: open.from,
155+
options: [snippetCompletion('.with(${})', { type: 'keyword', label: '.with' })]
156+
};
157+
}
158+
}
159+
138160
const open = context.matchBefore(/\$[\w\.]*/);
139161
if (!open) return null;
140162

0 commit comments

Comments
 (0)