Complete hashes in named arguments and lists, and the variants of cva()
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 55/100
- Issue type
- Feature
- Clarity
- Clearly specified
- Activity status
- Active
- Domain
- developer-experience, tooling
Research direction
Start by reading the implementation and tests for issue #108, which handles completion from a Twig function parameter's array shape. Trace how PHP parameter types and @psalm-type or @phpstan-type aliases are resolved, then follow the completion path for hash and sequence literals. Add coverage for named arguments, collection value types, and cva() variant suggestions; done means the listed completion cases work for general functions and the cva() variants.
Written by the indexing model from the issue text.
Description
Hi 👋🏻
This follows #108, which completes the hash of a Twig function argument from the array shape of its PHP parameter. symfony/ux-css now has a cva() Twig function (symfony/ux#4243) that needs a bit more: like html_cva() of twig/html-extra, it takes four named arguments.
Here is its PHP method:
/**
* @param CssStyles $base
* @param array<string, array<array-key, CssStyles>> $variants
* @param list<array{css?: CssStyles}> $compoundVariants
* @param array<string, string|int|float|bool> $defaultVariants
*/
public function cva(array $base = [], array $variants = [], array $compoundVariants = [], array $defaultVariants = []): Cva
And here is how it is used in Twig:
{% set button = cva(
base: { display: 'inline-flex', rounded: 'md' },
variants: {
variant: {
primary: { bg: 'blue.600', color: 'white' },
ghost: { bg: 'transparent', _hover: { bg: 'gray.100' } },
},
size: {
sm: { h: '8', px: '3' },
lg: { h: '12', px: '6' },
},
},
compoundVariants: [
{ variant: 'ghost', size: 'sm', css: { px: '2' } },
],
defaultVariants: { variant: 'primary', size: 'sm' },
) %}
These are the completions I would expect (▌ is the cursor):
| Cursor | Expected items |
|---|---|
base: { ▌ } |
CSS properties: display, alignItems... |
base: { color: '▌' } |
color tokens: blue.600, gray.700... |
variants: { variant: { primary: { ▌ } } } |
CSS properties |
compoundVariants: [{ ▌ }] |
variant, size, css |
compoundVariants: [{ variant: '▌' }] |
primary, ghost |
compoundVariants: [{ variant: ['▌'] }] |
primary, ghost |
compoundVariants: [{ css: { ▌ } }] |
CSS properties |
defaultVariants: { ▌ } |
variant, size |
defaultVariants: { size: '▌' } |
sm, lg |
This needs four rules:
- A hash passed as a named argument,
fn(name: { ... }), completes from the type of the PHP parameter of that name. - Collection types
array<K, V>,list<V>andV[]are followed to their value type, also through@psalm-typeand@phpstan-typealiases. - In a sequence literal
[{ ... }], each item completes from the value type of the list. - When the PHP callable has
variants,compoundVariantsanddefaultVariantsparameters (ordefaultVariant, forhtml_cva()), the default variants and each compound variant also complete the variant names and the values declared in thevariantsargument of the same call.
Rules 1 to 3 apply to every Twig function, only rule 4 is specific to cva().
The PhpStorm plugin does the same in Haehnchen/idea-php-symfony2-plugin#2910.
Thanks!
- Dominant language
- PHP
- Stars
- 171
- Forks
- 5
- PR merge metrics
- No merged PRs in 30d
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from symfony/language-tools
-
Difficulty 4/5 3-5 days Newbie friendliness 42/100
symfony/language-tools#132 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 42/100
symfony/language-tools#131 ·
All issues in symfony/language-tools
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 65/100
mailcow/mailcow-dockerized#7668 · 5 comments · 2 reactions ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 5 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
Icinga/icinga-notifications-web#653 ·
Maintainers usually reply within 1 day
-
Latte 3.1: "Positional argument after a named argument is deprecated" in templatesPossibly taken @sasule claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
contributte/datagrid#1337 ·
Maintainers usually reply within 4 days
-
[MCP Bundle] Importing routes with `type: mcp` fails when no MCP server is configured (client-only application)Possibly taken A pull request linked to this issue is open or already merged. OpenMCP Bundle
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day