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

feat: Code completion #1113

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .phpstorm.meta.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
declare(strict_types=1);

// see https://www.jetbrains.com/help/phpstorm/ide-advanced-metadata.html
namespace PHPSTORM_META {

override(\Github\Client::api(0), map([
$METHODS$
]));
}
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ composer require knplabs/github-api:^3.0 guzzlehttp/guzzle:^7.0.1 http-interop/h

## Advanced install

We are decoupled from any HTTP messaging client with help by [HTTPlug](https://httplug.io).
We are decoupled from any HTTP messaging client with help by [HTTPlug](https://httplug.io).

### Using a different http client

Expand All @@ -53,6 +53,14 @@ $client = Client::createWithHttpClient(new HttplugClient());

Read more about [using different clients in our docs](doc/customize.md).

## Code Completion (JetBrains PhpStorm)
To improve code-completion and ux approach in PhpStorm, advanced metadata is now added.

![Auto-Complete Api Names](https://user-images.githubusercontent.com/1327607/229752632-f1e4a1b3-a9f8-48be-9beb-d41927e96cde.png)

![Auto-Complete Api Methods](https://user-images.githubusercontent.com/1327607/229752677-3a2f3dc8-51d7-45b7-a7d0-0cde7ac145f7.png)


## Framework integrations

### Laravel
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
"phpstan/extension-installer": "^1.0.5",
"phpstan/phpstan-deprecation-rules": "^0.12.5",
"phpunit/phpunit": "^8.5 || ^9.4",
"symfony/phpunit-bridge": "^5.2"
"symfony/phpunit-bridge": "^5.2",
"phpstan/phpdoc-parser": "^1.27"
},
"autoload": {
"psr-4": { "Github\\": "lib/Github/" }
Expand Down
28 changes: 28 additions & 0 deletions generate-phpstorm-meta-file.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

use PHPStan\PhpDocParser\Lexer\Lexer;
use PHPStan\PhpDocParser\Parser\ConstExprParser;
use PHPStan\PhpDocParser\Parser\PhpDocParser;
use PHPStan\PhpDocParser\Parser\TokenIterator;
use PHPStan\PhpDocParser\Parser\TypeParser;

require 'vendor/autoload.php';

$reflection = new ReflectionClass(\Github\Client::class);

$lexer = new Lexer();
$constExprParser = new ConstExprParser();
$typeParser = new TypeParser($constExprParser);
$phpDocParser = new PhpDocParser($typeParser, $constExprParser);

$tokens = new TokenIterator($lexer->tokenize($reflection->getDocComment()));
$phpDocNode = $phpDocParser->parse($tokens);

$replacements = '';
foreach ($phpDocNode->getTagsByName('@method') as $node) {
$replacements .= "\"{$node->value->methodName}\" => \Github\\{$node->value->returnType->name}::class,".PHP_EOL;
}

$str = file_get_contents('./.phpstorm.meta.stub');
$str = str_replace('$METHODS$', $replacements, $str);
file_put_contents('.phpstorm.meta.php', $str);