我正在使用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二进制文件提供的代码linting。简而言之,您可以使用这些指令配置的功能:
// 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();