Skip to content
This repository was archived by the owner on Nov 9, 2026. It is now read-only.

Support for Variable and MethodCall with chain for autocompletion - #17

Closed
N1ebieski wants to merge 10 commits into
laravel:mainfrom
N1ebieski:Support-for-VariableParser-for-autocomplete-#8
Closed

N1ebieski wants to merge 10 commits into
laravel:mainfrom
N1ebieski:Support-for-VariableParser-for-autocomplete-#8

Conversation

@N1ebieski

Copy link
Copy Markdown
Contributor

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
@joetannenbaum

Copy link
Copy Markdown
Collaborator

Thank you for this PR! I apologize it took us so long to respond.

I'm closing this out as the VS Code extension no longer uses this package, it now uses https://github.com/laravel/lsp.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants