Visual Studio Code 中的 PHP 智能感知 [英] PHP Intellisense in Visual Studio Code

查看:39
本文介绍了Visual Studio Code 中的 PHP 智能感知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Visual Studio Code 在 PHP 中进行开发,但在获取代码以提供正确的智能感知结果时遇到了一些麻烦.例如,这个新创建的 Codeception 单元测试:

I'm using Visual Studio Code to develop in PHP, and I've been having some trouble getting Code to provide the proper intellisense results. For example, this newly created Codeception unit test:

<?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-> 时,我希望看到 assertFalseassertTrue 以及 提供的所有其他方法\Codeception\Test\Unit.但我得到的基本上是当前文件中存在的任何项目,仅此而已.

When I type $this-> I expect to see assertFalse, assertTrue, and all the other methods provided by \Codeception\Test\Unit. But what I get is basically whatever items exist within the current file and that's it.

我该怎么做才能让 Unit 类中的所有方法都显示出来?我已经安装了 PHP IntelliSense 扩展程序 v2.3.4.

What can I do to get all the methods from the Unit class to show up? I already have the PHP IntelliSense extension installed, v2.3.4.

推荐答案

Visual Studio Code 核心不包括高级 PHP 功能,只有 PHP 二进制文件提供的语法突出显示、简单代码完成和代码 linting,只要您安装了它.简而言之,您可以使用这些指令配置的功能:

Visual Studio Code core does not include advanced PHP features, just syntax highlighting, simple code completion and code linting provided by the PHP binary as long as you have it installed. In short, the features you can configure with these directives:

// 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"

对于其他任何事情,您都需要安装第三方扩展程序.

For anything else you need to install a third-party extension.

我个人的选择是 PHP Intelephense.特别是,它支持 docblock 注释,包括魔法属性:

My personal choice is PHP Intelephense. In particular, it supports docblock annotations, including magic properties:

/**
 * @property string $foo
 */
class Bar
{
}

... 和内联类型:

/** @var \Database $db */
$db->connect();

这篇关于Visual Studio Code 中的 PHP 智能感知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆