Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Variable and MethodCall with chain for autocompletion #17

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

N1ebieski
Copy link

This PR adds support for VariableParser and MethodCall with chain for autocomplete.

Example with VariableParser:

Before:

php-parser autocomplete "<div>{{ \$user->" --debug
[]

After:

php-parser autocomplete "<div>{{ \$user->" --debug
================================================================================
================================================================================
                              STARTING TO PARSE
================================================================================
================================================================================

Microsoft\PhpParser\Node\SourceFileNode <div>{{ $user->
+ Context: App\Contexts\Base
* Parsing: App\Parsers\SourceFileNodeParser

 Microsoft\PhpParser\Node\Statement\InlineHtml <div>{{ $user->
 + Context: App\Contexts\Base
 * Parsing: App\Parsers\InlineHtmlParser


================================================================================
================================================================================
                              STARTING TO PARSE
================================================================================
================================================================================

Microsoft\PhpParser\Node\SourceFileNode <?php $user->;
+ Context: App\Contexts\Base
* Parsing: App\Parsers\SourceFileNodeParser

 Microsoft\PhpParser\Node\Statement\InlineHtml <?php 
 + Context: App\Contexts\Base
 * Parsing: App\Parsers\InlineHtmlParser

 Microsoft\PhpParser\Node\Statement\ExpressionStatement $user->;
 + Context: App\Contexts\Base
 * Parsing: App\Parsers\ExpressionStatementParser

  Microsoft\PhpParser\Node\Expression\MemberAccessExpression $user->
  + Context: App\Contexts\MethodCall
  * Parsing: App\Parsers\MemberAccessExpressionParser

   Microsoft\PhpParser\Node\Expression\Variable $user
   + Context: App\Contexts\Variable
   * Parsing: App\Parsers\VariableParser

{
    "type": "variable",
    "autocompleting": true,
    "name": "user",
    "parent": {
        "type": "methodCall",
        "methodName": "",
        "className": null,
        "arguments": {
            "type": "arguments",
            "autocompletingIndex": 0,
            "children": []
        },
        "parent": {
            "type": "base",
            "parent": null
        }
    }
}

Example with MethodCall with chain:

Before:

php-parser autocomplete "<div>{{ \$user->post->" --debug
[]

After:

php-parser autocomplete "<div>{{ \$user->post->" --debug
================================================================================
================================================================================
                              STARTING TO PARSE
================================================================================
================================================================================

Microsoft\PhpParser\Node\SourceFileNode <div>{{ $user->post->
+ Context: App\Contexts\Base
* Parsing: App\Parsers\SourceFileNodeParser

 Microsoft\PhpParser\Node\Statement\InlineHtml <div>{{ $user->post->
 + Context: App\Contexts\Base
 * Parsing: App\Parsers\InlineHtmlParser


================================================================================
================================================================================
                              STARTING TO PARSE
================================================================================
================================================================================

Microsoft\PhpParser\Node\SourceFileNode <?php $user->post->;
+ Context: App\Contexts\Base
* Parsing: App\Parsers\SourceFileNodeParser

 Microsoft\PhpParser\Node\Statement\InlineHtml <?php 
 + Context: App\Contexts\Base
 * Parsing: App\Parsers\InlineHtmlParser

 Microsoft\PhpParser\Node\Statement\ExpressionStatement $user->post->;
 + Context: App\Contexts\Base
 * Parsing: App\Parsers\ExpressionStatementParser

  Microsoft\PhpParser\Node\Expression\MemberAccessExpression $user->post->
  + Context: App\Contexts\MethodCall
  * Parsing: App\Parsers\MemberAccessExpressionParser

   Microsoft\PhpParser\Node\Expression\MemberAccessExpression $user->post
   + Context: App\Contexts\MethodCall
   * Parsing: App\Parsers\MemberAccessExpressionParser

    Microsoft\PhpParser\Node\Expression\Variable $user
    + Context: App\Contexts\Variable
    * Parsing: App\Parsers\VariableParser

{
    "type": "methodCall",
    "autocompleting": true,
    "methodName": "post",
    "className": null,
    "arguments": {
        "type": "arguments",
        "autocompletingIndex": 0,
        "children": []
    },
    "parent": {
        "type": "methodCall",
        "methodName": "",
        "className": null,
        "arguments": {
            "type": "arguments",
            "autocompletingIndex": 0,
            "children": []
        },
        "parent": {
            "type": "base",
            "parent": null
        }
    }
}

Should not interfere with other autocompletions. For example:

php-parser autocomplete "<?php

use Illuminate\Support\Facades\Validator;

Validator::validate(\$attributes, ['name' => '" --debug

================================================================================
================================================================================
                              STARTING TO PARSE
================================================================================
================================================================================

Microsoft\PhpParser\Node\SourceFileNode <?php use Illuminate\Support\Facades\Validator; Va
+ Context: App\Contexts\Base
* Parsing: App\Parsers\SourceFileNodeParser

 Microsoft\PhpParser\Node\Statement\InlineHtml <?php 
 + Context: App\Contexts\Base
 * Parsing: App\Parsers\InlineHtmlParser

 Microsoft\PhpParser\Node\Statement\NamespaceUseDeclaration use Illuminate\Support\Facades\Validator;
  Microsoft\PhpParser\Node\DelimitedList\NamespaceUseClauseList Illuminate\Support\Facades\Validator
   Microsoft\PhpParser\Node\NamespaceUseClause Illuminate\Support\Facades\Validator
    Microsoft\PhpParser\Node\QualifiedName Illuminate\Support\Facades\Validator
 Microsoft\PhpParser\Node\Statement\ExpressionStatement Validator::validate($attributes, ['name' =>
 + Context: App\Contexts\Base
 * Parsing: App\Parsers\ExpressionStatementParser

  Microsoft\PhpParser\Node\Expression\CallExpression Validator::validate($attributes, ['name' =>
  + Context: App\Contexts\MethodCall
  * Parsing: App\Parsers\CallExpressionParser

   Microsoft\PhpParser\Node\Expression\ScopedPropertyAccessExpression Validator::validate
   + Context: App\Contexts\MethodCall
   * Parsing: App\Parsers\ScopedPropertyAccessExpressionParser

    Microsoft\PhpParser\Node\QualifiedName Validator
   Microsoft\PhpParser\Node\DelimitedList\ArgumentExpressionList $attributes, ['name' =>
   + Context: App\Contexts\MethodCall
   * Parsing: App\Parsers\ArgumentExpressionListParser

    Microsoft\PhpParser\Node\Expression\ArgumentExpression $attributes
    + Context: App\Contexts\Argument
    * Parsing: App\Parsers\ArgumentExpressionParser

     Microsoft\PhpParser\Node\Expression\Variable $attributes
     + Context: App\Contexts\Variable
     * Parsing: App\Parsers\VariableParser

    Microsoft\PhpParser\Node\Expression\ArgumentExpression ['name' =>
    + Context: App\Contexts\Argument
    * Parsing: App\Parsers\ArgumentExpressionParser

     Microsoft\PhpParser\Node\Expression\ArrayCreationExpression ['name' =>
     + Context: App\Contexts\ArrayValue
     * Parsing: App\Parsers\ArrayCreationExpressionParser

      Microsoft\PhpParser\Node\DelimitedList\ArrayElementList 'name' =>
       Microsoft\PhpParser\Node\ArrayElement 'name' =>
       + Context: App\Contexts\ArrayItem
       * Parsing: App\Parsers\ArrayElementParser

        Microsoft\PhpParser\Node\StringLiteral 'name'
        + Context: App\Contexts\StringValue
        * Parsing: App\Parsers\StringLiteralParser

{
    "type": "methodCall",
    "autocompleting": true,
    "methodName": "validate",
    "className": "Illuminate\\Support\\Facades\\Validator",
    "arguments": {
        "type": "arguments",
        "autocompletingIndex": 1,
        "children": [
            {
                "type": "argument",
                "name": null,
                "children": [
                    {
                        "type": "variable",
                        "name": "attributes"
                    }
                ]
            },
            {
                "type": "argument",
                "name": null,
                "children": [
                    {
                        "type": "array",
                        "autocompleting": true,
                        "children": [
                            {
                                "type": "array_item",
                                "key": {
                                    "type": "string",
                                    "value": "name"
                                },
                                "value": null,
                                "autocompletingValue": true
                            }
                        ],
                        "autocompletingKey": false,
                        "autocompletingValue": true
                    }
                ]
            }
        ]
    },
    "parent": {
        "type": "base",
        "parent": null
    }
}

This PR depends on #14 and #12

@N1ebieski N1ebieski changed the title Support for Variable and MethodCall with chain for autocomplete Support for Variable and MethodCall with chain for autocompletion Mar 30, 2025
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.

1 participant