PHP Visual Studio 代码中的智能感知
PHP Intellisense in Visual Studio Code
我正在使用 Visual Studio 代码在 PHP 中进行开发,但我在让代码提供正确的智能感知结果方面遇到了一些问题。例如,这个新创建的 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
class 中的所有方法?我已经安装了 PHP IntelliSense 扩展,v2.3.4。
Visual Studio Code core 不包括高级 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();
我正在使用 Visual Studio 代码在 PHP 中进行开发,但我在让代码提供正确的智能感知结果方面遇到了一些问题。例如,这个新创建的 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
class 中的所有方法?我已经安装了 PHP IntelliSense 扩展,v2.3.4。
Visual Studio Code core 不包括高级 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();