|
1 | 1 | import { snippetCompletion } from '@codemirror/autocomplete';
|
2 | 2 | import { syntaxTree } from '@codemirror/language';
|
3 | 3 |
|
4 |
| -/** @typedef {(node: import('@lezer/common').SyntaxNode, context: import('@codemirror/autocomplete').CompletionContext) => boolean} Test */ |
| 4 | +/** @typedef {(node: import('@lezer/common').SyntaxNode, context: import('@codemirror/autocomplete').CompletionContext, selected: import('./types').File) => boolean} Test */ |
5 | 5 |
|
6 | 6 | /**
|
7 | 7 | * Returns `true` if `$bindable()` is valid
|
@@ -39,8 +39,14 @@ function is_bindable(node, context) {
|
39 | 39 | * TODO only allow in `.svelte` files, and only at the top level
|
40 | 40 | * @type {Test}
|
41 | 41 | */
|
42 |
| -function is_props(node) { |
43 |
| - return node.name === 'VariableName' && node.parent?.name === 'VariableDeclaration'; |
| 42 | +function is_props(node, _, selected) { |
| 43 | + if (selected.type !== 'svelte') return false; |
| 44 | + |
| 45 | + return ( |
| 46 | + node.name === 'VariableName' && |
| 47 | + node.parent?.name === 'VariableDeclaration' && |
| 48 | + node.parent.parent?.name === 'Script' |
| 49 | + ); |
44 | 50 | }
|
45 | 51 |
|
46 | 52 | /**
|
@@ -188,7 +194,7 @@ export function autocomplete(context, selected, files) {
|
188 | 194 | return {
|
189 | 195 | from: open.from,
|
190 | 196 | options: options
|
191 |
| - .filter((option) => (option.test ? option.test(node, context) : true)) |
| 197 | + .filter((option) => (option.test ? option.test(node, context, selected) : true)) |
192 | 198 | .map((option) => option.option)
|
193 | 199 | };
|
194 | 200 | }
|
|
0 commit comments