Skip to content

Conversation

@N1ebieski
Copy link
Contributor

@N1ebieski N1ebieski commented Mar 17, 2025

Fixes #291, #474

This PR adds autocompletion rules names in FormRequest::rules method. It works for Livewire Forms as well.

rules

This PR depends on laravel/vs-code-php-parser-cli#16 and requires much more testing.

public fillingInArrayKey(): boolean {
if (this.result.type === "array") {
return (
this.result.parent?.type !== "array_item" &&
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@N1ebieski thanks! This looks good to go.

Before we merge, could you share a quick example of when this check is needed?

this.result.parent?.type !== "array_item"

Copy link
Contributor Author

@N1ebieski N1ebieski Dec 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TitasGailius this is necessary because if you start writing a rule for a field name, for example:

public function rules(): array
    {
        return [
            'id' => ['
        ];
    }

then inside fillingInArrayKey you will get:

obraz

As you see the result.parent.type is array_item. This is how we recognize that a user is trying to write a rule name. If you remove this condition, then this condition will evaluate to true.

For comparison, here is the scenario when a user starts writing a field name:

public function rules(): array
    {
        return [
            '
        ];
    }
obraz

As you see, result.parent.type is methodCall, so the extension knows that this is not a place for a rule name.

@TitasGailius TitasGailius merged commit ba2377b into laravel:main Dec 30, 2025
1 check passed
@TitasGailius
Copy link
Collaborator

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Auto-completion of rules in form request

2 participants