gpt4 book ai didi

How to fix code completion using DocBlock type hints with Intelephense?(如何将DocBlock类型的提示与Intelhense结合使用来修复代码完成?)

转载 作者:bug小助手 更新时间:2023-10-28 21:03:32 31 4
gpt4 key购买 nike



I'm trying to get better completion with the VSCode extension Intelephense and some things aren't making sense. To start here is some example code:

我试图用VSCode扩展Intelephense更好地完成,有些事情没有意义。下面是一些示例代码:


<?php
declare(strict_types=1);

// "square/square": "30.0.0.20230816"
use Square\SquareClient;
use Square\Models\CatalogObject;
use Square\Models\CatalogItem;

require 'vendor/autoload.php';

$client = new SquareClient([
'accessToken' => $_ENV['SQUARE_ACCESS_TOKEN'],
'environment' => 'sandbox'
]);

$res = $client->getCatalogApi()->listCatalog();

/* @var CatalogObject[] $catalog */
$catalog = $res->getResult()->getObjects();

if ($catalog) {

/* @var CatalogObject $item */
foreach ($catalog as $item) {

/* @var CatalogItem $data */
$data = $item->getItemData();

}
}


I get completion on $client->getCatalogApi() after scrolling past all global symbols & methods. I'd love to remove them because $client->$_COOKIE just doesn't seem helpful.

在滚动浏览所有全局符号和方法之后,我在$Client->getCatalogApi()上得到了完成。我很想删除它们,因为$CLIENT->$_COOKIE似乎没有什么帮助。


Second and more importantly I get why the type can't be determined for $catalog, $item and $data but it appears like hinting as I've done with @var <Type> $variable is supported by Intelephense but it's having no affect with Intelephense 1.9.5 (I've re-indexed). What I'm expecting is if I type for example $data->getItem one of the choices will be $data->getItemData(). Thank you!

其次,也是更重要的是,我知道为什么不能确定$CATALOG、$ITEM和$DATA的类型,但它看起来像是在暗示,就像我在@var $Variable时所做的那样,Intelhense支持$Variable,但它对Intelhense 1.9.5没有影响(我已经重新编制了索引)。例如,如果我输入$data->getItem,其中一个选项将是$data->getItemData()。谢谢!


VSCode 1.81.1.

Intelephense 1.9.5 (paid).

PHP 8.2.

VSCode 1.81.1。Intelhense 1.9.5(付费)。PHP 8.2.


更多回答
优秀答案推荐

So the answer to this question for me was a result of two issues. The first was code completion being "polluted" with a ton of items from the global namespace so even in situations where the completion had the right answer I had to scroll past all the globals to get to it. Here's an example:

所以对我来说,这个问题的答案是两个问题的结果。第一个问题是代码补全被来自全局命名空间的大量项“污染”,因此即使在补全有正确答案的情况下,我也必须滚动所有全局变量才能找到它。下面是一个例子:


example of code completion returning global items


To get rid of the globals you just have to disable VSCodes built-in PHP support:

要去除全局变量,您只需禁用VSCodes内置的PHP支持:



To disable the built-in PHP smart completions in favor of suggestions
from an installed PHP extension, uncheck PHP > Suggest: Basic, which
sets php.suggest.basic to false in your settings.json file.



The other issue I was bumping into is PHP Intelephense does not appear to support PHPDoc type hints (v1.9.5). To fix this I just installed the PHPActor LSP along with the VSCode extension which does understand the type hints.

我遇到的另一个问题是,PHP Intelhense似乎不支持PHPDoc类型提示(v1.9.5)。为了解决这个问题,我只安装了PHPActor LSP和VSCode扩展,它可以理解类型提示。


更多回答

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com