我正在使用Visual Studio Code开发PHP,并且在获取Code来提供正确的智能感知结果时遇到了一些麻烦。例如,此新创建的Codeception单元测试:
<?php
class MyTest extends \Codeception\Test\Unit
{
/**
* @var \UnitTester
*/
protected $tester;
protected function _before()
{
}
protected function _after()
{
}
// tests
public function testSomeFeature()
{
$this->assertFalse(false);
}
}
当我键入
$this->
时,我希望看到assertFalse
,assertTrue
以及\Codeception\Test\Unit
提供的所有其他方法。但是,我得到的基本上是当前文件中存在的所有项目,仅此而已。我该怎么做才能使
Unit
类中的所有方法都显示出来?我已经安装了PHP IntelliSense扩展v2.3.4。
最佳答案
Visual Studio Code核心不包含高级PHP功能,仅安装了PHP二进制文件即可提供语法高亮显示,简单代码完成和代码lint。简而言之,可以使用以下指令配置的功能:
// Controls whether the built-in PHP language suggestions are enabled. The support suggests PHP globals and variables.
"php.suggest.basic": true,
// Enable/disable built-in PHP validation.
"php.validate.enable": true,
// Points to the PHP executable.
"php.validate.executablePath": null,
// Whether the linter is run on save or on type.
"php.validate.run": "onSave"
对于其他任何事情,您都需要安装第三方扩展。
我个人的选择是PHP Intelephense。特别是,它支持docblock注释,包括魔术属性:
/**
* @property string $foo
*/
class Bar
{
}
...和内联类型:
/** @var \Database $db */
$db->connect();
关于visual-studio-code - Visual Studio Code中的PHP Intellisense,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52013743/